@@ -29,22 +29,16 @@ def group_response(response, registration_ids, key):
2929 # Pair up results and reg_ids
3030 mapping = zip (registration_ids , response ['results' ])
3131 # Filter by key
32- filtered = filter (lambda x : key in x [1 ], mapping )
33- # Only consider the value in the dict
34- tupled = [(s [0 ], s [1 ][key ]) for s in filtered ]
32+ filtered = ((reg_id , res [key ]) for reg_id , res in mapping if key in res )
3533 # Grouping of errors and mapping of ids
3634 if key is 'registration_id' :
37- grouping = {}
38- for k , v in tupled :
39- grouping [k ] = v
35+ grouping = dict (filtered )
4036 else :
4137 grouping = defaultdict (list )
42- for k , v in tupled :
38+ for k , v in filtered :
4339 grouping [v ].append (k )
4440
45- if len (grouping ) == 0 :
46- return
47- return grouping
41+ return grouping or None
4842
4943
5044def urlencode_utf8 (params ):
@@ -56,7 +50,7 @@ def urlencode_utf8(params):
5650 if hasattr (params , 'items' ):
5751 params = params .items ()
5852
59- params = (
53+ params = (
6054 '=' .join ((
6155 urllib .quote_plus (k .encode ('utf8' ), safe = '/' ),
6256 urllib .quote_plus (v .encode ('utf8' ), safe = '/' )
@@ -69,8 +63,8 @@ def urlencode_utf8(params):
6963class GCM (object ):
7064
7165 # Timeunit is milliseconds.
72- BACKOFF_INITIAL_DELAY = 1000 ;
73- MAX_BACKOFF_DELAY = 1024000 ;
66+ BACKOFF_INITIAL_DELAY = 1000
67+ MAX_BACKOFF_DELAY = 1024000
7468
7569 def __init__ (self , api_key , url = GCM_URL , proxy = None ):
7670 """ api_key : google api key
@@ -80,9 +74,9 @@ def __init__(self, api_key, url=GCM_URL, proxy=None):
8074 self .api_key = api_key
8175 self .url = url
8276 if proxy :
83- if isinstance (proxy ,basestring ):
77+ if isinstance (proxy , basestring ):
8478 protocol = url .split (':' )[0 ]
85- proxy = {protocol :proxy }
79+ proxy = {protocol : proxy }
8680
8781 auth = urllib2 .HTTPBasicAuthHandler ()
8882 opener = urllib2 .build_opener (urllib2 .ProxyHandler (proxy ), auth , urllib2 .HTTPHandler )
0 commit comments