Skip to content

Commit

Permalink
formatted again
Browse files Browse the repository at this point in the history
  • Loading branch information
nvmbrasserie committed Nov 20, 2024
1 parent 3ac38cb commit 3744f80
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions stdnum/ru/ogrn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3744f80

Please sign in to comment.