Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
shrapnel
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
shrapnel
Commits
ccde4c02
Commit
ccde4c02
authored
Sep 06, 2013
by
Sam Rushing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
proxy.__call__: call invoke correctly
json_rpc_remote: allow persistent http client (+ close method)
parent
52961ff1
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
4 deletions
+11
-4
coro/http/json_rpc.py
coro/http/json_rpc.py
+11
-4
No files found.
coro/http/json_rpc.py
View file @
ccde4c02
...
...
@@ -38,7 +38,7 @@ class proxy:
self
.
name
=
name
def
__call__
(
self
,
*
args
,
**
kwargs
):
return
self
.
remote
.
invoke
(
self
.
name
,
*
args
,
**
kwargs
)
return
self
.
remote
.
invoke
(
self
.
name
,
args
,
kwargs
)
class
json_rpc_remote
:
...
...
@@ -52,9 +52,11 @@ class json_rpc_remote:
self
.
auth
=
base64
.
b64encode
(
'%s:%s'
%
auth_info
)
else
:
self
.
auth
=
None
self
.
conn
=
None
def
invoke
(
self
,
name
,
*
args
,
**
kwargs
):
c
=
http_client
(
self
.
url_ob
.
hostname
,
self
.
url_ob
.
port
)
if
self
.
conn
is
None
:
self
.
conn
=
http_client
(
self
.
url_ob
.
hostname
,
self
.
url_ob
.
port
)
if
kwargs
:
assert
(
not
args
)
# no way to mix positional & named args
params
=
kwargs
...
...
@@ -63,14 +65,19 @@ class json_rpc_remote:
jreq
=
json
.
dumps
({
'method'
:
name
,
'params'
:
params
,
'id'
:
self
.
counter
})
self
.
counter
+=
1
if
self
.
auth
:
req
=
c
.
POST
(
self
.
url_ob
.
path
,
jreq
,
Authorization
=
'Basic %s'
%
(
self
.
auth
,))
req
=
self
.
conn
.
POST
(
self
.
url_ob
.
path
,
jreq
,
Authorization
=
'Basic %s'
%
(
self
.
auth
,))
else
:
req
=
c
.
POST
(
self
.
url_ob
.
path
,
jreq
)
req
=
self
.
conn
.
POST
(
self
.
url_ob
.
path
,
jreq
)
if
req
.
reply_code
==
'200'
:
jrep
=
json
.
loads
(
req
.
content
)
return
jrep
[
'result'
]
else
:
raise
Error
((
req
.
reply_code
,
req
.
content
))
def
close
(
self
):
if
self
.
conn
is
not
None
:
self
.
conn
=
None
self
.
conn
.
close
()
def
__getattr__
(
self
,
name
):
return
proxy
(
self
,
name
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment