From 9675c4471ec9680ae5287b9555dba3e808223e34 Mon Sep 17 00:00:00 2001 From: mib1185 Date: Tue, 2 Apr 2024 01:55:17 +0200 Subject: [PATCH 1/2] mark pattern variables raw strings --- ppadb/command/host/__init__.py | 2 +- ppadb/command/host_async/__init__.py | 2 +- ppadb/command/transport/__init__.py | 8 ++++---- ppadb/device.py | 4 ++-- ppadb/device_async.py | 4 ++-- ppadb/plugins/device/cpustat.py | 2 +- ppadb/plugins/device/traffic.py | 2 +- ppadb/plugins/device/utils.py | 6 +++--- 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/ppadb/command/host/__init__.py b/ppadb/command/host/__init__.py index 6711a53..ef0a3a2 100644 --- a/ppadb/command/host/__init__.py +++ b/ppadb/command/host/__init__.py @@ -3,7 +3,7 @@ class Host(Command): - CONNECT_RESULT_PATTERN = "(connected to|already connected)" + CONNECT_RESULT_PATTERN = r"(connected to|already connected)" OFFLINE = "offline" DEVICE = "device" diff --git a/ppadb/command/host_async/__init__.py b/ppadb/command/host_async/__init__.py index f32e011..e80a466 100644 --- a/ppadb/command/host_async/__init__.py +++ b/ppadb/command/host_async/__init__.py @@ -2,7 +2,7 @@ class HostAsync: - CONNECT_RESULT_PATTERN = "(connected to|already connected)" + CONNECT_RESULT_PATTERN = r"(connected to|already connected)" OFFLINE = "offline" DEVICE = "device" diff --git a/ppadb/command/transport/__init__.py b/ppadb/command/transport/__init__.py index 1adadf6..5586180 100644 --- a/ppadb/command/transport/__init__.py +++ b/ppadb/command/transport/__init__.py @@ -51,7 +51,7 @@ def screencap(self): return result def clear(self, package): - clear_result_pattern = "(Success|Failed)" + clear_result_pattern = r"(Success|Failed)" result = self.shell("pm clear {}".format(package)) m = re.search(clear_result_pattern, result) @@ -68,7 +68,7 @@ def framebuffer(self): def list_features(self): result = self.shell("pm list features 2>/dev/null") - result_pattern = "^feature:(.*?)(?:=(.*?))?\r?$" + result_pattern = r"^feature:(.*?)(?:=(.*?))?\r?$" features = {} for line in result.split('\n'): m = re.match(result_pattern, line) @@ -80,7 +80,7 @@ def list_features(self): def list_packages(self): result = self.shell("pm list packages 2>/dev/null") - result_pattern = "^package:(.*?)\r?$" + result_pattern = r"^package:(.*?)\r?$" packages = [] for line in result.split('\n'): @@ -92,7 +92,7 @@ def list_packages(self): def get_properties(self): result = self.shell("getprop") - result_pattern = "^\[([\s\S]*?)\]: \[([\s\S]*?)\]\r?$" + result_pattern = r"^\[([\s\S]*?)\]: \[([\s\S]*?)\]\r?$" properties = {} for line in result.split('\n'): diff --git a/ppadb/device.py b/ppadb/device.py index dd08ec4..79ec848 100644 --- a/ppadb/device.py +++ b/ppadb/device.py @@ -31,8 +31,8 @@ class Device(Transport, Serial, Input, Utils, WM, Traffic, CPUStat, BatteryStats): - INSTALL_RESULT_PATTERN = "(Success|Failure|Error)\s?(.*)" - UNINSTALL_RESULT_PATTERN = "(Success|Failure.*|.*Unknown package:.*)" + INSTALL_RESULT_PATTERN = r"(Success|Failure|Error)\s?(.*)" + UNINSTALL_RESULT_PATTERN = r"(Success|Failure.*|.*Unknown package:.*)" def __init__(self, client, serial): self.client = client diff --git a/ppadb/device_async.py b/ppadb/device_async.py index 5e4a8b0..59cb3b0 100644 --- a/ppadb/device_async.py +++ b/ppadb/device_async.py @@ -21,8 +21,8 @@ def _get_src_info(src): class DeviceAsync(TransportAsync): - INSTALL_RESULT_PATTERN = "(Success|Failure|Error)\s?(.*)" - UNINSTALL_RESULT_PATTERN = "(Success|Failure.*|.*Unknown package:.*)" + INSTALL_RESULT_PATTERN = r"(Success|Failure|Error)\s?(.*)" + UNINSTALL_RESULT_PATTERN = r"(Success|Failure.*|.*Unknown package:.*)" def __init__(self, client, serial): self.client = client diff --git a/ppadb/plugins/device/cpustat.py b/ppadb/plugins/device/cpustat.py index 1175f3d..9dd38e1 100644 --- a/ppadb/plugins/device/cpustat.py +++ b/ppadb/plugins/device/cpustat.py @@ -87,7 +87,7 @@ def total(self): class CPUStat(Plugin): total_cpu_pattern = re.compile( - "cpu\s+([\d]+)\s([\d]+)\s([\d]+)\s([\d]+)\s([\d]+)\s([\d]+)\s([\d]+)\s([\d]+)\s([\d]+)\s([\d]+)\s") + r"cpu\s+([\d]+)\s([\d]+)\s([\d]+)\s([\d]+)\s([\d]+)\s([\d]+)\s([\d]+)\s([\d]+)\s([\d]+)\s([\d]+)\s") def cpu_times(self): return self.get_total_cpu() diff --git a/ppadb/plugins/device/traffic.py b/ppadb/plugins/device/traffic.py index 0e1a66a..e44fbe9 100644 --- a/ppadb/plugins/device/traffic.py +++ b/ppadb/plugins/device/traffic.py @@ -33,7 +33,7 @@ def get_traffic(self, package_name): cmd = 'dumpsys package {} | grep userId'.format(package_name) result = self.shell(cmd).strip() - pattern = "userId=([\d]+)" + pattern = r"userId=([\d]+)" if result: match = re.search(pattern, result) diff --git a/ppadb/plugins/device/utils.py b/ppadb/plugins/device/utils.py index 225674d..be836ea 100644 --- a/ppadb/plugins/device/utils.py +++ b/ppadb/plugins/device/utils.py @@ -32,7 +32,7 @@ def get_top_activity(self): return None def get_top_activities(self): - pattern = "ACTIVITY\s([\w\.]+)/([\w\.]+)\s[\w\d]+\spid=([\d]+)" + pattern = r"ACTIVITY\s([\w\.]+)/([\w\.]+)\s[\w\d]+\spid=([\d]+)" cmd = "dumpsys activity top | grep ACTIVITY" result = self.shell(cmd) @@ -82,7 +82,7 @@ def get_uid(self, package_name): cmd = 'dumpsys package {} | grep userId'.format(package_name) result = self.shell(cmd).strip() - pattern = "userId=([\d]+)" + pattern = r"userId=([\d]+)" if result: match = re.search(pattern, result) @@ -99,7 +99,7 @@ def get_package_version_name(self, package_name): cmd = 'dumpsys package {} | grep versionName'.format(package_name) result = self.shell(cmd).strip() - pattern = "versionName=([\d\.]+)" + pattern = r"versionName=([\d\.]+)" if result: match = re.search(pattern, result) From b85afe786ea93b510ac2e8e162987aff3c63f063 Mon Sep 17 00:00:00 2001 From: mib1185 Date: Tue, 2 Apr 2024 02:40:13 +0200 Subject: [PATCH 2/2] mark more pattern variables raw strings --- ppadb/plugins/device/utils.py | 14 +++++++------- ppadb/plugins/device/wm.py | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ppadb/plugins/device/utils.py b/ppadb/plugins/device/utils.py index be836ea..99872ee 100644 --- a/ppadb/plugins/device/utils.py +++ b/ppadb/plugins/device/utils.py @@ -45,13 +45,13 @@ def get_top_activities(self): return activities def get_meminfo(self, package_name): - total_meminfo_re = re.compile('\s*TOTAL\s*(?P\d+)' - '\s*(?P\d+)' - '\s*(?P\d+)' - '\s*(?P\d+)' - '\s*(?P\d+)' - '\s*(?P\d+)' - '\s*(?P\d+)') + total_meminfo_re = re.compile(r'\s*TOTAL\s*(?P\d+)' + r'\s*(?P\d+)' + r'\s*(?P\d+)' + r'\s*(?P\d+)' + r'\s*(?P\d+)' + r'\s*(?P\d+)' + r'\s*(?P\d+)') cmd = 'dumpsys meminfo {}'.format(package_name) result = self.shell(cmd) diff --git a/ppadb/plugins/device/wm.py b/ppadb/plugins/device/wm.py index 7a3c520..6d88823 100644 --- a/ppadb/plugins/device/wm.py +++ b/ppadb/plugins/device/wm.py @@ -9,7 +9,7 @@ ]) class WM(Plugin): - SIZE_RE = 'Physical size:\s([\d]+)x([\d]+)' + SIZE_RE = r'Physical size:\s([\d]+)x([\d]+)' def wm_size(self): result = self.shell("wm size") match = re.search(self.SIZE_RE, result)