Repository: sangoma/ursine

Issue:
Missing `short_uri`
aiosip needs this method to generate URI addresses.

Discussion:

Patch:
diff --git a/ursine/uri.py b/ursine/uri.py
index e7feacc..57be602 100644
--- a/ursine/uri.py
+++ b/ursine/uri.py
@@ -200,6 +200,16 @@ class URI:
         else:
             return uri
 
+    def short_uri(self):
+        if self.user and self.password:
+            user = f'{self.user}:{self.password}@'
+        elif self.user:
+            user = f'{self.user}@'
+        else:
+            user = ''
+
+        return f'{self.scheme}:{user}{self.host}:{self.port}'
+
     def __repr__(self):
         return f'{self.__class__.__name__}({self})'
 


Test patch:
diff --git a/tests/test_uri.py b/tests/test_uri.py
index d74630d..36a8806 100644
--- a/tests/test_uri.py
+++ b/tests/test_uri.py
@@ -29,6 +29,19 @@ def test_to_str(uri, expect):
     assert str(URI(uri)) == expect
 
 
+@pytest.mark.parametrize('uri,expect', [
+    ('sip:localhost', 'sip:localhost:5060'),
+    ('sips:localhost', 'sips:localhost:5061'),
+    ('<sip:localhost>', 'sip:localhost:5060'),
+    (
+        'John Doe <sip:localhost:5080?x=y&a=b>',
+        'sip:localhost:5080',
+    )
+])
+def test_to_short_uri(uri, expect):
+    assert URI(uri).short_uri() == expect
+
+
 @pytest.mark.parametrize('uri,expect', [
     ('sip:localhost', 'URI(sip:localhost:5060;transport=udp)'),
     ('sips:localhost', 'URI(sips:localhost:5061;transport=tcp)'),