mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-24 19:52:54 +01:00
Added dqrepr.
This commit is contained in:
parent
7f90fdc712
commit
6287d61d9e
@ -194,4 +194,8 @@ def soundex(s, length=4):
|
||||
s = ''.join(L)
|
||||
return length and s[:length] or s.rstrip('0')
|
||||
|
||||
def dqrepr(s):
|
||||
"""Returns a repr() of s guaranteed to be in double quotes."""
|
||||
return '"' + repr("'\x00" + s)[6:]
|
||||
|
||||
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||
|
@ -97,3 +97,15 @@ class UtilsTest(unittest.TestCase):
|
||||
soundex = utils.soundex(name)
|
||||
self.assertEqual(soundex, key,
|
||||
'%s was %s, not %s' % (name, soundex, key))
|
||||
|
||||
def testDQRepr(self):
|
||||
L = [('foo', '"foo"'),
|
||||
('foo\'bar', '"foo\'bar"'),
|
||||
('foo"bar', '"foo\\"bar"'),
|
||||
('"', '"\\""'),
|
||||
('', '""'),
|
||||
('\x00', '"\\x00"')]
|
||||
for (s, r) in L:
|
||||
self.assertEqual(r, utils.dqrepr(s))
|
||||
self.assertEqual(s, eval(utils.dqrepr(s)))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user