fix run error for re.sub(): KeyError: '\S' 03/284903/1
authorbiao716.wang <biao716.wang@samsung.com>
Wed, 30 Nov 2022 09:40:17 +0000 (18:40 +0900)
committerbiao716.wang <biao716.wang@samsung.com>
Wed, 30 Nov 2022 09:40:21 +0000 (18:40 +0900)
It seems backslash handling changed in Python3.8:
https://docs.python.org/3.8/library/re.html

Change-Id: I43c9e9baa13598015fb9ef801bd435e78945c309
Signed-off-by: biao716.wang <biao716.wang@samsung.com>
gbp/git/repository.py
gbp/scripts/common/pq.py

index 3dfecdc1e1c164da7836466fe0f5d855305b0ee2..64053a55edc052f22527591a2dc97125f2d31f56 100644 (file)
@@ -101,7 +101,7 @@ class GitRepository(object):
         else:
             out, dummy, ret = self._git_inout('rev-parse', ['--show-toplevel'],
                                               capture_stderr=True)
-            self._path = os.path.abspath(out.strip())
+            self._path = os.path.abspath(out.decode().strip())
 
     def __init__(self, path):
         self._path = os.path.abspath(path)
@@ -111,8 +111,8 @@ class GitRepository(object):
                                               capture_stderr=True)
             cdup = out.strip().decode(sys.getfilesystemencoding())
             if ret:
-                raise GitRepositoryError("No Git repository at '%s': '%s'" % (self.path, out))
-            self._bare = False if out.strip() != 'true' else True
+                raise GitRepositoryError("No Git repository at '%s': '%s'" % (self.path, out.decode().strip()))
+            self._bare = False if out.decode().strip() != 'true' else True
 
             self._check_dirs()
 
@@ -183,8 +183,8 @@ class GitRepository(object):
         if not cwd:
             cwd = self.path
         ret = 0
-        stdout = ''
-        stderr = ''
+        stdout = b''
+        stderr = b''
         try:
             for outdata in self.__git_inout(command, args, input, extra_env,
                                             cwd, capture_stderr,
@@ -207,7 +207,7 @@ class GitRepository(object):
         """
         if not cwd:
             cwd = self.path
-        stderr = ''
+        stderr = b''
         try:
             for outdata in self.__git_inout(command, args, stdin, extra_env,
                                             cwd, capture_stderr, True):
@@ -266,8 +266,8 @@ class GitRepository(object):
                 if w_ind > len(stdin):
                     rm_polled_fd(popen.stdin, in_fds)
             # Read in chunks of 4k
-            stdout = popen.stdout.read(4096) if popen.stdout in ready[0] else ''
-            stderr = popen.stderr.read(4096) if popen.stderr in ready[0] else ''
+            stdout = popen.stdout.read(4096) if popen.stdout in ready[0] else b''
+            stderr = popen.stderr.read(4096) if popen.stderr in ready[0] else b''
             if popen.stdout in ready[0] and not stdout:
                 rm_polled_fd(popen.stdout, out_fds)
             if popen.stderr in ready[0] and not stderr:
@@ -1223,7 +1223,7 @@ class GitRepository(object):
 
         remotes = {}
         for rem in stdout.splitlines():
-            name, url_urltype = rem.remote.decode().strip().split('\t', 1)
+            name, url_urltype = rem.decode().strip().split('\t', 1)
             url, urltype = url_urltype.rsplit(' ', 1)
             urltype = urltype.strip('()')
             if not name in remotes:
index 0ea9f9e80d47d7ec2bdef4c62ac09bc7eacc0a7b..95516c087cde8bbf8d4e2647ae5fbe56bc9052d6 100644 (file)
@@ -49,7 +49,7 @@ def pq_branch_match(branch, pq_fmt_str):
     >>> pq_branch_match('foo/bar/1.0/pq', 'foo/%(br)s/%(ver)s/pq').groupdict()
     {'ver': '1.0', 'br': 'bar'}
     """
-    pq_re = '^%s$' % re.sub('%\(([a-z_\-]+)\)s', r'(?P<\1>\S+)', pq_fmt_str)
+    pq_re = '^%s$' % re.sub('%\(([a-z_\-]+)\)s', r'(?P<\1>\\S+)', pq_fmt_str)
     return  re.match(pq_re, branch)