mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-10 20:22:36 +01:00
utils.quoted
This commit is contained in:
parent
575d83b3ad
commit
601d58a662
@ -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.,
|
||||
|
@ -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'))
|
||||
|
Loading…
Reference in New Issue
Block a user