election_day.formats.imports.common =================================== .. py:module:: election_day.formats.imports.common Attributes ---------- .. autoapisummary:: election_day.formats.imports.common.ECHImportResultType election_day.formats.imports.common._T election_day.formats.imports.common.EXPATS election_day.formats.imports.common.STATI election_day.formats.imports.common.BALLOT_TYPES Classes ------- .. autoapisummary:: election_day.formats.imports.common.FileImportError Functions --------- .. autoapisummary:: election_day.formats.imports.common.load_csv election_day.formats.imports.common.load_xml election_day.formats.imports.common.get_entity_and_district election_day.formats.imports.common.line_is_relevant election_day.formats.imports.common.validate_integer election_day.formats.imports.common.validate_numeric election_day.formats.imports.common.validate_list_id election_day.formats.imports.common.validate_gender election_day.formats.imports.common.validate_color election_day.formats.imports.common.convert_ech_domain Module Contents --------------- .. py:data:: ECHImportResultType .. py:data:: _T .. py:data:: EXPATS :value: (9170, 19010, 19020, 19030, 19040, 19050, 19060, 19070, 19080, 19090, 19100, 19110, 19120,... .. py:data:: STATI :type: tuple[onegov.election_day.types.Status, Ellipsis] :value: ('unknown', 'interim', 'final') .. py:data:: BALLOT_TYPES :type: set[onegov.election_day.types.BallotType] .. py:class:: FileImportError(error: str, line: int | None = None, filename: str | None = None) .. py:attribute:: __slots__ :value: ('filename', 'line', 'error') .. py:attribute:: filename :value: None .. py:attribute:: error .. py:attribute:: line :value: None .. py:method:: __eq__(other: object) -> bool .. py:method:: __hash__() -> int .. py:function:: load_csv(file: IO[bytes], mimetype: str, expected_headers: collections.abc.Sequence[str] | None, filename: str | None = None, dialect: type[csv.Dialect] | csv.Dialect | str | None = None, encoding: str | None = None, rename_duplicate_column_names: bool = False) -> tuple[onegov.core.csv.DefaultCSVFile | None, FileImportError | None] Loads the given file and returns it as CSV file. :return: A tuple CSVFile, FileImportError. .. py:function:: load_xml(file: IO[bytes]) -> tuple[Any, None] | tuple[None, FileImportError] Loads the given eCH file and returns it as an object. :return: A tuple object tree, FileImportError. .. py:function:: get_entity_and_district(entity_id: int, entities: dict[int, dict[str, str]], election_or_vote: onegov.election_day.models.Election | onegov.election_day.models.Vote, principal: onegov.election_day.models.Canton | onegov.election_day.models.Municipality, errors: list[str] | None = None) -> tuple[str, str, str] 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. .. py:function:: line_is_relevant(line: onegov.core.csv.DefaultRow, number: str, district: str | None = None) -> bool .. py:function:: validate_integer(line: onegov.core.csv.DefaultRow, col: str, treat_none_as_default: bool = True, default: int = 0, optional: bool = False) -> int validate_integer(line: onegov.core.csv.DefaultRow, col: str, treat_none_as_default: bool, default: _T, optional: bool = False) -> int | _T 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. :param line: line object from csv reader :param col: attribute of line object :param default: default to return if line.col is None :param treat_none_as_default: raises ValueError if line.col is None :param optional: return the default, if the col does not exist. :return: integer value of line.col .. py:function:: 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 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 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. :param line: line object from csv reader :param col: attribute of line object :param precision: the precision (number of decimals) :param scale: the scale (number of decimals after decimal point) :param default: default to return if line.col is None :param treat_none_as_default: raises ValueError if line.col is None :param optional: return the default, if the col does not exist. :return: numeric value of line.col .. py:function:: validate_list_id(line: onegov.core.csv.DefaultRow, col: str, treat_empty_as_default: bool = True, default: str = '0') -> str validate_list_id(line: onegov.core.csv.DefaultRow, col: str, treat_empty_as_default: bool, default: _T) -> str | _T 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. .. py:function:: validate_gender(line: onegov.core.csv.DefaultRow) -> onegov.election_day.types.Gender | None .. py:function:: validate_color(line: onegov.core.csv.DefaultRow, col: str) -> str .. py:function:: convert_ech_domain(domain: xsdata_ech.e_ch_0252_1_0.DomainOfInfluenceType, principal: onegov.election_day.models.Canton | onegov.election_day.models.Municipality, entities: dict[int, dict[str, str]]) -> tuple[bool, onegov.election_day.types.DomainOfInfluence, str] 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.