Created
May 17, 2012 02:26
-
-
Save logic/2715756 to your computer and use it in GitHub Desktop.
Adding an HTTP method to urllib2.Request.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib2 | |
class MethodRequest(urllib2.Request): | |
def __init__(self, *args, **kwargs): | |
if 'method' in kwargs: | |
self._method = kwargs['method'] | |
del kwargs['method'] | |
else: | |
self._method = None | |
return urllib2.Request.__init__(self, *args, **kwargs) | |
def get_method(self, *args, **kwargs): | |
if self._method is not None: | |
return self._method | |
return urllib2.Request.get_method(self, *args, **kwargs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, works a charm!