本文整理汇总了Python中netman.regex.match函数的典型用法代码示例。如果您正苦于以下问题:Python match函数的具体用法?Python match怎么用?Python match使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了match函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: resolve_port_mode
def resolve_port_mode(interface_data):
for line in interface_data:
if regex.match("switchport mode (\S+)", line):
return regex[0]
elif regex.match("switchport access vlan .*", line):
return "access"
return None
示例2: get_vlan
def get_vlan(self, number):
result = self.shell.do("show vlan id {}".format(number))
if regex.match(".*\^.*", result[0]):
raise BadVlanNumber()
elif regex.match("^ERROR", result[0]):
raise UnknownVlan(number)
else:
return parse_vlan_list(result)[0]
示例3: parse_interface_names
def parse_interface_names(self, status_list):
interfaces = []
for line in status_list:
if regex.match("(\d\S+).*", line):
interfaces.append("ethernet {}".format(regex[0]))
elif regex.match("ch(\d+).*", line):
interfaces.append("port-channel {}".format(regex[0]))
return interfaces
示例4: get_vlan
def get_vlan(self, vlan_number):
result = self.page_reader.do(self.shell, "show vlan id {}".format(vlan_number))
if regex.match(".*\^.*", result[0]):
raise BadVlanNumber()
elif regex.match("^ERROR", result[0]):
raise UnknownVlan(vlan_number)
vlan = parse_vlan_list(result)[0]
return vlan
示例5: get_vlan_interfaces
def get_vlan_interfaces(self, vlan_number):
result = self.shell.do("show vlan id {}".format(vlan_number))
if regex.match(".*\^.*", result[0]):
raise BadVlanNumber()
elif regex.match("^ERROR", result[0]):
raise UnknownVlan(vlan_number)
return self.parse_interface_from_vlan_list(vlan_number, result)
示例6: parse_interface_names
def parse_interface_names(status_list):
interfaces = []
for line in status_list:
if regex.match("Te(\d+/\d+/\S+).*", line):
interfaces.append("tengigabitethernet {}".format(regex[0]))
elif regex.match("Po(\d+).*", line):
interfaces.append("port-channel {}".format(regex[0]))
return interfaces
示例7: get_vlan_interfaces
def get_vlan_interfaces(self, vlan_number):
result = self.shell.do("show vlan id {}".format(vlan_number), wait_for=("--More-- or (q)uit", "#"), include_last_line=True)
while len(result) > 0 and "--More--" in result[-1]:
result += self.shell.send_key("m", wait_for=("--More-- or (q)uit", "#"), include_last_line=True)
if regex.match(".*\^.*", result[0]):
raise BadVlanNumber()
elif regex.match("^ERROR", result[0]):
raise UnknownVlan(vlan_number)
return self.parse_interface_from_vlan_list(vlan_number, result)
示例8: parse_vlan_list
def parse_vlan_list(result):
vlans = []
for line in result:
if regex.match("^(\d+)(.*)", line):
number, leftovers = regex
name = None
if regex.match("^\s{1,6}(\S+).*", leftovers):
name = regex[0]
vlan = Vlan(number=int(number), name=name if int(number) > 1 else "default")
vlans.append(vlan)
return vlans
示例9: parse_vlan_list
def parse_vlan_list(result):
vlans = []
for line in result:
if regex.match('^(\d+)\s{1,6}(\S+).*', line):
number, name = regex
vlans.append(Vlan(number=int(number),
name=name if int(number) > 1 else "default"))
elif regex.match('^(\d+)\s+.*', line):
number = regex[0]
vlans.append(Vlan(number=int(number)))
return vlans
示例10: test_should_be_threadsafe
def test_should_be_threadsafe(self):
regex.match('^(\w+)\s(\w+)$', 'hello world')
def match_single_word():
regex.match('^(\w+)$', 'bonjour')
assert_that(regex[0], is_('bonjour'))
t = Thread(target=match_single_word)
t.start()
t.join()
assert_that(regex[1], is_('world'))
示例11: parse_vlan_list
def parse_vlan_list(result):
vlans = []
for line in result:
if regex.match("^(\d+)\s{1,6}(\S+).*", line):
number, name = regex
if name == "VLAN{:0>4}".format(number):
name = None
vlans.append(Vlan(number=int(number), name=name if int(number) > 1 else "default"))
elif regex.match("^(\d+)\s+.*", line):
number = regex[0]
vlans.append(Vlan(number=int(number)))
return vlans
示例12: parse_vlan_runningconfig
def parse_vlan_runningconfig(data):
vlan = {"tagged_interface": [], "untagged_interface": []}
if regex.match("^vlan (\d*)", data[0]):
vlan['id'] = int(regex[0])
for line in data:
if regex.match(" untagged (.*)", line):
for name in _to_real_names(parse_if_ranges(regex[0])):
vlan["untagged_interface"].append(name)
if regex.match(" tagged (.*)", line):
for name in _to_real_names(parse_if_ranges(regex[0])):
vlan["tagged_interface"].append(name)
return vlan
示例13: parse_interface_from_vlan_list
def parse_interface_from_vlan_list(self, vlan_number, result):
vlan_interfaces = []
number = None
for line in result:
if regex.match('^(\d+)(.*)', line):
number, leftover = regex
if int(number) == vlan_number:
if regex.match('^\s{1,6}\S*\s+([a-zA-Z0-9-,/]+).*', leftover):
vlan_interfaces.extend(self.parse_interface_port_list(regex[0]))
elif regex.match('^\s+([a-zA-Z0-9-,/]+).*', line) and int(number) == vlan_number:
vlan_interfaces.extend(self.parse_interface_port_list(regex[0]))
return vlan_interfaces
示例14: add_vlan
def add_vlan(self, number, name=None):
result = self.shell.do("show vlan id {}".format(number))
if regex.match(".*\^.*", result[0]):
raise BadVlanNumber()
elif regex.match("^VLAN", result[0]):
raise VlanAlreadyExist(number)
with self.config():
with self.vlan_database():
self.set('vlan {}', number)
if name is not None:
with self.interface("vlan {}".format(number)):
self.set('name {}', name).on_any_result(BadVlanName)
示例15: parse_vlan
def parse_vlan(vlan_data):
regex.match("^vlan (\d+).*", vlan_data[0])
current_vlan = VlanBrocade(int(regex[0]))
if regex.match("^vlan \d+ name ([^\s]*)", vlan_data[0]):
current_vlan.name = regex[0] if regex[0] != "DEFAULT-VLAN" else "default"
else:
current_vlan.name = None
for line in vlan_data[1:]:
if regex.match("^\srouter-interface ve (\d+)", line):
current_vlan.vlan_interface_name = regex[0]
return current_vlan