Robot Framework Integrated Development Environment (RIDE)
markuputils.py
Go to the documentation of this file.
1 # Copyright 2008-2015 Nokia Networks
2 # Copyright 2016- Robot Framework Foundation
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 
16 import re
17 
18 from .htmlformatters import LinkFormatter, HtmlFormatter
19 
20 
21 
24 _format_url = LinkFormatter().format_url
25 
28 _generic_escapes = (('&', '&amp;'), ('<', '&lt;'), ('>', '&gt;'))
29 
32 _attribute_escapes = _generic_escapes \
33  + (('"', '&quot;'), ('\n', '&#10;'), ('\r', '&#13;'), ('\t', '&#09;'))
34 
37 _illegal_chars_in_xml = re.compile(u'[\x00-\x08\x0B\x0C\x0E-\x1F\uFFFE\uFFFF]')
38 
39 
40 def html_escape(text, linkify=True):
41  text = _escape(text)
42  if linkify and '://' in text:
43  text = _format_url(text)
44  return text
45 
46 
47 def xml_escape(text):
48  return _illegal_chars_in_xml.sub('', _escape(text))
49 
50 
51 def html_format(text):
52  return HtmlFormatter().format(_escape(text))
53 
54 
55 def attribute_escape(attr):
56  attr = _escape(attr, _attribute_escapes)
57  return _illegal_chars_in_xml.sub('', attr)
58 
59 
60 def _escape(text, escapes=_generic_escapes):
61  for name, value in escapes:
62  if name in text: # performance optimization
63  text = text.replace(name, value)
64  return text
def _escape(text, escapes=_generic_escapes)
Definition: markuputils.py:60
def html_escape(text, linkify=True)
Definition: markuputils.py:40