From a733ba6ef9603536edbcb6ab1d44725408d87b63 Mon Sep 17 00:00:00 2001
From: Florian Sesser <florian@leastauthority.com>
Date: Mon, 13 Jan 2025 21:25:09 +0000
Subject: [PATCH 1/3] Mark a couple of strings with backslashes in them as 'raw
 strings'

Refs [ticket: 4158](https://tahoe-lafs.org/trac/tahoe-lafs/ticket/4158)
---
 src/allmydata/hashtree.py             | 4 ++--
 src/allmydata/interfaces.py           | 2 +-
 src/allmydata/node.py                 | 2 +-
 src/allmydata/test/cli/test_backup.py | 6 +++---
 src/allmydata/test/cli/test_cli.py    | 2 +-
 src/allmydata/test/test_runner.py     | 2 +-
 src/allmydata/test/web/test_web.py    | 2 +-
 src/allmydata/util/i2p_provider.py    | 2 +-
 src/allmydata/web/status.py           | 4 ++--
 9 files changed, 13 insertions(+), 13 deletions(-)

--- a/src/allmydata/hashtree.py
+++ b/src/allmydata/hashtree.py
@@ -70,7 +70,7 @@
 
 
 class CompleteBinaryTreeMixin(object):
-    """
+    r"""
     Adds convenience methods to a complete binary tree.
 
     Assumes the total number of elements in the binary tree may be
@@ -179,7 +179,7 @@
     return tagged_pair_hash(b'Merkle tree internal node', a, b)
 
 class HashTree(CompleteBinaryTreeMixin, list):
-    """
+    r"""
     Compute Merkle hashes at any node in a complete binary tree.
 
     Tree is indexed like so::
--- a/src/allmydata/interfaces.py
+++ b/src/allmydata/interfaces.py
@@ -406,7 +406,7 @@
         """
 
     def put_uri_extension(data):
-        """This block of data contains integrity-checking information (hashes
+        r"""This block of data contains integrity-checking information (hashes
         of plaintext, crypttext, and shares), as well as encoding parameters
         that are necessary to recover the data. This is a serialized dict
         mapping strings to other strings. The hash of this data is kept in
--- a/src/allmydata/node.py
+++ b/src/allmydata/node.py
@@ -90,7 +90,7 @@
     })
 
 # group 1 will be addr (dotted quad string), group 3 if any will be portnum (string)
-ADDR_RE = re.compile("^([1-9][0-9]*\.[1-9][0-9]*\.[1-9][0-9]*\.[1-9][0-9]*)(:([1-9][0-9]*))?$")
+ADDR_RE = re.compile(r"^([1-9][0-9]*\.[1-9][0-9]*\.[1-9][0-9]*\.[1-9][0-9]*)(:([1-9][0-9]*))?$")
 
 # this is put into README in new node-directories (for client and introducers)
 PRIV_README = """
--- a/src/allmydata/test/cli/test_backup.py
+++ b/src/allmydata/test/cli/test_backup.py
@@ -36,9 +36,9 @@
 
     def count_output(self, out):
         mo = re.search(r"(\d)+ files uploaded \((\d+) reused\), "
-                        "(\d)+ files skipped, "
-                        "(\d+) directories created \((\d+) reused\), "
-                        "(\d+) directories skipped", out)
+                        r"(\d)+ files skipped, "
+                        r"(\d+) directories created \((\d+) reused\), "
+                        r"(\d+) directories skipped", out)
         return [int(s) for s in mo.groups()]
 
     def count_output2(self, out):
--- a/src/allmydata/test/cli/test_cli.py
+++ b/src/allmydata/test/cli/test_cli.py
@@ -764,7 +764,7 @@
         # enough shares. The one remaining share might be in either the
         # COMPLETE or the PENDING state.
         in_complete_msg = "ran out of shares: complete=sh0 pending= overdue= unused= need 3"
-        in_pending_msg_regex = "ran out of shares: complete= pending=Share\(.+\) overdue= unused= need 3"
+        in_pending_msg_regex = r"ran out of shares: complete= pending=Share\(.+\) overdue= unused= need 3"
 
         d.addCallback(lambda ign: self.do_cli("get", self.uri_1share))
         def _check1(args):
--- a/src/allmydata/test/test_runner.py
+++ b/src/allmydata/test/test_runner.py
@@ -254,7 +254,7 @@
         # Fail if there is a non-empty line that doesn't end with a
         # punctuation mark.
         for line in err.splitlines():
-            self.failIf(re.search("[\S][^\.!?]$", line), (line,))
+            self.failIf(re.search(r"[\S][^\.!?]$", line), (line,))
 
         # test that the non --basedir form works too
         n2 = os.path.join(basedir, command + "-n2")
--- a/src/allmydata/test/web/test_web.py
+++ b/src/allmydata/test/web/test_web.py
@@ -1968,7 +1968,7 @@
     def test_CSS_FILE(self):
         d = self.GET("/tahoe.css", followRedirect=True)
         def _check(res):
-            CSS_STYLE=re.compile(b'toolbar\s{.+text-align:\scenter.+toolbar-item.+display:\sinline',re.DOTALL)
+            CSS_STYLE=re.compile(b'toolbar\\s{.+text-align:\\scenter.+toolbar-item.+display:\\sinline',re.DOTALL)
             self.failUnless(CSS_STYLE.search(res), res)
         d.addCallback(_check)
         return d
--- a/src/allmydata/util/i2p_provider.py
+++ b/src/allmydata/util/i2p_provider.py
@@ -189,7 +189,7 @@
         privkeyfile = self._get_i2p_config("dest.private_key_file")
         external_port = self._get_i2p_config("dest.port")
         sam_port = self._get_i2p_config("sam.port")
-        escaped_sam_port = sam_port.replace(':', '\:')
+        escaped_sam_port = sam_port.replace(':', r'\:')
         # for now, this returns a string, which then gets passed to
         # endpoints.serverFromString . But it can also return an Endpoint
         # directly, which means we don't need to encode all these options
--- a/src/allmydata/web/status.py
+++ b/src/allmydata/web/status.py
@@ -1556,8 +1556,8 @@
 
         def mangle_name(name):
             return re.sub(
-                u"_(\d\d)_(\d)_percentile",
-                u'{quantile="0.\g<1>\g<2>"}',
+                r"_(\d\d)_(\d)_percentile",
+                r'{quantile="0.\g<1>\g<2>"}',
                 name.replace(u".", u"_")
             )
 
