Show More
@@ -1059,6 +1059,8 b' def formatspec(expr, *args):' | |||
|
1059 | 1059 | %n = hex(arg), single-quoted |
|
1060 | 1060 | %% = a literal '%' |
|
1061 | 1061 | |
|
1062 | Prefixing the type with 'l' specifies a list of that type. | |
|
1063 | ||
|
1062 | 1064 | >>> formatspec('%d:: and not %d::', 10, 20) |
|
1063 | 1065 | '10:: and not 20::' |
|
1064 | 1066 | >>> formatspec('keyword(%s)', 'foo\\xe9') |
@@ -1067,11 +1069,23 b' def formatspec(expr, *args):' | |||
|
1067 | 1069 | >>> b.branch = b |
|
1068 | 1070 | >>> formatspec('branch(%b)', b) |
|
1069 | 1071 | "branch('default')" |
|
1072 | >>> formatspec('root(%ls)', ['a', 'b', 'c', 'd']) | |
|
1073 | "root(('a' or 'b' or 'c' or 'd'))" | |
|
1070 | 1074 | ''' |
|
1071 | 1075 | |
|
1072 | 1076 | def quote(s): |
|
1073 | 1077 | return repr(str(s)) |
|
1074 | 1078 | |
|
1079 | def argtype(c, arg): | |
|
1080 | if c == 'd': | |
|
1081 | return str(int(arg)) | |
|
1082 | elif c == 's': | |
|
1083 | return quote(arg) | |
|
1084 | elif c == 'n': | |
|
1085 | return quote(node.hex(arg)) | |
|
1086 | elif c == 'b': | |
|
1087 | return quote(arg.branch()) | |
|
1088 | ||
|
1075 | 1089 | ret = '' |
|
1076 | 1090 | pos = 0 |
|
1077 | 1091 | arg = 0 |
@@ -1082,17 +1096,15 b' def formatspec(expr, *args):' | |||
|
1082 | 1096 | d = expr[pos] |
|
1083 | 1097 | if d == '%': |
|
1084 | 1098 | ret += d |
|
1085 |
elif d |
|
|
1086 |
ret += |
|
|
1087 | arg += 1 | |
|
1088 | elif d == 's': | |
|
1089 | ret += quote(args[arg]) | |
|
1099 | elif d in 'dsnb': | |
|
1100 | ret += argtype(d, args[arg]) | |
|
1090 | 1101 | arg += 1 |
|
1091 |
elif d == ' |
|
|
1092 | ret += quote(node.hex(args[arg])) | |
|
1093 |
|
|
|
1094 |
|
|
|
1095 | ret += quote(args[arg].branch()) | |
|
1102 | elif d == 'l': | |
|
1103 | # a list of some type | |
|
1104 | pos += 1 | |
|
1105 | d = expr[pos] | |
|
1106 | lv = ' or '.join(argtype(d, e) for e in args[arg]) | |
|
1107 | ret += '(%s)' % lv | |
|
1096 | 1108 | arg += 1 |
|
1097 | 1109 | else: |
|
1098 | 1110 | raise util.Abort('unexpected revspec format character %s' % d) |
General Comments 0
You need to be logged in to leave comments.
Login now