PyAPNs
PyAPNs copied to clipboard
Use with python 3
Please update module to use with python 3.
This is far in the future
+1
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
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
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!
+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()
+1 :)
+1
@jmgirven feel free to suggest changes :)