From 55da48bac7e80728533608050e9a16fcf9fb848f Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Tue, 13 Aug 2024 16:50:30 -0700 Subject: [PATCH] Fix invalid escape sequences in strings - In Python 3.12 and above, these lead to messages such as "SyntaxWarning: invalid escape sequence '\s'". In versions of Python earlier than 3.12, they were DeprecationWarnings. In a later version of Python these will lead to a SyntaxError. Tests: - Verify that the new strings are equivalent to the old strings by old_string == new_string in the python interpreter in Python 3.12. old_string throws SyntaxWarning new_string does not. - Run 'python3 -m py_compile' on each python source file (except legacy files) and ensure that there are no syntax errors or warnings. Signed-off-by: Sunil Mohan Adapa --- pagekite/common.py | 2 +- pagekite/pk.py | 2 +- pagekite/proto/filters.py | 10 +++++----- pagekite/proto/selectables.py | 2 +- pagekite/ui/basic.py | 4 ++-- pagekite/ui/remote.py | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/pagekite/common.py b/pagekite/common.py index 777afc04..3c94afad 100755 --- a/pagekite/common.py +++ b/pagekite/common.py @@ -150,7 +150,7 @@ # Create our service-domain matching regexp import re -SERVICE_DOMAIN_RE = re.compile('\.(' + '|'.join(SERVICE_DOMAINS) + ')$') +SERVICE_DOMAIN_RE = re.compile(r'\.(' + '|'.join(SERVICE_DOMAINS) + ')$') SERVICE_SUBDOMAIN_RE = re.compile(r'^([A-Za-z0-9_-]+\.)*[A-Za-z0-9_-]+$') diff --git a/pagekite/pk.py b/pagekite/pk.py index 938bf03a..a332b3e3 100755 --- a/pagekite/pk.py +++ b/pagekite/pk.py @@ -1240,7 +1240,7 @@ def FindCACerts(self, use_curl_bundle=False): return self.pyfile # Fall back to distributed CA certs ACL_SHORTHAND = { - 'localhost': '((::ffff:)?127\..*|::1)', + 'localhost': r'((::ffff:)?127\..*|::1)', 'any': '.*' } def CheckAcls(self, acls, address, which, conn=None): diff --git a/pagekite/proto/filters.py b/pagekite/proto/filters.py index f1c9fa74..4209aff7 100755 --- a/pagekite/proto/filters.py +++ b/pagekite/proto/filters.py @@ -160,7 +160,7 @@ def filter_connected(self, tunnel, sid, data): class HttpHeaderFilter(TunnelFilter): """Filter that adds X-Forwarded-For and X-Forwarded-Proto to requests.""" FILTERS = ('data_in') - HTTP_HEADER = re.compile('(?ism)^(([A-Z]+) ([^\n]+) HTTP/\d+\.\d+\s*)$') + HTTP_HEADER = re.compile('(?ism)^(([A-Z]+) ([^\n]+) HTTP/\\d+\\.\\d+\\s*)$') DISABLE = 'rawheaders' def filter_data_in(self, tunnel, sid, data): @@ -213,15 +213,15 @@ class HttpSecurityFilter(HttpHeaderFilter): '((?:/+(?:xampp/|security/|licenses/|webalizer/|server-(?:status|info)|adm)' '|[^\n]*/' # WordPress admin pages - '(?:wp-admin/(?!admin-ajax|css/)|wp-config\.php' + r'(?:wp-admin/(?!admin-ajax|css/)|wp-config\.php' # Hackzor tricks - '|system32/|\.\.|\.ht(?:access|pass)' + r'|system32/|\.\.|\.ht(?:access|pass)' # phpMyAdmin and similar tools '|(?:php|sql)?my(?:sql)?(?:adm|manager)' # Setup pages for common PHP tools - '|(?:adm[^\n]*|install[^\n]*|setup)\.php)' + '|(?:adm[^\n]*|install[^\n]*|setup)\\.php)' ')[^\n]*)' - ' HTTP/\d+\.\d+\s*)$') + r' HTTP/\d+\.\d+\s*)$') REJECT = 'PAGEKITE_REJECT_' def filter_header_data_in(self, http_hdr, data, info): diff --git a/pagekite/proto/selectables.py b/pagekite/proto/selectables.py index 60b244b0..a79e9f1f 100755 --- a/pagekite/proto/selectables.py +++ b/pagekite/proto/selectables.py @@ -653,7 +653,7 @@ def ProcessLine(self, line, lines): TLS_CLIENTHELLO = '%c' % 0o26 SSL_CLIENTHELLO = '\x80' XML_PREAMBLE = ']+\sto=([^\s>]+)[^>]*>") +XMPP_REGEXP = re.compile(r"<[^>]+\sto=([^\s>]+)[^>]*>") class MagicProtocolParser(LineParser): """A Selectable which recognizes HTTP, TLS or XMPP preambles.""" diff --git a/pagekite/ui/basic.py b/pagekite/ui/basic.py index b62c5bd3..1755ca0d 100755 --- a/pagekite/ui/basic.py +++ b/pagekite/ui/basic.py @@ -54,8 +54,8 @@ class BasicUi(NullUi): DAEMON_FRIENDLY = False WANTS_STDERR = True EMAIL_RE = re.compile(r'^[a-z0-9!#$%&\'\*\+\/=?^_`{|}~-]+' - '(?:\.[a-z0-9!#$%&\'*+/=?^_`{|}~-]+)*@' - '(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)*' + '(?:\\.[a-z0-9!#$%&\'*+/=?^_`{|}~-]+)*@' + r'(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)*' '(?:[a-zA-Z]{2,16})$') def Notify(self, message, prefix=' ', popup=False, color=None, now=None, alignright=''): diff --git a/pagekite/ui/remote.py b/pagekite/ui/remote.py index f7c8a56f..50906a07 100755 --- a/pagekite/ui/remote.py +++ b/pagekite/ui/remote.py @@ -43,8 +43,8 @@ class RemoteUi(NullUi): ALLOWS_INPUT = True WANTS_STDERR = True EMAIL_RE = re.compile(r'^[a-z0-9!#$%&\'\*\+\/=?^_`{|}~-]+' - '(?:\.[a-z0-9!#$%&\'*+/=?^_`{|}~-]+)*@' - '(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)*' + '(?:\\.[a-z0-9!#$%&\'*+/=?^_`{|}~-]+)*@' + r'(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)*' '(?:[a-zA-Z]{2,4}|museum)$') def __init__(self, welcome=None, wfile=sys.stderr, rfile=sys.stdin):