From acdaaa9e26eaa9d45b60ad00a2ebd05e56808816 Mon Sep 17 00:00:00 2001 From: jmoore Date: Wed, 11 Sep 2019 09:58:37 +0100 Subject: [PATCH] Prefix escaped strings with 'r' This includes regexes as well as doc strings. Also filter deprecation warnings from tox output where possible to capture files that we cannot alter (e.g. `past.util.misc`) --- pytest.ini | 2 +- src/omero/cli.py | 16 ++++++++-------- src/omero/clients.py | 8 ++++---- src/omero/gateway/__init__.py | 4 ++-- src/omero/install/logs_library.py | 2 +- src/omero/install/perf_test.py | 2 +- src/omero/install/versions.py | 2 +- src/omero/plugins/admin.py | 22 +++++++++++----------- src/omero/plugins/metadata.py | 2 +- src/omero/plugins/obj.py | 12 ++++++------ src/omero/plugins/script.py | 4 ++-- src/omero/plugins/sessions.py | 2 +- src/omero/plugins/upload.py | 2 +- src/omero/util/importperf.py | 4 ++-- src/omero/util/metadata_utils.py | 4 ++-- src/omero/util/populate_metadata.py | 2 +- src/omero/util/populate_roi.py | 4 ++-- src/omero/util/pydict_text_io.py | 2 +- src/omero_model_PermissionsI.py | 2 +- src/path.py | 2 +- tox.ini | 1 + 21 files changed, 51 insertions(+), 50 deletions(-) diff --git a/pytest.ini b/pytest.ini index b54fe55eb..a9c136f50 100644 --- a/pytest.ini +++ b/pytest.ini @@ -7,5 +7,5 @@ markers = ## error::DeprecationWarning # Tests which will raise a deprecation warning should be updated # to use `pytest.deprecated_call(method, *args)` - filterwarnings = +filterwarnings = ignore::DeprecationWarning diff --git a/src/omero/cli.py b/src/omero/cli.py index 321071de7..64c6b56f1 100755 --- a/src/omero/cli.py +++ b/src/omero/cli.py @@ -99,9 +99,9 @@ OMERO_COMPONENTS = ['common', 'model', 'romio', 'renderer', 'server', 'blitz'] -COMMENT = re.compile("^\s*#") -RELFILE = re.compile("^\w") -LINEWSP = re.compile("^\s*\w+\s+") +COMMENT = re.compile(r"^\s*#") +RELFILE = re.compile(r"^\w") +LINEWSP = re.compile(r"^\s*\w+\s+") # # Possibilities: @@ -1101,10 +1101,10 @@ def _exists(self, p): elif not p.size: self.ctx.out("empty") else: - warn_regex = ('(-! )?[\d\-/]+\s+[\d:,.]+\s+([\w.]+:\s+)?' - 'warn(i(ng:)?)?\s') - err_regex = ('(!! )?[\d\-/]+\s+[\d:,.]+\s+([\w.]+:\s+)?' - 'error:?\s') + warn_regex = (r'(-! )?[\d\-/]+\s+[\d:,.]+\s+([\w.]+:\s+)?' + r'warn(i(ng:)?)?\s') + err_regex = (r'(!! )?[\d\-/]+\s+[\d:,.]+\s+([\w.]+:\s+)?' + r'error:?\s') warn = 0 err = 0 for l in p.lines(): @@ -1203,7 +1203,7 @@ def __call__(self, args): class CD(BaseControl): def _complete(self, text, line, begidx, endidx): - RE = re.compile("\s*cd\s*") + RE = re.compile(r"\s*cd\s*") m = RE.match(line) if m: replaced = RE.sub('', line) diff --git a/src/omero/clients.py b/src/omero/clients.py index a1b6c45f8..a7e883b38 100755 --- a/src/omero/clients.py +++ b/src/omero/clients.py @@ -325,10 +325,10 @@ def _check_for_hosturl(self, host, port, pmap): return {} hostmatch = re.match( - '(?P\\w+)://' - '(?P[^:/]+)' - '(:(?P\\d+))?' - '(?P/.*)?$', + r'(?P\\w+)://' + r'(?P[^:/]+)' + r'(:(?P\\d+))?' + r'(?P/.*)?$', host) if hostmatch: diff --git a/src/omero/gateway/__init__.py b/src/omero/gateway/__init__.py index 7b67a8eae..4a5da2cd5 100644 --- a/src/omero/gateway/__init__.py +++ b/src/omero/gateway/__init__.py @@ -2750,7 +2750,7 @@ def canCreate(self): False if the server is wholly in read-only mode, otherwise None """ - key_regex = '^omero\.cluster\.read_only\.runtime\.' + key_regex = r'^omero\.cluster\.read_only\.runtime\.' properties = self.getConfigService().getConfigValues(key_regex) values = frozenset(list(properties.values())) if not values: @@ -4702,7 +4702,7 @@ def debug(self, exc_class, args, kwargs): args, kwargs, exc_info=True) def handle_exception(self, e, *args, **kwargs): - """ + r""" Exception handler that is expected to be overridden by sub-classes. The expected behaviour is either to handle a type of exception and return the server side result or to raise the already thrown diff --git a/src/omero/install/logs_library.py b/src/omero/install/logs_library.py index 712695547..f7d86771d 100755 --- a/src/omero/install/logs_library.py +++ b/src/omero/install/logs_library.py @@ -178,7 +178,7 @@ def draw(self, renderer): def plot_threads(watcher, all_colors=("blue", "red", "yellow", "green", "pink", "purple")): - digit = re.compile(".*(\d+).*") + digit = re.compile(r".*(\d+).*") fig = plt.figure() ax = fig.add_subplot(111) diff --git a/src/omero/install/perf_test.py b/src/omero/install/perf_test.py index f674707af..10ad811a3 100755 --- a/src/omero/install/perf_test.py +++ b/src/omero/install/perf_test.py @@ -25,7 +25,7 @@ import omero.util.temp_files import uuid -command_pattern = "^\s*(\w+)(\((.*)\))?(:(.*))?$" +command_pattern = r"^\s*(\w+)(\((.*)\))?(:(.*))?$" command_pattern_compiled = re.compile(command_pattern) log = logging.getLogger("omero.perf") diff --git a/src/omero/install/versions.py b/src/omero/install/versions.py index d4b4c582b..efda3faf4 100755 --- a/src/omero/install/versions.py +++ b/src/omero/install/versions.py @@ -13,7 +13,7 @@ import logging # Regex copied from ome.api.IConfig.VERSION_REGEX -REGEX = re.compile("^.*?[-]?(\\d+[.]\\d+([.]\\d+)?)[-]?.*?$") +REGEX = re.compile(r"^.*?[-]?(\\d+[.]\\d+([.]\\d+)?)[-]?.*?$") LOG = logging.getLogger("omero.version") diff --git a/src/omero/plugins/admin.py b/src/omero/plugins/admin.py index 7c0eec933..2dc45d5b6 100755 --- a/src/omero/plugins/admin.py +++ b/src/omero/plugins/admin.py @@ -124,7 +124,7 @@ def _configure(self, parser): "BAD_CONFIG", 300, "Bad configuration: No IceGrid.Node.Data property") self.add_error( - "WIN_CONFIG", 400, """ + "WIN_CONFIG", 400, r""" %s is not in this directory. Aborting... @@ -717,7 +717,7 @@ def _descript(self, args): return descript def checkwindows(self, args): - """ + r""" Checks that the templates file as defined in etc\Windows.cfg can be found. """ @@ -1230,7 +1230,7 @@ def version(cmd): v = io[0].split() v.extend(io[1].split()) v = "".join(v) - m = re.match("^\D*(\d[.\d]+\d)\D?.*$", v) + m = re.match(r"^\D*(\d[.\d]+\d)\D?.*$", v) v = "%-10s" % m.group(1) self.ctx.out(v, False) try: @@ -1272,12 +1272,12 @@ def get_ports(input): tcp_port = None for line in router_lines: if not ssl_port and line.find("ROUTERPORT") >= 0: - m = re.match(".*?(\d+).*?$", line) + m = re.match(r".*?(\d+).*?$", line) if m: ssl_port = m.group(1) if not tcp_port and line.find("INSECUREROUTER") >= 0: - m = re.match("^.*?-p (\d+).*?$", line) + m = re.match(r"^.*?-p (\d+).*?$", line) if m: tcp_port = m.group(1) return ssl_port, tcp_port @@ -1367,15 +1367,15 @@ def parse_logs(): self.ctx.out("") # Parsing well known issues - ready = re.compile(".*?ome.services.util.ServerVersionCheck\ + ready = re.compile(r".*?ome.services.util.ServerVersionCheck\ .*OMERO.Version.*Ready..*?") - db_ready = re.compile(".*?Did.you.create.your.database[?].*?") - data_dir = re.compile(".*?Unable.to.initialize:.FullText.*?") - pg_password = re.compile(".*?org.postgresql.util.PSQLException:\ + db_ready = re.compile(r".*?Did.you.create.your.database[?].*?") + data_dir = re.compile(r".*?Unable.to.initialize:.FullText.*?") + pg_password = re.compile(r".*?org.postgresql.util.PSQLException:\ .FATAL:.password.*?authentication.failed.for.user.*?") - pg_user = re.compile(""".*?org.postgresql.util.PSQLException:\ + pg_user = re.compile(r""".*?org.postgresql.util.PSQLException:\ .FATAL:.role.".*?".does.not.exist.*?""") - pg_conn = re.compile(""".*?org.postgresql.util.PSQLException:\ + pg_conn = re.compile(r""".*?org.postgresql.util.PSQLException:\ .Connection.refused.""") issues = { diff --git a/src/omero/plugins/metadata.py b/src/omero/plugins/metadata.py index 1ecf2d734..9cc6486ad 100755 --- a/src/omero/plugins/metadata.py +++ b/src/omero/plugins/metadata.py @@ -41,7 +41,7 @@ ANNOTATION_TYPES = [t for t in dir(omero.model) - if re.match('[A-Za-z0-9]+Annotation$', t)] + if re.match(r'[A-Za-z0-9]+Annotation$', t)] def guess_mimetype(filename): diff --git a/src/omero/plugins/obj.py b/src/omero/plugins/obj.py index 6a977ef7e..8181e1c3f 100755 --- a/src/omero/plugins/obj.py +++ b/src/omero/plugins/obj.py @@ -41,7 +41,7 @@ class TxField(object): - ARG_RE = re.compile(("(?P[a-zA-Z][a-zA-Z0-9]*)" + ARG_RE = re.compile((r"(?P[a-zA-Z][a-zA-Z0-9]*)" "(?P[@])?=" "(?P.*)")) @@ -57,7 +57,7 @@ def __init__(self, tx_state, arg): self.oper = m.group("OPER") if self.oper == "@": # Treat value like an array lookup - if re.match('\d+$', self.value): + if re.match(r'\d+$', self.value): self.value = tx_state.get_row(int(self.value)) elif re.match(TxCmd.VAR_NAME + '$', self.value): self.value = tx_state.get_var(self.value) @@ -70,10 +70,10 @@ def __call__(self, obj): class TxCmd(object): - VAR_NAME = "(?P[a-zA-Z][a-zA-Z0-9]*)" - VAR_RE = re.compile(("^\s*%s" - "\s*=\s" - "(?P.*)$") % VAR_NAME) + VAR_NAME = r"(?P[a-zA-Z][a-zA-Z0-9]*)" + VAR_RE = re.compile((r"^\s*%s" + r"\s*=\s" + r"(?P.*)$") % VAR_NAME) def __init__(self, tx_state, arg_list=None, line=None): """ diff --git a/src/omero/plugins/script.py b/src/omero/plugins/script.py index d2858058e..12c3c8c9b 100755 --- a/src/omero/plugins/script.py +++ b/src/omero/plugins/script.py @@ -71,8 +71,8 @@ print "Finished script" """ -RE0 = re.compile("\s*script\s+upload\s*") -RE1 = re.compile("\s*script\s+upload\s+--official\s*") +RE0 = re.compile(r"\s*script\s+upload\s*") +RE1 = re.compile(r"\s*script\s+upload\s+--official\s*") class ScriptControl(BaseControl): diff --git a/src/omero/plugins/sessions.py b/src/omero/plugins/sessions.py index fff22ac44..f798def43 100644 --- a/src/omero/plugins/sessions.py +++ b/src/omero/plugins/sessions.py @@ -935,7 +935,7 @@ def _parse_conn(server, default_name): """Parse a connection string of form (user@)server(:port)""" import re - pat = '^((?P.+)@)?(?P.*?)(:(?P\d{1,5}))?$' + pat = r'^((?P.+)@)?(?P.*?)(:(?P\d{1,5}))?$' match = re.match(pat, server) server = match.group('server') name = match.group('name') diff --git a/src/omero/plugins/upload.py b/src/omero/plugins/upload.py index 3bb81cf99..cfed6b673 100755 --- a/src/omero/plugins/upload.py +++ b/src/omero/plugins/upload.py @@ -28,7 +28,7 @@ hash_sha1 = sha.new HELP = """Upload local files to the OMERO server""" -RE = re.compile("\s*upload\s*") +RE = re.compile(r"\s*upload\s*") UNKNOWN = 'type/unknown' diff --git a/src/omero/util/importperf.py b/src/omero/util/importperf.py index 92637ef5d..c75986720 100755 --- a/src/omero/util/importperf.py +++ b/src/omero/util/importperf.py @@ -107,12 +107,12 @@ class ImporterLog(object): # Regular expression for matching log4j log lines log_regex = re.compile( - '^(?P\S+\s+\S+)\s+(?P\d+)\s+' + r'^(?P\S+\s+\S+)\s+(?P\d+)\s+' '(?P\[.*?\])\s+(?P\S+)\s+(?P\S+)\s+-\s+' '(?P.*)$') # Regular expression for matching possible OMERO.importer status messages - status_regex = re.compile('^[A-Z_]*') + status_regex = re.compile(r'^[A-Z_]*') # Format string for matching log4j date/time strings date_time_fmt = '%Y-%m-%d %H:%M:%S' diff --git a/src/omero/util/metadata_utils.py b/src/omero/util/metadata_utils.py index 8ad38f562..c80146486 100644 --- a/src/omero/util/metadata_utils.py +++ b/src/omero/util/metadata_utils.py @@ -166,8 +166,8 @@ def validate_filled_column_config(cls, cfg): raise Exception("Option `position` must be an int") if cfg["clientvalue"]: - subbed = re.sub("\{\{\s*value\s*\}\}", '', cfg["clientvalue"]) - m = re.search("\{\{[\s\w]*}\}", subbed) + subbed = re.sub(r"\{\{\s*value\s*\}\}", '', cfg["clientvalue"]) + m = re.search(r"\{\{[\s\w]*}\}", subbed) if m: raise Exception( "clientvalue template parameter not found: %s" % m.group()) diff --git a/src/omero/util/populate_metadata.py b/src/omero/util/populate_metadata.py index ca431d56b..c69a8831f 100644 --- a/src/omero/util/populate_metadata.py +++ b/src/omero/util/populate_metadata.py @@ -1351,7 +1351,7 @@ def _get_additional_targets(self, target): def populate(self, table): def idcolumn_to_omeroclass(col): - clsname = re.search('::(\w+)Column$', col.ice_staticId()).group(1) + clsname = re.search(r'::(\w+)Column$', col.ice_staticId()).group(1) return clsname try: diff --git a/src/omero/util/populate_roi.py b/src/omero/util/populate_roi.py index 09b45330b..6dfabb8b0 100644 --- a/src/omero/util/populate_roi.py +++ b/src/omero/util/populate_roi.py @@ -268,11 +268,11 @@ class MIASPlateAnalysisCtx(AbstractPlateAnalysisCtx): datetime_format = '%Y-%m-%d-%Hh%Mm%Ss' # Regular expression matching a log filename - log_regex = re.compile('.*log(\d+-\d+-\d+-\d+h\d+m\d+s).txt$') + log_regex = re.compile(r'.*log(\d+-\d+-\d+-\d+h\d+m\d+s).txt$') # Regular expression matching a result filename detail_regex = re.compile( - '^Well(\d+)_(.*)_detail_(\d+-\d+-\d+-\d+h\d+m\d+s).txt$') + r'^Well(\d+)_(.*)_detail_(\d+-\d+-\d+-\d+h\d+m\d+s).txt$') # Companion file format companion_format = 'Companion/MIAS' diff --git a/src/omero/util/pydict_text_io.py b/src/omero/util/pydict_text_io.py index cfc327a95..eecc89f68 100644 --- a/src/omero/util/pydict_text_io.py +++ b/src/omero/util/pydict_text_io.py @@ -68,7 +68,7 @@ def load(fileobj, filetype=None, single=True, session=None): except ValueError: pass - m = re.match('originalfile:(\d+)$', fileobj, re.I) + m = re.match(r'originalfile:(\d+)$', fileobj, re.I) if m: rawdata, filetype = get_format_originalfileid( int(m.group(1)), filetype, session) diff --git a/src/omero_model_PermissionsI.py b/src/omero_model_PermissionsI.py index 96012b7aa..b7ab896a9 100644 --- a/src/omero_model_PermissionsI.py +++ b/src/omero_model_PermissionsI.py @@ -166,7 +166,7 @@ def from_string(self, perms): """ import re base = r"([rR\-_])([aAwW\-_])" - regex = re.compile("^(L?)%s$" % (base*3)) + regex = re.compile(r"^(L?)%s$" % (base*3)) match = regex.match(perms) if match is None: raise ValueError("Invalid permission string: %s" % perms) diff --git a/src/path.py b/src/path.py index 1f7d6642c..575005007 100644 --- a/src/path.py +++ b/src/path.py @@ -1555,7 +1555,7 @@ def _permission_mask(mode): >>> _permission_mask('go-x')(o777) == o766 True """ - parsed = re.match('(?P[ugo]+)(?P[-+])(?P[rwx]+)$', mode) + parsed = re.match(r'(?P[ugo]+)(?P[-+])(?P[rwx]+)$', mode) if not parsed: raise ValueError("Unrecognized symbolic mode", mode) spec_map = dict(r=4, w=2, x=1) diff --git a/tox.ini b/tox.ini index 42c033c13..22ee122be 100644 --- a/tox.ini +++ b/tox.ini @@ -15,6 +15,7 @@ deps = tables pytest-sugar pytest-xdist + pytest-warnings py27: https://github.com/ome/zeroc-ice-py-manylinux/releases/download/0.1.0/zeroc_ice-3.6.5-cp27-cp27mu-manylinux2010_x86_64.whl py36: https://github.com/ome/zeroc-ice-py-manylinux/releases/download/0.1.0/zeroc_ice-3.6.5-cp36-cp36m-manylinux2010_x86_64.whl setenv =