fulfilio / python-magento

Python API to access magento API
BSD 3-Clause "New" or "Revised" License
47 stars 61 forks source link

Python 3 support #4

Closed tomaszsmolarek closed 8 years ago

tomaszsmolarek commented 8 years ago

Per @sharoonthomas's request from https://github.com/openlabs/magento/issues/23

Seems like @giampaolo's patch works perfectly and allows to use code with python 3. Can we please add that to repo?

diff --git a/magento/api.py b/magento/api.py
index dc7c085..bda6977 100644
--- a/magento/api.py
+++ b/magento/api.py
@@ -9,9 +9,14 @@
     :license: AGPLv3, see LICENSE for more details
 '''

+import sys
+
 PROTOCOLS = []
 try:
-    from xmlrpclib import ServerProxy
+    if sys.version_info <= (2, ):
+        from xmlrpclib import ServerProxy
+    else:
+        from xmlrpc.client import ServerProxy
 except ImportError:
     pass
 else:
diff --git a/setup.py b/setup.py
index 16a1c32..ba9a7cb 100644
--- a/setup.py
+++ b/setup.py
@@ -8,10 +8,11 @@
     :license: AGPLv3, see LICENSE for more details

 '''
+
 import os
 from setuptools import setup

-execfile(os.path.join('magento', 'version.py'))
+exec(open(os.path.join('magento', 'version.py')).read())

 setup(
     name = 'magento',
@@ -26,15 +27,17 @@ setup(
     zip_safe=False,
     platforms='any',
     install_requires=[
-        'suds>=0.3.9',
+        'suds-jurko',
     ],
     classifiers=[
         'Development Status :: 6 - Mature',
         'Environment :: Web Environment',
         'Intended Audience :: Developers',
-        'License :: OSI Approved :: GNU Affero General Public License v3', 
+        'License :: OSI Approved :: GNU Affero General Public License v3',
         'Operating System :: OS Independent',
         'Programming Language :: Python',
+        'Programming Language :: Python :: 2',
+        'Programming Language :: Python :: 3',
         'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
         'Topic :: Software Development :: Libraries :: Python Modules'
     ],

Above code is written by @giampaolo.

listingmirror commented 8 years ago

+1 to merging Python 3 support. We have a bunch of forks for this which seems silly. Anything I can do to help get it merged?

sharoonthomas commented 8 years ago

Happy to merge a pull request

listingmirror commented 8 years ago

Perfect will prepare one today. Have used my fork for a few months and had success in python3

listingmirror commented 8 years ago

@sharoonthomas done at https://github.com/fulfilio/python-magento/pull/9

sharoonthomas commented 8 years ago

@listingmirror merged. Thanks for your contribution 👍