-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: validation des codes géographiques (#5)
Cette PR a pour but d'initialiser la validation de codes géographiques. - Codes fantoir - Communes, code postaux, code insee - Cantons - Départements, numéros de département - Régions, code région - Pays, codes pays iso2 et iso3 --------- Co-authored-by: Amélie Rondot <[email protected]>
- Loading branch information
1 parent
7c7e6b2
commit fa872be
Showing
36 changed files
with
141,988 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
{"venv":".venv", "venvPath":"."} | ||
{ | ||
"venv":".venv", | ||
"venvPath":".", | ||
"ignore": ["./src/frformat/code_postal_set.py"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,21 @@ | ||
# flake8: noqa | ||
from .custom_format import * | ||
from .french_gps_coordinates import FrenchGPSCoordinates as FrenchGPSCoordinates | ||
from .custom_format import * # isort:skip | ||
|
||
from .geo.canton import Canton as Canton | ||
from .geo.code_commune_insee import CodeCommuneInsee as CodeCommuneInsee | ||
from .geo.code_fantoir import CodeFantoir as CodeFantoir | ||
from .geo.code_pays import CodePaysISO2 as CodePaysISO2 | ||
from .geo.code_pays import CodePaysISO3 as CodePaysISO3 | ||
from .geo.code_postal import CodePostal as CodePostal | ||
from .geo.code_region import CodeRegion as CodeRegion | ||
from .geo.commune import Commune as Commune | ||
from .geo.coordonnees_gps_francaises import ( | ||
CoordonneesGPSFrancaises as CoordonneesGPSFrancaises, | ||
) | ||
from .geo.departement import Departement as Departement | ||
from .geo.numero_departement import NumeroDepartement as NumeroDepartement | ||
from .geo.pays import Pays as Pays | ||
from .geo.region import Region as Region | ||
from .nomenclature_acte_format import NomenclatureActe as NomenclatureActe | ||
from .siren_format import Siren as Siren | ||
from .siret_format import Siret as Siret | ||
from .siren import Siren as Siren | ||
from .siret import Siret as Siret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import re | ||
|
||
|
||
def normalize_text(val: str) -> str: | ||
val = val.lower() | ||
val = val.replace("-", " ") | ||
val = val.replace("_", " ") | ||
val = val.replace("'", " ") | ||
val = val.replace(",", " ") | ||
val = val.replace(" ", " ") | ||
val = re.sub(r"[èéêë]", "e", val) | ||
val = re.sub(r"[àáâãäå]", "a", val) | ||
val = re.sub(r"[ìíîï]", "i", val) | ||
val = re.sub(r"[òóôõö]", "o", val) | ||
val = re.sub(r"[ùúûü]", "u", val) | ||
return val |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from typing import Optional, Set | ||
|
||
from frformat import CustomFormat | ||
from frformat.common import normalize_text | ||
|
||
|
||
def new( | ||
name: str, | ||
description: str, | ||
strict_enum: Set[str], | ||
lenient_enum: Optional[Set[str]] = None, | ||
): | ||
if not lenient_enum: | ||
lenient_enum = {normalize_text(e) for e in strict_enum} | ||
|
||
class EnumFormat(CustomFormat): | ||
"""Checks if a value is in a given list | ||
May check with or without string normalization with the "strict" | ||
validation. | ||
""" | ||
|
||
@classmethod | ||
def name(cls) -> str: | ||
return name | ||
|
||
@classmethod | ||
def description(cls) -> str: | ||
return description | ||
|
||
@classmethod | ||
def is_valid(cls, value: str, strict: bool = True) -> bool: | ||
if not strict: | ||
norm_value = normalize_text(value) | ||
return norm_value in lenient_enum | ||
else: | ||
return value in strict_enum | ||
|
||
return EnumFormat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from frformat import enum_format | ||
from frformat.geo.canton_set import CANTON_SET | ||
|
||
name = "Nom de canton" | ||
description = ( | ||
"Vérifie que le nom de canton est un canton ou pseudo-canton français valide" | ||
) | ||
|
||
Canton = enum_format.new(name, description, CANTON_SET) |
Oops, something went wrong.