Commit 1c11d439 authored by Jérome Perrin's avatar Jérome Perrin

*: fix warnings with regex

parent a5a4d0a4
...@@ -1101,7 +1101,7 @@ class TemplateTool (BaseTool): ...@@ -1101,7 +1101,7 @@ class TemplateTool (BaseTool):
- 1.1 < 2.0 - 1.1 < 2.0
- 1.0.0 = 1.0 - 1.0.0 = 1.0
""" """
r = re.compile('(\d+|[a-zA-Z])') r = re.compile(r'(\d+|[a-zA-Z])')
v1 = r.findall(version1) v1 = r.findall(version1)
v2 = r.findall(version2) v2 = r.findall(version2)
......
...@@ -86,7 +86,7 @@ class CaptchasDotNet: ...@@ -86,7 +86,7 @@ class CaptchasDotNet:
return url return url
def image (self, random, id = 'captchas.net'): def image (self, random, id = 'captchas.net'):
return ''' return r'''
<img class="captchas_dot_net" <img class="captchas_dot_net"
id="%(id)s" src="%(source)s" width="%(width)d" height="%(height)d" id="%(id)s" src="%(source)s" width="%(width)d" height="%(height)d"
alt="The CAPTCHA image" /> alt="The CAPTCHA image" />
......
...@@ -215,8 +215,8 @@ class ImageFieldWidget(Widget.TextWidget): ...@@ -215,8 +215,8 @@ class ImageFieldWidget(Widget.TextWidget):
def _getPictureSize(self, picture_width, picture_height, target_width, def _getPictureSize(self, picture_width, picture_height, target_width,
target_height): target_height):
# if not match causes exception # if not match causes exception
width_tuple = re.match("(\d[\d\.]*)(.*)", target_width).groups() width_tuple = re.match(r"(\d[\d\.]*)(.*)", target_width).groups()
height_tuple = re.match("(\d[\d\.]*)(.*)", target_height).groups() height_tuple = re.match(r"(\d[\d\.]*)(.*)", target_height).groups()
unit = width_tuple[1] unit = width_tuple[1]
w = float(width_tuple[0]) w = float(width_tuple[0])
h = float(height_tuple[0]) h = float(height_tuple[0])
......
...@@ -684,7 +684,7 @@ class SelectionTool( BaseTool, SimpleItem ): ...@@ -684,7 +684,7 @@ class SelectionTool( BaseTool, SimpleItem ):
# qdsqdsq/Base_view/qsdsqd --> matches # qdsqdsq/Base_view/qsdsqd --> matches
# qdsqdsq/Base_viewAaa --> doesn't match # qdsqdsq/Base_viewAaa --> doesn't match
# qdsqdsq/Umpa_view --> doesn't match # qdsqdsq/Umpa_view --> doesn't match
if re.search('/%s($|\W+)' % form_id, url): if re.search(r'/%s($|\W+)' % form_id, url):
return form_id return form_id
return 'view' return 'view'
......
...@@ -617,8 +617,8 @@ class ODFStrategy(Implicit): ...@@ -617,8 +617,8 @@ class ODFStrategy(Implicit):
if svg_width is None or svg_height is None: if svg_width is None or svg_height is None:
return ('0cm', '0cm') return ('0cm', '0cm')
# if not match causes exception # if not match causes exception
width_tuple = re.match("(\d[\d\.]*)(.*)", svg_width).groups() width_tuple = re.match(r"(\d[\d\.]*)(.*)", svg_width).groups()
height_tuple = re.match("(\d[\d\.]*)(.*)", svg_height).groups() height_tuple = re.match(r"(\d[\d\.]*)(.*)", svg_height).groups()
unit = width_tuple[1] unit = width_tuple[1]
w = Decimal(width_tuple[0]) w = Decimal(width_tuple[0])
h = Decimal(height_tuple[0]) h = Decimal(height_tuple[0])
......
...@@ -278,7 +278,7 @@ class OOoTemplate(ZopePageTemplate): ...@@ -278,7 +278,7 @@ class OOoTemplate(ZopePageTemplate):
def renderIncludes(self, here, text, extra_context, request, sub_document=None): def renderIncludes(self, here, text, extra_context, request, sub_document=None):
attached_files_dict = {} attached_files_dict = {}
arguments_re = re.compile('''(\S+?)\s*=\s*('|")(.*?)\\2\s*''',re.DOTALL) arguments_re = re.compile(r'''(\S+?)\s*=\s*('|")(.*?)\2\s*''',re.DOTALL)
def getLengthInfos( opts_dict, opts_names ): def getLengthInfos( opts_dict, opts_names ):
ret = [] ret = []
for opt_name in opts_names: for opt_name in opts_names:
...@@ -442,7 +442,7 @@ class OOoTemplate(ZopePageTemplate): ...@@ -442,7 +442,7 @@ class OOoTemplate(ZopePageTemplate):
office_include.getparent().replace(office_include, draw_object) office_include.getparent().replace(office_include, draw_object)
text = bytes2str(etree.tostring(xml_doc, encoding='utf-8', xml_declaration=True, text = bytes2str(etree.tostring(xml_doc, encoding='utf-8', xml_declaration=True,
pretty_print=False)) pretty_print=False))
text = re.sub('<\s*office:include_img\s+(.*?)\s*/\s*>(?s)', replaceIncludesImg, text) text = re.sub(r'<\s*office:include_img\s+(.*?)\s*/\s*>(?s)', replaceIncludesImg, text)
return (text, attached_files_dict) return (text, attached_files_dict)
# Proxy method to PageTemplate # Proxy method to PageTemplate
......
...@@ -128,7 +128,7 @@ class PersistentContainer(Persistent): ...@@ -128,7 +128,7 @@ class PersistentContainer(Persistent):
self.value = state self.value = state
global registered_workflow_method_set global registered_workflow_method_set
wildcard_interaction_method_id_match = re.compile(r'[[.?*+{(\\]').search wildcard_interaction_method_id_match = re.compile(r'[\[.?*+{(\\]').search
workflow_method_registry = [] # XXX A set() would be better but would require a hash in WorkflowMethod class workflow_method_registry = [] # XXX A set() would be better but would require a hash in WorkflowMethod class
def resetRegisteredWorkflowMethod(portal_type=None): def resetRegisteredWorkflowMethod(portal_type=None):
......
...@@ -772,7 +772,7 @@ from .Accessor.Base import func_code ...@@ -772,7 +772,7 @@ from .Accessor.Base import func_code
from Products.CMFCore.utils import manage_addContentForm, manage_addContent from Products.CMFCore.utils import manage_addContentForm, manage_addContent
from AccessControl.PermissionRole import PermissionRole from AccessControl.PermissionRole import PermissionRole
python_file_parser = re.compile('^(.*)\.py$') python_file_parser = re.compile(r'^(.*)\.py$')
def getLocalPropertySheetList(): def getLocalPropertySheetList():
if not getConfiguration: if not getConfiguration:
...@@ -1750,12 +1750,12 @@ from six.moves.urllib.parse import urlsplit, urlunsplit, urljoin ...@@ -1750,12 +1750,12 @@ from six.moves.urllib.parse import urlsplit, urlunsplit, urljoin
# Regular expressions # Regular expressions
re_cleanup_anchors = re.compile('#.*') re_cleanup_anchors = re.compile('#.*')
re_extract_port = re.compile(':(\d+)$') re_extract_port = re.compile(r':(\d+)$')
def uppercaseLetter(matchobject): def uppercaseLetter(matchobject):
return matchobject.group(0).upper() return matchobject.group(0).upper()
re_cleanup_escaped_url = re.compile('%\w\d') re_cleanup_escaped_url = re.compile(r'%\w\d')
re_cleanup_slashes = re.compile('/{2,}') re_cleanup_slashes = re.compile('/{2,}')
re_cleanup_tail = re.compile('\??$') re_cleanup_tail = re.compile(r'\??$')
def legacyNormalizeUrl(url, base_url=None): def legacyNormalizeUrl(url, base_url=None):
"""this method does normalisation itself. """this method does normalisation itself.
......
...@@ -100,7 +100,7 @@ def DA_PUT(self, REQUEST, RESPONSE): ...@@ -100,7 +100,7 @@ def DA_PUT(self, REQUEST, RESPONSE):
if RESPONSE is not None: self.dav__init(REQUEST, RESPONSE) if RESPONSE is not None: self.dav__init(REQUEST, RESPONSE)
if RESPONSE is not None: self.dav__simpleifhandler(REQUEST, RESPONSE, refresh=1) if RESPONSE is not None: self.dav__simpleifhandler(REQUEST, RESPONSE, refresh=1)
body = REQUEST.get('BODY', '') body = REQUEST.get('BODY', '')
m = re.match('\s*<dtml-comment>(.*?)</dtml-comment>\s*\n', body, re.I | re.S) m = re.match(r'\s*<dtml-comment>(.*?)</dtml-comment>\s*\n', body, re.I | re.S)
if m: if m:
property_src = m.group(1) property_src = m.group(1)
parameters = {} parameters = {}
...@@ -121,7 +121,7 @@ def DA_PUT(self, REQUEST, RESPONSE): ...@@ -121,7 +121,7 @@ def DA_PUT(self, REQUEST, RESPONSE):
self.title = str(title) self.title = str(title)
self.connection_id = str(connection_id) self.connection_id = str(connection_id)
body = body[m.end():] body = body[m.end():]
m = re.match('\s*<params>(.*)</params>\s*\n', body, re.I | re.S) m = re.match(r'\s*<params>(.*)</params>\s*\n', body, re.I | re.S)
if m: if m:
self.arguments_src = m.group(1) self.arguments_src = m.group(1)
self._arg=parse(self.arguments_src) self._arg=parse(self.arguments_src)
......
...@@ -130,7 +130,7 @@ def patch_linecache(): ...@@ -130,7 +130,7 @@ def patch_linecache():
properly without requiring to create a temporary file on the filesystem properly without requiring to create a temporary file on the filesystem
The filename is is always '<portal_components/*>' for ZODB Components, The filename is is always '<portal_components/*>' for ZODB Components,
'(FILENAME)?Script \(Python\)' for Zope Python Scripts and 'Python '(FILENAME)?Script \\(Python\\)' for Zope Python Scripts and 'Python
Expression "CODE"' for TALES expressions. Expression "CODE"' for TALES expressions.
linecache.cache filled by linecache.updatecache() called by the original linecache.cache filled by linecache.updatecache() called by the original
......
...@@ -184,7 +184,7 @@ class EmailValidator(StringValidator): ...@@ -184,7 +184,7 @@ class EmailValidator(StringValidator):
# brackets around the address (we assume these would be added by # brackets around the address (we assume these would be added by
# some custom script if needed), and of course no characters that # some custom script if needed), and of course no characters that
# don't belong in an e-mail address. # don't belong in an e-mail address.
pattern = re.compile('^[0-9a-zA-Z_\'&.%+-]+@([0-9a-zA-Z]([0-9a-zA-Z-]*[0-9a-zA-Z])?\.)+[a-zA-Z]{2,}$') pattern = re.compile(r'^[0-9a-zA-Z_\'&.%+-]+@([0-9a-zA-Z]([0-9a-zA-Z-]*[0-9a-zA-Z])?\.)+[a-zA-Z]{2,}$')
def validate(self, field, key, REQUEST): def validate(self, field, key, REQUEST):
value = StringValidator.validate(self, field, key, REQUEST) value = StringValidator.validate(self, field, key, REQUEST)
......
...@@ -42,7 +42,7 @@ class commandtransform: ...@@ -42,7 +42,7 @@ class commandtransform:
def subObjects(self, tmpdir): def subObjects(self, tmpdir):
imgs = [] imgs = []
for f in os.listdir(tmpdir): for f in os.listdir(tmpdir):
result = re.match("^.+\.(?P<ext>.+)$", f) result = re.match(r"^.+\.(?P<ext>.+)$", f)
if result is not None: if result is not None:
ext = result.group('ext') ext = result.group('ext')
if ext in ('png', 'jpg', 'gif'): if ext in ('png', 'jpg', 'gif'):
......
...@@ -26,9 +26,9 @@ def register(): ...@@ -26,9 +26,9 @@ def register():
('(?im)<head [^>]>.*</head>', ' '), ('(?im)<head [^>]>.*</head>', ' '),
# added for ERP5, we want to transform <br/> in newlines # added for ERP5, we want to transform <br/> in newlines
('(?im)<br\s*/?>', '\n'), (r'(?im)<br\s*/?>', '\n'),
('(?im)</?(font|em|i|strong|b)(?=\W)[^>]*>', ''), (r'(?im)</?(font|em|i|strong|b)(?=\W)[^>]*>', ''),
('(?i)(?m)<[^>]*>', ' '), ('(?i)(?m)<[^>]*>', ' '),
(r'&([a-zA-Z0-9#]*?);', sub_func), (r'&([a-zA-Z0-9#]*?);', sub_func),
) )
...@@ -175,7 +175,7 @@ def hasScript(s): ...@@ -175,7 +175,7 @@ def hasScript(s):
def decode_htmlentities(s): def decode_htmlentities(s):
""" XSS code can be hidden with htmlentities """ """ XSS code can be hidden with htmlentities """
entity_pattern = re.compile("&#(?P<htmlentity>x?\w+)?;?") entity_pattern = re.compile(r"&#(?P<htmlentity>x?\w+)?;?")
s = entity_pattern.sub(decode_htmlentity,s) s = entity_pattern.sub(decode_htmlentity,s)
return s return s
...@@ -190,7 +190,7 @@ def decode_htmlentity(m): ...@@ -190,7 +190,7 @@ def decode_htmlentity(m):
except ValueError: except ValueError:
return entity_value return entity_value
charset_parser = re.compile('charset="?(?P<charset>[^"]*)"?[\S/]?', charset_parser = re.compile(r'charset="?(?P<charset>[^"]*)"?[\S/]?',
re.IGNORECASE) re.IGNORECASE)
class CharsetReplacer: class CharsetReplacer:
def __init__(self, encoding): def __init__(self, encoding):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment