Skip to content

Commit 3340710

Browse files
committed
Add TerminalVerb Class
1 parent 8bd310d commit 3340710

File tree

6 files changed

+49
-50
lines changed

6 files changed

+49
-50
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""
2+
verb.py
3+
4+
Defines the base verb class for all BXML verbs
5+
6+
@copyright Bandwidth INC
7+
"""
8+
from .verb import Verb
9+
10+
11+
class TerminalVerb(Verb):
12+
"""Base class for BXML verbs
13+
"""
14+
15+
def __init__(self, tag: str, content: str = None, attributes: dict = None, nested_verbs: list[Verb] = None):
16+
"""Initialize the verb model
17+
18+
Args:
19+
tag (str): Name of the XML element
20+
content (str, optional): XML element content. Defaults to None.
21+
attributes (dict, optional): XML element attributes. Defaults to None.
22+
nested_verbs (list[BxmlVerb], optional): XML element children. Defaults to None.
23+
"""
24+
super().__init__(tag=tag, content=content, attributes=attributes, nested_verbs=nested_verbs)
25+
26+
def add_verb(self, verb: Verb):
27+
"""Adding verbs is not allowed for this class
28+
29+
Args:
30+
verb (Verb): BXML verb
31+
32+
Raises:
33+
AttributeError: This method is not allowed for <SipUri>
34+
"""
35+
raise AttributeError('Adding verbs is not supported by this verb')

bandwidth/model/bxml/verb.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Verb:
1313
"""Base class for BXML verbs
1414
"""
1515

16-
def __init__(self, tag: str, content: str = None, attributes: dict = None, nested_verbs: list[BxmlVerb] = None):
16+
def __init__(self, tag: str, content: str = None, attributes: dict = None, nested_verbs: list[Verb] = None):
1717
"""Initialize the verb model
1818
1919
Args:
@@ -36,18 +36,18 @@ def __len__(self) -> int:
3636
int: Length of self._nested_verbs
3737
"""
3838
return len(self._nested_verbs)
39-
39+
4040
def __getitem__(self, position) -> Verb:
4141
"""Override default getitem method. Makes the object iterable.
4242
4343
Args:
4444
position (int): Desired self._nested_verbs list position
4545
4646
Returns:
47-
BxmlVerb: Desired BXML verb
47+
BxmlVerb: Desired BXML verb
4848
"""
4949
return self._nested_verbs[position]
50-
50+
5151
def _set_attributes(self, root: ET.Element):
5252
"""Set XML attributes on an Element
5353

bandwidth/model/bxml/verbs/bridge.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
66
@copyright Bandwidth INC
77
"""
8-
from ..verb import Verb
8+
from ..terminal_verb import TerminalVerb
99

1010

11-
class Bridge(Verb):
11+
class Bridge(TerminalVerb):
1212

1313
def __init__(
1414
self, target_call: str, bridge_complete_url: str=None,
@@ -62,6 +62,3 @@ def __init__(
6262
attributes=self.attributes,
6363
nested_verbs=None
6464
)
65-
66-
def add_verb(self, verb: Verb):
67-
raise AttributeError('Adding verbs is not supported by <Bridge>')

bandwidth/model/bxml/verbs/phone_number.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
66
@copyright Bandwidth INC
77
"""
8-
from ..verb import Verb
8+
from ..terminal_verb import TerminalVerb
99

1010

11-
class PhoneNumber(Verb):
11+
class PhoneNumber(TerminalVerb):
1212

1313
def __init__(
1414
self, number: str, transfer_answer_url: str=None, transfer_answer_method: str=None,
@@ -48,17 +48,6 @@ def __init__(
4848
super().__init__(
4949
tag="PhoneNumber",
5050
content=number,
51-
attributes=self.attributes,
51+
attributes=self.attributes,
5252
nested_verbs=None
5353
)
54-
55-
def add_verb(self, verb: Verb):
56-
"""Adding verbs is not allowed for <PhoneNumber>
57-
58-
Args:
59-
verb (Verb): BXML verb
60-
61-
Raises:
62-
AttributeError: This method is not allowed for <PhoneNumber>
63-
"""
64-
raise AttributeError('Adding verbs is not supported by <PhoneNumber>')

bandwidth/model/bxml/verbs/sip_uri.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
66
@copyright Bandwidth INC
77
"""
8-
from ..verb import Verb
8+
from ..terminal_verb import TerminalVerb
99

1010

11-
class SipUri(Verb):
11+
class SipUri(TerminalVerb):
1212

1313
def __init__(
1414
self, uri: str, uui: str=None, transfer_answer_url: str=None, transfer_answer_method: str=None,
@@ -50,17 +50,6 @@ def __init__(
5050
super().__init__(
5151
tag="SipUri",
5252
content=uri,
53-
attributes=self.attributes,
53+
attributes=self.attributes,
5454
nested_verbs=None
5555
)
56-
57-
def add_verb(self, verb: Verb):
58-
"""Adding verbs is not allowed for <SipUri>
59-
60-
Args:
61-
verb (Verb): BXML verb
62-
63-
Raises:
64-
AttributeError: This method is not allowed for <SipUri>
65-
"""
66-
raise AttributeError('Adding verbs is not supported by <SipUri>')

bandwidth/model/bxml/verbs/tag.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
66
@copyright Bandwidth INC
77
"""
8-
from ..verb import Verb
8+
from ..terminal_verb import TerminalVerb
99

1010

11-
class Tag(Verb):
11+
class Tag(TerminalVerb):
1212

1313
def __init__(self, content=""):
1414
"""Initialize a <Tag> verb
@@ -17,14 +17,3 @@ def __init__(self, content=""):
1717
content (str, optional): Custom tag value. Defaults to "".
1818
"""
1919
super().__init__(tag="Tag", content=content, attributes=None, nested_verbs=None)
20-
21-
def add_verb(self, verb: Verb):
22-
"""Adding verbs is not allowed for <Tag>
23-
24-
Args:
25-
verb (Verb): BXML verb
26-
27-
Raises:
28-
AttributeError: This method is not allowed for <Tag>
29-
"""
30-
raise AttributeError('Adding verbs is not supported by <Tag>')

0 commit comments

Comments
 (0)