Fix DeprecationWarning: invalid escape sequence. Fixes https://github.com/GNS3/gns3-gui/issues/2670

This commit is contained in:
grossmj 2019-01-17 18:01:58 +07:00
parent 4b52e9313e
commit 456ef1348b
9 changed files with 23 additions and 23 deletions

View File

@ -637,7 +637,7 @@ class BaseNode:
try: try:
await self._ubridge_send(cmd) await self._ubridge_send(cmd)
except UbridgeError as e: except UbridgeError as e:
match = re.search("Cannot compile filter '(.*)': syntax error", str(e)) match = re.search(r"Cannot compile filter '(.*)': syntax error", str(e))
if match: if match:
message = "Warning: ignoring BPF packet filter '{}' due to syntax error".format(self.name, match.group(1)) message = "Warning: ignoring BPF packet filter '{}' due to syntax error".format(self.name, match.group(1))
log.warning(message) log.warning(message)

View File

@ -171,10 +171,10 @@ class IOUVM(BaseNode):
try: try:
output = await gns3server.utils.asyncio.subprocess_check_output(self._path, "-h", cwd=self.working_dir, stderr=True) output = await gns3server.utils.asyncio.subprocess_check_output(self._path, "-h", cwd=self.working_dir, stderr=True)
match = re.search("-n <n>\s+Size of nvram in Kb \(default ([0-9]+)KB\)", output) match = re.search(r"-n <n>\s+Size of nvram in Kb \(default ([0-9]+)KB\)", output)
if match: if match:
self.nvram = int(match.group(1)) self.nvram = int(match.group(1))
match = re.search("-m <n>\s+Megabytes of router memory \(default ([0-9]+)MB\)", output) match = re.search(r"-m <n>\s+Megabytes of router memory \(default ([0-9]+)MB\)", output)
if match: if match:
self.ram = int(match.group(1)) self.ram = int(match.group(1))
except (ValueError, OSError, subprocess.SubprocessError) as e: except (ValueError, OSError, subprocess.SubprocessError) as e:
@ -380,7 +380,7 @@ class IOUVM(BaseNode):
log.warning("Could not determine the shared library dependencies for {}: {}".format(self._path, e)) log.warning("Could not determine the shared library dependencies for {}: {}".format(self._path, e))
return return
p = re.compile("([\.\w]+)\s=>\s+not found") p = re.compile(r"([\.\w]+)\s=>\s+not found")
missing_libs = p.findall(output) missing_libs = p.findall(output)
if missing_libs: if missing_libs:
raise IOUError("The following shared library dependencies cannot be found for IOU image {}: {}".format(self._path, raise IOUError("The following shared library dependencies cannot be found for IOU image {}: {}".format(self._path,
@ -604,7 +604,7 @@ class IOUVM(BaseNode):
if nio.capturing: if nio.capturing:
await self._ubridge_send('iol_bridge start_capture {name} "{output_file}" {data_link_type}'.format(name=bridge_name, await self._ubridge_send('iol_bridge start_capture {name} "{output_file}" {data_link_type}'.format(name=bridge_name,
output_file=nio.pcap_output_file, output_file=nio.pcap_output_file,
data_link_type=re.sub("^DLT_", "", nio.pcap_data_link_type))) data_link_type=re.sub(r"^DLT_", "", nio.pcap_data_link_type)))
await self._ubridge_apply_filters(bay_id, unit_id, nio.filters) await self._ubridge_apply_filters(bay_id, unit_id, nio.filters)
unit_id += 1 unit_id += 1
@ -1036,7 +1036,7 @@ class IOUVM(BaseNode):
env["IOURC"] = self.iourc_path env["IOURC"] = self.iourc_path
try: try:
output = await gns3server.utils.asyncio.subprocess_check_output(self._path, "-h", cwd=self.working_dir, env=env, stderr=True) output = await gns3server.utils.asyncio.subprocess_check_output(self._path, "-h", cwd=self.working_dir, env=env, stderr=True)
if re.search("-l\s+Enable Layer 1 keepalive messages", output): if re.search(r"-l\s+Enable Layer 1 keepalive messages", output):
command.extend(["-l"]) command.extend(["-l"])
else: else:
raise IOUError("layer 1 keepalive messages are not supported by {}".format(os.path.basename(self._path))) raise IOUError("layer 1 keepalive messages are not supported by {}".format(os.path.basename(self._path)))
@ -1295,7 +1295,7 @@ class IOUVM(BaseNode):
bay=adapter_number, bay=adapter_number,
unit=port_number, unit=port_number,
output_file=output_file, output_file=output_file,
data_link_type=re.sub("^DLT_", "", data_link_type))) data_link_type=re.sub(r"^DLT_", "", data_link_type)))
async def stop_capture(self, adapter_number, port_number): async def stop_capture(self, adapter_number, port_number):
""" """

