election_day.formats.imports.common
Attributes
Classes
Functions
|
Loads the given file and returns it as CSV file. |
|
Loads the given eCH file and returns it as an object. |
|
Returns the entity name and district or region (from our static data, |
|
|
Checks line of a csv file for a valid integer. |
|
Checks line of a csv file for a valid numeric number. |
|
Used to validate list_id that can also be alphanumeric. |
|
|
|
|
|
|
Convert the given eCH domain to our internal domain and domain |
Module Contents
- election_day.formats.imports.common.EXPATS = (9170, 19010, 19020, 19030, 19040, 19050, 19060, 19070, 19080, 19090, 19100, 19110, 19120,...[source]
- election_day.formats.imports.common.STATI: tuple[onegov.election_day.types.Status, Ellipsis] = ('unknown', 'interim', 'final')[source]
- election_day.formats.imports.common.BALLOT_TYPES: set[onegov.election_day.types.BallotType][source]
- class election_day.formats.imports.common.FileImportError(error: str, line: int | None = None, filename: str | None = None)[source]
- election_day.formats.imports.common.load_csv(file: IO[bytes], mimetype: str, expected_headers: Sequence[str] | None, filename: str | None = None, dialect: type[Dialect] | Dialect | str | None = None, encoding: str | None = None, rename_duplicate_column_names: bool = False) tuple[DefaultCSVFile | None, FileImportError | None] [source]
Loads the given file and returns it as CSV file.
- Returns:
A tuple CSVFile, FileImportError.
- election_day.formats.imports.common.load_xml(file: IO[bytes]) tuple[Any, None] | tuple[None, FileImportError] [source]
Loads the given eCH file and returns it as an object.
- Returns:
A tuple object tree, FileImportError.
- election_day.formats.imports.common.get_entity_and_district(entity_id: int, entities: dict[int, dict[str, str]], election_or_vote: Election | Vote, principal: Canton | Municipality, errors: list[str] | None = None) tuple[str, str, str] [source]
Returns the entity name and district or region (from our static data, depending on the domain of the election). Adds optionally an error, if the district or region is not part of this election or vote.
- election_day.formats.imports.common.line_is_relevant(line: onegov.core.csv.DefaultRow, number: str, district: str | None = None) bool [source]
- election_day.formats.imports.common.validate_integer(line: onegov.core.csv.DefaultRow, col: str, treat_none_as_default: bool = True, default: int = 0, optional: bool = False) int [source]
- election_day.formats.imports.common.validate_integer(line: onegov.core.csv.DefaultRow, col: str, treat_none_as_default: bool, default: _T, optional: bool = False) int | _T
- election_day.formats.imports.common.validate_integer(line: onegov.core.csv.DefaultRow, col: str, treat_none_as_default: bool = True, *, default: _T, optional: bool = False) int | _T
Checks line of a csv file for a valid integer. Raises an error if the attribute is not there.
- Parameters:
line – line object from csv reader
col – attribute of line object
default – default to return if line.col is None
treat_none_as_default – raises ValueError if line.col is None
optional – return the default, if the col does not exist.
- Returns:
integer value of line.col
- election_day.formats.imports.common.validate_numeric(line: onegov.core.csv.DefaultRow, col: str, precision: int, scale: int, treat_none_as_default: bool = True, default: decimal.Decimal = Decimal(0), optional: bool = False) decimal.Decimal [source]
- election_day.formats.imports.common.validate_numeric(line: onegov.core.csv.DefaultRow, col: str, precision: int, scale: int, treat_none_as_default: bool, default: _T, optional: bool = False) decimal.Decimal | _T
- election_day.formats.imports.common.validate_numeric(line: onegov.core.csv.DefaultRow, col: str, precision: int, scale: int, treat_none_as_default: bool = True, *, default: _T, optional: bool = False) decimal.Decimal | _T
Checks line of a csv file for a valid numeric number. Raises an error if the attribute is not there.
- Parameters:
line – line object from csv reader
col – attribute of line object
precision – the precision (number of decimals)
scale – the scale (number of decimals after decimal point)
default – default to return if line.col is None
treat_none_as_default – raises ValueError if line.col is None
optional – return the default, if the col does not exist.
- Returns:
numeric value of line.col
- election_day.formats.imports.common.validate_list_id(line: onegov.core.csv.DefaultRow, col: str, treat_empty_as_default: bool = True, default: str = '0') str [source]
- election_day.formats.imports.common.validate_list_id(line: onegov.core.csv.DefaultRow, col: str, treat_empty_as_default: bool, default: _T) str | _T
- election_day.formats.imports.common.validate_list_id(line: onegov.core.csv.DefaultRow, col: str, treat_empty_as_default: bool = True, *, default: _T) str | _T
Used to validate list_id that can also be alphanumeric. Example: 03B.04 Previously, the list_id was also 0 if it was empty.
- election_day.formats.imports.common.validate_gender(line: onegov.core.csv.DefaultRow) Gender | None [source]
- election_day.formats.imports.common.validate_color(line: onegov.core.csv.DefaultRow, col: str) str [source]
- election_day.formats.imports.common.convert_ech_domain(domain: xsdata_ech.e_ch_0252_1_0.DomainOfInfluenceType, principal: Canton | Municipality, entities: dict[int, dict[str, str]]) tuple[bool, onegov.election_day.types.DomainOfInfluence, str] [source]
Convert the given eCH domain to our internal domain and domain segment.
Return True as first argument, if the domain is supported for the given principal.