| 8 | |
| 9 | |
| 10 | class Browser(object): |
| 11 | __slots__ = ("log", "options", "bucket", "cj", "_size", "http", "dl") |
| 12 | |
| 13 | def __init__(self, bucket=None, options={}): |
| 14 | self.log = getLogger("log") |
| 15 | |
| 16 | self.options = options #holds pycurl options |
| 17 | self.bucket = bucket |
| 18 | |
| 19 | self.cj = None # needs to be setted later |
| 20 | self._size = 0 |
| 21 | |
| 22 | self.renewHTTPRequest() |
| 23 | self.dl = None |
| 24 | |
| 25 | |
| 26 | def renewHTTPRequest(self): |
| 27 | if hasattr(self, "http"): self.http.close() |
| 28 | self.http = HTTPRequest(self.cj, self.options) |
| 29 | |
| 30 | def setLastURL(self, val): |
| 31 | self.http.lastURL = val |
| 32 | |
| 33 | # tunnel some attributes from HTTP Request to Browser |
| 34 | lastEffectiveURL = property(lambda self: self.http.lastEffectiveURL) |
| 35 | lastURL = property(lambda self: self.http.lastURL, setLastURL) |
| 36 | code = property(lambda self: self.http.code) |
| 37 | cookieJar = property(lambda self: self.cj) |
| 38 | |
| 39 | def setCookieJar(self, cj): |
| 40 | self.cj = cj |
| 41 | self.http.cj = cj |
| 42 | |
| 43 | @property |
| 44 | def speed(self): |
| 45 | if self.dl: |
| 46 | return self.dl.speed |
| 47 | return 0 |
| 48 | |
| 49 | @property |
| 50 | def size(self): |
| 51 | if self._size: |
| 52 | return self._size |
| 53 | if self.dl: |
| 54 | return self.dl.size |
| 55 | return 0 |
| 56 | |
| 57 | @property |
| 58 | def arrived(self): |
| 59 | if self.dl: |
| 60 | return self.dl.arrived |
| 61 | return 0 |
| 62 | |
| 63 | @property |
| 64 | def percent(self): |
| 65 | if not self.size: return 0 |
| 66 | return (self.arrived * 100) / self.size |
| 67 |
no test coverage detected