Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
djrandom-py
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ale
djrandom-py
Commits
60a9d81c
Commit
60a9d81c
authored
13 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
throttle HTTPS connections too (doh!)
parent
1b5131fe
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
client/djrandom_client/throttle.py
+22
-4
22 additions, 4 deletions
client/djrandom_client/throttle.py
client/djrandom_client/upload.py
+2
-1
2 additions, 1 deletion
client/djrandom_client/upload.py
with
24 additions
and
5 deletions
client/djrandom_client/throttle.py
+
22
−
4
View file @
60a9d81c
...
...
@@ -63,19 +63,17 @@ def set_rate_limit(kbps):
_bucket
=
TokenBucket
(
2
*
bps
,
bps
)
class
ThrottledHTTPConnection
(
httplib
.
HTTPConnection
):
class
ThrottledHTTPConnection
Mixin
(
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
)
This diff is collapsed.
Click to expand it.
client/djrandom_client/upload.py
+
2
−
1
View file @
60a9d81c
...
...
@@ -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
(),
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment