-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ported to python 3, compatible with python 2 #41
base: master
Are you sure you want to change the base?
Conversation
… <2.6 so supporting both python 2 & 3 is more reasonable
…er between python 2 & 3
…ion outside the exception handler
Conflicts: distribute_setup.py pyamf/adapters/_django_utils_translation.py pyamf/alias.py pyamf/amf3.py
This is awesome! I know what I will be doing this weekend .. |
Glad you're interested :) |
Just a bump. Any progress on this PR? With some additional modifications: diff --git a/pyamf/__init__.py b/pyamf/__init__.py
index 738c5b6..caba861 100644
--- a/pyamf/__init__.py
+++ b/pyamf/__init__.py
@@ -13,7 +13,7 @@ is compatible with the Adobe U{Flash Player
import types
import inspect
-from six import iteritems
+from six import iteritems, text_type
from pyamf import util, _version
from pyamf.adapters import register_adapters
@@ -238,7 +238,7 @@ class ErrorAlias(ClassAlias):
def getEncodableAttributes(self, obj, **kwargs):
attrs = ClassAlias.getEncodableAttributes(self, obj, **kwargs)
- attrs['message'] = unicode(obj)
+ attrs['message'] = text_type(obj)
attrs['name'] = obj.__class__.__name__
return attrs
diff --git a/pyamf/remoting/gateway/__init__.py b/pyamf/remoting/gateway/__init__.py
index 924fe63..f6e1911 100644
--- a/pyamf/remoting/gateway/__init__.py
+++ b/pyamf/remoting/gateway/__init__.py
@@ -317,7 +317,10 @@ class BaseGateway(object):
if isinstance(service, class_types):
name = service.__name__
elif isinstance(service, types.FunctionType):
- name = service.func_name
+ if hasattr(service, 'func_name'):
+ name = service.func_name
+ else:
+ name = service.__name__
elif isinstance(service, types.ModuleType):
name = service.__name__
else:
diff --git a/pyamf/tests/gateway/test_django.py b/pyamf/tests/gateway/test_django.py
index 04f18cb..38c9edd 100644
--- a/pyamf/tests/gateway/test_django.py
+++ b/pyamf/tests/gateway/test_django.py
@@ -16,7 +16,10 @@ import os
try:
from cStringIO import StringIO
except ImportError:
- from StringIO import StringIO
+ try:
+ from StringIO import StringIO
+ except ImportError:
+ from io import StringIO
try:
import django as _django
diff --git a/pyamf/tests/gateway/test_wsgi.py b/pyamf/tests/gateway/test_wsgi.py
index 2f16088..3b661a8 100644
--- a/pyamf/tests/gateway/test_wsgi.py
+++ b/pyamf/tests/gateway/test_wsgi.py
@@ -81,7 +81,7 @@ class WSGIServerTestCase(unittest.TestCase):
response = self.doRequest(request, start_response)
- envelope = remoting.decode(''.join(response))
+ envelope = remoting.decode(b''.join(response))
message = envelope['/1']
@@ -184,7 +184,7 @@ class WSGIServerTestCase(unittest.TestCase):
self.gw.timezone_offset = -18000
response = self.doRequest(self.makeRequest('echo', now), None)
- envelope = remoting.decode(''.join(response))
+ envelope = remoting.decode(b''.join(response))
message = envelope['/1']
self.assertEqual(message.body, now)
diff --git a/pyamf/util/pure.py b/pyamf/util/pure.py
index bde9bbf..9579c82 100644
--- a/pyamf/util/pure.py
+++ b/pyamf/util/pure.py
@@ -118,6 +118,8 @@ class BytesIOProxy(object):
@param s: Raw bytes
"""
+ if isinstance(s, text_type):
+ s = s.encode('utf-8', 'replace')
self._buffer.write(s)
self._len_changed = True
diff --git a/setup.py b/setup.py
index b46cf8c..59bdde7 100644
--- a/setup.py
+++ b/setup.py
@@ -68,7 +68,7 @@ def setup_package():
zip_safe=False,
extras_require=setupinfo.get_extras_require(),
classifiers=(
- filter(None, classifiers.strip().split('\n')) +
+ list(filter(None, classifiers.strip().split('\n'))) +
setupinfo.get_trove_classifiers()
),
**setupinfo.extra_setup_args()) Both I'm using Python 3.4.3 and Python 2.7.10 on Arch Linux. None of cython, django, sqlalchemy, twisted and gae_sdk is installed on my machine. |
Well, I think the patch for setup.py in #54 is better. Ignore mine. |
Inspired by @t0m's efforts, I've ported over everything except for the cython stuff to python 3 this weekend, so that all unit tests pass on python 3.4 and 2.6, except for the following which I don't have the appropriate setup and haven't tested:
It's not intended to be compatible for pythons <=2.5 and there are too many compatibility issues there with python 3, I hope this is ok (I think lots of packages aiming to support python 2 & 3 do the same thing).
Issue #24.