Skip to content

Commit

Permalink
Use regex literals for re.* functions
Browse files Browse the repository at this point in the history
  • Loading branch information
mrexodia committed Jan 6, 2024
1 parent 0b0de2c commit ad82438
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 16 deletions.
6 changes: 3 additions & 3 deletions miasm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ def _version_from_git_describe():

if process.returncode == 0:
tag = out.decode().strip()
match = re.match('^v?(.+?)-(\\d+)-g[a-f0-9]+$', tag)
match = re.match(r'^v?(.+?)-(\d+)-g[a-f0-9]+$', tag)
if match:
# remove the 'v' prefix and add a '.devN' suffix
return '%s.dev%s' % (match.group(1), match.group(2))
else:
# just remove the 'v' prefix
return re.sub('^v', '', tag)
return re.sub(r'^v', '', tag)
else:
raise subprocess.CalledProcessError(process.returncode, err)

Expand All @@ -71,7 +71,7 @@ def _version():
# See 'man gitattributes' for more details.
git_archive_id = '$Format:%h %d$'
sha1 = git_archive_id.strip().split()[0]
match = re.search('tag:(\\S+)', git_archive_id)
match = re.search(r'tag:(\S+)', git_archive_id)
if match:
return "git-archive.dev" + match.group(1)
elif sha1:
Expand Down
2 changes: 1 addition & 1 deletion miasm/arch/x86/arch.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ def offsize(p):


def get_prefix(s):
g = re.search('(\S+)(\s+)', s)
g = re.search(r'(\S+)(\s+)', s)
if not g:
return None, s
prefix, b = g.groups()
Expand Down
4 changes: 2 additions & 2 deletions miasm/core/cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ def cb_op_mul(tokens):


def isbin(s):
return re.match('[0-1]+$', s)
return re.match(r'[0-1]+$', s)


def int2bin(i, l):
Expand Down Expand Up @@ -1301,7 +1301,7 @@ def dis(cls, bs_o, mode_o = None, offset=0):
@classmethod
def fromstring(cls, text, loc_db, mode = None):
global total_scans
name = re.search('(\S+)', text).groups()
name = re.search(r'(\S+)', text).groups()
if not name:
raise ValueError('cannot find name', text)
name = name[0]
Expand Down
2 changes: 1 addition & 1 deletion miasm/core/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __init__(self):
# N -> Nodes N2 with a edge (N2 -> N)
self._nodes_pred = {}

self.escape_chars = re.compile('[' + re.escape('{}') + '&|<>' + ']')
self.escape_chars = re.compile(r'[\{\}&|<>]')


def __repr__(self):
Expand Down
4 changes: 2 additions & 2 deletions miasm/core/sembuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class MiasmTransformer(ast.NodeTransformer):
"""

# Parsers
parse_integer = re.compile("^i([0-9]+)$")
parse_mem = re.compile("^mem([0-9]+)$")
parse_integer = re.compile(r"^i([0-9]+)$")
parse_mem = re.compile(r"^mem([0-9]+)$")

# Visitors
def visit_Call(self, node):
Expand Down
2 changes: 1 addition & 1 deletion miasm/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

COLOR_MNEMO = "blue1"

ESCAPE_CHARS = re.compile('[' + re.escape('{}') + '&|<>' + ']')
ESCAPE_CHARS = re.compile(r'[\{\}&|<>]')

def set_html_text_color(text, color):
return '<font color="%s">%s</font>' % (color, text)
Expand Down
2 changes: 1 addition & 1 deletion miasm/ir/ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def _expr_loc_to_symb(expr, loc_db):
return m2_expr.ExprId(name, expr.size)


ESCAPE_CHARS = re.compile('[' + re.escape('{}') + '&|<>' + ']')
ESCAPE_CHARS = re.compile(r'[\{\}&|<>]')

class TranslatorHtml(Translator):
__LANG__ = "custom_expr_color"
Expand Down
4 changes: 2 additions & 2 deletions miasm/os_dep/linux/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from miasm.jitter.csts import PAGE_READ, PAGE_WRITE


REGEXP_T = type(re.compile(''))
REGEXP_T = type(re.compile(r''))

StatInfo = namedtuple("StatInfo", [
"st_dev", "st_ino", "st_nlink", "st_mode", "st_uid", "st_gid", "st_rdev",
Expand Down Expand Up @@ -262,7 +262,7 @@ def _convert_re(expr):
expr.flags,
exc_info=True,
)
return re.compile('$X')
return re.compile(r'$X')
return expr

# Remove '../', etc.
Expand Down
4 changes: 2 additions & 2 deletions test/analysis/depgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def get_out_regs(self, _):
def bloc2graph(irgraph, label=False, lines=True):
"""Render dot graph of @blocks"""

escape_chars = re.compile('[' + re.escape('{}') + ']')
escape_chars = re.compile(r'[\{\}]')
label_attr = 'colspan="2" align="center" bgcolor="grey"'
edge_attr = 'label = "%s" color="%s" style="bold"'
td_attr = 'align="left"'
Expand Down Expand Up @@ -179,7 +179,7 @@ def bloc2graph(irgraph, label=False, lines=True):
def dg2graph(graph, label=False, lines=True):
"""Render dot graph of @blocks"""

escape_chars = re.compile('[' + re.escape('{}') + ']')
escape_chars = re.compile(r'[\{\}]')
label_attr = 'colspan="2" align="center" bgcolor="grey"'
edge_attr = 'label = "%s" color="%s" style="bold"'
td_attr = 'align="left"'
Expand Down
2 changes: 1 addition & 1 deletion test/arch/mep/asm/ut_helpers_asm.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def check_instruction(mn_str, mn_hex, multi=None, offset=0):
"""Try to disassemble and assemble this instruction"""

# Rename objdump registers names
mn_str = re.sub("\$([0-9]+)", lambda m: "R"+m.group(1), mn_str)
mn_str = re.sub(r"\$([0-9]+)", lambda m: "R"+m.group(1), mn_str)
mn_str = mn_str.replace("$", "")

# Disassemble
Expand Down

0 comments on commit ad82438

Please sign in to comment.