utils.quoted

This commit is contained in:
James Vega 2004-10-23 19:40:00 +00:00
parent 575d83b3ad
commit 601d58a662
2 changed files with 13 additions and 0 deletions

View File

@ -212,6 +212,13 @@ def dqrepr(s):
# return '"' + repr("'\x00" + s)[6:]
return '"%s"' % s.encode('string_escape').replace('"', '\\"')
#XXX We're using this to centralize how we quote a string since %r/repr()
# doesn't play nicely with unicode characters. This eventually needs to be
# replaced to *not* use repr()
def quoted(s):
"""Returns a quoted s."""
return repr(s)
nonEscapedSlashes = re.compile(r'(?<!\\)/')
def perlReToPythonRe(s):
"""Converts a string representation of a Perl regular expression (i.e.,

View File

@ -146,6 +146,12 @@ class UtilsTest(SupyTestCase):
self.assertEqual(s, eval(r), s)
self.failUnless(r[0] == '"' and r[-1] == '"', s)
def testQuoted(self):
s = 'foo'
t = 'let\'s'
self.assertEqual("'%s'" % s, utils.quoted(s), s)
self.assertEqual('"%s"' % t, utils.quoted(t), t)
def testPerlReToPythonRe(self):
r = utils.perlReToPythonRe('m/foo/')
self.failUnless(r.search('foo'))