View File

@ -177,7 +177,7 @@ class Qemu(BaseManager):
try: try:
with open(version_file, "rb") as file: with open(version_file, "rb") as file:
version = file.read().decode("utf-8").strip() version = file.read().decode("utf-8").strip()
match = re.search("[0-9\.]+", version) match = re.search(r"[0-9\.]+", version)
if match: if match:
return version return version
except (UnicodeDecodeError, OSError) as e: except (UnicodeDecodeError, OSError) as e:
@ -186,7 +186,7 @@ class Qemu(BaseManager):
else: else:
try: try:
output = await subprocess_check_output(qemu_path, "-version") output = await subprocess_check_output(qemu_path, "-version")
match = re.search("version\s+([0-9a-z\-\.]+)", output) match = re.search(r"version\s+([0-9a-z\-\.]+)", output)
if match: if match:
version = match.group(1) version = match.group(1)
return version return version
@ -205,7 +205,7 @@ class Qemu(BaseManager):
try: try:
output = await subprocess_check_output(qemu_img_path, "--version") output = await subprocess_check_output(qemu_img_path, "--version")
match = re.search("version\s+([0-9a-z\-\.]+)", output) match = re.search(r"version\s+([0-9a-z\-\.]+)", output)
if match: if match:
version = match.group(1) version = match.group(1)
return version return version

View File

@ -221,7 +221,7 @@ class VirtualBoxVM(BaseNode):
for image in tree.getroot().findall("{http://www.virtualbox.org/}Image"): for image in tree.getroot().findall("{http://www.virtualbox.org/}Image"):
currentSnapshot = machine.get("currentSnapshot") currentSnapshot = machine.get("currentSnapshot")
if currentSnapshot: if currentSnapshot:
newSnapshot = re.sub("\{.*\}", "{" + str(uuid.uuid4()) + "}", currentSnapshot) newSnapshot = re.sub(r"\{.*\}", "{" + str(uuid.uuid4()) + "}", currentSnapshot)
shutil.move(os.path.join(self.working_dir, self._vmname, "Snapshots", currentSnapshot) + ".vdi", shutil.move(os.path.join(self.working_dir, self._vmname, "Snapshots", currentSnapshot) + ".vdi",
os.path.join(self.working_dir, self._vmname, "Snapshots", newSnapshot) + ".vdi") os.path.join(self.working_dir, self._vmname, "Snapshots", newSnapshot) + ".vdi")
image.set("uuid", newSnapshot) image.set("uuid", newSnapshot)
@ -443,7 +443,7 @@ class VirtualBoxVM(BaseNode):
hdd_files = await self._get_all_hdd_files() hdd_files = await self._get_all_hdd_files()
vm_info = await self._get_vm_info() vm_info = await self._get_vm_info()
for entry, value in vm_info.items(): for entry, value in vm_info.items():
match = re.search("^([\s\w]+)\-(\d)\-(\d)$", entry) # match Controller-PortNumber-DeviceNumber entry match = re.search(r"^([\s\w]+)\-(\d)\-(\d)$", entry) # match Controller-PortNumber-DeviceNumber entry
if match: if match:
controller = match.group(1) controller = match.group(1)
port = match.group(2) port = match.group(2)

View File

