Skip to content

Commit

Permalink
test py27
Browse files Browse the repository at this point in the history
  • Loading branch information
nvmbrasserie committed Nov 21, 2024
1 parent 15d8f0b commit 83561a1
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions stdnum/ru/ogrn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -70,17 +69,17 @@ 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:
raise InvalidLength()
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])
Expand All @@ -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)
Expand Down

0 comments on commit 83561a1

Please sign in to comment.