From 45a2e777b2b397078f47dee77ca7c125963ed91f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Ch=C4=99=C4=87?= Date: Fri, 30 May 2014 13:50:51 +0200 Subject: [PATCH 1/7] Refactor proxy. --- smsapi/proxy.py | 56 ++++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/smsapi/proxy.py b/smsapi/proxy.py index 6273ea5..c9005f9 100644 --- a/smsapi/proxy.py +++ b/smsapi/proxy.py @@ -17,10 +17,10 @@ from mimetools import choose_boundary except ImportError: from uuid import uuid4 - + def choose_boundary(): return str(uuid4()) - + if sys.version_info[0] == 3: text_type = str @@ -33,7 +33,7 @@ class ApiProxyError(Exception): class ApiProxy(object): - + def __init__(self, hostname=None, data=None): super(ApiProxy, self).__init__() @@ -51,21 +51,21 @@ def execute(self): class ApiHttpProxy(ApiProxy): - + user_agent = 'PySmsAPI' - + def __init__(self, hostname=None, data=None): super(ApiHttpProxy, self).__init__(hostname, data) - + self.headers = {} - + self.body = {} - + def execute(self, uri=None, data=None): - + if isinstance(data, dict): - self.data.update(data) - + self.data.update(data) + headers, body = self.prepare_request() response = None @@ -73,7 +73,7 @@ def execute(self, uri=None, data=None): if isinstance(self.hostname, (list, tuple)): for host in self.hostname: response = self.connect(host, uri, body, headers) - + if response and response.getcode() == 200: break else: @@ -81,20 +81,20 @@ def execute(self, uri=None, data=None): if not response: raise ApiProxyError("Unable connect to the specified url: %s" % str(self.hostname)) - + return response - + def connect(self, hostname, uri, body, headers): try: uri = uri or '' if hostname.endswith('/'): url = hostname + uri else: - url = '%s/%s' % (hostname, uri) + url = '%s/%s' % (hostname, uri) req = Request(url, body, headers) response = urlopen(req) - + return response except (URLError, ValueError): return False @@ -104,7 +104,7 @@ def add_file(self, filepath): self.files.append(filepath) else: raise ValueError('Argument must be a file.') - + def prepare_request(self): headers = { @@ -112,22 +112,22 @@ def prepare_request(self): } if isinstance(self.data, dict): - self.data.update(self.data) - + self.data.update(self.data) + if self.files: content_type, data = self.encode_multipart_data() headers.update({ - 'Content-Type': content_type, + 'Content-Type': content_type, 'Content-Length': str(len(data)) }) else: headers.update({ 'Content-type': "application/x-www-form-urlencoded; charset=utf-8" }) - + data = urlencode(self.data) - + return headers, data def encode_multipart_data(self): @@ -136,30 +136,30 @@ def encode(data): if isinstance(data, text_type): data = data.encode('utf-8') return data - + boundary = choose_boundary() body = BytesIO() - + for (key, value) in self.data.items(): body.write(encode('--%s\r\n' % boundary)) body.write(encode('Content-Disposition: form-data; name="%s"' % key)) body.write(encode('\r\n\r\n' + value + '\r\n')) - + for _file in self.files: body.write(encode('--%s\r\n' % boundary)) body.write(encode('Content-Disposition: form-data; name="file"; filename="%s"\r\n' % _file)) body.write(encode('Content-Type: %s\r\n' % mimetypes.guess_type(_file)[0] or 'application/octet-stream')) body.write(encode('\r\n')) - + try: with open(_file, 'rb') as f: data = f.read() body.write(encode(data)) except IOError: raise - - body.write(encode('\r\n')) + + body.write(encode('\r\n')) body.write(encode('--%s--\r\n\r\n' % boundary)) From a2b60963bfa75c805dcbd099c948cc920489e272 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Ch=C4=99=C4=87?= Date: Fri, 30 May 2014 13:51:19 +0200 Subject: [PATCH 2/7] Fix creating requests for python3. --- smsapi/proxy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/smsapi/proxy.py b/smsapi/proxy.py index c9005f9..3f95e6c 100644 --- a/smsapi/proxy.py +++ b/smsapi/proxy.py @@ -92,7 +92,7 @@ def connect(self, hostname, uri, body, headers): else: url = '%s/%s' % (hostname, uri) - req = Request(url, body, headers) + req = Request(url, body.encode('UTF-8'), headers) response = urlopen(req) return response From 5d580a216812fac1146f7ec38d62469cb2544f6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Ch=C4=99=C4=87?= Date: Fri, 30 May 2014 13:57:31 +0200 Subject: [PATCH 3/7] Bump version to 1.0_beta.pozytywnie. --- smsapi/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/smsapi/__init__.py b/smsapi/__init__.py index 61f67b0..c161c5b 100644 --- a/smsapi/__init__.py +++ b/smsapi/__init__.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- __title__ = 'SmsApi' -__version__ = '1.0_beta' +__version__ = '1.0_beta.pozytywnie' __author__ = 'SMSAPI' __license__ = 'Apache 2.0' __copyright__ = 'Copyright 2013 SMSAPI' From b45d5fbf9184c213f4645d3a9dfc48be5b17f8f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Ch=C4=99=C4=87?= Date: Fri, 11 Jul 2014 16:13:06 +0200 Subject: [PATCH 4/7] Prepare setup.py for pypi submission. --- setup.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/setup.py b/setup.py index 3465d7c..cec1b8e 100644 --- a/setup.py +++ b/setup.py @@ -14,13 +14,13 @@ from distutils.core import setup setup( - name='smsapi', + name='smsapi-pozytywnie', version=smsapi.__version__, description='Python library for manage SmsApi account via HTTP/S', long_description=open('README.md').read(), author='SMSAPI', author_email='bok@smsapi.pl', - url='https://github.com/smsapi/python-client', + url='https://github.com/Kern3l/smsapi-python-client', packages=['smsapi', 'smsapi.actions'], package_data={'': ['LICENSE', 'NOTICE'], 'requests': ['*.pem']}, package_dir={'smsapi': 'smsapi'}, @@ -29,13 +29,12 @@ classifiers=( 'Development Status :: 4 - Beta', 'Intended Audience :: Developers', - 'License :: Apache 2.0', - 'Topic :: Communications :: Mobile messages' + 'License :: OSI Approved :: Apache Software License', 'Topic :: Internet :: WWW/HTTP', - 'Topic :: Software Development :: Libraries :: Python Modules' + 'Topic :: Software Development :: Libraries :: Python Modules', 'Programming Language :: Python :: 2.6', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3.3', ), test_suite='tests.suite' -) \ No newline at end of file +) From 0697cba0a33b2e0bfc6c20944535da3604d0d4f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Ch=C4=99=C4=87?= Date: Fri, 11 Jul 2014 16:38:19 +0200 Subject: [PATCH 5/7] Add MANIFEST.in. --- MANIFEST.in | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 MANIFEST.in diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..04f196a --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,2 @@ +include README.md +include LICENSE From 434dd2cdfd23979528c87d4b393bdcde5ad70848 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Ch=C4=99=C4=87?= Date: Fri, 11 Jul 2014 16:38:41 +0200 Subject: [PATCH 6/7] Fix setup.py. --- setup.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/setup.py b/setup.py index cec1b8e..40796d2 100644 --- a/setup.py +++ b/setup.py @@ -17,7 +17,6 @@ name='smsapi-pozytywnie', version=smsapi.__version__, description='Python library for manage SmsApi account via HTTP/S', - long_description=open('README.md').read(), author='SMSAPI', author_email='bok@smsapi.pl', url='https://github.com/Kern3l/smsapi-python-client', @@ -25,7 +24,6 @@ package_data={'': ['LICENSE', 'NOTICE'], 'requests': ['*.pem']}, package_dir={'smsapi': 'smsapi'}, include_package_data=True, - license=open('LICENSE').read(), classifiers=( 'Development Status :: 4 - Beta', 'Intended Audience :: Developers', From 1dbb1538b16c9ec76ab7763581c4394e353f3d6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Ch=C4=99=C4=87?= Date: Fri, 11 Jul 2014 16:39:04 +0200 Subject: [PATCH 7/7] Bump version number. --- smsapi/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/smsapi/__init__.py b/smsapi/__init__.py index 61f67b0..cc57cd8 100644 --- a/smsapi/__init__.py +++ b/smsapi/__init__.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- __title__ = 'SmsApi' -__version__ = '1.0_beta' +__version__ = '1.0_beta3' __author__ = 'SMSAPI' __license__ = 'Apache 2.0' __copyright__ = 'Copyright 2013 SMSAPI'