Mercurial > python-hglib
comparison hglib/util.py @ 19:19d2c55c3928
util: introduce skiplines
author | Idan Kamara <idankk86@gmail.com> |
---|---|
date | Thu, 11 Aug 2011 15:42:58 +0300 |
parents | 5882a698ad5c |
children | 3d7e0325ba1c |
comparison
equal
deleted
inserted
replaced
18:518149e32888 | 19:19d2c55c3928 |
---|---|
20 | 20 |
21 for line in cs: | 21 for line in cs: |
22 n -= 1 | 22 n -= 1 |
23 if n == 0: | 23 if n == 0: |
24 return cs.read() | 24 return cs.read() |
25 return '' | |
26 | |
27 def skiplines(s, prefix): | |
28 """ | |
29 Skip lines starting with prefix in s | |
30 | |
31 >>> skiplines('a\\nb\\na\\n', 'a') | |
32 'b\\na\\n' | |
33 >>> skiplines('a\\na\\n', 'a') | |
34 '' | |
35 >>> skiplines('', 'a') | |
36 '' | |
37 >>> skiplines('a\\nb', 'b') | |
38 'a\\nb' | |
39 """ | |
40 cs = cStringIO.StringIO(s) | |
41 | |
42 for line in cs: | |
43 if not line.startswith(prefix): | |
44 return line + cs.read() | |
45 | |
25 return '' | 46 return '' |
26 | 47 |
27 def cmdbuilder(name, *args, **kwargs): | 48 def cmdbuilder(name, *args, **kwargs): |
28 """ | 49 """ |
29 A helper for building the command arguments | 50 A helper for building the command arguments |