@ -135,7 +135,7 @@ class VMware(BaseManager):
except OSError: except OSError:
pass pass
if version is not None: if version is not None:
match = re.search("([0-9]+)\.", version) match = re.search(r"([0-9]+)\.", version)
if match: if match:
version = match.group(1) version = match.group(1)
return version return version
@ -222,14 +222,14 @@ class VMware(BaseManager):
try: try:
output = await subprocess_check_output(vmware_path, "-v") output = await subprocess_check_output(vmware_path, "-v")
match = re.search("VMware Workstation ([0-9]+)\.", output) match = re.search(r"VMware Workstation ([0-9]+)\.", output)
version = None version = None
if match: if match:
# VMware Workstation has been detected # VMware Workstation has been detected
version = match.group(1) version = match.group(1)
log.debug("VMware Workstation version {} detected".format(version)) log.debug("VMware Workstation version {} detected".format(version))
await self._check_vmware_workstation_requirements(version) await self._check_vmware_workstation_requirements(version)
match = re.search("VMware Player ([0-9]+)\.", output) match = re.search(r"VMware Player ([0-9]+)\.", output)
if match: if match:
# VMware Player has been detected # VMware Player has been detected
version = match.group(1) version = match.group(1)
@ -278,7 +278,7 @@ class VMware(BaseManager):
try: try:
with open(vmware_networking_file, "r", encoding="utf-8") as f: with open(vmware_networking_file, "r", encoding="utf-8") as f:
for line in f.read().splitlines(): for line in f.read().splitlines():
match = re.search("VNET_([0-9]+)_VIRTUAL_ADAPTER", line) match = re.search(r"VNET_([0-9]+)_VIRTUAL_ADAPTER", line)
if match: if match:
vmnet = "vmnet{}".format(match.group(1)) vmnet = "vmnet{}".format(match.group(1))
if vmnet not in ("vmnet0", "vmnet1", "vmnet8"): if vmnet not in ("vmnet0", "vmnet1", "vmnet8"):
@ -297,7 +297,7 @@ class VMware(BaseManager):
windows_name = interface["netcard"] windows_name = interface["netcard"]
else: else:
windows_name = interface["name"] windows_name = interface["name"]
match = re.search("(VMnet[0-9]+)", windows_name) match = re.search(r"(VMnet[0-9]+)", windows_name)
if match: if match:
vmnet = match.group(1) vmnet = match.group(1)
if vmnet not in ("VMnet0", "VMnet1", "VMnet8"): if vmnet not in ("VMnet0", "VMnet1", "VMnet8"):
@ -312,7 +312,7 @@ class VMware(BaseManager):
self._vmnet_start_range = self.config.get_section_config("VMware").getint("vmnet_start_range", self._vmnet_start_range) self._vmnet_start_range = self.config.get_section_config("VMware").getint("vmnet_start_range", self._vmnet_start_range)
self._vmnet_end_range = self.config.get_section_config("VMware").getint("vmnet_end_range", self._vmnet_end_range) self._vmnet_end_range = self.config.get_section_config("VMware").getint("vmnet_end_range", self._vmnet_end_range)
match = re.search("vmnet([0-9]+)$", vmnet, re.IGNORECASE) match = re.search(r"vmnet([0-9]+)$", vmnet, re.IGNORECASE)
if match: if match:
vmnet_number = match.group(1) vmnet_number = match.group(1)
if self._vmnet_start_range <= int(vmnet_number) <= self._vmnet_end_range: if self._vmnet_start_range <= int(vmnet_number) <= self._vmnet_end_range:
@ -424,7 +424,7 @@ class VMware(BaseManager):
try: try:
output = await subprocess_check_output(vmrun_path) output = await subprocess_check_output(vmrun_path)
match = re.search("vmrun version ([0-9\.]+)", output) match = re.search(r"vmrun version ([0-9\.]+)", output)
version = None version = None
if match: if match:
version = match.group(1) version = match.group(1)

View File

@ -204,7 +204,7 @@ class VPCSVM(BaseNode):
""" """
try: try:
output = await subprocess_check_output(self._vpcs_path(), "-v", cwd=self.working_dir) output = await subprocess_check_output(self._vpcs_path(), "-v", cwd=self.working_dir)
match = re.search("Welcome to Virtual PC Simulator, version ([0-9a-z\.]+)", output) match = re.search(r"Welcome to Virtual PC Simulator, version ([0-9a-z\.]+)", output)
if match: if match:
version = match.group(1) version = match.group(1)
self._vpcs_version = parse_version(version) self._vpcs_version = parse_version(version)

View File

@ -365,7 +365,7 @@ class Link:
self._nodes[1]["node"].name, self._nodes[1]["node"].name,
self._nodes[1]["adapter_number"], self._nodes[1]["adapter_number"],
self._nodes[1]["port_number"]) self._nodes[1]["port_number"])
return re.sub("[^0-9A-Za-z_-]", "", capture_file_name) + ".pcap" return re.sub(r"[^0-9A-Za-z_-]", "", capture_file_name) + ".pcap"
@property @property
def id(self): def id(self):

View File

@ -135,7 +135,7 @@ class Hypervisor(UBridgeHypervisor):
""" """
try: try:
output = await subprocess_check_output(self._path, "-v", cwd=self._working_dir, env=env) output = await subprocess_check_output(self._path, "-v", cwd=self._working_dir, env=env)
match = re.search("ubridge version ([0-9a-z\.]+)", output) match = re.search(r"ubridge version ([0-9a-z\.]+)", output)
if match: if match:
self._version = match.group(1) self._version = match.group(1)
if sys.platform.startswith("win") or sys.platform.startswith("darwin"): if sys.platform.startswith("win") or sys.platform.startswith("darwin"):

View File

@ -129,7 +129,7 @@ class Documentation:
def _file_path(self, path): def _file_path(self, path):
path = path.replace("compute", "") path = path.replace("compute", "")
path = path.replace("controller", "") path = path.replace("controller", "")
return re.sub("^v2", "", re.sub("[^a-z0-9]", "", path)) return re.sub("^v2", "", re.sub(r"[^a-z0-9]", "", path))
def _write_definitions(self, f, schema): def _write_definitions(self, f, schema):
if "definitions" in schema: if "definitions" in schema: