Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@classmethod
def exists(cls, id_, **kwargs):
"""Check whether a resource exists.
Args:
id_: The id or other key which specifies a unique object.
kwargs: Any keyword arguments for query.
Returns:
True if the resource is found, False otherwise.
"""
prefix_options, query_options = cls._split_options(kwargs)
path = cls._element_path(id_, prefix_options, query_options)
try:
_ = cls.connection.head(path, cls.headers)
return True
except connection.Error:
return False
try:
self.errors.clear()
if self.id:
response = self.klass.connection.put(
self._element_path(self.id, self._prefix_options),
self.klass.headers,
data=self.to_xml())
else:
response = self.klass.connection.post(
self._collection_path(self._prefix_options),
self.klass.headers,
data=self.to_xml())
new_id = self._id_from_response(response)
if new_id:
self.id = new_id
except connection.ResourceInvalid, err:
self.errors.from_xml(err.response.body)
return False
try:
attributes = self.klass.format.decode(response.body)
except formats.Error:
return True
if attributes:
self._update(attributes)
return True
def _open(self, *args, **kwargs):
self.response = None
try:
self.response = super(ShopifyConnection, self)._open(*args, **kwargs)
except pyactiveresource.connection.ConnectionError as err:
self.response = err.response
raise
return self.response