From af272d58276a9d1415a563e4ac763a6207742342 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Sun, 13 Feb 2011 17:13:10 -0500 Subject: [PATCH] Base GET in place. No AUTH yet. --- requests/core.py | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/requests/core.py b/requests/core.py index 21c879a..977e4b2 100644 --- a/requests/core.py +++ b/requests/core.py @@ -36,8 +36,11 @@ class Request(object): def __init__(self): self.headers = dict() self.method = None + self.params = {} + self.data = None self.response = Response() self.auth = None + self.sent = False def __setattr__(self, name, value): @@ -48,11 +51,42 @@ class Request(object): object.__setattr__(self, name, value) - def send(self): - """Sends the request. """ + def send(self, anyway=False): + """Sends the request. + + :param anyway: If True, request will be sent, even if it has already been sent. + """ + + if self.method.lower() == 'get': + if (not self.sent) or anyway: + r = urllib.urlopen('http://kennethreitz.com') + self.response.headers = r.headers.dict + self.response.status_code = r.code + self.response.content = r.read() + + success = True + + elif self.method.lower() == 'head': + if (not self.sent) or anyway: + pass + + elif self.method.lower() == 'put': + if (not self.sent) or anyway: + pass + + elif self.method.lower() == 'post': + if (not self.sent) or anyway: + pass + + elif self.method.lower() == 'delete': + if (not self.sent) or anyway: + pass + #set self.response - # return True / False + if success: + self.sent = True + return success class Response(object): -- 2.7.4