Esempio n. 1
0
 def _fix_title(self, title, categ_id, _ws_re=re.compile(r'\s+'),
                _status_re=re.compile(r'<font[^>]+>\s*(open|closed)\s*$')):
     orig = title
     title = _status_re.sub(r'(\1)', title)  # XXX: remove for 2.0; only needed for a CERN indico catgory
     title = HTMLParser().unescape(strip_tags(title))
     title = _ws_re.sub(' ', title).strip()
     if title != orig:
         self.print_warning('Sanitized category title', event_id=categ_id)
         self.print_warning('%[red!]{}%[reset] => %[green!]{}%[reset]'.format(orig, title))
     return title
Esempio n. 2
0
 def _fix_title(self, title, categ_id, _ws_re=re.compile(r'\s+'),
                _status_re=re.compile(r'<font[^>]+>\s*(open|closed)\s*$')):
     orig = title
     title = _status_re.sub(r'(\1)', title)  # XXX: remove for 2.0; only needed for a CERN indico catgory
     title = HTMLParser().unescape(strip_tags(title))
     title = _ws_re.sub(' ', title).strip()
     if title != orig:
         self.print_warning('Sanitized category title', event_id=categ_id)
         self.print_warning(cformat('%{red!}OLD: {}').format(orig))
         self.print_warning(cformat('%{green!}NEW: {}').format(title))
     return title
Esempio n. 3
0
    def _draw_item(self, canvas, item, tpl_data, content, margin_x, margin_y):
        style = ParagraphStyle({})
        style.alignment = ALIGNMENTS[item['text_align']]
        style.textColor = COLORS[item['color']]
        style.fontSize = _extract_font_size(item['font_size'])
        style.leading = style.fontSize

        if item['bold'] and item['italic']:
            style.fontName = FONT_STYLES[item['font_family']][3]
        elif item['italic']:
            style.fontName = FONT_STYLES[item['font_family']][2]
        elif item['bold']:
            style.fontName = FONT_STYLES[item['font_family']][1]
        else:
            style.fontName = FONT_STYLES[item['font_family']][0]

        item_x = float(item['x']) / PIXELS_CM * cm
        item_y = float(item['y']) / PIXELS_CM * cm
        item_width = item['width'] / PIXELS_CM * cm
        item_height = (item['height'] / PIXELS_CM *
                       cm) if item.get('height') is not None else None

        if isinstance(content, Image):
            canvas.drawImage(ImageReader(content), margin_x + item_x,
                             self.height - margin_y - item_height - item_y,
                             item_width, item_height)
        else:
            content = strip_tags(content)
            for line in content.splitlines():
                p = Paragraph(line, style)
                available_height = (tpl_data.height_cm -
                                    (item_y / PIXELS_CM)) * cm

                w, h = p.wrap(item_width, available_height)
                if w > item_width or h > available_height:
                    # TODO: add warning
                    pass

                p.drawOn(canvas, margin_x + item_x,
                         self.height - margin_y - item_y - h)
                item_y += h
Esempio n. 4
0
def _sanitize(title):
    return WHITESPACE_RE.sub(
        ' ',
        HTMLParser().unescape(strip_tags(convert_to_unicode(title)))).strip()
Esempio n. 5
0
def _sanitize_title(title):
    return WHITESPACE_RE.sub(" ", HTMLParser().unescape(strip_tags(convert_to_unicode(title)))).strip()
Esempio n. 6
0
 def _sanitize_title(self, title, _ws_re=re.compile(r'\s+')):
     title = convert_to_unicode(title)
     title = HTMLParser().unescape(strip_tags(title))
     return _ws_re.sub(' ', title).strip()
Esempio n. 7
0
def sanitize_user_input(string, html=False):
    string = convert_to_unicode(string)
    if not html:
        string = HTMLParser().unescape(strip_tags(string))
    return WHITESPACE_RE.sub(' ', string).strip()
Esempio n. 8
0
def _sanitize(string, html=False):
    string = convert_to_unicode(string)
    if not html:
        string = HTMLParser().unescape(strip_tags(string))
    return WHITESPACE_RE.sub(' ', string).strip()
Esempio n. 9
0
 def _sanitize_title(self, title, _ws_re=re.compile(r'\s+')):
     title = convert_to_unicode(title)
     title = HTMLParser().unescape(strip_tags(title))
     return _ws_re.sub(' ', title).strip()