Skip to content
Merged
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
6 changes: 3 additions & 3 deletions pyodata/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ def _fetch_metadata(connection, url, logger):

if resp.status_code != 200:
raise HttpError(
'Metadata request failed, status code: {}, body:\n{}'.format(resp.status_code, resp.content), resp)
f'Metadata request failed, status code: {resp.status_code}, body:\n{resp.content}', resp)

mime_type = resp.headers['content-type']
if not any((typ in ['application/xml', 'text/xml'] for typ in mime_type.split(';'))):
raise HttpError(
'Metadata request did not return XML, MIME type: {}, body:\n{}'.format(mime_type, resp.content),
f'Metadata request did not return XML, MIME type: {mime_type}, body:\n{resp.content}',
resp)

return resp.content
Expand Down Expand Up @@ -73,4 +73,4 @@ def __new__(cls, url, connection, odata_version=ODATA_VERSION_2, namespaces=None

return service

raise PyODataException('No implementation for selected odata version {}'.format(odata_version))
raise PyODataException(f'No implementation for selected odata version {odata_version}')
156 changes: 78 additions & 78 deletions pyodata/v2/model.py

Large diffs are not rendered by default.

38 changes: 19 additions & 19 deletions pyodata/v2/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ def encode_multipart(boundary, http_requests):

for req in http_requests:

lines.append('--{0}'.format(boundary))
lines.append(f'--{boundary}')

if not isinstance(req, MultipartRequest):
lines.extend(('Content-Type: application/http ', 'Content-Transfer-Encoding:binary'))

lines.append('')

# request line (method + path + query params)
line = '{method} {path}'.format(method=req.get_method(), path=req.get_path())
line = f'{req.get_method()} {req.get_path()}'
query_params = '&'.join(['{}={}'.format(key, val) for key, val in req.get_query_params().items()])
if query_params:
line += '?' + query_params
Expand All @@ -63,7 +63,7 @@ def encode_multipart(boundary, http_requests):

# request specific headers
for hdr, hdr_val in req.get_headers().items():
lines.append('{}: {}'.format(hdr, hdr_val))
lines.append(f'{hdr}: {hdr_val}')

lines.append('')

Expand All @@ -76,7 +76,7 @@ def encode_multipart(boundary, http_requests):
# 400 Bad fromat from SAP gateway
lines.append('')

lines.append('--{0}--'.format(boundary))
lines.append(f'--{boundary}--')

return '\r\n'.join(lines)

Expand All @@ -96,7 +96,7 @@ def decode(message):
messages.append(part.get_payload())
return messages

data = "Content-Type: {}\n".format(content_type) + data
data = f"Content-Type: {content_type}\n" + data
parser = Parser()
parsed = parser.parsestr(data)
decoded = decode(parsed)
Expand Down Expand Up @@ -196,7 +196,7 @@ def __init__(self, entity_type, single_key=None, **args):
else:
for key_prop in self._key:
if key_prop.name not in args:
raise PyODataException('Missing value for key property {}'.format(key_prop.name))
raise PyODataException(f'Missing value for key property {key_prop.name}')

self._type = EntityKey.TYPE_COMPLEX

Expand All @@ -220,14 +220,14 @@ def to_key_string_without_parentheses(self):
# raise RuntimeError('Entity key is not complete, missing value of property: {0}'.format(key_prop.name))

key_pairs.append(
'{0}={1}'.format(key_prop.name, key_prop.to_literal(self._proprties[key_prop.name])))
f'{key_prop.name}={key_prop.to_literal(self._proprties[key_prop.name])}')

return ','.join(key_pairs)

def to_key_string(self):
"""Gets the string representation of the key, including parentheses"""

return '({})'.format(self.to_key_string_without_parentheses())
return f'({self.to_key_string_without_parentheses()})'

