stringutil: drop escapedata() in favor of escapestr()
authorYuya Nishihara <yuya@tcha.org>
Wed, 04 Apr 2018 23:26:49 +0900
changeset 37322 a67fd1fe5109
parent 37321 e826fe7a08c7
child 37323 8c31b434697f
stringutil: drop escapedata() in favor of escapestr() They are quite similar. Let's choose one that uses standard Python escape.
mercurial/debugcommands.py
mercurial/util.py
mercurial/utils/stringutil.py
tests/test-http-api-httpv2.t
tests/test-http-protocol.t
tests/test-ssh-proto.t
--- a/mercurial/debugcommands.py	Fri Mar 30 18:57:13 2018 -0700
+++ b/mercurial/debugcommands.py	Wed Apr 04 23:26:49 2018 +0900
@@ -2964,9 +2964,9 @@
                     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 @@
                       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
 
--- a/mercurial/util.py	Fri Mar 30 18:57:13 2018 -0700
+++ b/mercurial/util.py	Wed Apr 04 23:26:49 2018 +0900
@@ -748,10 +748,10 @@
         # 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 @@
         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 @@
 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')
--- a/mercurial/utils/stringutil.py	Fri Mar 30 18:57:13 2018 -0700
+++ b/mercurial/utils/stringutil.py	Wed Apr 04 23:26:49 2018 +0900
@@ -23,24 +23,10 @@
     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):
--- a/tests/test-http-api-httpv2.t	Fri Mar 30 18:57:13 2018 -0700
+++ b/tests/test-http-api-httpv2.t	Wed Apr 04 23:26:49 2018 +0900
@@ -393,7 +393,7 @@
   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 @@
   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
--- a/tests/test-http-protocol.t	Fri Mar 30 18:57:13 2018 -0700
+++ b/tests/test-http-protocol.t	Wed Apr 04 23:26:49 2018 +0900
@@ -206,10 +206,10 @@
   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 @@
   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
--- a/tests/test-ssh-proto.t	Fri Mar 30 18:57:13 2018 -0700
+++ b/tests/test-ssh-proto.t	Wed Apr 04 23:26:49 2018 +0900
@@ -1342,10 +1342,10 @@
   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 @@
   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 @@
   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 @@
   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 @@
   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 @@
   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 @@
   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 @@
   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 @@
   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 @@
   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 @@
   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 @@
   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 @@
   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 @@
   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 @@
   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 @@
   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