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 diff --git a/setup.py b/setup.py index 3465d7c..40796d2 100644 --- a/setup.py +++ b/setup.py @@ -14,28 +14,25 @@ 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'}, include_package_data=True, - license=open('LICENSE').read(), 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 +) 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' diff --git a/smsapi/proxy.py b/smsapi/proxy.py index 6273ea5..3f95e6c 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) + req = Request(url, body.encode('UTF-8'), 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))