cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / chrome / common / extensions / docs / server2 / url_fetcher_urllib2.py
blob211deaa1a3016cb326d0d7685eef1d1a81982c81
1 # Copyright 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 import logging
6 import time
8 from future import Future
9 from url_fetcher import UrlFetcher
10 from urllib2 import urlopen, Request, HTTPError
13 class UrlFetcherUrllib2(UrlFetcher):
14 """UrlFetcher implementation for use outside of AppEngine. Does NOT support
15 async fetching, so FetchAsync calls are still blocking.
16 """
17 class _Response(object):
18 def __init__(self, code, content=None, headers={}):
19 self.status_code = code
20 self.content = content
21 self.headers = headers
23 def FetchImpl(self, url, headers):
24 request = Request(url, headers=headers)
25 try:
26 urlresponse = urlopen(request)
27 response = self._Response(urlresponse.code, urlresponse.read(),
28 urlresponse.headers.dict)
29 urlresponse.close()
30 return response
31 except HTTPError as e:
32 return self._Response(e.code, e.reason, e.headers.dict)
34 def FetchAsyncImpl(self, url, headers):
35 return Future(callback=lambda: self.FetchImpl(url, headers))