How to use the pyodata.v2.model.Schema function in pyodata

To help you get started, we’ve selected a few pyodata examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github SAP / python-pyodata / tests / test_model_v2.py View on Github external
def test_namespace_whitelist(mock_from_etree, xml_builder_factory):
    """Test correct handling of whitelisted namespaces"""

    xml_builder = xml_builder_factory()
    xml_builder.namespaces['edmx'] = 'http://docs.oasis-open.org/odata/ns/edmx'
    xml_builder.namespaces['edm'] = 'http://docs.oasis-open.org/odata/ns/edm'
    xml_builder.add_schema('', '')
    xml = xml_builder.serialize()

    MetadataBuilder(xml).build()
    assert Schema.from_etree is mock_from_etree
    mock_from_etree.assert_called_once()
github SAP / python-pyodata / tests / test_model_v2.py View on Github external
def test_whitelisted_edm_namespace(mock_from_etree, xml_builder_factory):
    """Test correct handling of whitelisted Microsoft's edm namespace"""

    xml_builder = xml_builder_factory()
    xml_builder.namespaces['edm'] = 'http://schemas.microsoft.com/ado/2009/11/edm'
    xml_builder.add_schema('', '')
    xml = xml_builder.serialize()

    MetadataBuilder(xml).build()
    assert Schema.from_etree is mock_from_etree
    mock_from_etree.assert_called_once()
github SAP / python-pyodata / pyodata / v2 / model.py View on Github external
namespaces['edmx'] = namespace

        if 'edm' not in self._config.namespaces:
            namespace = etree.QName(schema.tag).namespace

            if namespace not in self.EDM_WHITELIST:
                raise PyODataParserError(f'Unsupported Schema namespace - {namespace}')

            namespaces['edm'] = namespace

        self._config.namespaces = namespaces

        self.update_global_variables_with_alias(self.get_aliases(xml, self._config))

        edm_schemas = xml.xpath('/edmx:Edmx/edmx:DataServices/edm:Schema', namespaces=self._config.namespaces)
        schema = Schema.from_etree(edm_schemas, self._config)
        return schema
github SAP / python-pyodata / pyodata / v2 / model.py View on Github external
def __init__(self, config: Config):
        super(Schema, self).__init__()

        self._decls = Schema.Declarations()
        self._config = config
github SAP / python-pyodata / pyodata / v2 / model.py View on Github external
def from_etree(schema_nodes, config: Config):
        schema = Schema(config)

        # Parse Schema nodes by parts to get over the problem of not-yet known
        # entity types referenced by entity sets, function imports and
        # annotations.

        # First, process EnumType, EntityType and ComplexType nodes. They have almost no dependencies on other elements.
        for schema_node in schema_nodes:
            namespace = schema_node.get('Namespace')
            decl = Schema.Declaration(namespace)
            schema._decls[namespace] = decl

            for enum_type in schema_node.xpath('edm:EnumType', namespaces=config.namespaces):
                try:
                    etype = EnumType.from_etree(enum_type, namespace, config)
                except (PyODataParserError, AttributeError) as ex:
                    config.err_policy(ParserError.ENUM_TYPE).resolve(ex)
github SAP / python-pyodata / pyodata / v2 / model.py View on Github external
def __init__(self, namespace):
            super(Schema.Declaration, self).__init__()

            self.namespace = namespace

            self.entity_types = dict()
            self.complex_types = dict()
            self.enum_types = dict()
            self.entity_sets = dict()
            self.function_imports = dict()
            self.associations = dict()
            self.association_sets = dict()
github SAP / python-pyodata / pyodata / v2 / model.py View on Github external
def __getitem__(self, key):
            try:
                return super(Schema.Declarations, self).__getitem__(key)
            except KeyError:
                raise KeyError('There is no Schema Namespace {}'.format(key))