Permalink
Browse files

Add support for python 2.5.

  • Loading branch information...
1 parent 2b589c5 commit 07785ead59fc1da1d35c0be6e765e742b00917ea @dylanahsmith dylanahsmith committed Sep 2, 2011
Showing with 47 additions and 42 deletions.
  1. +5 −1 CHANGELOG
  2. +23 −22 lib/resources.py
  3. +2 −2 lib/session.py
  4. +16 −16 scripts/shopify_api.py
  5. +1 −1 setup.py
View
@@ -1,6 +1,10 @@
+== Version 0.1.2
+
+* Add python 2.5 compatibility
+
== Version 0.1.1
-* Make creating a session simpler wtih django
+* Make creating a session simpler with django
== Version 0.1.0
View
@@ -18,28 +18,29 @@ def encode(self, options):
# pyactiveresource (version 1.0.1) doesn't support encoding to_json
return pyactiveresource.util.to_xml(options)
- @property
- def primary_key(self):
+ def __get_primary_key(self):
return self._primary_key
- @primary_key.setter
- def primary_key(self, value):
+ def __set_primary_key(self, value):
self._primary_key = value
- @property
- def id(self):
+ primary_key = property(__get_primary_key, __set_primary_key, None,
+ 'Primary key to identity the resource (defaults to "id")')
+
+ def __get_id(self):
if self._primary_key != "id":
return getattr(self, self._primary_key)
else:
return super(self.__class__, self).__getattr__("id")
- @id.setter
- def id(self, value):
+ def __set_id(self, value):
if self._primary_key != "id":
return setattr(self, self._primary_key, value)
else:
return super(self.__class__, self).__setattr__("id", value)
+ id = property(__get_id, __set_id, None, 'Value stored in the primary key')
+
class Shop(ShopifyResource):
@classmethod
def current(cls):
@@ -127,7 +128,7 @@ def price_range(self):
min_price = min(prices)
max_price = max(prices)
if min_price != max_price:
- return "{0} - {1}".format(f % min_price, f % max_price)
+ return "%f - %f" % (f % min_price, f % max_price)
else:
return f % min_price
@@ -150,15 +151,15 @@ class Variant(ShopifyResource):
@classmethod
def prefix(cls, options={}):
product_id = options.get("product_id")
- return "/admin/" if product_id is None else "/admin/products/{0}".format(product_id)
+ return "/admin/" if product_id is None else "/admin/products/%s" % (product_id)
class Image(ShopifyResource):
_prefix_source = "/admin/products/$product_id/"
def __getattr__(self, name):
if name in ["pico", "icon", "thumb", "small", "compact", "medium", "large", "grande", "original"]:
- return re.sub(r"/(.*)\.(\w{2,4})", r"\1_{0}.\2".format(name), self.src)
+ return re.sub(r"/(.*)\.(\w{2,4})", r"\1_%s.\2" % (name), self.src)
else:
return super(self.__class__, self).__getattr__(name)
@@ -201,7 +202,7 @@ class Metafield(ShopifyResource):
@classmethod
def prefix(cls, options={}):
- return "/admin/" if options.get("resource") is None else "/admin/{0}/{1}".format(options["resource"], options["resource_id"])
+ return "/admin/" if options.get("resource") is None else "/admin/%s/%s" % (options["resource"], options["resource_id"])
class Comment(ShopifyResource):
@@ -241,7 +242,7 @@ class Event(ShopifyResource):
@classmethod
def prefix(cls, options={}):
- return "/admin/" if options.get("resource") is None else "/admin/{0}/{1}/".format(options["resource"], options["resource_id"])
+ return "/admin/" if options.get("resource") is None else "/admin/%s/%s/" % (options["resource"], options["resource_id"])
class Customer(ShopifyResource):
@@ -262,14 +263,14 @@ class Asset(ShopifyResource):
@classmethod
def prefix(cls, options={}):
- return "/admin/" if options.get("theme_id") is None else "/admin/themes/{0}/".format(options["theme_id"])
+ return "/admin/" if options.get("theme_id") is None else "/admin/themes/%s/" % (options["theme_id"])
@classmethod
def _element_path(cls, id, prefix_options={}, query_options=None):
if query_options is None:
prefix_options, query_options = cls._split_options(prefix_options)
- return "{0}{1}.{2}{3}".format(cls.prefix(prefix_options), cls.plural,
- cls.format.extension, cls._query_string(query_options))
+ return "%s%s.%s%s" % (cls.prefix(prefix_options), cls.plural,
+ cls.format.extension, cls._query_string(query_options))
@classmethod
def find(cls, key=None, **kwargs):
@@ -282,22 +283,22 @@ def find(cls, key=None, **kwargs):
params = {"asset[key]": key}
params.update(kwargs)
theme_id = params.get("theme_id")
- path_prefix = "/admin/themes/{0}".format(theme_id) if theme_id else "/admin"
- return cls.find_one("{0}/assets.{1}".format(path_prefix, cls.format.extension), **params)
+ path_prefix = "/admin/themes/%s" % (theme_id) if theme_id else "/admin"
+ return cls.find_one("%s/assets.%s" % (path_prefix, cls.format.extension), **params)
- @property
- def value(self):
+ def __get_value(self):
data = self.attributes.get("value")
if data:
return data
data = self.attributes.get("attachment")
if data:
return base64.b64decode(data)
- @value.setter
- def value(self, data):
+ def __set_value(self, data):
self.attach(data)
+ value = property(__get_value, __set_value, None, "The asset's value or attachment")
+
def attach(self, data):
self.attachment = base64.b64encode(data)
View
@@ -77,11 +77,11 @@ def shop(self):
@classmethod
def create_permission_url(cls, shop_url):
shop_url = cls.__prepare_url(shop_url)
- return "{0}://{1}/admin/api/auth?api_key={2}".format(cls.protocol, shop_url, cls.api_key)
+ return "%s://%s/admin/api/auth?api_key=%s" % (cls.protocol, shop_url, cls.api_key)
@property
def site(self):
- return "{0}://{1}:{2}@{3}/admin".format(self.protocol, self.api_key, self.__computed_password(), self.url)
+ return "%s://%s:%s@%s/admin" % (self.protocol, self.api_key, self.__computed_password(), self.url)
def __computed_password(self):
return md5(self.secret + self.token).hexdigest()
View
@@ -52,7 +52,7 @@ def run_task(cls, task=None, *args):
if len(matches) == 1:
task = matches[0]
else:
- print >>sys.stderr, 'Could not find task "{0}".'.format(task)
+ print >>sys.stderr, 'Could not find task "%s".' % (task)
task_func = getattr(cls, task)
task_func(*args)
@@ -64,7 +64,7 @@ def help(cls, task=None):
usage_list = []
for task in iter(cls._tasks):
task_func = getattr(cls, task)
- usage_string = " {0} {1}".format(cls._prog, task_func.usage)
+ usage_string = " %s %s" % (cls._prog, task_func.usage)
desc = task_func.__doc__.splitlines()[0]
usage_list.append((usage_string, desc))
max_len = reduce(lambda m, item: max(m, len(item[0])), usage_list, 0)
@@ -73,15 +73,15 @@ def help(cls, task=None):
for line, desc in usage_list:
task_func = getattr(cls, task)
if desc:
- line = "{0}{1} # {2}".format(line, " " * (max_len - len(line)), desc)
+ line = "%s%s # %s" % (line, " " * (max_len - len(line)), desc)
if len(line) > cols:
line = line[:cols - 3] + "..."
print(line)
else:
task_func = getattr(cls, task)
print("Usage:")
- print(" {0} {1}".format(cls._prog, task_func.usage))
- print()
+ print(" %s %s" % (cls._prog, task_func.usage))
+ print("")
print(task_func.__doc__)
@@ -108,12 +108,12 @@ def add(cls, connection):
raise ConfigFileError("There is already a config file at " + filename)
else:
config = dict(protocol='https')
- domain = raw_input("Domain? (leave blank for {0}.myshopify.com) ".format(connection))
+ domain = raw_input("Domain? (leave blank for %s.myshopify.com) " % (connection))
if not domain.strip():
- domain = "{0}.myshopify.com".format(connection)
+ domain = "%s.myshopify.com" % (connection)
config['domain'] = domain
- print()
- print("open https://{0}/admin/api in your browser to get API credentials".format(domain))
+ print("")
+ print("open https://%s/admin/api in your browser to get API credentials" % (domain))
config['api_key'] = raw_input("API key? ")
config['password'] = raw_input("Password? ")
if not os.path.isdir(cls._shop_config_dir):
@@ -144,7 +144,7 @@ def edit(cls, connection=None):
if editor:
subprocess.call([editor, filename])
else:
- print "Please set an editor in the EDITOR environment variable"
+ print("Please set an editor in the EDITOR environment variable")
else:
cls._no_config_file_error(filename)
@@ -156,8 +156,8 @@ def show(cls, connection=None):
connection = cls._default_connection()
filename = cls._get_config_filename(connection)
if os.path.exists(filename):
- print filename
- print file(filename).read()
+ print(filename)
+ print(file(filename).read())
else:
cls._no_config_file_error(filename)
@@ -187,7 +187,7 @@ def console(cls, connection=None):
cls._no_config_file_error(filename)
config = yaml.safe_load(file(filename).read())
- print("using {0}".format(config["domain"]))
+ print("using %s" % (config["domain"]))
shopify.ShopifyResource.site = cls._get_site_from_config(config)
start_interpreter(shopify=shopify)
@@ -225,7 +225,7 @@ def _get_site_from_config(cls, config):
api_key = config.get("api_key")
password = config.get("password")
domain = config.get("domain")
- return "{0}://{1}:{2}@{3}/admin".format(protocol, api_key, password, domain)
+ return "%s://%s:%s@%s/admin" % (protocol, api_key, password, domain)
@classmethod
def _is_default(cls, connection):
@@ -237,5 +237,5 @@ def _no_config_file_error(cls, filename):
try:
Tasks.run_task(*sys.argv[1:])
-except ConfigFileError as e:
- print e
+except ConfigFileError, e:
+ print(e)
View
@@ -1,7 +1,7 @@
from distutils.core import setup
NAME='ShopifyAPI'
-VERSION='0.1.1'
+VERSION='0.1.2'
DESCRIPTION='Shopify API for Python'
LONG_DESCRIPTION="""\
The ShopifyAPI library allows python developers to programmatically

0 comments on commit 07785ea

Please sign in to comment.