Skip to content

Commit

Permalink
Accepted pull request that handles enums.
Browse files Browse the repository at this point in the history
Accepted pull request that makes query extendable.
Accepted pull request that fixes query encoding.

Made the mako templates respect python formatting a bit better, makes the files bigger but the IDEs shouldn't complain as much.
Made the service work with URLs that do not end in /

Changelog: added
eblis committed Oct 9, 2024
1 parent de4e4f8 commit e5d01c0
Showing 5 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion odata/reflect-templates/entity.mako
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

<%page args="name, entity"/>\
<% short_name = name.split(".")[-1] %>\
class ${short_name}(ReflectionBase):
@@ -22,4 +23,3 @@ None
<% attr = getattr(entity, nav_prop['name']) %>\
<%include file="nav_property.mako" args="nav_property=attr, values=nav_prop"/>
%endfor

4 changes: 3 additions & 1 deletion odata/reflect-templates/enum_entity.mako
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@


<%page args="name, entity"/>\
<% short_name = name.split(".")[-1] %>\
${short_name} = Enum("${short_name}", {\
%for prop in entity:
"${prop.name}" : "${prop.value}",\
"${prop.name}": "${prop.value}", \
%endfor
})
7 changes: 6 additions & 1 deletion odata/reflect-templates/main.mako
Original file line number Diff line number Diff line change
@@ -22,25 +22,30 @@ from odata.entity import EntityBase
from odata.property import StringProperty, IntegerProperty, NavigationProperty, DatetimeProperty, DecimalProperty, FloatProperty, BooleanProperty, UUIDProperty
from odata.enumtype import EnumType, EnumTypeProperty


class ReflectionBase(EntityBase):
pass

# ************ Start enum type definitions ************
%for type_name in enum_types:
<%include file="enum_entity.mako" args="name=type_name, entity=enum_types[type_name]"/>
%endfor


# ************ End enum type definitions ************

# ************ Start type definitions ************
%for type_name in types:
<%include file="entity.mako" args="name=type_name, entity=types[type_name]"/>
%endfor
# ************ End type definitions ************

# ************ End type definitions ************

# ************ Start entity definitions ************

%for entity in entities:
<%include file="entity.mako" args="name=entity, entity=entities[entity]"/>
%endfor

# ************ End entity definitions ************

8 changes: 4 additions & 4 deletions odata/service.py
Original file line number Diff line number Diff line change
@@ -87,9 +87,9 @@ class ODataService(object):
:param quiet_progress: Don't show any progress information while reflecting metadata and while other long duration tasks are running. Default is to show progress
:raises ODataConnectionError: Fetching metadata failed. Server returned an HTTP error code
"""
def __init__(self, url, base=None, reflect_entities=False, reflect_output_package: Optional[str] = None, session=None, extra_headers: dict = None, auth=None, quiet_progress=False):
self.url = url
self.metadata_url = urllib.parse.urljoin(url + "/", "$metadata")
def __init__(self, url: str, base=None, reflect_entities=False, reflect_output_package: Optional[str] = None, session=None, extra_headers: dict = None, auth=None, quiet_progress=False):
self.url = url if url.endswith("/") else url + "/" # make sure url ends with / otherwise we have problems
self.metadata_url = urllib.parse.urljoin(self.url, "$metadata")
self.collections = {}
self.log = logging.getLogger('odata.service')
self.default_context = Context(auth=auth, session=session, extra_headers=extra_headers)
@@ -156,7 +156,7 @@ def __init__(self, url, base=None, reflect_entities=False, reflect_output_packag
if reflect_output_package:
self._write_reflected_types(metadata_url=self.metadata_url, package=reflect_output_package)

self.Entity.__odata_url_base__ = url
self.Entity.__odata_url_base__ = self.url
self.Entity.__odata_service__ = self

def __repr__(self):
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "python-odata"
version = "0.5.8"
version = "0.6.0"
description = "A simple library for read/write access to OData services."
license="MIT"
authors = ["Tuomas Mursu <tuomas.mursu@kapsi.fi>", "Cristian Libotean <eblis102@gmail.com>"]

0 comments on commit e5d01c0

Please sign in to comment.