Skip to content

Commit

Permalink
Prefix escaped strings with 'r'
Browse files Browse the repository at this point in the history
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`)
  • Loading branch information
joshmoore committed Sep 11, 2019
1 parent f416cc0 commit acdaaa9
Show file tree
Hide file tree
Showing 21 changed files with 51 additions and 50 deletions.
2 changes: 1 addition & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 8 additions & 8 deletions src/omero/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions src/omero/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,10 @@ def _check_for_hosturl(self, host, port, pmap):
return {}

hostmatch = re.match(
'(?P<protocol>\\w+)://'
'(?P<server>[^:/]+)'
'(:(?P<port>\\d+))?'
'(?P<path>/.*)?$',
r'(?P<protocol>\\w+)://'
r'(?P<server>[^:/]+)'
r'(:(?P<port>\\d+))?'
r'(?P<path>/.*)?$',
host)

if hostmatch:
Expand Down
4 changes: 2 additions & 2 deletions src/omero/gateway/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/omero/install/logs_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/omero/install/perf_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
2 changes: 1 addition & 1 deletion src/omero/install/versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")


Expand Down
22 changes: 11 additions & 11 deletions src/omero/plugins/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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...
Expand Down Expand Up @@ -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.
"""
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion src/omero/plugins/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
12 changes: 6 additions & 6 deletions src/omero/plugins/obj.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

class TxField(object):

ARG_RE = re.compile(("(?P<FIELD>[a-zA-Z][a-zA-Z0-9]*)"
ARG_RE = re.compile((r"(?P<FIELD>[a-zA-Z][a-zA-Z0-9]*)"
"(?P<OPER>[@])?="
"(?P<VALUE>.*)"))

Expand All @@ -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)
Expand All @@ -70,10 +70,10 @@ def __call__(self, obj):

class TxCmd(object):

VAR_NAME = "(?P<DEST>[a-zA-Z][a-zA-Z0-9]*)"
VAR_RE = re.compile(("^\s*%s"
"\s*=\s"
"(?P<REST>.*)$") % VAR_NAME)
VAR_NAME = r"(?P<DEST>[a-zA-Z][a-zA-Z0-9]*)"
VAR_RE = re.compile((r"^\s*%s"
r"\s*=\s"
r"(?P<REST>.*)$") % VAR_NAME)

def __init__(self, tx_state, arg_list=None, line=None):
"""
Expand Down
4 changes: 2 additions & 2 deletions src/omero/plugins/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion src/omero/plugins/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,7 @@ def _parse_conn(server, default_name):
"""Parse a connection string of form (user@)server(:port)"""

import re
pat = '^((?P<name>.+)@)?(?P<server>.*?)(:(?P<port>\d{1,5}))?$'
pat = r'^((?P<name>.+)@)?(?P<server>.*?)(:(?P<port>\d{1,5}))?$'
match = re.match(pat, server)
server = match.group('server')
name = match.group('name')
Expand Down
2 changes: 1 addition & 1 deletion src/omero/plugins/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'


Expand Down
4 changes: 2 additions & 2 deletions src/omero/util/importperf.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ class ImporterLog(object):

# Regular expression for matching log4j log lines
log_regex = re.compile(
'^(?P<date_time>\S+\s+\S+)\s+(?P<ms_elapsed>\d+)\s+'
r'^(?P<date_time>\S+\s+\S+)\s+(?P<ms_elapsed>\d+)\s+'
'(?P<thread>\[.*?\])\s+(?P<level>\S+)\s+(?P<class>\S+)\s+-\s+'
'(?P<message>.*)$')

# 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'
Expand Down
4 changes: 2 additions & 2 deletions src/omero/util/metadata_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion src/omero/util/populate_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions src/omero/util/populate_roi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion src/omero/util/pydict_text_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/omero_model_PermissionsI.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -1555,7 +1555,7 @@ def _permission_mask(mode):
>>> _permission_mask('go-x')(o777) == o766
True
"""
parsed = re.match('(?P<who>[ugo]+)(?P<op>[-+])(?P<what>[rwx]+)$', mode)
parsed = re.match(r'(?P<who>[ugo]+)(?P<op>[-+])(?P<what>[rwx]+)$', mode)
if not parsed:
raise ValueError("Unrecognized symbolic mode", mode)
spec_map = dict(r=4, w=2, x=1)
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down

0 comments on commit acdaaa9

Please sign in to comment.