Skip to content

Commit

Permalink
Merge pull request #841 from OOPMan/upstream-issue-836
Browse files Browse the repository at this point in the history
#836: register/subscribe decorators support different URI syntax from what session.register and session.subscribe support
  • Loading branch information
oberstet committed May 23, 2017
2 parents 89ac1f4 + 1314f40 commit a936217
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
18 changes: 18 additions & 0 deletions autobahn/wamp/test/test_uri_pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def test_valid_uris(self):
u"123",
u"com.myapp.<product:int>.update",
u"com.myapp.<category:string>.<subcategory>.list"
u"com.myapp.something..update"
]:
p = Pattern(u, Pattern.URI_TARGET_ENDPOINT)
self.assertIsInstance(p, Pattern)
Expand Down Expand Up @@ -159,6 +160,23 @@ def circle(name=None, details=None):
self.assertEqual(circle._wampuris[0].uri(), u"com.myapp.circle.<name:string>")
self.assertEqual(circle._wampuris[0]._type, Pattern.URI_TYPE_WILDCARD)

@wamp.register(u"com.myapp.something..update",
RegisterOptions(match=u"wildcard", details_arg="details"))
def something(dynamic=None, details=None):
""" Do nothing. """
self.assertTrue(hasattr(something, '_wampuris'))
self.assertTrue(type(something._wampuris) == list)
self.assertEqual(len(something._wampuris), 1)
self.assertIsInstance(something._wampuris[0], Pattern)
self.assertIsInstance(something._wampuris[0].options, RegisterOptions)
self.assertEqual(something._wampuris[0].options.match, u"wildcard")
self.assertEqual(something._wampuris[0].options.details_arg, "details")
self.assertTrue(something._wampuris[0].is_endpoint())
self.assertFalse(something._wampuris[0].is_handler())
self.assertFalse(something._wampuris[0].is_exception())
self.assertEqual(something._wampuris[0].uri(), u"com.myapp.something..update")
self.assertEqual(something._wampuris[0]._type, Pattern.URI_TYPE_WILDCARD)

def test_decorate_handler(self):

@wamp.subscribe(u"com.myapp.on_shutdown")
Expand Down
10 changes: 10 additions & 0 deletions autobahn/wamp/uri.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ def __init__(self, uri, target, options=None):
:type options: None or RegisterOptions or SubscribeOptions
"""
assert(type(uri) == six.text_type)
assert(len(uri) > 0)
assert(target in [Pattern.URI_TARGET_ENDPOINT,
Pattern.URI_TARGET_HANDLER,
Pattern.URI_TARGET_EXCEPTION])
Expand All @@ -160,6 +161,7 @@ def __init__(self, uri, target, options=None):
components = uri.split('.')
pl = []
nc = {}
group_count = 0
for i in range(len(components)):
component = components[i]

Expand All @@ -185,6 +187,7 @@ def __init__(self, uri, target, options=None):
raise Exception("logic error")

pl.append("(?P<{0}>[a-z0-9_]+)".format(name))
group_count += 1
continue

match = Pattern._URI_NAMED_COMPONENT.match(component)
Expand All @@ -195,13 +198,20 @@ def __init__(self, uri, target, options=None):

nc[name] = str
pl.append("(?P<{0}>[a-z0-9_]+)".format(name))
group_count += 1
continue

match = Pattern._URI_COMPONENT.match(component)
if match:
pl.append(component)
continue

if component == '':
group_count += 1
pl.append("([a-z0-9][a-z0-9_\-]*)")
nc[group_count] = str
continue

raise Exception("invalid URI")

if nc:
Expand Down

0 comments on commit a936217

Please sign in to comment.