Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_splitting(self):
self.assertEqual(Markup('a b').split(), [
Markup('a'),
Markup('b')
])
self.assertEqual(Markup('a b').rsplit(), [
Markup('a'),
Markup('b')
])
self.assertEqual(Markup('a\nb').splitlines(), [
Markup('a'),
Markup('b')
])
def test_splitting(self):
self.assertEqual(Markup('a b').split(), [
Markup('a'),
Markup('b')
])
self.assertEqual(Markup('a b').rsplit(), [
Markup('a'),
Markup('b')
])
self.assertEqual(Markup('a\nb').splitlines(), [
Markup('a'),
Markup('b')
])
def rsplit(self, *args, **kwargs):
return list(map(self.__class__, text_type.rsplit(self, *args, **kwargs)))
rsplit.__doc__ = text_type.rsplit.__doc__
def split(self, *args, **kwargs):
return list(map(self.__class__, text_type.split(self, *args, **kwargs)))
split.__doc__ = text_type.split.__doc__
def join(self, seq):
return self.__class__(text_type.join(self, map(self.escape, seq)))
join.__doc__ = text_type.join.__doc__
def split(self, *args, **kwargs):
return list(map(self.__class__, text_type.split(self, *args, **kwargs)))
split.__doc__ = text_type.split.__doc__
def rsplit(self, *args, **kwargs):
return list(map(self.__class__, text_type.rsplit(self, *args, **kwargs)))
rsplit.__doc__ = text_type.rsplit.__doc__
def splitlines(self, *args, **kwargs):
return list(map(self.__class__, text_type.splitlines(
self, *args, **kwargs)))
splitlines.__doc__ = text_type.splitlines.__doc__
def unescape(self):
r"""Unescape markup again into an text_type string. This also resolves
known HTML4 and XHTML entities:
>>> Markup("Main » <em>About</em>").unescape()
u'Main \xbb <em>About</em>'
"""
from markupsafe._constants import HTML_ENTITIES
def handle_match(m):
name = m.group(1)
if name in HTML_ENTITIES:
return unichr(HTML_ENTITIES[name])
try:
if name[:2] in ('#x', '#X'):
return unichr(int(name[2:], 16))
def test_formatting(self):
for actual, expected in (
(Markup('%i') % 3.14, '3'),
(Markup('%.2f') % 3.14159, '3.14'),
(Markup('%s %s %s') % ('<', 123, '>'), '< 123 >'),
(Markup('<em>{awesome}</em>').format(awesome=''),
'<em><awesome></em>'),
(Markup('{0[1][bar]}').format([0, {'bar': ''}]),
'<bar/>'),
(Markup('{0[1][bar]}').format([0, {'bar': Markup('')}]),
'')):
assert actual == expected, "%r should be %r!" % (actual, expected)
# Read log line by line
from . import proto
records = []
for line in open(logfile):
v = json.loads(line)
r = {'time': time.strftime(TIME_FORMAT, time.localtime(v.get('timestamp')))}
d = v.get('data', {})
tag = v.get('tag')
# Process Function, Snapshot, Memory, CPU ...
if tag == proto.TAG_FUNCTION:
tag = markupsafe.Markup('function')
args = map(json.dumps, d.get('args'))
kwargs = [ '%s=%s' %(k, json.dumps(_v)) for k, _v in d.get('kwargs', {}).items() ]
message = '<code style="color:green">%s(%s)</code>' %(d.get('name'), ', '.join(args+kwargs))
message = markupsafe.Markup(message)
elif tag == proto.TAG_SNAPSHOT:
message = markupsafe.Markup("<img src="%s" width="100%%">" % d.get('filename'))
elif tag == proto.TAG_CPU:
message = '%d%%' %(d)
cpus.append([r, d])
elif tag == proto.TAG_MEMORY:
mems.append([r, d['PSS']])
message = json.dumps(d)
else:
message = None
if message:
r['tag'] = tag
r['message'] = message
records.append(r)
def test_formatting(self):
for actual, expected in (
(Markup('%i') % 3.14, '3'),
(Markup('%.2f') % 3.14159, '3.14'),
(Markup('%s %s %s') % ('<', 123, '>'), '< 123 >'),
(Markup('<em>{awesome}</em>').format(awesome=''),
'<em><awesome></em>'),
(Markup('{0[1][bar]}').format([0, {'bar': ''}]),
'<bar/>'),
(Markup('{0[1][bar]}').format([0, {'bar': Markup('')}]),
'')):
assert actual == expected, "%r should be %r!" % (actual, expected)
def test_formatting(self):
for actual, expected in (
(Markup('%i') % 3.14, '3'),
(Markup('%.2f') % 3.14159, '3.14'),
(Markup('%s %s %s') % ('<', 123, '>'), '< 123 >'),
(Markup('<em>{awesome}</em>').format(awesome=''),
'<em><awesome></em>'),
(Markup('{0[1][bar]}').format([0, {'bar': ''}]),
'<bar/>'),
(Markup('{0[1][bar]}').format([0, {'bar': Markup('')}]),
'')):
assert actual == expected, "%r should be %r!" % (actual, expected)