Subject: Bug#1629: python3 SyntaxWarning in several packages

From: Chris King <[email-masked]>
Date: Mon, 22 Jul 2024 22:36:29 +0930

Package: python-x2go

Version: 0.6.1.4

During installation of python3-x2go package, presumably when code is 
compiled, the following warnings are emitted:

Setting up python3-x2go (0.6.1.4-1) ...
/usr/lib/python3/dist-packages/x2go/_paramiko.py:165: SyntaxWarning: 
invalid escape sequence '\['
  if re.match('^\[.*\]\:'+str(SSH_PORT)+'$', hostname):
/usr/lib/python3/dist-packages/x2go/backends/control/plain.py:1426: 
SyntaxWarning: invalid escape sequence '\['
  if re.match('^Name\[%s\]=.*' % lang_regio, line) or 
re.match('Name\[%s\]=.*' % lang_only, line):
/usr/lib/python3/dist-packages/x2go/backends/control/plain.py:1426: 
SyntaxWarning: invalid escape sequence '\['
  if re.match('^Name\[%s\]=.*' % lang_regio, line) or 
re.match('Name\[%s\]=.*' % lang_only, line):
/usr/lib/python3/dist-packages/x2go/backends/control/plain.py:1430: 
SyntaxWarning: invalid escape sequence '\['
  elif re.match('^Comment\[%s\]=.*' % lang_regio, line) or 
re.match('Comment\[%s\]=.*' % lang_only, line):
/usr/lib/python3/dist-packages/x2go/backends/control/plain.py:1430: 
SyntaxWarning: invalid escape sequence '\['
  elif re.match('^Comment\[%s\]=.*' % lang_regio, line) or 
re.match('Comment\[%s\]=.*' % lang_only, line):
/usr/lib/python3/dist-packages/x2go/backends/profiles/httpbroker.py:79: 
SyntaxWarning: invalid escape sequence '\.'
  match = 
re.match('^(?P<protocol>(http(|s)))://(|(?P<user>[a-zA-Z0-9_\.-]+)(|:(?P<password>.*))@)(?P<hostname>[a-zA-Z0-9\.-]+)(|:(?
P<port>[0-9]+))($|/(?P<path>.*)$)', broker_url)
/usr/lib/python3/dist-packages/x2go/utils.py:111: SyntaxWarning: invalid 
escape sequence '\w'
  value = re.sub('[^\w\s-]', '', value).strip().lower()
/usr/lib/python3/dist-packages/x2go/utils.py:531: SyntaxWarning: invalid 
escape sequence '\:'
  return bool((path.startswith('/') or re.match('^[%s]\:\\\\' % 
string.ascii_letters, path)))

====

As these are regex strings, given the specific meaning of escape 
character "\", the most python3-compatible way to suppress these 
warnings, and for compatibility into the future is to convert them to 
raw strings

eg.

  if re.match(*_r_*'^\[.*\]\:'+str(SSH_PORT)+'$', hostname):

====

My platform... not that I think it particularly impacts this bug, or its 
fix...

kubuntu-24.04  pyhoca-cli/0.6.1.3  python3/3.12.3 
remmina-plugin-x2go/1.4.35  remmina/1.4.35  x2goclient/4.1.2.3

These are just console warnings on installation at this time... and can 
be left for one of those days when one is ambivalent about having a 
third bath in a boring day.

I haven't reported this bug elsewhere.

All hail to wonderful package maintainers.

Chris.