##// END OF EJS Templates
stringutil: add function to pretty print an object...
Gregory Szorc -
r37316:2f859ad7 default
parent child Browse files
Show More
@@ -2969,7 +2969,7 b' def debugwireproto(ui, repo, path=None, '
2969 2969 stringutil.escapedata(output))
2970 2970 else:
2971 2971 res = peer._call(command, **pycompat.strkwargs(args))
2972 ui.status(_('response: %s\n') % stringutil.escapedata(res))
2972 ui.status(_('response: %s\n') % stringutil.pprint(res))
2973 2973
2974 2974 elif action == 'batchbegin':
2975 2975 if batchedcommands is not None:
@@ -37,6 +37,20 b' def escapedata(s):'
37 37
38 38 return _DATA_ESCAPE_RE.sub(lambda m: _DATA_ESCAPE_MAP[m.group(0)], s)
39 39
40 def pprint(o):
41 """Pretty print an object."""
42 if isinstance(o, (bytes, bytearray)):
43 return "b'%s'" % escapedata(o)
44 elif isinstance(o, list):
45 return '[%s]' % (b', '.join(pprint(a) for a in o))
46 elif isinstance(o, dict):
47 return '{%s}' % (b', '.join(
48 '%s: %s' % (pprint(k), pprint(v)) for k, v in sorted(o.items())))
49 elif isinstance(o, bool):
50 return b'True' if o else b'False'
51 else:
52 raise error.ProgrammingError('do not know how to format %r' % o)
53
40 54 def binary(s):
41 55 """return true if a string is binary data"""
42 56 return bool(s and '\0' in s)
@@ -209,7 +209,7 b' Test listkeys for listing namespaces'
209 209 s> bookmarks \n
210 210 s> namespaces \n
211 211 s> phases
212 response: bookmarks \nnamespaces \nphases
212 response: b'bookmarks \nnamespaces \nphases '
213 213
214 214 Same thing, but with "httprequest" command
215 215
@@ -1345,7 +1345,7 b' Test listkeys for listing namespaces'
1345 1345 o> bookmarks \n
1346 1346 o> namespaces \n
1347 1347 o> phases
1348 response: bookmarks \nnamespaces \nphases
1348 response: b'bookmarks \nnamespaces \nphases '
1349 1349
1350 1350 testing ssh2
1351 1351 creating ssh peer from handshake results
@@ -1376,7 +1376,7 b' Test listkeys for listing namespaces'
1376 1376 o> bookmarks \n
1377 1377 o> namespaces \n
1378 1378 o> phases
1379 response: bookmarks \nnamespaces \nphases
1379 response: b'bookmarks \nnamespaces \nphases '
1380 1380
1381 1381 $ cd ..
1382 1382
@@ -1421,7 +1421,7 b' With no bookmarks set'
1421 1421 i> flush() -> None
1422 1422 o> bufferedreadline() -> 2:
1423 1423 o> 0\n
1424 response:
1424 response: b''
1425 1425
1426 1426 testing ssh2
1427 1427 creating ssh peer from handshake results
@@ -1448,7 +1448,7 b' With no bookmarks set'
1448 1448 i> flush() -> None
1449 1449 o> bufferedreadline() -> 2:
1450 1450 o> 0\n
1451 response:
1451 response: b''
1452 1452
1453 1453 With a single bookmark set
1454 1454
@@ -1483,7 +1483,7 b' With a single bookmark set'
1483 1483 o> bufferedreadline() -> 3:
1484 1484 o> 46\n
1485 1485 o> bufferedread(46) -> 46: bookA 68986213bd4485ea51533535e3fc9e78007a711f
1486 response: bookA 68986213bd4485ea51533535e3fc9e78007a711f
1486 response: b'bookA 68986213bd4485ea51533535e3fc9e78007a711f'
1487 1487
1488 1488 testing ssh2
1489 1489 creating ssh peer from handshake results
@@ -1511,7 +1511,7 b' With a single bookmark set'
1511 1511 o> bufferedreadline() -> 3:
1512 1512 o> 46\n
1513 1513 o> bufferedread(46) -> 46: bookA 68986213bd4485ea51533535e3fc9e78007a711f
1514 response: bookA 68986213bd4485ea51533535e3fc9e78007a711f
1514 response: b'bookA 68986213bd4485ea51533535e3fc9e78007a711f'
1515 1515
1516 1516 With multiple bookmarks set
1517 1517
@@ -1548,7 +1548,7 b' With multiple bookmarks set'
1548 1548 o> bufferedread(93) -> 93:
1549 1549 o> bookA 68986213bd4485ea51533535e3fc9e78007a711f\n
1550 1550 o> bookB 1880f3755e2e52e3199e0ee5638128b08642f34d
1551 response: bookA 68986213bd4485ea51533535e3fc9e78007a711f\nbookB 1880f3755e2e52e3199e0ee5638128b08642f34d
1551 response: b'bookA 68986213bd4485ea51533535e3fc9e78007a711f\nbookB 1880f3755e2e52e3199e0ee5638128b08642f34d'
1552 1552
1553 1553 testing ssh2
1554 1554 creating ssh peer from handshake results
@@ -1578,7 +1578,7 b' With multiple bookmarks set'
1578 1578 o> bufferedread(93) -> 93:
1579 1579 o> bookA 68986213bd4485ea51533535e3fc9e78007a711f\n
1580 1580 o> bookB 1880f3755e2e52e3199e0ee5638128b08642f34d
1581 response: bookA 68986213bd4485ea51533535e3fc9e78007a711f\nbookB 1880f3755e2e52e3199e0ee5638128b08642f34d
1581 response: b'bookA 68986213bd4485ea51533535e3fc9e78007a711f\nbookB 1880f3755e2e52e3199e0ee5638128b08642f34d'
1582 1582
1583 1583 Test pushkey for bookmarks
1584 1584
@@ -1624,7 +1624,7 b' Test pushkey for bookmarks'
1624 1624 o> 2\n
1625 1625 o> bufferedread(2) -> 2:
1626 1626 o> 1\n
1627 response: 1\n
1627 response: b'1\n'
1628 1628
1629 1629 testing ssh2
1630 1630 creating ssh peer from handshake results
@@ -1661,7 +1661,7 b' Test pushkey for bookmarks'
1661 1661 o> 2\n
1662 1662 o> bufferedread(2) -> 2:
1663 1663 o> 1\n
1664 response: 1\n
1664 response: b'1\n'
1665 1665
1666 1666 $ hg bookmarks
1667 1667 bookA 0:68986213bd44
@@ -1707,7 +1707,7 b' Phases on empty repo'
1707 1707 o> bufferedreadline() -> 3:
1708 1708 o> 15\n
1709 1709 o> bufferedread(15) -> 15: publishing True
1710 response: publishing True
1710 response: b'publishing True'
1711 1711
1712 1712 testing ssh2
1713 1713 creating ssh peer from handshake results
@@ -1735,7 +1735,7 b' Phases on empty repo'
1735 1735 o> bufferedreadline() -> 3:
1736 1736 o> 15\n
1737 1737 o> bufferedread(15) -> 15: publishing True
1738 response: publishing True
1738 response: b'publishing True'
1739 1739
1740 1740 Create some commits
1741 1741
@@ -1789,7 +1789,7 b' Two draft heads'
1789 1789 o> 20b8a89289d80036e6c4e87c2083e3bea1586637 1\n
1790 1790 o> c4750011d906c18ea2f0527419cbc1a544435150 1\n
1791 1791 o> publishing True
1792 response: 20b8a89289d80036e6c4e87c2083e3bea1586637 1\nc4750011d906c18ea2f0527419cbc1a544435150 1\npublishing True
1792 response: b'20b8a89289d80036e6c4e87c2083e3bea1586637 1\nc4750011d906c18ea2f0527419cbc1a544435150 1\npublishing True'
1793 1793
1794 1794 testing ssh2
1795 1795 creating ssh peer from handshake results
@@ -1820,7 +1820,7 b' Two draft heads'
1820 1820 o> 20b8a89289d80036e6c4e87c2083e3bea1586637 1\n
1821 1821 o> c4750011d906c18ea2f0527419cbc1a544435150 1\n
1822 1822 o> publishing True
1823 response: 20b8a89289d80036e6c4e87c2083e3bea1586637 1\nc4750011d906c18ea2f0527419cbc1a544435150 1\npublishing True
1823 response: b'20b8a89289d80036e6c4e87c2083e3bea1586637 1\nc4750011d906c18ea2f0527419cbc1a544435150 1\npublishing True'
1824 1824
1825 1825 Single draft head
1826 1826
@@ -1857,7 +1857,7 b' Single draft head'
1857 1857 o> bufferedread(58) -> 58:
1858 1858 o> c4750011d906c18ea2f0527419cbc1a544435150 1\n
1859 1859 o> publishing True
1860 response: c4750011d906c18ea2f0527419cbc1a544435150 1\npublishing True
1860 response: b'c4750011d906c18ea2f0527419cbc1a544435150 1\npublishing True'
1861 1861
1862 1862 testing ssh2
1863 1863 creating ssh peer from handshake results
@@ -1887,7 +1887,7 b' Single draft head'
1887 1887 o> bufferedread(58) -> 58:
1888 1888 o> c4750011d906c18ea2f0527419cbc1a544435150 1\n
1889 1889 o> publishing True
1890 response: c4750011d906c18ea2f0527419cbc1a544435150 1\npublishing True
1890 response: b'c4750011d906c18ea2f0527419cbc1a544435150 1\npublishing True'
1891 1891
1892 1892 All public heads
1893 1893
@@ -1922,7 +1922,7 b' All public heads'
1922 1922 o> bufferedreadline() -> 3:
1923 1923 o> 15\n
1924 1924 o> bufferedread(15) -> 15: publishing True
1925 response: publishing True
1925 response: b'publishing True'
1926 1926
1927 1927 testing ssh2
1928 1928 creating ssh peer from handshake results
@@ -1950,7 +1950,7 b' All public heads'
1950 1950 o> bufferedreadline() -> 3:
1951 1951 o> 15\n
1952 1952 o> bufferedread(15) -> 15: publishing True
1953 response: publishing True
1953 response: b'publishing True'
1954 1954
1955 1955 Setting public phase via pushkey
1956 1956
@@ -1999,7 +1999,7 b' Setting public phase via pushkey'
1999 1999 o> 2\n
2000 2000 o> bufferedread(2) -> 2:
2001 2001 o> 1\n
2002 response: 1\n
2002 response: b'1\n'
2003 2003
2004 2004 testing ssh2
2005 2005 creating ssh peer from handshake results
@@ -2037,7 +2037,7 b' Setting public phase via pushkey'
2037 2037 o> 2\n
2038 2038 o> bufferedread(2) -> 2:
2039 2039 o> 1\n
2040 response: 1\n
2040 response: b'1\n'
2041 2041
2042 2042 $ hg phase .
2043 2043 4: public
General Comments 0
You need to be logged in to leave comments. Login now