objstr: Implement "%(key)s" % {} formatting for strings and dicts.

Also, make sure that args to "*" format specifiers are bounds-checked
properly and don't lead for segfaults in case of mismatch.
This commit is contained in:
Paul Sokolovsky
2014-06-05 20:02:15 +03:00
parent 1e82ef3ae8
commit 75ce9256b2
5 changed files with 76 additions and 17 deletions

View File

@@ -48,3 +48,29 @@ print("%#X" % 18)
print("%#6o" % 18)
print("%#6x" % 18)
print("%#06x" % 18)
print("%*d" % (5, 10))
print("%*.*d" % (2, 2, 20))
# TODO: Formatted incorrectly
#print("%*.*d" % (5, 8, 20))
# Cases when "*" used and there's not enough values total
try:
print("%*s" % 5)
except TypeError:
print("TypeError")
try:
print("%*.*s" % (1, 15))
except TypeError:
print("TypeError")
print("%(foo)s" % {"foo": "bar", "baz": False})
try:
print("%(foo)s" % {})
except KeyError:
print("KeyError")
# Using in "*" with dict got to fail
try:
print("%(foo)*s" % {"foo": "bar"})
except TypeError:
print("TypeError")