Skip to content

Commit acf8374

Browse files
authored
Merge pull request #69 from kontsaki/drop_py27
merge master on drop_py27
2 parents ab27aa5 + 87f8efc commit acf8374

19 files changed

+423
-458
lines changed

pysipp/__init__.py

Lines changed: 31 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,23 @@
1515
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1616

1717
# Authors : Tyler Goodlet
18-
'''
18+
"""
1919
pysipp - a python wrapper for launching SIPp
20-
'''
20+
"""
2121
import sys
2222
from os.path import dirname
2323
from . import plugin, netplug, agent
2424
from .load import iter_scen_dirs
2525
from .agent import client, server
2626

2727

28-
__package__ = 'pysipp'
29-
__author__ = 'Tyler Goodlet ([email protected])'
28+
__package__ = "pysipp"
29+
__author__ = "Tyler Goodlet ([email protected])"
3030

31-
__all__ = ['walk', 'client', 'server', 'plugin']
31+
__all__ = ["walk", "client", "server", "plugin"]
3232

3333

34-
def walk(rootpath, delay_conf_scen=False, autolocalsocks=True,
35-
**scenkwargs):
34+
def walk(rootpath, delay_conf_scen=False, autolocalsocks=True, **scenkwargs):
3635
"""SIPp scenario generator.
3736
3837
Build and return scenario objects for each scenario directory.
@@ -48,23 +47,21 @@ def walk(rootpath, delay_conf_scen=False, autolocalsocks=True,
4847
assert dirname(confpy.__file__) == path
4948

5049
# predicate hook based filtering
51-
res = hooks.pysipp_load_scendir(
52-
path=path, xmls=xmls, confpy=confpy)
50+
res = hooks.pysipp_load_scendir(path=path, xmls=xmls, confpy=confpy)
5351
if res and not all(res):
5452
continue
5553

5654
agents = []
5755
for xml in xmls:
58-
if 'uac' in xml.lower():
56+
if "uac" in xml.lower():
5957
ua = agent.client(scen_file=xml)
6058
agents.append(ua)
61-
elif 'uas' in xml.lower():
59+
elif "uas" in xml.lower():
6260
ua = agent.server(scen_file=xml)
6361
agents.insert(0, ua) # servers are always launched first
6462
else:
6563
raise ValueError(
66-
"xml script must contain one of 'uac' or 'uas':\n{}"
67-
.format(xml)
64+
"xml script must contain one of 'uac' or 'uas':\n{}".format(xml)
6865
)
6966

7067
if delay_conf_scen:
@@ -81,17 +78,13 @@ def walk(rootpath, delay_conf_scen=False, autolocalsocks=True,
8178
yield path, scen
8279

8380

84-
def scenario(dirpath=None, proxyaddr=None, autolocalsocks=True,
85-
**scenkwargs):
81+
def scenario(dirpath=None, proxyaddr=None, autolocalsocks=True, **scenkwargs):
8682
"""Return a single Scenario loaded from `dirpath` if provided else the
8783
basic default call flow.
8884
"""
8985
if dirpath:
9086
# deliver single scenario from dir
91-
path, scen = next(
92-
walk(dirpath, autolocalsocks=autolocalsocks,
93-
**scenkwargs)
94-
)
87+
path, scen = next(walk(dirpath, autolocalsocks=autolocalsocks, **scenkwargs))
9588
else:
9689
with plugin.register([netplug] if autolocalsocks else []):
9790
# deliver the default scenario bound to loopback sockets
@@ -100,13 +93,13 @@ def scenario(dirpath=None, proxyaddr=None, autolocalsocks=True,
10093

10194
# same as above
10295
scen = plugin.mng.hook.pysipp_conf_scen_protocol(
103-
agents=[uas, uac], confpy=None,
96+
agents=[uas, uac],
97+
confpy=None,
10498
scenkwargs=scenkwargs,
10599
)
106100

107101
if proxyaddr is not None:
108-
assert isinstance(proxyaddr, tuple), (
109-
'proxyaddr must be a (addr, port) tuple')
102+
assert isinstance(proxyaddr, tuple), "proxyaddr must be a (addr, port) tuple"
110103
scen.clientdefaults.proxyaddr = proxyaddr
111104

112105
return scen
@@ -123,8 +116,7 @@ def pysipp_load_scendir(path, xmls, confpy):
123116

124117
@plugin.hookimpl
125118
def pysipp_conf_scen_protocol(agents, confpy, scenkwargs):
126-
"""Perform default configuration rule set
127-
"""
119+
"""Perform default configuration rule set"""
128120
# more sanity
129121
if confpy:
130122
ua = agents[0]
@@ -138,13 +130,19 @@ def pysipp_conf_scen_protocol(agents, confpy, scenkwargs):
138130
scen = agent.Scenario(agents, confpy=confpy)
139131

140132
# order the agents for launch
141-
agents = list(hooks.pysipp_order_agents(
142-
agents=scen.agents, clients=scen.clients,
143-
servers=scen.servers)) or agents
133+
agents = (
134+
list(
135+
hooks.pysipp_order_agents(
136+
agents=scen.agents, clients=scen.clients, servers=scen.servers
137+
)
138+
)
139+
or agents
140+
)
144141

145142
# create scenario wrapper
146143
scen = hooks.pysipp_new_scen(
147-
agents=agents, confpy=confpy, scenkwargs=scenkwargs)
144+
agents=agents, confpy=confpy, scenkwargs=scenkwargs
145+
)
148146

149147
# configure scenario
150148
hooks.pysipp_conf_scen(agents=scen.agents, scen=scen)
@@ -158,10 +156,8 @@ def pysipp_conf_scen_protocol(agents, confpy, scenkwargs):
158156

159157
@plugin.hookimpl
160158
def pysipp_order_agents(agents, clients, servers):
161-
"""Lexicographically sort agents by name and always start servers first
162-
"""
163-
return (agents[name] for name in
164-
sorted(servers) + sorted(clients))
159+
"""Lexicographically sort agents by name and always start servers first"""
160+
return (agents[name] for name in sorted(servers) + sorted(clients))
165161

166162

167163
@plugin.hookimpl
@@ -171,14 +167,13 @@ def pysipp_new_scen(agents, confpy, scenkwargs):
171167

172168
@plugin.hookimpl(trylast=True)
173169
def pysipp_conf_scen(agents, scen):
174-
"""Default validation logic and routing with media
175-
"""
170+
"""Default validation logic and routing with media"""
176171
if scen.servers:
177172
# point all clients to send requests to 'primary' server agent
178173
# if they aren't already
179-
servers_addr = scen.serverdefaults.get('srcaddr', ('127.0.0.1', 5060))
174+
servers_addr = scen.serverdefaults.get("srcaddr", ("127.0.0.1", 5060))
180175
uas = scen.prepare_agent(list(scen.servers.values())[0])
181-
scen.clientdefaults.setdefault('destaddr', uas.srcaddr or servers_addr)
176+
scen.clientdefaults.setdefault("destaddr", uas.srcaddr or servers_addr)
182177

183178
elif not scen.clientdefaults.proxyaddr:
184179
# no servers in scenario so point proxy addr to remote socket addr

0 commit comments

Comments
 (0)