Use urllib.urlencode for encoding heavy lifting in entrez.py.
authorW. Trevor King <wking@drexel.edu>
Sat, 16 Apr 2011 01:37:07 +0000 (21:37 -0400)
committerW. Trevor King <wking@drexel.edu>
Sat, 16 Apr 2011 01:37:07 +0000 (21:37 -0400)
posts/entrez/entrez.py

index 30a65665aaecfdfd2b3d64714ed8c8c003af9905..60ae214c167564c648729ed2d8854d2967d5088f 100755 (executable)
@@ -86,20 +86,8 @@ del _handler, _formatter
 ## XML and list utility functions
 
 def urlencode(param_dict):
-    params = ""
-    for key,value in param_dict.items():
-        if value == None:
-            continue # ignore unused parameter
-        #if type(value)== : # convert True/False to 'y'/<no-entry>
-        #    if value == True:
-        #        params += "%s=y&" % (key,)
-        #    #else:
-        #    #    params += "%s=n&" % (key,)
-        if value != None:
-            params += "%s=%s&" % (key, str(value))
-    if len(params) > 1:
-        params = params[:-1] # remove trailing &
-    return params
+    return urllib.urlencode(
+        [(k,v) for k,v in param_dict.iteritems() if v is not None])
 
 def unique(seq, keepstr=True):
     """