Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions odata/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ class MetaData(object):
'Edm.Guid': UUIDProperty,
}

def __init__(self, service):
def __init__(self, service, metadata_local_file_path=None):
self.url = service.url + '$metadata/'
self.connection = service.default_context.connection
self.service = service
self.metadata_local_file_path = metadata_local_file_path

def property_type_to_python(self, edm_type):
return self.property_types.get(edm_type, StringProperty)
Expand Down Expand Up @@ -219,9 +220,15 @@ def get_entity_or_prop_from_type(typename):
return base_class, entities, all_types

def load_document(self):
self.log.info('Loading metadata document: {0}'.format(self.url))
response = self.connection._do_get(self.url)
return ET.fromstring(response.content)
if self.metadata_local_file_path:
self.log.info('Reading metadata document: {0}'.format(self.metadata_local_file_path))
with open(self.metadata_local_file_path, 'r') as metadata_file:
content = metadata_file.read()
return ET.fromstring(content)
else:
self.log.info('Loading metadata document: {0}'.format(self.url))
response = self.connection._do_get(self.url)
return ET.fromstring(response.content)

def _parse_action(self, xmlq, action_element, schema_name):
action = {
Expand Down
4 changes: 2 additions & 2 deletions odata/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class ODataService(object):
:param auth: Custom Requests auth object to use for credentials
:raises ODataConnectionError: Fetching metadata failed. Server returned an HTTP error code
"""
def __init__(self, url, base=None, reflect_entities=False, session=None, auth=None):
def __init__(self, url, base=None, reflect_entities=False, session=None, auth=None, metadata_local_file_path=None):
self.url = url
self.metadata_url = ''
self.collections = {}
Expand Down Expand Up @@ -115,7 +115,7 @@ def __init__(self, url, base=None, reflect_entities=False, session=None, auth=No
:type types: dict
"""

self.metadata = MetaData(self)
self.metadata = MetaData(self, metadata_local_file_path)
self.Base = base or declarative_base()
"""
Entity base class. Either a custom one given in init or a generated one. Can be used to define entities
Expand Down