Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/encoding.py @ 38823:e7aa113b14f7
global: use pycompat.xrange()
On Python 3, our module importer automatically rewrites xrange()
to pycompat.xrange().
We want to move away from the custom importer on Python 3.
This commit converts all instances of xrange() to use
pycompat.xrange().
Differential Revision: https://phab.mercurial-scm.org/D4032
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Wed, 01 Aug 2018 13:00:45 -0700 |
parents | 7acec9408e1c |
children | 24e493ec2229 |
comparison
equal
deleted
inserted
replaced
38822:7eba8f83129b | 38823:e7aa113b14f7 |
---|---|
249 return len(d) | 249 return len(d) |
250 | 250 |
251 def getcols(s, start, c): | 251 def getcols(s, start, c): |
252 '''Use colwidth to find a c-column substring of s starting at byte | 252 '''Use colwidth to find a c-column substring of s starting at byte |
253 index start''' | 253 index start''' |
254 for x in xrange(start + c, len(s)): | 254 for x in pycompat.xrange(start + c, len(s)): |
255 t = s[start:x] | 255 t = s[start:x] |
256 if colwidth(t) == c: | 256 if colwidth(t) == c: |
257 return t | 257 return t |
258 | 258 |
259 def trim(s, width, ellipsis='', leftside=False): | 259 def trim(s, width, ellipsis='', leftside=False): |
344 uslice = lambda i: u[i:] | 344 uslice = lambda i: u[i:] |
345 concat = lambda s: ellipsis + s | 345 concat = lambda s: ellipsis + s |
346 else: | 346 else: |
347 uslice = lambda i: u[:-i] | 347 uslice = lambda i: u[:-i] |
348 concat = lambda s: s + ellipsis | 348 concat = lambda s: s + ellipsis |
349 for i in xrange(1, len(u)): | 349 for i in pycompat.xrange(1, len(u)): |
350 usub = uslice(i) | 350 usub = uslice(i) |
351 if ucolwidth(usub) <= width: | 351 if ucolwidth(usub) <= width: |
352 return concat(usub.encode(_sysstr(encoding))) | 352 return concat(usub.encode(_sysstr(encoding))) |
353 return ellipsis # no enough room for multi-column characters | 353 return ellipsis # no enough room for multi-column characters |
354 | 354 |