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

Use with python 3 #85

Open ghost opened 9 years ago

ghost commented 9 years ago

Please update module to use with python 3.

djacobs commented 9 years ago

This is far in the future

aechiara commented 9 years ago

+1

jbg commented 9 years ago

Any idea what would be necessary to support Python 3? I haven’t written any code targeting Python 2.x in over a year now, but need to implement APNS and am having trouble finding an APNS library that works & supports Python 3. I’d rather spend some effort improving this library than start another one!

I get this when trying to pip install apns on Python 3.4:

error: file '/home/.../venv/build/apns/apns-send' does not exist
aechiara commented 9 years ago

I was able to install into Python 3.4 venv, my problem was executing it. If i remember correctly the problem was related to character encoding when converting to bytes in order to make the request

jbg commented 9 years ago

After writing the above, I cloned the git repository rather than using the release on PyPi and was able to install it without trouble.

I had to replace a couple of cases of except Exception, e: with except Exception as e: and replace a couple of uses of xrange with range, and then I was able to send APNS notifications. Nice!

jmgirven commented 9 years ago

+1

Python 2to3 agrees with you about changing the uses of except Exception, e: and xrange.

It seems tests.py needs some conversions between bytes and strings as well. It seems achievable, but having only just discovered the library, I am avoiding jumping in and suggesting changes.

2to3 results for tests.py:

@@ -102,7 +102,7 @@
         feedback_server._chunks = mock_chunks_generator

         i = 0;
-        for (token_hex, fail_time) in feedback_server.items():
+        for (token_hex, fail_time) in list(feedback_server.items()):
             self.assertEqual(token_hex, mock_tokens[i])
             i += 1
         self.assertEqual(i, NUM_MOCK_TOKENS)
@@ -204,9 +204,9 @@
             '.' * (max_raw_payload_bytes + 1))

         # Test unicode 2-byte characters payload
-        Payload(u'\u0100' * int(max_raw_payload_bytes / 2))
+        Payload('\u0100' * int(max_raw_payload_bytes / 2))
         self.assertRaises(PayloadTooLargeError, Payload,
-            u'\u0100' * (int(max_raw_payload_bytes / 2) + 1))
+            '\u0100' * (int(max_raw_payload_bytes / 2) + 1))

 if __name__ == '__main__':
     unittest.main()
alexzrh commented 9 years ago

+1 :)

adminq80 commented 8 years ago

+1

djacobs commented 8 years ago

@jmgirven feel free to suggest changes :)