]> jfr.im git - z_archive/twitter.git/commitdiff
Speed up method_for_uri()
authorBeat Bolli <redacted>
Tue, 23 Sep 2014 17:24:19 +0000 (19:24 +0200)
committerBeat Bolli <redacted>
Tue, 23 Sep 2014 17:24:19 +0000 (19:24 +0200)
Prepare a regex in advance that handles all POST APIs with a single
search() call.

twitter/api.py

index 9c065540e4d5c9f2a21be1c7b31a2ab5978d0881..51024ccede2d87b4556919d22b750c37bd47564e 100644 (file)
@@ -129,13 +129,13 @@ def wrap_response(response, headers):
         res = response
     return res
 
+
+POST_ACTIONS_RE = re.compile('(' + '|'.join(POST_ACTIONS) + r')(/\d+)?$')
+
 def method_for_uri(uri):
-    method = "GET"
-    for action in POST_ACTIONS:
-        if re.search("%s(/\d+)?$" % action, uri):
-            method = "POST"
-            break
-    return method
+    if POST_ACTIONS_RE.search(uri):
+        return "POST"
+    return "GET"
 
 class TwitterCall(object):