braintree / braintree_python

Braintree Python library
https://developer.paypal.com/braintree/docs/start/overview
MIT License
242 stars 115 forks source link

fix python 3 compatibility for oauth_gateway.py #58

Closed felixonmars closed 9 years ago

felixonmars commented 9 years ago

All unit tests failed with Python 3 with release 3.17.0:

======================================================================
ERROR: Failure: SyntaxError (invalid syntax (oauth_gateway.py, line 37))
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3.4/site-packages/nose/failure.py", line 39, in runTest
    raise self.exc_val.with_traceback(self.tb)
  File "/usr/lib/python3.4/site-packages/nose/loader.py", line 418, in loadTestsFromName
    addr.filename, addr.module)
  File "/usr/lib/python3.4/site-packages/nose/importer.py", line 47, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "/usr/lib/python3.4/site-packages/nose/importer.py", line 94, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File "/usr/lib/python3.4/imp.py", line 235, in load_module
    return load_source(name, filename, file)
  File "/usr/lib/python3.4/imp.py", line 171, in load_source
    module = methods.load()
  File "<frozen importlib._bootstrap>", line 1220, in load
  File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1129, in _exec
  File "<frozen importlib._bootstrap>", line 1471, in exec_module
  File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
  File "/build/python-braintree/src/braintree_python-3.17.0/tests/unit/test_xml_util.py", line 1, in <module>
    from tests.test_helper import *
  File "/build/python-braintree/src/braintree_python-3.17.0/tests/test_helper.py", line 14, in <module>
    from braintree import *
  File "/build/python-braintree/src/braintree_python-3.17.0/braintree/__init__.py", line 7, in <module>
    from braintree.braintree_gateway import BraintreeGateway
  File "/build/python-braintree/src/braintree_python-3.17.0/braintree/braintree_gateway.py", line 10, in <module>
    from braintree.oauth_gateway import OAuthGateway
  File "/build/python-braintree/src/braintree_python-3.17.0/braintree/oauth_gateway.py", line 37
    def clean_values(accumulator, (key, value)):
                                  ^
SyntaxError: invalid syntax

Tuple parameter unpacking was removed since Python 3.0 (PEP 3113), and there is also reference to urllib.quote_plus and reduce() which are not directly usable in Python 3. This PR addresses all what I have found so far and make the tests passing again.

mekza commented 9 years ago

:+1:

ThatHurleyGuy commented 9 years ago

@felixonmars Thanks for the catch here! We'll merge this and get out a new release of the library ASAP

felixonmars commented 9 years ago

My pleasure, and thanks for the fast response :)