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 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)
return lambda kwargs: Markup(
''.join(tmpl.generate(**kwargs).serialize('xhtml'))
)
break
relativestart = start - m.start
relativeend = end - m.start
if i < relativestart:
for j in range(i, relativestart):
if m.match[j].isspace():
expandedmatch += markupsafe.Markup(' ')
else:
expandedmatch += markupsafe.escape(m.match[j])
i = relativestart + 1
if m.start <= start and end <= m.end:
s = m.match[relativestart:relativeend]
if kind == 'substitution':
content = markupsafe.Markup(_substitutionmarkup(s))
else:
content = s
expandedmatch += markupsafe.Markup(
'<span class="expansion-{0}">{1}</span>').format(kind, content)
i = relativeend
if i < len(m.match):
expandedmatch += markupsafe.escape(m.match[i:])
assert expandedmatch
d['match'] = expandedmatch
def js(self):
return Markup(HTML.script(literal("""\
$(document).ready(function() {
$('.%s').clickover({
html: true,
title: 'Download information',
placement: '%s',
trigger: 'click'
});
});""" % (self._opener_class, self.options['doc_position']))))