Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(968)

Unified Diff: chrome/common/extensions/docs/server2/url_fetcher_urllib2.py

Issue 1151283007: Docserver overhaul: Gitiles away from me. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove inform_users template to fix presubmit failure (it's now a redirect) Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/common/extensions/docs/server2/url_fetcher_urllib2.py
diff --git a/chrome/common/extensions/docs/server2/url_fetcher_urllib2.py b/chrome/common/extensions/docs/server2/url_fetcher_urllib2.py
new file mode 100644
index 0000000000000000000000000000000000000000..211deaa1a3016cb326d0d7685eef1d1a81982c81
--- /dev/null
+++ b/chrome/common/extensions/docs/server2/url_fetcher_urllib2.py
@@ -0,0 +1,35 @@
+# Copyright 2015 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import logging
+import time
+
+from future import Future
+from url_fetcher import UrlFetcher
+from urllib2 import urlopen, Request, HTTPError
+
+
+class UrlFetcherUrllib2(UrlFetcher):
+ """UrlFetcher implementation for use outside of AppEngine. Does NOT support
+ async fetching, so FetchAsync calls are still blocking.
+ """
+ class _Response(object):
+ def __init__(self, code, content=None, headers={}):
+ self.status_code = code
+ self.content = content
+ self.headers = headers
+
+ def FetchImpl(self, url, headers):
+ request = Request(url, headers=headers)
+ try:
+ urlresponse = urlopen(request)
+ response = self._Response(urlresponse.code, urlresponse.read(),
+ urlresponse.headers.dict)
+ urlresponse.close()
+ return response
+ except HTTPError as e:
+ return self._Response(e.code, e.reason, e.headers.dict)
+
+ def FetchAsyncImpl(self, url, headers):
+ return Future(callback=lambda: self.FetchImpl(url, headers))

Powered by Google App Engine
This is Rietveld 408576698