Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
LOFAR
Manage
Activity
Members
Labels
Plan
Issues
Wiki
Jira issues
Open Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Insights
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
RadioObservatory
LOFAR
Commits
fbfab27b
Commit
fbfab27b
authored
9 years ago
by
Jan Rinze Peterzon
Browse files
Options
Downloads
Patches
Plain Diff
Task #8531: refactor argument parsing for RPC.
parent
180e4b2e
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
LCS/Messaging/python/messaging/RPC.py
+4
-20
4 additions, 20 deletions
LCS/Messaging/python/messaging/RPC.py
LCS/Messaging/python/messaging/messages.py
+27
-0
27 additions, 0 deletions
LCS/Messaging/python/messaging/messages.py
with
31 additions
and
20 deletions
LCS/Messaging/python/messaging/RPC.py
+
4
−
20
View file @
fbfab27b
...
...
@@ -21,7 +21,7 @@
# RPC invocation with possible timeout
from
lofar.messaging.messagebus
import
ToBus
,
FromBus
from
lofar.messaging.messages
import
ServiceMessage
,
ReplyMessage
from
lofar.messaging.messages
import
ServiceMessage
,
ReplyMessage
,
analyze_args
,
args_as_content
import
uuid
class
RPCException
(
Exception
):
...
...
@@ -77,7 +77,7 @@ class RPC():
"""
self
.
Request
.
close
()
def
__call__
(
self
,
*
msg
,
**
kwargs
):
def
__call__
(
self
,
*
args
,
**
kwargs
):
"""
Enable the use of the object to directly invoke the RPC.
...
...
@@ -90,24 +90,8 @@ class RPC():
timeout
=
kwargs
.
pop
(
"
timeout
"
,
self
.
timeout
)
Content
=
list
(
msg
)
HasKwArgs
=
(
len
(
kwargs
)
>
0
)
# more than one argument given?
HasArgs
=
(
len
(
msg
)
>
1
)
or
((
len
(
kwargs
)
>
0
)
and
(
len
(
msg
)
>
0
))
if
HasArgs
:
# convert arguments to list
Content
=
list
(
msg
)
if
HasKwArgs
:
# if both positional and named arguments then
# we add the kwargs dictionary as the last item in the list
Content
.
append
(
kwargs
)
else
:
if
HasKwArgs
:
# we have only one named argument
Content
=
kwargs
else
:
# we have only one positional argument
Content
=
Content
[
0
]
Content
=
args_as_content
(
*
args
,
**
kwargs
)
HasArgs
,
HasKwArgs
=
analyze_args
(
args
,
kwargs
)
# create unique reply address for this rpc call
options
=
{
'
create
'
:
'
always
'
,
'
delete
'
:
'
receiver
'
}
ReplyAddress
=
"
reply.
"
+
str
(
uuid
.
uuid4
())
...
...
This diff is collapsed.
Click to expand it.
LCS/Messaging/python/messaging/messages.py
+
27
−
0
View file @
fbfab27b
...
...
@@ -96,6 +96,33 @@ def to_qpid_message(msg):
return
msg
.
qpid_msg
raise
InvalidMessage
(
"
Invalid message type: %r
"
%
type
(
msg
))
def
analyze_args
(
args
,
kwargs
):
HasKwArgs
=
(
len
(
kwargs
)
>
0
)
# more than one argument given?
HasMultipleArgs
=
(
len
(
args
)
>
1
)
or
((
len
(
kwargs
)
>
0
)
and
(
len
(
args
)
>
0
))
return
(
HasMultipleArgs
,
HasKwArgs
)
def
args_as_content
(
*
args
,
**
kwargs
):
"""
Convert positional args and named args into a message body.
:param msg: Message to be converted into a Qpid message.
:return: Qpid message
:raise InvalidMessage if `msg` cannot be converted into a Qpid message.
"""
HasMultipleArgs
,
HasKwArgs
=
analyze_args
(
args
,
kwargs
)
if
HasMultipleArgs
:
# convert arguments to list
Content
=
list
(
args
)
if
HasKwArgs
:
# if both positional and named arguments then
# we add the kwargs dictionary as the last item in the list
Content
.
append
(
kwargs
)
return
Content
if
HasKwArgs
:
# we have only one named argument
return
kwargs
# we have only one positional argument
return
list
(
args
)[
0
]
class
MessageFactory
(
Factory
):
"""
...
...
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