Patchwork stringutil: drop escapedata() in favor of escapestr()

login
register
mail settings
Submitter Yuya Nishihara
Date April 4, 2018, 2:35 p.m.
Message ID <69b1e6f9cc986d2763a0.1522852556@mimosa>
Download mbox | patch
Permalink /patch/30256/
State Accepted
Headers show

Comments

Yuya Nishihara - April 4, 2018, 2:35 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1522852009 -32400
#      Wed Apr 04 23:26:49 2018 +0900
# Node ID 69b1e6f9cc986d2763a00646179a956930a86a0d
# Parent  e826fe7a08c73ed484bb09d7ea2b2093750cec27
stringutil: drop escapedata() in favor of escapestr()

They are quite similar. Let's choose one that uses standard Python escape.
Augie Fackler - April 4, 2018, 5:53 p.m.
On Wed, Apr 04, 2018 at 11:35:56PM +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1522852009 -32400
> #      Wed Apr 04 23:26:49 2018 +0900
> # Node ID 69b1e6f9cc986d2763a00646179a956930a86a0d
> # Parent  e826fe7a08c73ed484bb09d7ea2b2093750cec27
> stringutil: drop escapedata() in favor of escapestr()

queued, thanks

Patch

diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py
--- a/mercurial/debugcommands.py
+++ b/mercurial/debugcommands.py
@@ -2964,9 +2964,9 @@  def debugwireproto(ui, repo, path=None, 
                     del args['PUSHFILE']
                     res, output = peer._callpush(command, fh,
                                                  **pycompat.strkwargs(args))
-                    ui.status(_('result: %s\n') % stringutil.escapedata(res))
+                    ui.status(_('result: %s\n') % stringutil.escapestr(res))
                     ui.status(_('remote output: %s\n') %
-                              stringutil.escapedata(output))
+                              stringutil.escapestr(output))
             else:
                 res = peer._call(command, **pycompat.strkwargs(args))
                 ui.status(_('response: %s\n') % stringutil.pprint(res))
@@ -2984,7 +2984,7 @@  def debugwireproto(ui, repo, path=None, 
                       len(batchedcommands))
             for i, chunk in enumerate(peer._submitbatch(batchedcommands)):
                 ui.status(_('response #%d: %s\n') %
-                          (i, stringutil.escapedata(chunk)))
+                          (i, stringutil.escapestr(chunk)))
 
             batchedcommands = None
 
diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -748,10 +748,10 @@  class baseproxyobserver(object):
         # Simple case writes all data on a single line.
         if b'\n' not in data:
             if self.logdataapis:
-                self.fh.write(': %s\n' % stringutil.escapedata(data))
+                self.fh.write(': %s\n' % stringutil.escapestr(data))
             else:
                 self.fh.write('%s>     %s\n'
-                              % (self.name, stringutil.escapedata(data)))
+                              % (self.name, stringutil.escapestr(data)))
             self.fh.flush()
             return
 
@@ -762,7 +762,7 @@  class baseproxyobserver(object):
         lines = data.splitlines(True)
         for line in lines:
             self.fh.write('%s>     %s\n'
-                          % (self.name, stringutil.escapedata(line)))
+                          % (self.name, stringutil.escapestr(line)))
         self.fh.flush()
 
 class fileobjectobserver(baseproxyobserver):
