Skip to content

Commit

Permalink
Merge branch 'develop' into qb
Browse files Browse the repository at this point in the history
  • Loading branch information
javihern98 committed Jul 1, 2024
2 parents 619cda6 + c0ec819 commit 858aae3
Show file tree
Hide file tree
Showing 10 changed files with 1,579 additions and 10 deletions.
11 changes: 7 additions & 4 deletions src/pysdmx/io/xml/sdmx21/reader/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""SDMX 2.1 reader package."""
"""SDMX 2.1 XML reader package."""

from typing import Any, Dict, Optional

Expand All @@ -15,9 +15,11 @@
REG_INTERFACE,
STRSPE,
STRUCTURE,
STRUCTURES,
XML_OPTIONS,
)
from pysdmx.io.xml.sdmx21.doc_validation import validate_doc
from pysdmx.io.xml.sdmx21.reader.metadata_read import StructureParser
from pysdmx.io.xml.sdmx21.reader.submission_reader import (
handle_registry_interface,
)
Expand Down Expand Up @@ -91,9 +93,10 @@ def __generate_sdmx_objects_from_xml(
code = dict_info[ERROR][ERROR_MESSAGE][ERROR_CODE]
text = dict_info[ERROR][ERROR_MESSAGE][ERROR_TEXT]
raise ClientError(int(code), text)
# Leaving this commented for metadata read (#39)
# if STRUCTURE in dict_info:
# return create_structures(dict_info[STRUCTURE][STRUCTURES])
if STRUCTURE in dict_info:
return StructureParser().format_structures(
dict_info[STRUCTURE][STRUCTURES]
)
if REG_INTERFACE in dict_info:
return handle_registry_interface(dict_info)
raise ValueError("Cannot parse this sdmx data")
141 changes: 141 additions & 0 deletions src/pysdmx/io/xml/sdmx21/reader/__utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
"""Utility functions and constants for the parsers module."""

from typing import Any, Dict, List

# Common
ID = "id"
AGENCY_ID = "agencyID"
XMLNS = "xmlns"
VERSION = "version"

# Structure Specific
VALUE = "Value"

# Header
REF = "Ref"

# Structures
# Common
NAME = "Name"
DESC = "Description"
STR_URL = "structureURL"
STR_URL_LOW = "structure_url"
SER_URL = "serviceURL"
SER_URL_LOW = "service_url"
IS_EXTERNAL_REF = "isExternalReference"
IS_EXTERNAL_REF_LOW = "is_external_reference"
IS_FINAL = "isFinal"
IS_FINAL_LOW = "is_final"
IS_PARTIAL = "isPartial"
IS_PARTIAL_LOW = "is_partial"
# General
ANNOTATIONS = "Annotations"

# Individual
CL = "Codelist"
CON = "Concept"

# Dimension
DIM = "Dimension"

# Measure
PRIM_MEASURE = "PrimaryMeasure"

# Group Dimension
GROUP = "Group"
DIM_REF = "DimensionReference"

# Constraints
KEY_VALUE = "KeyValue"

# Annotation
ANNOTATION = "Annotation"
ANNOTATION_TITLE = "AnnotationTitle"
ANNOTATION_TYPE = "AnnotationType"
ANNOTATION_TEXT = "AnnotationText"
ANNOTATION_URL = "AnnotationURL"

TITLE = "title"
TEXT = "text"
TYPE = "type"
URL = "url"

# Facets
FACETS = "facets"
TEXT_TYPE = "textType"
TEXT_TYPE_LOW = "text_type"

# Contact
CONTACT = "Contact"
DEPARTMENT = "Department"
ROLE = "Role"
URIS = "uris"
EMAILS = "emails"
TELEPHONES = "telephones"
FAXES = "faxes"
URI = "URI"
EMAIL = "Email"
X400 = "X400"
TELEPHONE = "Telephone"
FAX = "Fax"

# Extras
AGENCY = "Agency"
PAR_ID = "maintainableParentID"
PAR_VER = "maintainableParentVersion"

# Errors
missing_rep: Dict[str, List[Any]] = {"CON": [], "CS": [], "CL": []}
dsd_id: str = ""

# Structure types
AGENCIES = "AgencyScheme"
ORGS = "OrganisationSchemes"
CLS = "Codelists"
CONCEPTS = "ConceptSchemes"
CS = "ConceptScheme"
CODE = "Code"

FacetType = {
"minLength": "min_length",
"maxLength": "max_length",
"minValue": "min_value",
"maxValue": "max_value",
"startValue": "start_value",
"endValue": "end_value",
"interval": "interval",
"timeInterval": "time_interval",
"decimals": "decimals",
"pattern": "pattern",
"startTime": "start_time",
"endTime": "end_time",
"isSequence": "is_sequence",
}


def unique_id(agencyID: str, id_: str, version: str) -> str:
"""Create a unique ID for an object.
Args:
agencyID: The agency ID
id_: The ID of the object
version: The version of the object
Returns:
A string with the unique ID
"""
return f"{agencyID}:{id_}({version})"


def add_list(element: Any) -> List[Any]:
"""Make sure an element is a list and convert it if it is not.
Args:
element: The element to be converted
Returns:
A list with the element
"""
if not isinstance(element, list):
element = [element]
return element
Loading

0 comments on commit 858aae3

Please sign in to comment.