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
ff7baf34
Commit
ff7baf34
authored
Jul 01, 2013
by
Sam Rushing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
client: add support for Basic Auth
client: getattr proxy object
parent
499d1860
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
7 deletions
+37
-7
coro/http/json_rpc.py
coro/http/json_rpc.py
+37
-7
No files found.
coro/http/json_rpc.py
View file @
ff7baf34
...
...
@@ -3,6 +3,7 @@
import
json
import
urlparse
import
coro
import
base64
from
coro.http.client
import
client
as
http_client
from
coro.http.protocol
import
header_set
...
...
@@ -27,20 +28,49 @@ class json_rpc_handler:
request
.
push
(
json
.
dumps
(
rd
))
request
.
done
()
class
Error
(
Exception
):
pass
class
proxy
:
def
__init__
(
self
,
remote
,
name
):
self
.
remote
=
remote
self
.
name
=
name
def
__call__
(
self
,
*
args
,
**
kwargs
):
return
self
.
remote
.
invoke
(
self
.
name
,
*
args
,
**
kwargs
)
class
json_rpc_remote
:
def
__init__
(
self
,
url
):
def
__init__
(
self
,
url
,
auth_info
=
None
):
self
.
url
=
url
self
.
url_ob
=
urlparse
.
urlparse
(
url
)
assert
(
self
.
url_ob
.
scheme
==
'http'
)
self
.
counter
=
0
if
auth_info
:
# basic only
self
.
auth
=
base64
.
b64encode
(
'%s:%s'
%
auth_info
)
else
:
self
.
auth
=
None
def
invoke
(
self
,
name
,
*
args
):
def
invoke
(
self
,
name
,
*
args
,
**
kwargs
):
c
=
http_client
(
self
.
url_ob
.
hostname
,
self
.
url_ob
.
port
)
jreq
=
json
.
dumps
({
'method'
:
name
,
'params'
:
list
(
args
),
'id'
:
self
.
counter
})
if
kwargs
:
assert
(
not
args
)
# no way to mix positional & named args
params
=
kwargs
else
:
params
=
list
(
args
)
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
,))
else
:
req
=
c
.
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
__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