Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Turris
Sentinel
sn
Commits
82f13946
Unverified
Commit
82f13946
authored
Feb 01, 2018
by
Martin Prudek
🌀
Browse files
Main class renamed, exception addded
parent
a0b5b53e
Changes
4
Hide whitespace changes
Inline
Side-by-side
examples/client.py
View file @
82f13946
...
...
@@ -9,7 +9,7 @@ from random import randint
ctx
=
zmq
.
Context
.
instance
()
sctx
=
sn
.
Resources
(
ctx
)
sctx
=
sn
.
SN
(
ctx
)
# Resources are passed using internal argument parser:
# Socket "sock_cli" is enforced to be "REQ" type:
sock_cli
=
sctx
.
get_socket
((
"sock_cli"
,
"REQ"
))
...
...
examples/client2.py
View file @
82f13946
...
...
@@ -12,7 +12,7 @@ aparser = sn.get_arg_parser()
args
=
sn
.
parse
(
aparser
)
ctx
=
zmq
.
Context
.
instance
()
sctx
=
sn
.
Resources
(
ctx
,
args
)
sctx
=
sn
.
SN
(
ctx
,
args
)
sock_cli
,
sock_cli2
=
sctx
.
get_socket
(
"sock_cli"
,
(
"sock_cli2"
,
"REQ"
))
rand_ID
=
randint
(
10
,
99
)
...
...
examples/server.py
View file @
82f13946
...
...
@@ -9,7 +9,7 @@ import sn
ctx
=
zmq
.
Context
.
instance
()
# Resources are passed using internal argument parser:
sctx
=
sn
.
Resources
(
ctx
)
sctx
=
sn
.
SN
(
ctx
)
sock_srv
=
sctx
.
get_socket
(
"sock_srv"
)
# Some work:
...
...
sn/network.py
View file @
82f13946
...
...
@@ -6,8 +6,10 @@ import zmq
from
collections
import
namedtuple
class
SentinelError
(
Exception
):
pass
class
InvalidMsgError
(
Exception
):
class
InvalidMsgError
(
SentinelError
):
pass
...
...
@@ -39,7 +41,8 @@ def get_arg_parser():
""" Creates own arguments parser and return it as an object.
"""
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'--resource'
,
nargs
=
1
,
action
=
'append'
)
parser
.
add_argument
(
'--resource'
,
nargs
=
1
,
action
=
'append'
,
required
=
True
,
help
=
'resource format: sockname,[conn/bind],sock_type,ip_address,port'
)
parser
.
add_argument
(
'--disable-ipv6'
,
action
=
'store_true'
)
return
parser
...
...
@@ -68,8 +71,8 @@ def resource_parser(config_list):
resources
[
splitted
[
0
]]
=
list
()
resources
[
splitted
[
0
]].
append
(
Connection
(
*
splitted
[
1
:]))
else
:
raise
SockConfigError
(
"Resource {
arg
} is
\
invalid."
.
format
(
arg
=
config
))
raise
SockConfigError
(
"Resource {} is
"
\
"
invalid."
.
format
(
config
))
return
resources
...
...
@@ -77,7 +80,7 @@ class SockConfigError(Exception):
pass
class
Resources
:
class
SN
:
""" This class serves as a container for all resources. This class provides
an API-like interface for requesting ZMQ sockets based on available
resources.
...
...
@@ -129,14 +132,14 @@ class Resources:
type
(
socket
)
==
tuple
and
not
self
.
sock_configs
[
sock_name
].
is_type
(
socket
[
1
])
):
raise
SockConfigError
(
"Socket type does not match
\
required value!"
)
raise
SockConfigError
(
"Socket type does not match
"
\
"
required value!"
)
if
not
self
.
sock_configs
[
sock_name
].
socket
:
self
.
sock_configs
[
sock_name
].
connect
()
ret
.
append
(
self
.
sock_configs
[
sock_name
].
socket
)
else
:
raise
SockConfigError
(
"Resource {
arg
} not
\
provided."
.
format
(
arg
=
sock_name
))
raise
SockConfigError
(
"Resource {} not
"
\
"
provided."
.
format
(
sock_name
))
if
len
(
ret
)
==
1
:
return
ret
[
0
]
else
:
...
...
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