Ported to python 3, compatible with python 2#41
Open
simonzack wants to merge 24 commits intohydralabs:masterfrom
Open
Ported to python 3, compatible with python 2#41simonzack wants to merge 24 commits intohydralabs:masterfrom
simonzack wants to merge 24 commits intohydralabs:masterfrom
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
Member
|
This is awesome! I know what I will be doing this weekend .. |
Author
|
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.