Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to define default company_name with service #49

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion odata/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ODataConnection(object):
'OData-Version': '4.0',
'User-Agent': 'python-odata {0}'.format(version),
}
timeout = 90
timeout = 270

def __init__(self, session=None, auth=None):
if session is None:
Expand Down
5 changes: 3 additions & 2 deletions odata/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import logging
import sys

has_lxml = False
try:
from lxml import etree as ET

has_lxml = True
except ImportError:
if sys.version_info < (2, 7):
Expand All @@ -19,7 +21,6 @@


class MetaData(object):

log = logging.getLogger('odata.metadata')
namespaces = {
'edm': 'http://docs.oasis-open.org/odata/ns/edm',
Expand All @@ -41,7 +42,7 @@ class MetaData(object):
_annotation_term_computed = 'Org.OData.Core.V1.Computed'

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

Expand Down
13 changes: 10 additions & 3 deletions odata/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
from .exceptions import ODataError
from .context import Context
from .action import Action, Function
from requests.utils import requote_uri

__all__ = (
'ODataService',
Expand All @@ -76,9 +77,15 @@ 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):
self.url = url
self.metadata_url = ''

def __init__(self, url:str, base=None, reflect_entities=False, session=None, auth=None, company_name=None):
if company_name:
self.url = "%s/Company('%s')/" % (url.rstrip('/'), requote_uri(company_name))
self.metadata_url = "%s/$metadata#Company('%s')/" % (url.rstrip('/'), requote_uri(company_name))
else:
self.url = "%s/" % (url.rstrip('/'))
self.metadata_url = "%s/$metadata/" % (url.rstrip('/'))

self.collections = {}
self.log = logging.getLogger('odata.service')
self.default_context = Context(auth=auth, session=session)
Expand Down