Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
sjrpc
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor 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
Mirror
sjrpc
Commits
37501d9a
Commit
37501d9a
authored
13 years ago
by
Antoine Millet
Browse files
Options
Downloads
Patches
Plain Diff
Added create_rpc and create_tunnel shortcuts with label auto assignation
parent
2c3b6c7d
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
sjrpc/core/exceptions.py
+8
-0
8 additions, 0 deletions
sjrpc/core/exceptions.py
sjrpc/core/rpcconnection.py
+21
-4
21 additions, 4 deletions
sjrpc/core/rpcconnection.py
with
29 additions
and
4 deletions
sjrpc/core/exceptions.py
+
8
−
0
View file @
37501d9a
...
...
@@ -23,3 +23,11 @@ class SocketRpcError(Exception):
'''
Exception used internally to raise a socket fault.
'''
class
NoFreeLabelError
(
Exception
):
'''
Exception raised when no more free labels are available for protocol
allocation.
'''
This diff is collapsed.
Click to expand it.
sjrpc/core/rpcconnection.py
+
21
−
4
View file @
37501d9a
...
...
@@ -11,9 +11,8 @@ import struct
import
socket
import
logging
from
sjrpc.core.protocols.rpc
import
RpcProtocol
from
sjrpc.core.protocols
import
Protocol
from
sjrpc.core.exceptions
import
RpcError
from
sjrpc.core.protocols
import
Protocol
,
RpcProtocol
,
TunnelProtocol
from
sjrpc.core.exceptions
import
RpcError
,
NoFreeLabelError
import
pyev
...
...
@@ -54,6 +53,7 @@ class RpcConnection(object):
MESSAGE_HEADER
=
'
!HL
'
MESSAGE_HEADER_FALLBACK
=
'
!L
'
MAX_LABEL
=
2
**
16
SHORTCUTS_MAINRPC
=
(
'
call
'
,
'
async_call
'
)
def
__init__
(
self
,
sock
,
loop
=
None
,
enable_tcp_keepalive
=
False
,
...
...
@@ -294,7 +294,12 @@ class RpcConnection(object):
'''
Register a new protocol for the specified label.
'''
if
label
is
None
:
for
label
in
xrange
(
0
,
RpcConnection
.
MAX_LABEL
):
if
label
not
in
self
.
_protocols
:
break
else
:
raise
NoFreeLabelError
(
'
No more label number are availables
'
)
if
label
in
self
.
_protocols
:
raise
KeyError
(
'
A protocol is already registered for this label
'
)
elif
not
isinstance
(
label
,
int
):
...
...
@@ -312,6 +317,18 @@ class RpcConnection(object):
else
:
raise
KeyError
(
'
No protocol registered for this label
'
)
def
create_rpc
(
self
,
label
=
None
,
*
args
,
**
kwargs
):
'''
Shortcut which can be used to create rpc protocols.
'''
return
self
.
register_protocol
(
label
,
RpcProtocol
,
*
args
,
**
kwargs
)
def
create_tunnel
(
self
,
label
=
None
,
*
args
,
**
kwargs
):
'''
Shortcut which can be used to create tunnels protocols.
'''
return
self
.
register_protocol
(
label
,
TunnelProtocol
,
*
args
,
**
kwargs
)
def
get_protocol
(
self
,
label
):
'''
Get the protocol registered for specified label.
...
...
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