david / django-roa (http://welldev.org/)
Turn your models into remote resources that you can access through Django's ORM. ROA stands for Resource Oriented Architecture.
| commit 129: | 6fb5496bda07 |
| parent 128: | fe8c29bac8f8 |
| branch: | default |
Update to the latest restkit's tip
Changed (Δ1.0 KB):
raw changeset »
restkit/ext/eventlet_pool.py (18 lines added, 1 lines removed)
restkit/httpc.py (11 lines added, 3 lines removed)
restkit/pool.py (18 lines added, 11 lines removed)
Up to file-list restkit/ext/eventlet_pool.py:
| … | … | @@ -99,4 +99,21 @@ class ConnectionPool(Pool): |
99 |
99 |
return make_connection(self.uri, self.use_proxy) |
100 |
100 |
|
101 |
101 |
def put(self, connection): |
102 |
|
|
102 |
if self.current_size > self.max_size: |
|
103 |
self.current_size -= 1 |
|
104 |
# close the connection if needed |
|
105 |
if connection.sock is not None: |
|
106 |
connection.close() |
|
107 |
return |
|
108 |
||
109 |
try: |
|
110 |
response = connection.getresponse() |
|
111 |
response.read() |
|
112 |
except httplib.ResponseNotReady: |
|
113 |
pass |
|
114 |
except: |
|
115 |
connection.close() |
|
116 |
||
117 |
if connection.sock is None: |
|
118 |
connection = self.create() |
|
119 |
Pool.put(self, connection) |
Up to file-list restkit/httpc.py:
| … | … | @@ -121,7 +121,9 @@ class HttpClient(object): |
121 |
121 |
if conn_key in self.connections: |
122 |
122 |
pool = self.connections[conn_key] |
123 |
123 |
else: |
124 |
pool = self.connections[conn_key] = self.pool_class(uri, |
|
124 |
pool = self.connections[conn_key] = self.pool_class(uri, |
|
125 |
use_proxy=self.use_proxy, min_size=self.min_size, |
|
126 |
max_size=self.max_size) |
|
125 |
127 |
connection = pool.get() |
126 |
128 |
return connection |
127 |
129 |
|
| … | … | @@ -131,7 +133,9 @@ class HttpClient(object): |
131 |
133 |
if conn_key in self.connections: |
132 |
134 |
pool = self.connections[conn_key] |
133 |
135 |
else: |
134 |
pool = self.connections[conn_key] =self.pool_class(uri, |
|
136 |
pool = self.connections[conn_key] =self.pool_class(uri, |
|
137 |
use_proxy=self.use_proxy, min_size=self.min_size, |
|
138 |
max_size=self.max_size) |
|
135 |
139 |
pool.put(connection) |
136 |
140 |
|
137 |
141 |
|
| … | … | @@ -184,9 +188,11 @@ class HttpClient(object): |
184 |
188 |
|
185 |
189 |
except socket.gaierror: |
186 |
190 |
connection.close() |
191 |
self._release_connection(uri, connection) |
|
187 |
192 |
raise errors.ResourceNotFound("Unable to find the server at %s" % connection.host, 404) |
188 |
193 |
except (socket.error, httplib.HTTPException): |
189 |
194 |
connection.close() |
195 |
self._release_connection(uri, connection) |
|
190 |
196 |
if i == 0: |
191 |
197 |
continue |
192 |
198 |
else: |
| … | … | @@ -265,7 +271,8 @@ class HttpClient(object): |
265 |
271 |
resp.final_url = self.final_url |
266 |
272 |
|
267 |
273 |
if method == "HEAD": |
268 |
|
|
274 |
response.close() |
|
275 |
self._release_connection(uri, connection) |
|
269 |
276 |
return resp, "" |
270 |
277 |
else: |
271 |
278 |
return resp, _decompress_content(resp, response, |
| … | … | @@ -300,6 +307,7 @@ def _decompress_content(resp, response, |
300 |
307 |
release_callback() |
301 |
308 |
return data |
302 |
309 |
except Exception, e: |
310 |
release_callback() |
|
303 |
311 |
raise errors.ResponseError("Decompression failed %s" % str(e)) |
304 |
312 |
|
305 |
313 |
Up to file-list restkit/pool.py:
| … | … | @@ -135,10 +135,6 @@ class Pool(object): |
135 |
135 |
try: |
136 |
136 |
if self.free_items: |
137 |
137 |
return self.free_items.popleft() |
138 |
if self.current_size < self.max_size: |
|
139 |
created = self.create() |
|
140 |
self.current_size += 1 |
|
141 |
return created |
|
142 |
138 |
|
143 |
139 |
try: |
144 |
140 |
return self.channel.get(False) |
| … | … | @@ -146,7 +142,7 @@ class Pool(object): |
146 |
142 |
created = self.create() |
147 |
143 |
self.current_size += 1 |
148 |
144 |
return created |
149 |
||
145 |
||
150 |
146 |
finally: |
151 |
147 |
self.lock.release() |
152 |
148 |
|
| … | … | @@ -186,7 +182,7 @@ class Pool(object): |
186 |
182 |
def waiting(self): |
187 |
183 |
"""Return the number of routines waiting for a pool item. |
188 |
184 |
""" |
189 |
return |
|
185 |
return (self.channel.qsize() < self.max_size) |
|
190 |
186 |
|
191 |
187 |
def create(self): |
192 |
188 |
"""Generate a new pool item |
| … | … | @@ -203,14 +199,25 @@ class ConnectionPool(Pool): |
203 |
199 |
return make_connection(self.uri, self.use_proxy) |
204 |
200 |
|
205 |
201 |
def put(self, connection): |
206 |
# close the connection if needed |
|
207 |
if connection.sock is not None: |
|
208 |
connection.close() |
|
209 |
||
210 |
202 |
if self.current_size > self.max_size: |
211 |
203 |
self.lock.acquire() |
212 |
204 |
self.current_size -= 1 |
205 |
# close the connection if needed |
|
206 |
if connection.sock is not None: |
|
207 |
connection.close() |
|
213 |
208 |
self.lock.release() |
214 |
209 |
return |
215 |
210 |
|
216 |
|
|
211 |
try: |
|
212 |
response = connection.getresponse() |
|
213 |
response.read() |
|
214 |
except httplib.ResponseNotReady: |
|
215 |
pass |
|
216 |
except: |
|
217 |
connection.close() |
|
218 |
||
219 |
||
220 |
if connection.sock is None: |
|
221 |
connection = self.create() |
|
222 |
||
223 |
Pool.put(self, connection) |
