Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
audy committed Feb 6, 2019
1 parent a358b7d commit b76410a
Showing 1 changed file with 29 additions and 15 deletions.
44 changes: 29 additions & 15 deletions onecodex/vendored/potion_client/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ class Reference(collections.Mapping):
This implementation makes the assumption that a {$ref} object always points to an object, never an array or
any of the other types.
"""

_client = None
__properties = None

def __init__(self, uri, client=None):
self._status = None
self._uri = uri
self.__properties = {'$uri': uri}
self.__properties = {"$uri": uri}
if client is not None:
self._client = client

Expand Down Expand Up @@ -62,8 +63,7 @@ def __len__(self):
return len(self._properties)

def __repr__(self):
return '{cls}({uri})'.format(cls=self.__class__.__name__,
uri=repr(self._uri))
return "{cls}({uri})".format(cls=self.__class__.__name__, uri=repr(self._uri))


class Resource(Reference):
Expand All @@ -78,7 +78,10 @@ class Resource(Reference):
def __new__(cls, uri=None, **kwargs):
instance = None
if uri is not None:
if not (isinstance(uri, six.string_types) and uri.startswith('/')) and cls._self is not None:
if (
not (isinstance(uri, six.string_types) and uri.startswith("/"))
and cls._self is not None
):
uri = cls._self.href.format(id=uri)

instances = cls._client._instances
Expand All @@ -87,7 +90,7 @@ def __new__(cls, uri=None, **kwargs):
if instance is None:
instance = super(Resource, cls).__new__(cls)
super(Resource, instance).__init__(uri)
instance._properties = {'$uri': uri}
instance._properties = {"$uri": uri}
if not kwargs:
instance._status = None
else:
Expand All @@ -107,7 +110,7 @@ def __init__(self, uri=None, **kwargs):
@property
def id(self):
if self._uri is not None:
id_ = self._uri[self._uri.rfind("/") + 1 :]
id_ = self._uri[self._uri.rfind("/") + 1:]
return id_
return None

Expand All @@ -131,17 +134,23 @@ def first(cls, **params):
try:
return cls._instances(per_page=1, **params)[0]
except IndexError:
raise ItemNotFound("No '{}' item found matching: {}".format(cls.__name__, repr(params)))
raise ItemNotFound(
"No '{}' item found matching: {}".format(cls.__name__, repr(params))
)

@classmethod
def one(cls, **params):
matching = cls._instances(per_page=1, **params)
if len(matching) > 1:
raise MultipleItemsFound("Multiple items found matching: {}".format(repr(params)))
raise MultipleItemsFound(
"Multiple items found matching: {}".format(repr(params))
)
try:
return matching[0]
except IndexError:
raise ItemNotFound("No '{}' item found matching: {}".format(cls.__name__, repr(params)))
raise ItemNotFound(
"No '{}' item found matching: {}".format(cls.__name__, repr(params))
)

@classmethod
def fetch(cls, id):
Expand All @@ -163,19 +172,24 @@ def delete(self):
return self._destroy(id=self.id)

def _repr_html_(self):
return '''<table>
return """<table>
<thead>
<tr>
<th colspan="2"><code>{cls}({id})</code></th>
</tr>
</thead>
<tbody>{properties}</tbody>
</table>'''.format(
</table>""".format(
cls=self.__class__.__name__,
id=escape(repr(self.id)),
properties='\n'.join('<tr><td>{}</td><td><code>{}</code></td>'.format(escape(k),
escape(pformat(v)))
for k, v in self._properties.items() if not k.startswith('$')))
properties="\n".join(
"<tr><td>{}</td><td><code>{}</code></td>".format(
escape(k), escape(pformat(v))
)
for k, v in self._properties.items()
if not k.startswith("$")
),
)

def __repr__(self):
# if self._status == 200:
Expand All @@ -185,4 +199,4 @@ def __repr__(self):
# id=repr(self.id),
# properties=', '.join(parts))
# TODO some way to define a good key for display
return '{cls}({id})'.format(cls=self.__class__.__name__, id=repr(self.id))
return "{cls}({id})".format(cls=self.__class__.__name__, id=repr(self.id))

0 comments on commit b76410a

Please sign in to comment.