diff --git a/client/djrandom_client/throttle.py b/client/djrandom_client/throttle.py index 78f0fb7e29aff948af69003dcad09dc378e2e047..1aea61ffc4a586212c2d6049bdade489728e4ab5 100644 --- a/client/djrandom_client/throttle.py +++ b/client/djrandom_client/throttle.py @@ -63,19 +63,17 @@ def set_rate_limit(kbps): _bucket = TokenBucket(2 * bps, bps) -class ThrottledHTTPConnection(httplib.HTTPConnection): +class ThrottledHTTPConnectionMixin(object): BLOCK_SIZE = 4096 - def send(self, str): + def throttled_send(self, str): if self.sock is None: if self.auto_open: self.connect() else: raise httplib.NotConnected() - if self.debuglevel > 0: - print "send:", repr(str) try: tot = len(str) for off in xrange(0, tot, self.BLOCK_SIZE): @@ -93,9 +91,29 @@ class ThrottledHTTPConnection(httplib.HTTPConnection): raise +class ThrottledHTTPSConnection(httplib.HTTPSConnection, + ThrottledHTTPConnectionMixin): + + def send(self, str): + return self.throttled_send(str) + + +class ThrottledHTTPConnection(httplib.HTTPConnection, + ThrottledHTTPConnectionMixin): + + def send(self, str): + return self.throttled_send(str) + + class ThrottledHTTPHandler(urllib2.HTTPHandler): def http_open(self, req): return self.do_open(ThrottledHTTPConnection, req) +class ThrottledHTTPSHandler(urllib2.HTTPSHandler): + + def https_open(self, req): + return self.do_open(ThrottledHTTPSConnection, req) + + diff --git a/client/djrandom_client/upload.py b/client/djrandom_client/upload.py index 3b37bfd48a0c337bcbf567f3c2cf304b7115dd35..44a6513de7937510ab1a1589ac455cc9b21ebc89 100644 --- a/client/djrandom_client/upload.py +++ b/client/djrandom_client/upload.py @@ -68,7 +68,8 @@ class Uploader(threading.Thread): self.queue = Queue.Queue(100) self.db_path = db_path self.stats = stats.Stats(state_path) - self.opener = urllib2.build_opener(throttle.ThrottledHTTPHandler) + self.opener = urllib2.build_opener(throttle.ThrottledHTTPHandler, + throttle.ThrottledHTTPSHandler) user_agent = 'djrandom_client/%s (%s %s Python/%s)' % ( version.VERSION, platform.system(), platform.machine(),