samiamim / apns-python-wrapper

Automatically exported from code.google.com/p/apns-python-wrapper
0 stars 0 forks source link

Still doesn't handle unicode strings #7

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Steps to reproduce:
>>> import APNSWrapper
>>> a = APNSWrapper.APNSNotification()
>>> a.alert(u"BLAHBLAHBLAH")
<APNSWrapper.notifications.APNSNotification object at 0x426c70>
>>> a.badge(4)
>>> a.tokenHex(<YOUR_KEY_HERE>)
<APNSWrapper.notifications.APNSNotification object at 0x426c70>
>>> b = APNSWrapper.APNSNotificationWrapper(certificate=<PATH_TO_YOUR_FILE>, 
sandbox=True)
>>> b.append(a)
>>> b.notify()
True

The device will set the badge correctly (to 4) but it won't show any alert 
message. This is because there is no alert message sent, since it's unicode.

I've included a patch below.

--- a/APNSWrapper/notifications.py  Wed May 19 21:41:49 2010 +0300
+++ b/APNSWrapper/notifications.py  Wed Jul 07 11:50:51 2010 -0400
@@ -324,6 +324,9 @@
             if isinstance(self.alertObject, str):
                 alertArgument = _doublequote(self.alertObject)
                 apsKeys.append('"alert":"%s"' % alertArgument)
+            elif isinstance(self.alertObject, unicode):
+                alertArgument = _doublequote(self.alertObject.encode("utf-8"))
+                apsKeys.append('"alert":"%s"' % alertArgument)
             elif isinstance(self.alertObject, APNSAlert):
                 alertArgument = self.alertObject._build()
                 apsKeys.append('"alert":{%s}' % alertArgument)

Original issue reported on code.google.com by appfirst...@gmail.com on 7 Jul 2010 at 3:59

GoogleCodeExporter commented 9 years ago
APNSProperty does not also handle unicode as the data.

if not isinstance(data, (int, str, list, tuple, float)):
should be:
if not isinstance(data, (int, str, list, tuple, float, unicode)):

Original comment by 9th...@gmail.com on 8 Jul 2010 at 8:57

GoogleCodeExporter commented 9 years ago
I also run into this issue and had to encode the msg in UTF-8 before pushing it 
: 
msg.encode("utf-8")

Morever, I'm having issue trying to push  the '\n' char in a message like "This 
is a \n test". Did anybody manage to achieve that ? :/

Original comment by lionel.g...@gmail.com on 7 Jul 2011 at 1:43

GoogleCodeExporter commented 9 years ago
I working on it these days so there's a lot of changes is coming - so please, 
be patient, I will release new version if few days

Original comment by klymys...@gmail.com on 14 Jul 2011 at 9:31

GoogleCodeExporter commented 9 years ago
This bombs:
   alert.loc_args([u"Márcio"])

I had to patch line 73 of notifications.py to look like this:

self.locArgs = [ '"%s"'.encode('utf8') % x.encode('utf8') for x in la ]

Original comment by march...@fui.ai on 21 Sep 2012 at 2:16

GoogleCodeExporter commented 9 years ago
Make that 

     self.locArgs = [ '"%s"'.encode('utf8') % unicode(x).encode('utf8') for x in la ]

(so that it can eat any values, like teh original code).

Original comment by march...@fui.ai on 21 Sep 2012 at 2:21