Skip to content

Instantly share code, notes, and snippets.

@bcse
Created March 18, 2013 02:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bcse/5184554 to your computer and use it in GitHub Desktop.
Save bcse/5184554 to your computer and use it in GitHub Desktop.
Extending urllib2.Request, so we can assign HTTP verb manually.
from urllib2 import Request as RequestBase
class Request(RequestBase):
def __init__(self, url, data=None, headers=None, origin_req_host=None,
unverifiable=False, method=None):
if headers is None:
headers = {}
super(Request, self).__init__(url, data, headers, origin_req_host, unverifiable)
self.method = method
def get_method(self):
if self.method is not None:
return self.method
else:
return super(Request, self).get_method()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment