From: Beat Bolli Date: Tue, 23 Sep 2014 17:24:19 +0000 (+0200) Subject: Speed up method_for_uri() X-Git-Tag: twitter-1.16.0~19^2~1 X-Git-Url: https://jfr.im/git/z_archive/twitter.git/commitdiff_plain/2b986d8ddf567b6fa9738baf7d802bf92078ba40 Speed up method_for_uri() Prepare a regex in advance that handles all POST APIs with a single search() call. --- diff --git a/twitter/api.py b/twitter/api.py index 9c06554..51024cc 100644 --- a/twitter/api.py +++ b/twitter/api.py @@ -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):