Re: [PATCH 8 of 8 py3] drawdag: port to python 3

2017-09-16 Thread Yuya Nishihara
On Fri, 15 Sep 2017 19:14:11 -0400, Augie Fackler wrote:
> # HG changeset patch
> # User Augie Fackler 
> # Date 1503465796 14400
> #  Wed Aug 23 01:23:16 2017 -0400
> # Node ID d08554602cdbd245ddd213af325473da037a240f
> # Parent  962f6b24541c419fc135ebd75de8529344d85d31
> drawdag: port to python 3

Queued 6-8, thanks.

> ->>> pprint.pprint({k: [vv for vv in v]
> -...  for k, v in _parseasciigraph(br'''
> +>>> pprint.pprint({pycompat.sysstr(k): [pycompat.sysstr(vv) for vv in v]
> +...  for k, v in _parseasciigraph(b'''
>  ...  ofoo
>  ...  |\
>  ...  +---o  bar
> @@ -150,11 +151,11 @@ def _parseasciigraph(text):
>  ... ''').items()})
>  {'a': [],
>   'b': ['a'],
> - 'bar': ['b', 'a'],
> + 'bar': ['baz'],
>   'baz': [],
>   'c': ['b'],
>   'd': ['b'],
> - 'foo': ['baz', 'b']}
> + 'foo': ['b']}
>  """

Fixed these test changes caused by missed br''.
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


[PATCH 8 of 8 py3] drawdag: port to python 3

2017-09-15 Thread Augie Fackler
# HG changeset patch
# User Augie Fackler 
# Date 1503465796 14400
#  Wed Aug 23 01:23:16 2017 -0400
# Node ID d08554602cdbd245ddd213af325473da037a240f
# Parent  962f6b24541c419fc135ebd75de8529344d85d31
drawdag: port to python 3

diff --git a/tests/drawdag.py b/tests/drawdag.py
--- a/tests/drawdag.py
+++ b/tests/drawdag.py
@@ -92,6 +92,7 @@ from mercurial import (
 error,
 node,
 obsolete,
+pycompat,
 registrar,
 scmutil,
 tags as tagsmod,
@@ -100,9 +101,9 @@ from mercurial import (
 cmdtable = {}
 command = registrar.command(cmdtable)
 
-_pipechars = '\\/+-|'
-_nonpipechars = ''.join(chr(i) for i in xrange(33, 127)
-if chr(i) not in _pipechars)
+_pipechars = b'\\/+-|'
+_nonpipechars = b''.join(pycompat.bytechr(i) for i in range(33, 127)
+if pycompat.bytechr(i) not in _pipechars)
 
 def _isname(ch):
 """char -> bool. return True if ch looks like part of a name, False
@@ -113,7 +114,7 @@ def _parseasciigraph(text):
 r"""str -> {str : [str]}. convert the ASCII graph to edges
 
 >>> import pprint
->>> pprint.pprint({k: [vv for vv in v]
+>>> pprint.pprint({pycompat.sysstr(k): [pycompat.sysstr(vv) for vv in v]
 ...  for k, v in _parseasciigraph(b'''
 ...G
 ...|
@@ -132,8 +133,8 @@ def _parseasciigraph(text):
  'G': ['F'],
  'H': ['A'],
  'I': ['H']}
->>> pprint.pprint({k: [vv for vv in v]
-...  for k, v in _parseasciigraph(br'''
+>>> pprint.pprint({pycompat.sysstr(k): [pycompat.sysstr(vv) for vv in v]
+...  for k, v in _parseasciigraph(b'''
 ...  ofoo
 ...  |\
 ...  +---o  bar
@@ -150,11 +151,11 @@ def _parseasciigraph(text):
 ... ''').items()})
 {'a': [],
  'b': ['a'],
- 'bar': ['b', 'a'],
+ 'bar': ['baz'],
  'baz': [],
  'c': ['b'],
  'd': ['b'],
- 'foo': ['baz', 'b']}
+ 'foo': ['b']}
 """
 lines = text.splitlines()
 edges = collections.defaultdict(list)  # {node: []}
@@ -163,16 +164,16 @@ def _parseasciigraph(text):
 """(int, int) -> char. give a coordinate, return the char. return a
 space for anything out of range"""
 if x < 0 or y < 0:
-return ' '
+return b' '
 try:
-return lines[y][x]
+return lines[y][x:x + 1] or b' '
 except IndexError:
-return ' '
+return b' '
 
 def getname(y, x):
 """(int, int) -> str. like get(y, x) but concatenate left and right
 parts. if name is an 'o', try to replace it to the right"""
-result = ''
+result = b''
 for i in itertools.count(0):
 ch = get(y, x - i)
 if not _isname(ch):
@@ -183,17 +184,17 @@ def _parseasciigraph(text):
 if not _isname(ch):
 break
 result += ch
-if result == 'o':
+if result == b'o':
 # special handling, find the name to the right
-result = ''
+result = b''
 for i in itertools.count(2):
 ch = get(y, x + i)
-if ch == ' ' or ch in _pipechars:
+if ch == b' ' or ch in _pipechars:
 if result or x + i >= len(lines[y]):
 break
 else:
 result += ch
-return result or 'o'
+return result or b'o'
 return result
 
 def parents(y, x):
@@ -209,19 +210,19 @@ def _parseasciigraph(text):
 if '-' (or '+') is not in excepted, and get(y, x) is '-' (or '+'),
 the next line (y + 1, x) will be checked instead."""
 ch = get(y, x)
-if any(ch == c and c not in expected for c in '-+'):
+if any(ch == c and c not in expected for c in (b'-', b'+')):
 y += 1
 return follow(y + 1, x, expected)
-if ch in expected or ('o' in expected and _isname(ch)):
+if ch in expected or (b'o' in expected and _isname(ch)):
 visit.append((y, x))
 
 #  -o-  # starting point:
 #  /|\ # follow '-' (horizontally), and '/|\' (to the bottom)
-follow(y + 1, x, '|')
-follow(y + 1, x - 1, '/')
-follow(y + 1, x + 1, '\\')
-follow(y, x - 1, '-')
-follow(y, x + 1, '-')
+follow(y + 1, x, b'|')
+follow(y + 1, x - 1, b'/')
+follow(y + 1, x + 1, b'\\')
+follow(y, x - 1, b'-')
+follow(y, x + 1, b'-')
 
 while visit:
 y, x = visit.pop()
@@ -232,28 +233,28 @@ def _parseasciigraph(text):
 if _isname(ch):
 result.append(getname(y, x))
 continue
-elif ch == '|':
-follow(y + 1, x, '/|o')
-follow(y + 1, x - 1, '/')
-follow(y + 1, x + 1, '\\')
-elif ch == '+':
-follow(y, x -