rpathsync / restlib
Python REST Library
Clone this repository (size: 74.1 KB): HTTPS / SSH
$ hg clone http://bitbucket.org/rpathsync/restlib/
| commit 35: | 4ddedf4cc10e |
| parent 34: | b4a958754929 |
| branch: | default |
Add a request attribute for the remote IP.
10 months ago
Changed (Δ354 bytes):
raw changeset »
restlib/http/modpython.py (4 lines added, 0 lines removed)
restlib/http/request.py (5 lines added, 0 lines removed)
restlib/http/simplehttp.py (4 lines added, 2 lines removed)
Up to file-list restlib/http/modpython.py:
| … | … | @@ -37,6 +37,10 @@ class ModPythonRequest(request.Request): |
37 |
37 |
def _getReadFd(self): |
38 |
38 |
return self._req |
39 |
39 |
|
40 |
def _getRemote(self): |
|
41 |
"Return the C{(address, port)} of the remote host." |
|
42 |
return self._req.connection.remote_addr |
|
43 |
||
40 |
44 |
def _getUri(self): |
41 |
45 |
return self._req.uri[len(self.basePath):] |
42 |
46 |
Up to file-list restlib/http/request.py:
| … | … | @@ -33,6 +33,7 @@ class Request(object): |
33 |
33 |
self.baseUrl = self._getBaseUrl() |
34 |
34 |
self.host = self._getHost() |
35 |
35 |
self.headers = self._getHeaders() |
36 |
self.remote = self._getRemote() |
|
36 |
37 |
|
37 |
38 |
method = self._getHttpMethod() |
38 |
39 |
|
| … | … | @@ -67,6 +68,10 @@ class Request(object): |
67 |
68 |
def _getReadFd(self): |
68 |
69 |
raise NotImplementedError() |
69 |
70 |
|
71 |
def _getRemote(self): |
|
72 |
"Return the C{(address, port)} of the remote host." |
|
73 |
raise NotImplementedError() |
|
74 |
||
70 |
75 |
def _getPostData(self): |
71 |
76 |
# cgi will read the body when it doesn't recognize the content type |
72 |
77 |
ctypes = set(['multipart/form-data', |
Up to file-list restlib/http/simplehttp.py:
| … | … | @@ -36,6 +36,10 @@ class SimpleHttpRequest(request.Request) |
36 |
36 |
def _getReadFd(self): |
37 |
37 |
return self._req.rfile |
38 |
38 |
|
39 |
def _getRemote(self): |
|
40 |
"Return the C{(address, port)} of the remote host." |
|
41 |
return self._req.client_address |
|
42 |
||
39 |
43 |
def _getFullPath(self): |
40 |
44 |
return self._req.path |
41 |
45 |
|
| … | … | @@ -55,8 +59,6 @@ class SimpleHttpRequest(request.Request) |
55 |
59 |
def getContentLength(self): |
56 |
60 |
return int(self.headers.get('content-length', 0)) |
57 |
61 |
|
58 |
def getRequestIP(self): |
|
59 |
return self._req.client_address[0] |
|
60 |
62 |
|
61 |
63 |
class SimpleHttpHandler(handler.HttpHandler): |
62 |
64 |
requestClass = SimpleHttpRequest |
