-
Notifications
You must be signed in to change notification settings - Fork 434
Expand file tree
/
Copy pathlisting.py
More file actions
32 lines (23 loc) · 714 Bytes
/
listing.py
File metadata and controls
32 lines (23 loc) · 714 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# -*- coding: utf-8 -*-
"""
Created : 2021-07-30
@author: Eric Lapouyade
"""
from ._compat import escape
class Listing(object):
r"""class to manage \n and \a without to use RichText,
by this way you keep the current template styling
use {{ mylisting }} in your template and
context={ mylisting:Listing(the_listing_with_newlines) }
"""
def __init__(self, text):
# If not a string : cast to string (ex: int, dict etc...)
if not isinstance(text, (str, bytes)):
text = str(text)
self.xml = escape(text)
def __unicode__(self):
return self.xml
def __str__(self):
return self.xml
def __html__(self):
return self.xml