djacobs / PyAPNs

Python library for interacting with the Apple Push Notification service (APNs)
http://pypi.python.org/pypi/apns/
MIT License
1.22k stars 376 forks source link

Python 3 compatibility #106

Closed jmgirven closed 8 years ago

jmgirven commented 9 years ago

This commit takes the current version and makes it compatible with Python 3 (#85). Nothing too complicated. 2to3 does most of the work.

There are no major changes in apns.py, just syntax and explicitly made some parts of the codes bytes to compatible across 2 and 3.

Similar in tests.py. Only line 191-193 needed a small change to account for different ordered dictionaries. An alternative could be test the beginning of the line, the end of the line, and json parse the middle and compare.

jimhorng commented 9 years ago

to make code py3 compatible is good, however, it's better to keep py2 function's behavior when running by py2, for example xrange(), if you turn xrange() into range() which becomes a list instead of iterator, that will harm resource consumption and performance. Maybe you can take reference from cheetsheet use pip install future

# Python 2 and 3: backward-compatible
from past.builtins import xrange
for i in xrange(10**8):
    ...
ExplodingCabbage commented 8 years ago

@jimhorng I don't think the range vs xrange performance difference is worth caring about here. We're talking about sometimes creating a list of 10 integers when you otherwise wouldn't have to. That really, really doesn't matter in the grand scheme of things; it's not worth adding any complexity to the code just to avoid creating a list of 10 ints.

jimhorng commented 8 years ago

@ExplodingCabbage agreed +1