def __repr__(self):
return self.to_key_string()
Expand Down Expand Up @@ -292,7 +292,7 @@ def add_headers(self, value):
"""

if not isinstance(value, dict):
raise TypeError("Headers must be of type 'dict' not {}".format(type(value)))
raise TypeError(f"Headers must be of type 'dict' not {type(value)}")

self._headers.update(value)

Expand Down Expand Up @@ -420,7 +420,7 @@ def __init__(self, handler, master_key, entity_set_proxy, nav_property):
self._nav_property = nav_property

def get_path(self):
return "{}/{}".format(super(NavEntityGetRequest, self).get_path(), self._nav_property)
return f"{super(NavEntityGetRequest, self).get_path()}/{self._nav_property}"


class EntityCreateRequest(ODataHttpRequest):
Expand Down Expand Up @@ -586,7 +586,7 @@ def set(self, **kwargs):
val = self._entity_type.proprty(key).to_json(val)
except KeyError:
raise PyODataException(
'Property {} is not declared in {} entity type'.format(key, self._entity_type.name))
f'Property {key} is not declared in {self._entity_type.name} entity type')

self._values[key] = val

Expand Down Expand Up @@ -858,7 +858,7 @@ def nav(self, nav_property):
navigation_entity_set = self._service.schema.entity_set(end.entity_set_name, association_info.namespace)

if not navigation_entity_set:
raise PyODataException('No association set for role {}'.format(navigation_property.to_role))
raise PyODataException(f'No association set for role {navigation_property.to_role}')

roles = navigation_property.association.end_roles
if all((role.multiplicity != model.EndRole.MULTIPLICITY_ZERO_OR_MORE for role in roles)):
Expand Down Expand Up @@ -974,7 +974,7 @@ def build_expression(operator, operands):
if len(operands) < 2:
raise ExpressionError('The $filter operator \'{}\' needs at least two operands'.format(operator))

return '({})'.format(' {} '.format(operator).join(operands))
return f"({' {} '.format(operator).join(operands)})"

@staticmethod
def and_(*operands):
Expand All @@ -992,7 +992,7 @@ def or_(*operands):
def format_filter(proprty, operator, value):
"""Creates a filter expression """

return '{} {} {}'.format(proprty.name, operator, proprty.to_literal(value))
return f'{proprty.name} {operator} {proprty.to_literal(value)}'

def __eq__(self, value):
return GetEntitySetFilter.format_filter(self._proprty, 'eq', value)
Expand Down Expand Up @@ -1194,7 +1194,7 @@ def _build_expression(self, field_name, operator, value):

if operator == 'range':
if not isinstance(value, (tuple, list)):
raise TypeError('Range must be tuple or list not {}'.format(type(value)))
raise TypeError(f'Range must be tuple or list not {type(value)}')

if len(value) != 2:
raise ValueError('Only two items can be passed in a range.')
Expand Down Expand Up @@ -1321,7 +1321,7 @@ def nav(self, nav_property, key):

if not navigation_entity_set:
raise PyODataException(
'No association set for role {} {}'.format(navigation_property.to_role, association_set.end_roles))
f'No association set for role {navigation_property.to_role} {association_set.end_roles}')

roles = navigation_property.association.end_roles
if all((role.multiplicity != model.EndRole.MULTIPLICITY_ZERO_OR_MORE for role in roles)):
Expand Down Expand Up @@ -1498,7 +1498,7 @@ def __getattr__(self, name):
return self._entity_sets[name]
except KeyError:
raise AttributeError(
'EntitySet {0} not defined in {1}.'.format(name, ','.join(list(self._entity_sets.keys()))))
f"EntitySet {name} not defined in {','.join(list(self._entity_sets.keys()))}.")


class FunctionContainer:
Expand All @@ -1519,7 +1519,7 @@ def __getattr__(self, name):

if name not in self._functions:
raise AttributeError(
'Function {0} not defined in {1}.'.format(name, ','.join(list(self._functions.keys()))))
f"Function {name} not defined in {','.join(list(self._functions.keys()))}.")

fimport = self._service.schema.function_import(name)

Expand Down Expand Up @@ -1742,7 +1742,7 @@ def get_boundary(self):

def get_default_headers(self):
# pylint: disable=no-self-use
return {'Content-Type': 'multipart/mixed;boundary={}'.format(self.get_boundary())}
return {'Content-Type': f'multipart/mixed;boundary={self.get_boundary()}'}

def get_body(self):
return encode_multipart(self.get_boundary(), self.requests)
Expand Down
2 changes: 1 addition & 1 deletion pyodata/vendor/SAP.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def json_get(obj, member, typ, default=None):

value = obj.get(member, default)
if not isinstance(value, typ):
raise ValueError('%s is not a %s' % (member, typ.__name__))
raise ValueError(f'{member} is not a {typ.__name__}')

return value

Expand Down
10 changes: 5 additions & 5 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def test_create_service_application_xml(metadata):

responses.add(
responses.GET,
"{0}/$metadata".format(SERVICE_URL),
f"{SERVICE_URL}/$metadata",
content_type='application/xml',
body=metadata,
status=200)
Expand All @@ -62,7 +62,7 @@ def test_create_service_text_xml(metadata):

responses.add(
responses.GET,
"{0}/$metadata".format(SERVICE_URL),
f"{SERVICE_URL}/$metadata",
content_type='text/xml',
body=metadata,
status=200)
Expand All @@ -84,7 +84,7 @@ def test_metadata_not_reachable():

responses.add(
responses.GET,
"{0}/$metadata".format(SERVICE_URL),
f"{SERVICE_URL}/$metadata",
content_type='text/html',
status=404)

Expand All @@ -99,7 +99,7 @@ def test_metadata_saml_not_authorized():

responses.add(
responses.GET,
"{0}/$metadata".format(SERVICE_URL),
f"{SERVICE_URL}/$metadata",
content_type='text/html; charset=utf-8',
status=200)

Expand All @@ -116,7 +116,7 @@ def test_client_custom_configuration(mock_warning, metadata):

responses.add(
responses.GET,
"{0}/$metadata".format(SERVICE_URL),
f"{SERVICE_URL}/$metadata",
content_type='application/xml',
body=metadata,
status=200)
Expand Down
Loading