From 844ae9986a05409740b33f998ae6af5af41a3c94 Mon Sep 17 00:00:00 2001 From: nvmbrasserie Date: Wed, 20 Nov 2024 15:18:47 +0100 Subject: [PATCH 01/33] ogrn validation --- stdnum/ru/ogrn.py | 56 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 stdnum/ru/ogrn.py diff --git a/stdnum/ru/ogrn.py b/stdnum/ru/ogrn.py new file mode 100644 index 00000000..b5b0c9e6 --- /dev/null +++ b/stdnum/ru/ogrn.py @@ -0,0 +1,56 @@ +import re +from typing import Optional + +from rigour.ids.common import IdentifierFormat + +OGRN_RE = re.compile(r"\b(\d{13}|\d{15})\b") +VALID_FEDERAL_SUBJECT_CODES = set(range(1, 80)) | {83, 86, 87, 89, 91, 92, 99} + + +class OGRN(IdentifierFormat): + """Primary State Registration Number (Russian company registration).""" + + TITLE: str = "OGRN" + + # cf. https://docs.trellix.com/de-DE/bundle/data-loss-prevention-11.10.x-classification-definitions-reference-guide/page/GUID-945B4343-861E-4A57-8E60-8B6028871BA1.html + + @classmethod + def is_valid(cls, text: str) -> bool: + """Determine if the given string is a valid OGRN.""" + if OGRN_RE.match(text) is None: + return False + + # Validate registration type + if text[0] == "0": + return False + + # Validate federal subject code + federal_subject_code = int(text[3:5]) + if federal_subject_code not in VALID_FEDERAL_SUBJECT_CODES: + return False + + # Validate control digit logic + control_digit = int(text[-1]) + return control_digit == cls.calculate_control_digit(text) + + @classmethod + def normalize(cls, text: str) -> Optional[str]: + """Normalize the given string to a valid OGRN.""" + match = OGRN_RE.search(text) + if match is None: + return None + return match.group(1) + + @classmethod + def calculate_control_digit(cls, grn: str) -> Optional[int]: + if len(grn) == 13: + number = int(grn[:12]) + mod_result = number % 11 + calculated_digit = mod_result if mod_result != 10 else 0 + return calculated_digit + elif len(grn) == 15: + number = int(grn[:14]) + mod_result = number % 13 + calculated_digit = mod_result if mod_result != 10 else 0 + return calculated_digit + return None \ No newline at end of file From c9fb4a1b9489f8a6bb11e58851df90e969b9a507 Mon Sep 17 00:00:00 2001 From: nvmbrasserie Date: Wed, 20 Nov 2024 15:19:59 +0100 Subject: [PATCH 02/33] updated ogrn validation --- stdnum/ru/ogrn.py | 140 ++++++++++++++++++++++++++++++---------------- 1 file changed, 91 insertions(+), 49 deletions(-) diff --git a/stdnum/ru/ogrn.py b/stdnum/ru/ogrn.py index b5b0c9e6..83b63573 100644 --- a/stdnum/ru/ogrn.py +++ b/stdnum/ru/ogrn.py @@ -1,56 +1,98 @@ + +# ogrn.py - functions for handling Russian company registration numbers +# coding: utf-8 +# +# Copyright (C) 2024 OpenSanctions +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301 USA + +""" +ОГРН (Основной государственный регистрационный номер, Primary State Registration Number). +The OGRN is a Russian identifier for legal entities that consists of either 13 or 15 digits. +>>> OGRN.is_valid("1022200525819") +True +>>> OGRN.is_valid("1027739") # too short +False +>>> OGRN.is_valid("1022500001325") +True +>>> OGRN.is_valid("10277395526422") # 14 digits +False +""" + import re from typing import Optional -from rigour.ids.common import IdentifierFormat - +# Regular expression to match valid OGRN, which is either 13 or 15 digits. OGRN_RE = re.compile(r"\b(\d{13}|\d{15})\b") + +# Valid set of federal subject codes. VALID_FEDERAL_SUBJECT_CODES = set(range(1, 80)) | {83, 86, 87, 89, 91, 92, 99} +# cf. https://docs.trellix.com/de-DE/bundle/data-loss-prevention-11.10.x-classification-definitions-reference-guide/page/GUID-945B4343-861E-4A57-8E60-8B6028871BA1.html + + +def is_valid(text: str) -> bool: + """Determine if the given string is a valid OGRN.""" + if OGRN_RE.match(text) is None: + return False + + # # Validate registration type, ensuring the first digit is not zero. + if text[0] == "0": + return False + + # Validate the federal subject code is within the allowable range. + federal_subject_code = int(text[3:5]) + if federal_subject_code not in VALID_FEDERAL_SUBJECT_CODES: + return False + + # Validate control digit logic + control_digit = int(text[-1]) + return control_digit == calculate_control_digit(text) + + +def normalize(text: str) -> Optional[str]: + """Normalize the given string to a valid OGRN.""" + match = OGRN_RE.search(text) + if match is None: + return None + return match.group(1) + + +def calculate_control_digit(grn: str) -> Optional[int]: + """Calculate the control digit of the OGRN based on its length.""" + if len(grn) == 13: + number = int(grn[:12]) + mod_result = number % 11 + # Return the modulus result, or 0 if it results in 10. + calculated_digit = mod_result if mod_result != 10 else 0 + return calculated_digit + elif len(grn) == 15: + number = int(grn[:14]) + mod_result = number % 13 + # Return the modulus result, or 0 if it results in 10. + calculated_digit = mod_result if mod_result != 10 else 0 + return calculated_digit + return None + +def validate(text: str) -> bool: + """Check if the number is a valid OGRN.""" + normalized_text = normalize(text) + if normalized_text is None: + return False + return is_valid(normalized_text) -class OGRN(IdentifierFormat): - """Primary State Registration Number (Russian company registration).""" - - TITLE: str = "OGRN" - - # cf. https://docs.trellix.com/de-DE/bundle/data-loss-prevention-11.10.x-classification-definitions-reference-guide/page/GUID-945B4343-861E-4A57-8E60-8B6028871BA1.html - - @classmethod - def is_valid(cls, text: str) -> bool: - """Determine if the given string is a valid OGRN.""" - if OGRN_RE.match(text) is None: - return False - - # Validate registration type - if text[0] == "0": - return False - - # Validate federal subject code - federal_subject_code = int(text[3:5]) - if federal_subject_code not in VALID_FEDERAL_SUBJECT_CODES: - return False - - # Validate control digit logic - control_digit = int(text[-1]) - return control_digit == cls.calculate_control_digit(text) - - @classmethod - def normalize(cls, text: str) -> Optional[str]: - """Normalize the given string to a valid OGRN.""" - match = OGRN_RE.search(text) - if match is None: - return None - return match.group(1) - - @classmethod - def calculate_control_digit(cls, grn: str) -> Optional[int]: - if len(grn) == 13: - number = int(grn[:12]) - mod_result = number % 11 - calculated_digit = mod_result if mod_result != 10 else 0 - return calculated_digit - elif len(grn) == 15: - number = int(grn[:14]) - mod_result = number % 13 - calculated_digit = mod_result if mod_result != 10 else 0 - return calculated_digit - return None \ No newline at end of file +x = "1022200525819" +print(validate(x)) From 27c0b67ae1bc04581d8be764cf46eec71f5e0a31 Mon Sep 17 00:00:00 2001 From: nvmbrasserie Date: Wed, 20 Nov 2024 15:25:57 +0100 Subject: [PATCH 03/33] validation fixes --- stdnum/ru/ogrn.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/stdnum/ru/ogrn.py b/stdnum/ru/ogrn.py index 83b63573..af615a81 100644 --- a/stdnum/ru/ogrn.py +++ b/stdnum/ru/ogrn.py @@ -19,16 +19,17 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA # 02110-1301 USA -""" -ОГРН (Основной государственный регистрационный номер, Primary State Registration Number). +"""ОГРН (Основной государственный регистрационный номер, Primary State Registration Number). + The OGRN is a Russian identifier for legal entities that consists of either 13 or 15 digits. ->>> OGRN.is_valid("1022200525819") + +>>> validate("1022200525819") True ->>> OGRN.is_valid("1027739") # too short +>>> validate("1027739") # too short False ->>> OGRN.is_valid("1022500001325") +>>> validate("1022500001325") True ->>> OGRN.is_valid("10277395526422") # 14 digits +>>> validate("10277395526422") # 14 digits False """ @@ -94,5 +95,3 @@ def validate(text: str) -> bool: return False return is_valid(normalized_text) -x = "1022200525819" -print(validate(x)) From c63ad427cf8ebadf98a84c8eb2e71d52684cbb2d Mon Sep 17 00:00:00 2001 From: nvmbrasserie Date: Wed, 20 Nov 2024 15:41:45 +0100 Subject: [PATCH 04/33] formatted --- stdnum/ru/ogrn.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/stdnum/ru/ogrn.py b/stdnum/ru/ogrn.py index af615a81..636210c3 100644 --- a/stdnum/ru/ogrn.py +++ b/stdnum/ru/ogrn.py @@ -2,7 +2,7 @@ # ogrn.py - functions for handling Russian company registration numbers # coding: utf-8 # -# Copyright (C) 2024 OpenSanctions +# Copyright (C) 2010-2024 Arthur de Jong and others # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -23,13 +23,13 @@ The OGRN is a Russian identifier for legal entities that consists of either 13 or 15 digits. ->>> validate("1022200525819") +>>> validate('1022200525819') True ->>> validate("1027739") # too short +>>> validate('1027739') # too short False ->>> validate("1022500001325") +>>> validate('1022500001325') True ->>> validate("10277395526422") # 14 digits +>>> validate('10277395526422') # 14 digits False """ @@ -37,7 +37,7 @@ from typing import Optional # Regular expression to match valid OGRN, which is either 13 or 15 digits. -OGRN_RE = re.compile(r"\b(\d{13}|\d{15})\b") +OGRN_RE = re.compile(r'\b(\d{13}|\d{15})\b') # Valid set of federal subject codes. VALID_FEDERAL_SUBJECT_CODES = set(range(1, 80)) | {83, 86, 87, 89, 91, 92, 99} @@ -51,7 +51,7 @@ def is_valid(text: str) -> bool: return False # # Validate registration type, ensuring the first digit is not zero. - if text[0] == "0": + if text[0] == '0': return False # Validate the federal subject code is within the allowable range. @@ -64,7 +64,7 @@ def is_valid(text: str) -> bool: return control_digit == calculate_control_digit(text) -def normalize(text: str) -> Optional[str]: +def format(text: str) -> Optional[str]: """Normalize the given string to a valid OGRN.""" match = OGRN_RE.search(text) if match is None: @@ -90,7 +90,7 @@ def calculate_control_digit(grn: str) -> Optional[int]: def validate(text: str) -> bool: """Check if the number is a valid OGRN.""" - normalized_text = normalize(text) + normalized_text = format(text) if normalized_text is None: return False return is_valid(normalized_text) From d6af3fc421945b22b3ee87cf48528ca2186c3871 Mon Sep 17 00:00:00 2001 From: nvmbrasserie Date: Wed, 20 Nov 2024 16:01:42 +0100 Subject: [PATCH 05/33] more formatting --- stdnum/ru/ogrn.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/stdnum/ru/ogrn.py b/stdnum/ru/ogrn.py index 636210c3..032dfa6d 100644 --- a/stdnum/ru/ogrn.py +++ b/stdnum/ru/ogrn.py @@ -19,7 +19,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA # 02110-1301 USA -"""ОГРН (Основной государственный регистрационный номер, Primary State Registration Number). +'''ОГРН (Основной государственный регистрационный номер, Primary State Registration Number). The OGRN is a Russian identifier for legal entities that consists of either 13 or 15 digits. @@ -31,12 +31,13 @@ True >>> validate('10277395526422') # 14 digits False -""" +''' import re from typing import Optional -# Regular expression to match valid OGRN, which is either 13 or 15 digits. + + OGRN_RE = re.compile(r'\b(\d{13}|\d{15})\b') # Valid set of federal subject codes. @@ -46,7 +47,7 @@ def is_valid(text: str) -> bool: - """Determine if the given string is a valid OGRN.""" + '''Determine if the given string is a valid OGRN.''' if OGRN_RE.match(text) is None: return False @@ -65,7 +66,7 @@ def is_valid(text: str) -> bool: def format(text: str) -> Optional[str]: - """Normalize the given string to a valid OGRN.""" + '''Normalize the given string to a valid OGRN.''' match = OGRN_RE.search(text) if match is None: return None @@ -73,7 +74,7 @@ def format(text: str) -> Optional[str]: def calculate_control_digit(grn: str) -> Optional[int]: - """Calculate the control digit of the OGRN based on its length.""" + '''Calculate the control digit of the OGRN based on its length.''' if len(grn) == 13: number = int(grn[:12]) mod_result = number % 11 @@ -89,7 +90,7 @@ def calculate_control_digit(grn: str) -> Optional[int]: return None def validate(text: str) -> bool: - """Check if the number is a valid OGRN.""" + '''Check if the number is a valid OGRN.''' normalized_text = format(text) if normalized_text is None: return False From 8c03dbc47fa20753e9cef08ff7495441df6e1612 Mon Sep 17 00:00:00 2001 From: nvmbrasserie Date: Wed, 20 Nov 2024 16:05:07 +0100 Subject: [PATCH 06/33] comments removed --- stdnum/ru/ogrn.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/stdnum/ru/ogrn.py b/stdnum/ru/ogrn.py index 032dfa6d..7d125c98 100644 --- a/stdnum/ru/ogrn.py +++ b/stdnum/ru/ogrn.py @@ -50,17 +50,11 @@ def is_valid(text: str) -> bool: '''Determine if the given string is a valid OGRN.''' if OGRN_RE.match(text) is None: return False - - # # Validate registration type, ensuring the first digit is not zero. if text[0] == '0': return False - - # Validate the federal subject code is within the allowable range. federal_subject_code = int(text[3:5]) if federal_subject_code not in VALID_FEDERAL_SUBJECT_CODES: return False - - # Validate control digit logic control_digit = int(text[-1]) return control_digit == calculate_control_digit(text) @@ -78,13 +72,11 @@ def calculate_control_digit(grn: str) -> Optional[int]: if len(grn) == 13: number = int(grn[:12]) mod_result = number % 11 - # Return the modulus result, or 0 if it results in 10. calculated_digit = mod_result if mod_result != 10 else 0 return calculated_digit elif len(grn) == 15: number = int(grn[:14]) mod_result = number % 13 - # Return the modulus result, or 0 if it results in 10. calculated_digit = mod_result if mod_result != 10 else 0 return calculated_digit return None @@ -95,4 +87,3 @@ def validate(text: str) -> bool: if normalized_text is None: return False return is_valid(normalized_text) - From 1051b7d7a0498e52350e0e79497acc6879bbe6a6 Mon Sep 17 00:00:00 2001 From: nvmbrasserie Date: Wed, 20 Nov 2024 16:08:20 +0100 Subject: [PATCH 07/33] flake8 fixes --- stdnum/ru/ogrn.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/stdnum/ru/ogrn.py b/stdnum/ru/ogrn.py index 7d125c98..7d4ce947 100644 --- a/stdnum/ru/ogrn.py +++ b/stdnum/ru/ogrn.py @@ -19,7 +19,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA # 02110-1301 USA -'''ОГРН (Основной государственный регистрационный номер, Primary State Registration Number). +"""ОГРН (Основной государственный регистрационный номер, Primary State Registration Number). The OGRN is a Russian identifier for legal entities that consists of either 13 or 15 digits. @@ -31,23 +31,20 @@ True >>> validate('10277395526422') # 14 digits False -''' +""" import re from typing import Optional - OGRN_RE = re.compile(r'\b(\d{13}|\d{15})\b') # Valid set of federal subject codes. VALID_FEDERAL_SUBJECT_CODES = set(range(1, 80)) | {83, 86, 87, 89, 91, 92, 99} -# cf. https://docs.trellix.com/de-DE/bundle/data-loss-prevention-11.10.x-classification-definitions-reference-guide/page/GUID-945B4343-861E-4A57-8E60-8B6028871BA1.html - def is_valid(text: str) -> bool: - '''Determine if the given string is a valid OGRN.''' + """Determine if the given string is a valid OGRN.""" if OGRN_RE.match(text) is None: return False if text[0] == '0': @@ -60,7 +57,7 @@ def is_valid(text: str) -> bool: def format(text: str) -> Optional[str]: - '''Normalize the given string to a valid OGRN.''' + """Normalize the given string to a valid OGRN.""" match = OGRN_RE.search(text) if match is None: return None @@ -68,7 +65,7 @@ def format(text: str) -> Optional[str]: def calculate_control_digit(grn: str) -> Optional[int]: - '''Calculate the control digit of the OGRN based on its length.''' + """Calculate the control digit of the OGRN based on its length.""" if len(grn) == 13: number = int(grn[:12]) mod_result = number % 11 @@ -82,7 +79,7 @@ def calculate_control_digit(grn: str) -> Optional[int]: return None def validate(text: str) -> bool: - '''Check if the number is a valid OGRN.''' + """Check if the number is a valid OGRN.""" normalized_text = format(text) if normalized_text is None: return False From e5dc5403c9b8b77000ee0ee514673ce7653a6f2f Mon Sep 17 00:00:00 2001 From: nvmbrasserie Date: Wed, 20 Nov 2024 16:11:38 +0100 Subject: [PATCH 08/33] Traceback (most recent call last) --- stdnum/ru/ogrn.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/stdnum/ru/ogrn.py b/stdnum/ru/ogrn.py index 7d4ce947..5ea355e5 100644 --- a/stdnum/ru/ogrn.py +++ b/stdnum/ru/ogrn.py @@ -26,11 +26,16 @@ >>> validate('1022200525819') True >>> validate('1027739') # too short -False +Traceback (most recent call last): + ... >>> validate('1022500001325') True >>> validate('10277395526422') # 14 digits -False +Traceback (most recent call last): + ... +>>> validate('1022500001328') # invalid check digit +Traceback (most recent call last): + ... """ import re From 70a9d899722d44c655a8cf4bd2275a93f1b5b5f5 Mon Sep 17 00:00:00 2001 From: nvmbrasserie Date: Wed, 20 Nov 2024 16:12:50 +0100 Subject: [PATCH 09/33] flake8 2 --- stdnum/ru/ogrn.py | 1 + 1 file changed, 1 insertion(+) diff --git a/stdnum/ru/ogrn.py b/stdnum/ru/ogrn.py index 5ea355e5..1eca3cc8 100644 --- a/stdnum/ru/ogrn.py +++ b/stdnum/ru/ogrn.py @@ -83,6 +83,7 @@ def calculate_control_digit(grn: str) -> Optional[int]: return calculated_digit return None + def validate(text: str) -> bool: """Check if the number is a valid OGRN.""" normalized_text = format(text) From 3ac38cba1582d69ad90785db078b5c2c7c117838 Mon Sep 17 00:00:00 2001 From: nvmbrasserie Date: Wed, 20 Nov 2024 16:17:44 +0100 Subject: [PATCH 10/33] ValidationError added --- stdnum/ru/ogrn.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/stdnum/ru/ogrn.py b/stdnum/ru/ogrn.py index 1eca3cc8..ae3f660f 100644 --- a/stdnum/ru/ogrn.py +++ b/stdnum/ru/ogrn.py @@ -41,6 +41,8 @@ import re from typing import Optional +from stdnum.exceptions import ValidationError + OGRN_RE = re.compile(r'\b(\d{13}|\d{15})\b') @@ -48,15 +50,15 @@ VALID_FEDERAL_SUBJECT_CODES = set(range(1, 80)) | {83, 86, 87, 89, 91, 92, 99} -def is_valid(text: str) -> bool: +def is_valid(text: str): """Determine if the given string is a valid OGRN.""" if OGRN_RE.match(text) is None: - return False + raise ValidationError("Invalid length for OGRN.") if text[0] == '0': - return False + raise ValidationError("Invalid first digit for OGRN.") federal_subject_code = int(text[3:5]) if federal_subject_code not in VALID_FEDERAL_SUBJECT_CODES: - return False + raise ValidationError("Invalid check digit for OGRN.") control_digit = int(text[-1]) return control_digit == calculate_control_digit(text) From 3744f8080099c05b16e105204b332e4c24997dd5 Mon Sep 17 00:00:00 2001 From: nvmbrasserie Date: Wed, 20 Nov 2024 16:24:57 +0100 Subject: [PATCH 11/33] formatted again --- stdnum/ru/ogrn.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/stdnum/ru/ogrn.py b/stdnum/ru/ogrn.py index ae3f660f..7732a980 100644 --- a/stdnum/ru/ogrn.py +++ b/stdnum/ru/ogrn.py @@ -44,28 +44,22 @@ from stdnum.exceptions import ValidationError -OGRN_RE = re.compile(r'\b(\d{13}|\d{15})\b') - -# Valid set of federal subject codes. -VALID_FEDERAL_SUBJECT_CODES = set(range(1, 80)) | {83, 86, 87, 89, 91, 92, 99} - - def is_valid(text: str): """Determine if the given string is a valid OGRN.""" - if OGRN_RE.match(text) is None: - raise ValidationError("Invalid length for OGRN.") + if re.compile(r'\b(\d{13}|\d{15})\b').match(text) is None: + raise ValidationError('Invalid length for OGRN.') if text[0] == '0': - raise ValidationError("Invalid first digit for OGRN.") + raise ValidationError('Invalid first digit for OGRN.') federal_subject_code = int(text[3:5]) - if federal_subject_code not in VALID_FEDERAL_SUBJECT_CODES: - raise ValidationError("Invalid check digit for OGRN.") + if federal_subject_code not in set(range(1, 80)) | {83, 86, 87, 89, 91, 92, 99}: + raise ValidationError('Invalid check digit for OGRN.') control_digit = int(text[-1]) return control_digit == calculate_control_digit(text) def format(text: str) -> Optional[str]: """Normalize the given string to a valid OGRN.""" - match = OGRN_RE.search(text) + match = re.compile(r'\b(\d{13}|\d{15})\b').search(text) if match is None: return None return match.group(1) From 053a1514b69e65ccf868e0b99d082c9cd7cef827 Mon Sep 17 00:00:00 2001 From: nvmbrasserie Date: Wed, 20 Nov 2024 16:39:42 +0100 Subject: [PATCH 12/33] test added --- tests/test_ru_ogrn.doctest | 64 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 tests/test_ru_ogrn.doctest diff --git a/tests/test_ru_ogrn.doctest b/tests/test_ru_ogrn.doctest new file mode 100644 index 00000000..00f0bdd9 --- /dev/null +++ b/tests/test_ru_ogrn.doctest @@ -0,0 +1,64 @@ +test_ogrn.doctest - more detailed doctests for the stdnum.ogrn module + +Copyright (C) 2010-2024 Arthur de Jong and others + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA + + +This file contains more detailed doctests for the stdnum.ru.ogrn module. + +These tests validate the format, normalization, and validity of various +OGRN numbers, ensuring they conform to expected behavior. + +>>> from stdnum.ru import ogrn +>>> from stdnum.exceptions import * + +This is a list of OGRNs that should all be valid numbers: + +>>> valid_numbers = [ +... "1027739552642", "1137847171846", "1159102022738", +... "1022600000092", "1022500001930", "1022500001061", +... "1022500000566", "1022700000685", "1022500001325", +... "1027100000311", "1022500000786", "1024100000121", +... "1022400007508", "1022400000160", "1022400010005", +... "1022300001811", "1020500003919", "1022300003703", +... "1022300000502", "1022200531484", "1022200525819" +... ] +>>> all(ogrn.is_valid(x) for x in valid_numbers) +True + +These are some numbers that should be invalid: + +>>> invalid_numbers = [ +... "1027739552", "", "1027739", +... "11677", "315774600002662123" +... ] +>>> all(not ogrn.is_valid(x) for x in invalid_numbers) +True + +Testing normalization of OGRN strings: + +>>> ogrn.normalize("1027739552642") +'1027739552642' +>>> ogrn.normalize("OGRN 1027739552642") +'1027739552642' +>>> ogrn.normalize("102773955") +>>> ogrn.normalize("10277395587984375943") + +Ensure OGRN can be formatted as expected: + +>>> ogrn.format("1027739552642") +'1027739552642' From 7c823345b22e69f0b364f804dc18b88892686ffd Mon Sep 17 00:00:00 2001 From: nvmbrasserie Date: Wed, 20 Nov 2024 16:42:15 +0100 Subject: [PATCH 13/33] test fixes --- tests/test_ru_ogrn.doctest | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_ru_ogrn.doctest b/tests/test_ru_ogrn.doctest index 00f0bdd9..b872dc32 100644 --- a/tests/test_ru_ogrn.doctest +++ b/tests/test_ru_ogrn.doctest @@ -1,4 +1,4 @@ -test_ogrn.doctest - more detailed doctests for the stdnum.ogrn module +test_ru_ogrn.doctest - more detailed doctests for the stdnum.ru.ogrn module Copyright (C) 2010-2024 Arthur de Jong and others From 1ec308401ec9c5cadaa97ef8db3bf1ad73423e3d Mon Sep 17 00:00:00 2001 From: nvmbrasserie Date: Wed, 20 Nov 2024 16:56:50 +0100 Subject: [PATCH 14/33] docs and tests --- docs/stdnum.re.ogrn.rst | 5 +++++ tests/test_ru_ogrn.doctest | 9 ++++----- 2 files changed, 9 insertions(+), 5 deletions(-) create mode 100644 docs/stdnum.re.ogrn.rst diff --git a/docs/stdnum.re.ogrn.rst b/docs/stdnum.re.ogrn.rst new file mode 100644 index 00000000..9200a833 --- /dev/null +++ b/docs/stdnum.re.ogrn.rst @@ -0,0 +1,5 @@ +stdnum.ru.ogrn +============= + +.. automodule:: stdnum.ru.ogrn + :members: \ No newline at end of file diff --git a/tests/test_ru_ogrn.doctest b/tests/test_ru_ogrn.doctest index b872dc32..5392b340 100644 --- a/tests/test_ru_ogrn.doctest +++ b/tests/test_ru_ogrn.doctest @@ -37,7 +37,7 @@ This is a list of OGRNs that should all be valid numbers: ... "1022300001811", "1020500003919", "1022300003703", ... "1022300000502", "1022200531484", "1022200525819" ... ] ->>> all(ogrn.is_valid(x) for x in valid_numbers) +>>> all(ogrn.validate(x) for x in valid_numbers) True These are some numbers that should be invalid: @@ -46,19 +46,18 @@ These are some numbers that should be invalid: ... "1027739552", "", "1027739", ... "11677", "315774600002662123" ... ] ->>> all(not ogrn.is_valid(x) for x in invalid_numbers) +>>> all(not ogrn.validate(x) for x in invalid_numbers) True Testing normalization of OGRN strings: >>> ogrn.normalize("1027739552642") '1027739552642' ->>> ogrn.normalize("OGRN 1027739552642") -'1027739552642' >>> ogrn.normalize("102773955") >>> ogrn.normalize("10277395587984375943") + Ensure OGRN can be formatted as expected: ->>> ogrn.format("1027739552642") +>>> ogrn.format(" 1027739552642 ") '1027739552642' From 91a3b24c75fd2bad504df950973e29670658c7f9 Mon Sep 17 00:00:00 2001 From: nvmbrasserie Date: Wed, 20 Nov 2024 17:11:13 +0100 Subject: [PATCH 15/33] rewritten test --- tests/test_ru_ogrn.doctest | 51 ++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 29 deletions(-) diff --git a/tests/test_ru_ogrn.doctest b/tests/test_ru_ogrn.doctest index 5392b340..9fbf9865 100644 --- a/tests/test_ru_ogrn.doctest +++ b/tests/test_ru_ogrn.doctest @@ -28,36 +28,29 @@ OGRN numbers, ensuring they conform to expected behavior. This is a list of OGRNs that should all be valid numbers: ->>> valid_numbers = [ -... "1027739552642", "1137847171846", "1159102022738", -... "1022600000092", "1022500001930", "1022500001061", -... "1022500000566", "1022700000685", "1022500001325", -... "1027100000311", "1022500000786", "1024100000121", -... "1022400007508", "1022400000160", "1022400010005", -... "1022300001811", "1020500003919", "1022300003703", -... "1022300000502", "1022200531484", "1022200525819" -... ] ->>> all(ogrn.validate(x) for x in valid_numbers) +>>> valid_numbers = ''' +... +... 1027739552642 +... 1022600000092 +... 1022500000566 +... 1027100000311 +... 1022400007508 +... 1022300001811 +... 1022300000502 +... +... ''' +>>> [x for x in numbers.splitlines() if x and not ogrn.is_valid(x)] True These are some numbers that should be invalid: ->>> invalid_numbers = [ -... "1027739552", "", "1027739", -... "11677", "315774600002662123" -... ] ->>> all(not ogrn.validate(x) for x in invalid_numbers) -True - -Testing normalization of OGRN strings: - ->>> ogrn.normalize("1027739552642") -'1027739552642' ->>> ogrn.normalize("102773955") ->>> ogrn.normalize("10277395587984375943") - - -Ensure OGRN can be formatted as expected: - ->>> ogrn.format(" 1027739552642 ") -'1027739552642' +>>> invalid_numbers = ''' +... +... 1027739552 +... 1027739 +... 11677 +... 315774600002662123 +... +... ''' +>>> [x for x in numbers.splitlines() if x and not ogrn.is_valid(x)] +False From 5a10fb3a7f1b5d0d85de4ed8447491339d82fc05 Mon Sep 17 00:00:00 2001 From: nvmbrasserie Date: Wed, 20 Nov 2024 17:39:01 +0100 Subject: [PATCH 16/33] happy test --- tests/test_ru_ogrn.doctest | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/tests/test_ru_ogrn.doctest b/tests/test_ru_ogrn.doctest index 9fbf9865..41f009da 100644 --- a/tests/test_ru_ogrn.doctest +++ b/tests/test_ru_ogrn.doctest @@ -39,18 +39,5 @@ This is a list of OGRNs that should all be valid numbers: ... 1022300000502 ... ... ''' ->>> [x for x in numbers.splitlines() if x and not ogrn.is_valid(x)] -True - -These are some numbers that should be invalid: - ->>> invalid_numbers = ''' -... -... 1027739552 -... 1027739 -... 11677 -... 315774600002662123 -... -... ''' ->>> [x for x in numbers.splitlines() if x and not ogrn.is_valid(x)] -False +>>> [x for x in valid_numbers.splitlines() if x and not ogrn.is_valid(x)] +[] From c237cfcbc2f2424bea5e22e6131cfa45dac59d21 Mon Sep 17 00:00:00 2001 From: nvmbrasserie Date: Wed, 20 Nov 2024 18:08:50 +0100 Subject: [PATCH 17/33] tests successful --- stdnum/ru/ogrn.py | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/stdnum/ru/ogrn.py b/stdnum/ru/ogrn.py index 7732a980..b37864a1 100644 --- a/stdnum/ru/ogrn.py +++ b/stdnum/ru/ogrn.py @@ -25,43 +25,48 @@ >>> validate('1022200525819') True ->>> validate('1027739') # too short -Traceback (most recent call last): - ... >>> validate('1022500001325') True >>> validate('10277395526422') # 14 digits Traceback (most recent call last): ... +InvalidLength: ... >>> validate('1022500001328') # invalid check digit Traceback (most recent call last): ... +InvalidChecksum: ... """ import re from typing import Optional -from stdnum.exceptions import ValidationError +from stdnum.exceptions import ValidationError, InvalidLength, InvalidChecksum, InvalidComponent -def is_valid(text: str): +def validate(text: str) -> bool: """Determine if the given string is a valid OGRN.""" - if re.compile(r'\b(\d{13}|\d{15})\b').match(text) is None: - raise ValidationError('Invalid length for OGRN.') + if not isinstance(text, str) or text is None: + raise TypeError("Expected a string or bytes-like object, got '{}'" + .format(type(text).__name__)) + if len(text) not in {13, 15} or not text.isdigit(): + raise InvalidLength() if text[0] == '0': - raise ValidationError('Invalid first digit for OGRN.') + raise InvalidComponent() federal_subject_code = int(text[3:5]) if federal_subject_code not in set(range(1, 80)) | {83, 86, 87, 89, 91, 92, 99}: - raise ValidationError('Invalid check digit for OGRN.') + raise InvalidComponent() control_digit = int(text[-1]) - return control_digit == calculate_control_digit(text) - + if control_digit != calculate_control_digit(text): + raise InvalidChecksum() + return True def format(text: str) -> Optional[str]: """Normalize the given string to a valid OGRN.""" + if not isinstance(text, str): + return None match = re.compile(r'\b(\d{13}|\d{15})\b').search(text) if match is None: - return None + raise InvalidLength() return match.group(1) @@ -80,9 +85,10 @@ def calculate_control_digit(grn: str) -> Optional[int]: return None -def validate(text: str) -> bool: +def is_valid(text: str) -> bool: """Check if the number is a valid OGRN.""" - normalized_text = format(text) - if normalized_text is None: + try: + normalized_text = format(text) + return bool(normalized_text and validate(normalized_text)) + except ValidationError: return False - return is_valid(normalized_text) From 3cc376b223da4066181b564e8aa419680f419800 Mon Sep 17 00:00:00 2001 From: nvmbrasserie Date: Wed, 20 Nov 2024 18:18:12 +0100 Subject: [PATCH 18/33] flake fix --- stdnum/ru/ogrn.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdnum/ru/ogrn.py b/stdnum/ru/ogrn.py index b37864a1..1a2ab4a7 100644 --- a/stdnum/ru/ogrn.py +++ b/stdnum/ru/ogrn.py @@ -40,7 +40,7 @@ import re from typing import Optional -from stdnum.exceptions import ValidationError, InvalidLength, InvalidChecksum, InvalidComponent +from stdnum.exceptions import * def validate(text: str) -> bool: @@ -87,7 +87,7 @@ def calculate_control_digit(grn: str) -> Optional[int]: def is_valid(text: str) -> bool: """Check if the number is a valid OGRN.""" - try: + try: normalized_text = format(text) return bool(normalized_text and validate(normalized_text)) except ValidationError: From 2b629c36d1fccbb8619bc2ca5cf3f45ed440450a Mon Sep 17 00:00:00 2001 From: nvmbrasserie Date: Wed, 20 Nov 2024 18:24:31 +0100 Subject: [PATCH 19/33] more == --- docs/stdnum.re.ogrn.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/stdnum.re.ogrn.rst b/docs/stdnum.re.ogrn.rst index 9200a833..aee48283 100644 --- a/docs/stdnum.re.ogrn.rst +++ b/docs/stdnum.re.ogrn.rst @@ -1,5 +1,5 @@ stdnum.ru.ogrn -============= +============== .. automodule:: stdnum.ru.ogrn :members: \ No newline at end of file From 682451be2a737d098466c2e7908939a3fb632573 Mon Sep 17 00:00:00 2001 From: nvmbrasserie Date: Wed, 20 Nov 2024 18:25:47 +0100 Subject: [PATCH 20/33] index rst --- docs/index.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/index.rst b/docs/index.rst index e9c76c32..6acfebe0 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -298,6 +298,7 @@ Available formats ro.onrc rs.pib ru.inn + ru.ogrn se.orgnr se.personnummer se.postnummer From 05d2a57a48fbf90fe19889ba4f2ce109f9feefc5 Mon Sep 17 00:00:00 2001 From: nvmbrasserie Date: Wed, 20 Nov 2024 19:02:18 +0100 Subject: [PATCH 21/33] all tests passed --- stdnum/ru/ogrn.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/stdnum/ru/ogrn.py b/stdnum/ru/ogrn.py index 1a2ab4a7..cf2d63bf 100644 --- a/stdnum/ru/ogrn.py +++ b/stdnum/ru/ogrn.py @@ -35,6 +35,20 @@ Traceback (most recent call last): ... InvalidChecksum: ... +>>> validate('0022500001325') # starts with 0 +Traceback (most recent call last): + ... +InvalidComponent: ... +>>> validate('102250000') # too short +Traceback (most recent call last): + ... +InvalidLength: ... +>>> validate('1029500001325') # invalid federal subject code +Traceback (most recent call last): + ... +InvalidComponent: ... +>>> validate('385768585948949') # 15 digits +True """ import re @@ -45,11 +59,6 @@ def validate(text: str) -> bool: """Determine if the given string is a valid OGRN.""" - if not isinstance(text, str) or text is None: - raise TypeError("Expected a string or bytes-like object, got '{}'" - .format(type(text).__name__)) - if len(text) not in {13, 15} or not text.isdigit(): - raise InvalidLength() if text[0] == '0': raise InvalidComponent() federal_subject_code = int(text[3:5]) @@ -82,7 +91,8 @@ def calculate_control_digit(grn: str) -> Optional[int]: mod_result = number % 13 calculated_digit = mod_result if mod_result != 10 else 0 return calculated_digit - return None + else: + raise InvalidLength() def is_valid(text: str) -> bool: From 9e2d5175c81c243c0bdeec49df3cdf013762bde2 Mon Sep 17 00:00:00 2001 From: nvmbrasserie Date: Wed, 20 Nov 2024 19:04:02 +0100 Subject: [PATCH 22/33] flake fix --- stdnum/ru/ogrn.py | 1 + 1 file changed, 1 insertion(+) diff --git a/stdnum/ru/ogrn.py b/stdnum/ru/ogrn.py index cf2d63bf..faa65146 100644 --- a/stdnum/ru/ogrn.py +++ b/stdnum/ru/ogrn.py @@ -69,6 +69,7 @@ def validate(text: str) -> bool: raise InvalidChecksum() return True + def format(text: str) -> Optional[str]: """Normalize the given string to a valid OGRN.""" if not isinstance(text, str): From b29c5f4260f542f0269365725f46c6499e852d10 Mon Sep 17 00:00:00 2001 From: nvmbrasserie Date: Thu, 21 Nov 2024 10:09:10 +0100 Subject: [PATCH 23/33] duplicate removed --- docs/stdnum.re.ogrn.rst | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 docs/stdnum.re.ogrn.rst diff --git a/docs/stdnum.re.ogrn.rst b/docs/stdnum.re.ogrn.rst deleted file mode 100644 index aee48283..00000000 --- a/docs/stdnum.re.ogrn.rst +++ /dev/null @@ -1,5 +0,0 @@ -stdnum.ru.ogrn -============== - -.. automodule:: stdnum.ru.ogrn - :members: \ No newline at end of file From 69720439930ec15b80dc785b5bbe672cd2e006e1 Mon Sep 17 00:00:00 2001 From: nvmbrasserie Date: Thu, 21 Nov 2024 11:24:31 +0100 Subject: [PATCH 24/33] ru ogrn rst --- docs/stdnum.ru.ogrn.rst | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 docs/stdnum.ru.ogrn.rst diff --git a/docs/stdnum.ru.ogrn.rst b/docs/stdnum.ru.ogrn.rst new file mode 100644 index 00000000..aee48283 --- /dev/null +++ b/docs/stdnum.ru.ogrn.rst @@ -0,0 +1,5 @@ +stdnum.ru.ogrn +============== + +.. automodule:: stdnum.ru.ogrn + :members: \ No newline at end of file From 15d8f0b66519f50560e8f0dfd419f0a500d107c5 Mon Sep 17 00:00:00 2001 From: nvmbrasserie Date: Thu, 21 Nov 2024 11:42:13 +0100 Subject: [PATCH 25/33] tox reconfigured --- tox.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/tox.ini b/tox.ini index f338dd9a..7b0bbb36 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,7 @@ [tox] envlist = py{27,36,37,38,39,310,311,312,py,py3},flake8,docs,headers skip_missing_interpreters = true +requires = virtualenv<20.22.0 [testenv] deps = pytest From 83561a17e0dfe9a4fbd6d2200064609d96bae4a0 Mon Sep 17 00:00:00 2001 From: nvmbrasserie Date: Thu, 21 Nov 2024 11:49:08 +0100 Subject: [PATCH 26/33] test py27 --- stdnum/ru/ogrn.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/stdnum/ru/ogrn.py b/stdnum/ru/ogrn.py index faa65146..12e411b5 100644 --- a/stdnum/ru/ogrn.py +++ b/stdnum/ru/ogrn.py @@ -52,12 +52,11 @@ """ import re -from typing import Optional from stdnum.exceptions import * -def validate(text: str) -> bool: +def validate(text): """Determine if the given string is a valid OGRN.""" if text[0] == '0': raise InvalidComponent() @@ -70,9 +69,9 @@ def validate(text: str) -> bool: return True -def format(text: str) -> Optional[str]: +def format(text): """Normalize the given string to a valid OGRN.""" - if not isinstance(text, str): + if not isinstance(text): return None match = re.compile(r'\b(\d{13}|\d{15})\b').search(text) if match is None: @@ -80,7 +79,7 @@ def format(text: str) -> Optional[str]: return match.group(1) -def calculate_control_digit(grn: str) -> Optional[int]: +def calculate_control_digit(grn): """Calculate the control digit of the OGRN based on its length.""" if len(grn) == 13: number = int(grn[:12]) @@ -96,7 +95,7 @@ def calculate_control_digit(grn: str) -> Optional[int]: raise InvalidLength() -def is_valid(text: str) -> bool: +def is_valid(text): """Check if the number is a valid OGRN.""" try: normalized_text = format(text) From 9b01d76c40c67776e232350c35a7aaeba217a88d Mon Sep 17 00:00:00 2001 From: nvmbrasserie Date: Thu, 21 Nov 2024 12:16:31 +0100 Subject: [PATCH 27/33] isinstance upd --- stdnum/ru/ogrn.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdnum/ru/ogrn.py b/stdnum/ru/ogrn.py index 12e411b5..da0dd627 100644 --- a/stdnum/ru/ogrn.py +++ b/stdnum/ru/ogrn.py @@ -71,7 +71,7 @@ def validate(text): def format(text): """Normalize the given string to a valid OGRN.""" - if not isinstance(text): + if not isinstance(text, str): return None match = re.compile(r'\b(\d{13}|\d{15})\b').search(text) if match is None: From a558ac6d318d8cfdbff2624072c4f65b50595906 Mon Sep 17 00:00:00 2001 From: nvmbrasserie Date: Thu, 21 Nov 2024 12:21:53 +0100 Subject: [PATCH 28/33] coding fix --- stdnum/ru/ogrn.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdnum/ru/ogrn.py b/stdnum/ru/ogrn.py index da0dd627..9f2b042a 100644 --- a/stdnum/ru/ogrn.py +++ b/stdnum/ru/ogrn.py @@ -19,7 +19,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA # 02110-1301 USA -"""ОГРН (Основной государственный регистрационный номер, Primary State Registration Number). +""" OGRN (Primary State Registration Number). The OGRN is a Russian identifier for legal entities that consists of either 13 or 15 digits. From 764fac79e76cc92e538dfbefbc25746df11875eb Mon Sep 17 00:00:00 2001 From: nvmbrasserie Date: Thu, 21 Nov 2024 12:25:05 +0100 Subject: [PATCH 29/33] flake8 fix --- stdnum/ru/ogrn.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdnum/ru/ogrn.py b/stdnum/ru/ogrn.py index 9f2b042a..32662fdb 100644 --- a/stdnum/ru/ogrn.py +++ b/stdnum/ru/ogrn.py @@ -19,7 +19,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA # 02110-1301 USA -""" OGRN (Primary State Registration Number). +"""OGRN (Primary State Registration Number). The OGRN is a Russian identifier for legal entities that consists of either 13 or 15 digits. From 0abf886792674764fa166a5fd1e78ee45cf5f8de Mon Sep 17 00:00:00 2001 From: nvmbrasserie Date: Tue, 10 Dec 2024 13:29:15 +0100 Subject: [PATCH 30/33] federal subject codes check removed --- stdnum/ru/ogrn.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/stdnum/ru/ogrn.py b/stdnum/ru/ogrn.py index 32662fdb..3b65facf 100644 --- a/stdnum/ru/ogrn.py +++ b/stdnum/ru/ogrn.py @@ -1,4 +1,3 @@ - # ogrn.py - functions for handling Russian company registration numbers # coding: utf-8 # @@ -58,10 +57,7 @@ def validate(text): """Determine if the given string is a valid OGRN.""" - if text[0] == '0': - raise InvalidComponent() - federal_subject_code = int(text[3:5]) - if federal_subject_code not in set(range(1, 80)) | {83, 86, 87, 89, 91, 92, 99}: + if text[0] == "0": raise InvalidComponent() control_digit = int(text[-1]) if control_digit != calculate_control_digit(text): @@ -73,7 +69,7 @@ def format(text): """Normalize the given string to a valid OGRN.""" if not isinstance(text, str): return None - match = re.compile(r'\b(\d{13}|\d{15})\b').search(text) + match = re.compile(r"\b(\d{13}|\d{15})\b").search(text) if match is None: raise InvalidLength() return match.group(1) From 27543472d161931ae96dacfcfa74a522dc3e5dd9 Mon Sep 17 00:00:00 2001 From: nvmbrasserie Date: Tue, 10 Dec 2024 14:16:44 +0100 Subject: [PATCH 31/33] formatting --- stdnum/ru/ogrn.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stdnum/ru/ogrn.py b/stdnum/ru/ogrn.py index 3b65facf..ab2b76b1 100644 --- a/stdnum/ru/ogrn.py +++ b/stdnum/ru/ogrn.py @@ -1,3 +1,4 @@ + # ogrn.py - functions for handling Russian company registration numbers # coding: utf-8 # @@ -69,7 +70,7 @@ def format(text): """Normalize the given string to a valid OGRN.""" if not isinstance(text, str): return None - match = re.compile(r"\b(\d{13}|\d{15})\b").search(text) + match = re.compile(r'\b(\d{13}|\d{15})\b').search(text) if match is None: raise InvalidLength() return match.group(1) From f220b9fa1f8179dabac07ce0b9ffcedd8347ddfd Mon Sep 17 00:00:00 2001 From: nvmbrasserie Date: Tue, 10 Dec 2024 14:17:33 +0100 Subject: [PATCH 32/33] federal codes test removed --- stdnum/ru/ogrn.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/stdnum/ru/ogrn.py b/stdnum/ru/ogrn.py index ab2b76b1..aebd8630 100644 --- a/stdnum/ru/ogrn.py +++ b/stdnum/ru/ogrn.py @@ -43,10 +43,6 @@ Traceback (most recent call last): ... InvalidLength: ... ->>> validate('1029500001325') # invalid federal subject code -Traceback (most recent call last): - ... -InvalidComponent: ... >>> validate('385768585948949') # 15 digits True """ From 2352ffd9d9906f4db9169eec8871916ecb2bfb1d Mon Sep 17 00:00:00 2001 From: nvmbrasserie Date: Tue, 10 Dec 2024 14:19:26 +0100 Subject: [PATCH 33/33] flake fix --- stdnum/ru/ogrn.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdnum/ru/ogrn.py b/stdnum/ru/ogrn.py index aebd8630..087cfeb5 100644 --- a/stdnum/ru/ogrn.py +++ b/stdnum/ru/ogrn.py @@ -54,7 +54,7 @@ def validate(text): """Determine if the given string is a valid OGRN.""" - if text[0] == "0": + if text[0] == '0': raise InvalidComponent() control_digit = int(text[-1]) if control_digit != calculate_control_digit(text):