@@ -3845,7 +3845,6 @@  gui = _deprecatedfunc(procutil.gui, '4.6
 hgcmd = _deprecatedfunc(procutil.hgcmd, '4.6')
 rundetached = _deprecatedfunc(procutil.rundetached, '4.6')
 
-escapedata = _deprecatedfunc(stringutil.escapedata, '4.6')
 binary = _deprecatedfunc(stringutil.binary, '4.6')
 stringmatcher = _deprecatedfunc(stringutil.stringmatcher, '4.6')
 shortuser = _deprecatedfunc(stringutil.shortuser, '4.6')
diff --git a/mercurial/utils/stringutil.py b/mercurial/utils/stringutil.py
--- a/mercurial/utils/stringutil.py
+++ b/mercurial/utils/stringutil.py
@@ -23,24 +23,10 @@  from .. import (
     pycompat,
 )
 
-_DATA_ESCAPE_MAP = {pycompat.bytechr(i): br'\x%02x' % i for i in range(256)}
-_DATA_ESCAPE_MAP.update({
-    b'\\': b'\\\\',
-    b'\r': br'\r',
-    b'\n': br'\n',
-})
-_DATA_ESCAPE_RE = remod.compile(br'[\x00-\x08\x0a-\x1f\\\x7f-\xff]')
-
-def escapedata(s):
-    if isinstance(s, bytearray):
-        s = bytes(s)
-
-    return _DATA_ESCAPE_RE.sub(lambda m: _DATA_ESCAPE_MAP[m.group(0)], s)
-
 def pprint(o):
     """Pretty print an object."""
     if isinstance(o, (bytes, bytearray)):
-        return "b'%s'" % escapedata(o)
+        return "b'%s'" % escapestr(o)
     elif isinstance(o, list):
         return '[%s]' % (b', '.join(pprint(a) for a in o))
     elif isinstance(o, dict):
diff --git a/tests/test-http-api-httpv2.t b/tests/test-http-api-httpv2.t
--- a/tests/test-http-api-httpv2.t
+++ b/tests/test-http-api-httpv2.t
@@ -393,7 +393,7 @@  Command frames can be reflected via debu
   s>     content-length: 47\r\n
   s>     host: $LOCALIP:$HGPORT\r\n (glob)
   s>     \r\n
-  s>     '\x00\x00\x01\x00\x01\x01\x11\xa2Dargs\xa2CfooDval1Dbar1CvalDnameHcommand1
+  s>     \'\x00\x00\x01\x00\x01\x01\x11\xa2Dargs\xa2CfooDval1Dbar1CvalDnameHcommand1
   s> makefile('rb', None)
   s>     HTTP/1.1 200 OK\r\n
   s>     Server: testing stub value\r\n
@@ -504,9 +504,9 @@  Interleaved requests to "multirequest" a
   s>     Transfer-Encoding: chunked\r\n
   s>     \r\n
   s>     26\r\n
-  s>     \x1e\x00\x00\x03\x00\x02\x01Bbookmarks	\n
-  s>     namespaces	\n
-  s>     phases	
+  s>     \x1e\x00\x00\x03\x00\x02\x01Bbookmarks\t\n
+  s>     namespaces\t\n
+  s>     phases\t
   s>     \r\n
   s>     8\r\n
   s>     \x00\x00\x00\x01\x00\x02\x00B
diff --git a/tests/test-http-protocol.t b/tests/test-http-protocol.t
--- a/tests/test-http-protocol.t
+++ b/tests/test-http-protocol.t
@@ -206,10 +206,10 @@  Test listkeys for listing namespaces
   s>     Content-Type: application/mercurial-0.1\r\n
   s>     Content-Length: 30\r\n
   s>     \r\n
-  s>     bookmarks	\n
-  s>     namespaces	\n
-  s>     phases	
-  response: b'bookmarks	\nnamespaces	\nphases	'
+  s>     bookmarks\t\n
+  s>     namespaces\t\n
+  s>     phases\t
+  response: b'bookmarks\t\nnamespaces\t\nphases\t'
 
 Same thing, but with "httprequest" command
 
@@ -232,8 +232,8 @@  Same thing, but with "httprequest" comma
   s>     Content-Type: application/mercurial-0.1\r\n
   s>     Content-Length: 30\r\n
   s>     \r\n
-  s>     bookmarks	\n
-  s>     namespaces	\n
-  s>     phases	
+  s>     bookmarks\t\n
+  s>     namespaces\t\n
+  s>     phases\t
 
   $ killdaemons.py
diff --git a/tests/test-ssh-proto.t b/tests/test-ssh-proto.t
--- a/tests/test-ssh-proto.t
+++ b/tests/test-ssh-proto.t
@@ -1342,10 +1342,10 @@  Test listkeys for listing namespaces
   o> bufferedreadline() -> 3:
   o>     30\n
   o> bufferedread(30) -> 30:
-  o>     bookmarks	\n
-  o>     namespaces	\n
-  o>     phases	
-  response: b'bookmarks	\nnamespaces	\nphases	'
+  o>     bookmarks\t\n
+  o>     namespaces\t\n
+  o>     phases\t
+  response: b'bookmarks\t\nnamespaces\t\nphases\t'
   
   testing ssh2
   creating ssh peer from handshake results
@@ -1373,10 +1373,10 @@  Test listkeys for listing namespaces
   o> bufferedreadline() -> 3:
   o>     30\n
   o> bufferedread(30) -> 30:
-  o>     bookmarks	\n
-  o>     namespaces	\n
-  o>     phases	
-  response: b'bookmarks	\nnamespaces	\nphases	'
+  o>     bookmarks\t\n
+  o>     namespaces\t\n
+  o>     phases\t
+  response: b'bookmarks\t\nnamespaces\t\nphases\t'
 
   $ cd ..
 
@@ -1482,8 +1482,8 @@  With a single bookmark set
   i> flush() -> None
   o> bufferedreadline() -> 3:
   o>     46\n
-  o> bufferedread(46) -> 46: bookA	68986213bd4485ea51533535e3fc9e78007a711f
-  response: b'bookA	68986213bd4485ea51533535e3fc9e78007a711f'
+  o> bufferedread(46) -> 46: bookA\t68986213bd4485ea51533535e3fc9e78007a711f
+  response: b'bookA\t68986213bd4485ea51533535e3fc9e78007a711f'
   
   testing ssh2
   creating ssh peer from handshake results
@@ -1510,8 +1510,8 @@  With a single bookmark set
   i> flush() -> None
   o> bufferedreadline() -> 3:
   o>     46\n
-  o> bufferedread(46) -> 46: bookA	68986213bd4485ea51533535e3fc9e78007a711f
-  response: b'bookA	68986213bd4485ea51533535e3fc9e78007a711f'
+  o> bufferedread(46) -> 46: bookA\t68986213bd4485ea51533535e3fc9e78007a711f
+  response: b'bookA\t68986213bd4485ea51533535e3fc9e78007a711f'
 
 With multiple bookmarks set
 
@@ -1546,9 +1546,9 @@  With multiple bookmarks set
   o> bufferedreadline() -> 3:
   o>     93\n
   o> bufferedread(93) -> 93:
-  o>     bookA	68986213bd4485ea51533535e3fc9e78007a711f\n
-  o>     bookB	1880f3755e2e52e3199e0ee5638128b08642f34d
-  response: b'bookA	68986213bd4485ea51533535e3fc9e78007a711f\nbookB	1880f3755e2e52e3199e0ee5638128b08642f34d'
+  o>     bookA\t68986213bd4485ea51533535e3fc9e78007a711f\n
+  o>     bookB\t1880f3755e2e52e3199e0ee5638128b08642f34d
+  response: b'bookA\t68986213bd4485ea51533535e3fc9e78007a711f\nbookB\t1880f3755e2e52e3199e0ee5638128b08642f34d'
   
   testing ssh2
   creating ssh peer from handshake results
@@ -1576,9 +1576,9 @@  With multiple bookmarks set
   o> bufferedreadline() -> 3:
   o>     93\n
   o> bufferedread(93) -> 93:
-  o>     bookA	68986213bd4485ea51533535e3fc9e78007a711f\n
-  o>     bookB	1880f3755e2e52e3199e0ee5638128b08642f34d
-  response: b'bookA	68986213bd4485ea51533535e3fc9e78007a711f\nbookB	1880f3755e2e52e3199e0ee5638128b08642f34d'
+  o>     bookA\t68986213bd4485ea51533535e3fc9e78007a711f\n
+  o>     bookB\t1880f3755e2e52e3199e0ee5638128b08642f34d
+  response: b'bookA\t68986213bd4485ea51533535e3fc9e78007a711f\nbookB\t1880f3755e2e52e3199e0ee5638128b08642f34d'
 
 Test pushkey for bookmarks
 
@@ -1706,8 +1706,8 @@  Phases on empty repo
   i> flush() -> None
   o> bufferedreadline() -> 3:
   o>     15\n
-  o> bufferedread(15) -> 15: publishing	True
-  response: b'publishing	True'
+  o> bufferedread(15) -> 15: publishing\tTrue
+  response: b'publishing\tTrue'
   
   testing ssh2
   creating ssh peer from handshake results
@@ -1734,8 +1734,8 @@  Phases on empty repo
   i> flush() -> None
   o> bufferedreadline() -> 3:
   o>     15\n
-  o> bufferedread(15) -> 15: publishing	True
-  response: b'publishing	True'
+  o> bufferedread(15) -> 15: publishing\tTrue
+  response: b'publishing\tTrue'
 
 Create some commits
 
@@ -1786,10 +1786,10 @@  Two draft heads
   o> bufferedreadline() -> 4:
   o>     101\n
   o> bufferedread(101) -> 101:
-  o>     20b8a89289d80036e6c4e87c2083e3bea1586637	1\n
-  o>     c4750011d906c18ea2f0527419cbc1a544435150	1\n
-  o>     publishing	True
-  response: b'20b8a89289d80036e6c4e87c2083e3bea1586637	1\nc4750011d906c18ea2f0527419cbc1a544435150	1\npublishing	True'
+  o>     20b8a89289d80036e6c4e87c2083e3bea1586637\t1\n
+  o>     c4750011d906c18ea2f0527419cbc1a544435150\t1\n
+  o>     publishing\tTrue
+  response: b'20b8a89289d80036e6c4e87c2083e3bea1586637\t1\nc4750011d906c18ea2f0527419cbc1a544435150\t1\npublishing\tTrue'
   
   testing ssh2
   creating ssh peer from handshake results
@@ -1817,10 +1817,10 @@  Two draft heads
   o> bufferedreadline() -> 4:
   o>     101\n
   o> bufferedread(101) -> 101:
-  o>     20b8a89289d80036e6c4e87c2083e3bea1586637	1\n
-  o>     c4750011d906c18ea2f0527419cbc1a544435150	1\n
-  o>     publishing	True
-  response: b'20b8a89289d80036e6c4e87c2083e3bea1586637	1\nc4750011d906c18ea2f0527419cbc1a544435150	1\npublishing	True'
+  o>     20b8a89289d80036e6c4e87c2083e3bea1586637\t1\n
+  o>     c4750011d906c18ea2f0527419cbc1a544435150\t1\n
+  o>     publishing\tTrue
+  response: b'20b8a89289d80036e6c4e87c2083e3bea1586637\t1\nc4750011d906c18ea2f0527419cbc1a544435150\t1\npublishing\tTrue'
 
 Single draft head
 
@@ -1855,9 +1855,9 @@  Single draft head
   o> bufferedreadline() -> 3:
   o>     58\n
   o> bufferedread(58) -> 58:
-  o>     c4750011d906c18ea2f0527419cbc1a544435150	1\n
-  o>     publishing	True
-  response: b'c4750011d906c18ea2f0527419cbc1a544435150	1\npublishing	True'
+  o>     c4750011d906c18ea2f0527419cbc1a544435150\t1\n
+  o>     publishing\tTrue
+  response: b'c4750011d906c18ea2f0527419cbc1a544435150\t1\npublishing\tTrue'
   
   testing ssh2
   creating ssh peer from handshake results
@@ -1885,9 +1885,9 @@  Single draft head
   o> bufferedreadline() -> 3:
   o>     58\n
   o> bufferedread(58) -> 58:
-  o>     c4750011d906c18ea2f0527419cbc1a544435150	1\n
-  o>     publishing	True
-  response: b'c4750011d906c18ea2f0527419cbc1a544435150	1\npublishing	True'
+  o>     c4750011d906c18ea2f0527419cbc1a544435150\t1\n
+  o>     publishing\tTrue
+  response: b'c4750011d906c18ea2f0527419cbc1a544435150\t1\npublishing\tTrue'
 
 All public heads
 
@@ -1921,8 +1921,8 @@  All public heads
   i> flush() -> None
   o> bufferedreadline() -> 3:
   o>     15\n
-  o> bufferedread(15) -> 15: publishing	True
-  response: b'publishing	True'
+  o> bufferedread(15) -> 15: publishing\tTrue
+  response: b'publishing\tTrue'
   
   testing ssh2
   creating ssh peer from handshake results
@@ -1949,8 +1949,8 @@  All public heads
   i> flush() -> None
   o> bufferedreadline() -> 3:
   o>     15\n
-  o> bufferedread(15) -> 15: publishing	True
-  response: b'publishing	True'
+  o> bufferedread(15) -> 15: publishing\tTrue
+  response: b'publishing\tTrue'
 
 Setting public phase via pushkey
 
@@ -2099,13 +2099,13 @@  Test batching of requests
   o>     278\n
   o> bufferedread(278) -> 278:
   o>     bfebe6bd38eebc6f8202e419c1171268987ea6a6 4ee3fcef1c800fa2bf23e20af7c83ff111d9c7ab\n
-  o>     ;bookA	4ee3fcef1c800fa2bf23e20af7c83ff111d9c7ab\n
-  o>     bookB	bfebe6bd38eebc6f8202e419c1171268987ea6a6;4ee3fcef1c800fa2bf23e20af7c83ff111d9c7ab	1\n
-  o>     bfebe6bd38eebc6f8202e419c1171268987ea6a6	1\n
-  o>     publishing	True
+  o>     ;bookA\t4ee3fcef1c800fa2bf23e20af7c83ff111d9c7ab\n
+  o>     bookB\tbfebe6bd38eebc6f8202e419c1171268987ea6a6;4ee3fcef1c800fa2bf23e20af7c83ff111d9c7ab\t1\n
+  o>     bfebe6bd38eebc6f8202e419c1171268987ea6a6\t1\n
+  o>     publishing\tTrue
   response #0: bfebe6bd38eebc6f8202e419c1171268987ea6a6 4ee3fcef1c800fa2bf23e20af7c83ff111d9c7ab\n
-  response #1: bookA	4ee3fcef1c800fa2bf23e20af7c83ff111d9c7ab\nbookB	bfebe6bd38eebc6f8202e419c1171268987ea6a6
-  response #2: 4ee3fcef1c800fa2bf23e20af7c83ff111d9c7ab	1\nbfebe6bd38eebc6f8202e419c1171268987ea6a6	1\npublishing	True
+  response #1: bookA\t4ee3fcef1c800fa2bf23e20af7c83ff111d9c7ab\nbookB\tbfebe6bd38eebc6f8202e419c1171268987ea6a6
+  response #2: 4ee3fcef1c800fa2bf23e20af7c83ff111d9c7ab\t1\nbfebe6bd38eebc6f8202e419c1171268987ea6a6\t1\npublishing\tTrue
   
   testing ssh2
   creating ssh peer from handshake results
@@ -2136,10 +2136,10 @@  Test batching of requests
   o>     278\n
   o> bufferedread(278) -> 278:
   o>     bfebe6bd38eebc6f8202e419c1171268987ea6a6 4ee3fcef1c800fa2bf23e20af7c83ff111d9c7ab\n
-  o>     ;bookA	4ee3fcef1c800fa2bf23e20af7c83ff111d9c7ab\n
-  o>     bookB	bfebe6bd38eebc6f8202e419c1171268987ea6a6;4ee3fcef1c800fa2bf23e20af7c83ff111d9c7ab	1\n
-  o>     bfebe6bd38eebc6f8202e419c1171268987ea6a6	1\n
-  o>     publishing	True
+  o>     ;bookA\t4ee3fcef1c800fa2bf23e20af7c83ff111d9c7ab\n
+  o>     bookB\tbfebe6bd38eebc6f8202e419c1171268987ea6a6;4ee3fcef1c800fa2bf23e20af7c83ff111d9c7ab\t1\n
+  o>     bfebe6bd38eebc6f8202e419c1171268987ea6a6\t1\n
+  o>     publishing\tTrue
   response #0: bfebe6bd38eebc6f8202e419c1171268987ea6a6 4ee3fcef1c800fa2bf23e20af7c83ff111d9c7ab\n
-  response #1: bookA	4ee3fcef1c800fa2bf23e20af7c83ff111d9c7ab\nbookB	bfebe6bd38eebc6f8202e419c1171268987ea6a6
-  response #2: 4ee3fcef1c800fa2bf23e20af7c83ff111d9c7ab	1\nbfebe6bd38eebc6f8202e419c1171268987ea6a6	1\npublishing	True
+  response #1: bookA\t4ee3fcef1c800fa2bf23e20af7c83ff111d9c7ab\nbookB\tbfebe6bd38eebc6f8202e419c1171268987ea6a6
+  response #2: 4ee3fcef1c800fa2bf23e20af7c83ff111d9c7ab\t1\nbfebe6bd38eebc6f8202e419c1171268987ea6a6\t1\npublishing\tTrue