def test_known_values(self): self.assertEqual( ulines( tu.normalize_text('''some really malformated text. With some times some veeeeeeeeeeeeeeerrrrryyyyyyyyyyyyyyyyyyy loooooooooooooooooooooong linnnnnnnnnnnes and empty lines! ''')), '''some really malformated text. With some times some veeeeeeeeeeeeeeerrrrryyyyyyyyyyyyyyyyyyy loooooooooooooooooooooong linnnnnnnnnnnes and empty lines!''') self.assertMultiLineEqual( ulines( tu.normalize_text('''\ some ReST formated text ======================= With some times some veeeeeeeeeeeeeeerrrrryyyyyyyyyyyyyyyyyyy loooooooooooooooooooooong linnnnnnnnnnnes and normal lines! another paragraph ''', rest=True)), '''\ some ReST formated text ======================= With some times some veeeeeeeeeeeeeeerrrrryyyyyyyyyyyyyyyyyyy loooooooooooooooooooooong linnnnnnnnnnnes and normal lines! another paragraph''')
def test_known_values(self): self.assertEqual(ulines(tu.normalize_text('''some really malformated text. With some times some veeeeeeeeeeeeeeerrrrryyyyyyyyyyyyyyyyyyy loooooooooooooooooooooong linnnnnnnnnnnes and empty lines! ''')), '''some really malformated text. With some times some veeeeeeeeeeeeeeerrrrryyyyyyyyyyyyyyyyyyy loooooooooooooooooooooong linnnnnnnnnnnes and empty lines!''') self.assertMultiLineEqual(ulines(tu.normalize_text('''\ some ReST formated text ======================= With some times some veeeeeeeeeeeeeeerrrrryyyyyyyyyyyyyyyyyyy loooooooooooooooooooooong linnnnnnnnnnnes and normal lines! another paragraph ''', rest=True)), '''\ some ReST formated text ======================= With some times some veeeeeeeeeeeeeeerrrrryyyyyyyyyyyyyyyyyyy loooooooooooooooooooooong linnnnnnnnnnnes and normal lines! another paragraph''')
def format_help(self, checkerref=False): """return the help string for the given message id""" desc = self.descr if checkerref: desc += ' This message belongs to the %s checker.' % \ self.checker.name title = self.msg if self.symbol: msgid = '%s (%s)' % (self.symbol, self.msgid) else: msgid = self.msgid if self.minversion or self.maxversion: restr = [] if self.minversion: restr.append('< %s' % '.'.join([str(n) for n in self.minversion])) if self.maxversion: restr.append('>= %s' % '.'.join([str(n) for n in self.maxversion])) restr = ' or '.join(restr) if checkerref: desc += " It can't be emitted when using Python %s." % restr else: desc += " This message can't be emitted when using Python %s." % restr desc = normalize_text(' '.join(desc.split()), indent=' ') if title != '%s': title = title.splitlines()[0] return ':%s: *%s*\n%s' % (msgid, title, desc) return ':%s:\n%s' % (msgid, desc)
def test_nonregr_unsplitable_word(self): self.assertEqual(ulines(tu.normalize_text('''petit complement : http://www.plonefr.net/blog/archive/2005/10/30/tester-la-future-infrastructure-i18n ''', 80)), '''petit complement : http://www.plonefr.net/blog/archive/2005/10/30/tester-la-future-infrastructure-i18n''')
def test_known_values(self): self.assertEqual(ulines(tu.normalize_text("""This package contains test files shared by the logilab-common package. It isn't necessary to install this package unless you want to execute or look at the tests.""", indent=' ', line_len=70)), """\ This package contains test files shared by the logilab-common package. It isn't necessary to install this package unless you want to execute or look at the tests.""")
def rest_format_section(stream, section, options, encoding=None, doc=None): """format an options section using as ReST formatted output""" encoding = _get_encoding(encoding, stream) if section: print('%s\n%s' % (section, "'"*len(section)), file=stream) if doc: print(_encode(normalize_text(doc, line_len=79, indent=''), encoding), file=stream) print(file=stream) for optname, optdict, value in options: help = optdict.get('help') print(':%s:' % optname, file=stream) if help: help = normalize_text(help, line_len=79, indent=' ') print(_encode(help, encoding), file=stream) if value: value = _encode(format_option_value(optdict, value), encoding) print(file=stream) print(' Default: ``%s``' % value.replace("`` ", "```` ``"), file=stream)
def rest_format_section(stream, section, options, encoding=None, doc=None): """format an options section using the INI format""" encoding = _get_encoding(encoding, stream) if section: print >> stream, "%s\n%s" % (section, "'" * len(section)) if doc: print >> stream, _encode(normalize_text(doc, line_len=79, indent=""), encoding) print >> stream for optname, optdict, value in options: help = optdict.get("help") print >> stream, ":%s:" % optname if help: help = normalize_text(help, line_len=79, indent=" ") print >> stream, _encode(help, encoding) if value: value = _encode(format_option_value(optdict, value), encoding) print >> stream, "" print >> stream, " Default: ``%s``" % value.replace("`` ", "```` ``")
def test_nonregr_rest_normalize(self): self.assertEqual( ulines( tu.normalize_text( """... Il est donc evident que tout le monde doit lire le compte-rendu de RSH et aller discuter avec les autres si c'est utile ou necessaire. """, rest=True)), """... Il est donc evident que tout le monde doit lire le compte-rendu de RSH et aller discuter avec les autres si c'est utile ou necessaire.""")
def render_row(self, context, data): document = data context.fillSlots('doctitle', document.title) # XXX abstract attribute should be a unicode string try: abstract = normalize_text(unicode(document.abstract)) except Exception, exc: print exc abstract = u'No abstract available for this document [%s]' % exc
def context(self, **kwargs): context = super(ExpenseAcceptedView, self).context(**kwargs) entity = self.cw_rset.complete_entity(0, 0) description = entity.printable_value('description', format='text/plain') description = normalize_text(description, 80) detail = u'\n'.join(line.view('textoutofcontext') for line in entity.has_lines) context.update({'description': description, 'title': entity.title, 'url': entity.absolute_url(), 'detail': detail, }) return context
def get_message_help(self, msgid, checkerref=False): """return the help string for the given message id""" msg = self.check_message_id(msgid) desc = normalize_text(" ".join(msg.descr.split()), indent=" ") if checkerref: desc += " This message belongs to the %s checker." % msg.checker.name title = msg.msg if title != "%s": title = title.splitlines()[0] return ":%s: *%s*\n%s" % (msg.msgid, title, desc) return ":%s:\n%s" % (msg.msgid, desc)
def context(self, **kwargs): entity = self.cw_rset.get_entity(self.cw_row or 0, self.cw_col or 0) content = entity.printable_value(self.content_attr, format='text/plain') if content: contentformat = getattr(entity, self.content_attr + '_format', 'text/rest') # XXX don't try to wrap rest until we've a proper transformation (see # #103822) if contentformat != 'text/rest': content = normalize_text(content, 80) return super(ContentAddedView, self).context(content=content, **kwargs)
def get_message_help(self, msgid, checkerref=False): """return the help string for the given message id""" msg = self.check_message_id(msgid) desc = normalize_text(' '.join(msg.descr.split()), indent=' ') if checkerref: desc += ' This message belongs to the %s checker.' % \ msg.checker.name title = msg.msg if title != '%s': title = title.splitlines()[0] return ':%s: *%s*\n%s' % (msg.msgid, title, desc) return ':%s:\n%s' % (msg.msgid, desc)
def render_row(self, context, data): document = data words = self.query.split() context.fillSlots('mime_type', re.sub("/", "_", document.mime_type)) context.fillSlots('doctitle', tags.xml(boldifyText(document.title, words))) # XXX abstract attribute should be a unicode string try: abstract = makeAbstract(document.text, words) abstract = normalize_text(unicode(abstract)) except Exception, exc: import traceback traceback.print_exc() print exc abstract = u'No abstract available for this document [%s]' % exc
def ini_format(stream, options, encoding): """format options using the INI format""" for optname, optdict, value in options: value = format_option_value(optdict, value) help = optdict.get("help") if help: help = normalize_text(help, line_len=79, indent="# ") print >> stream print >> stream, _encode(help, encoding) else: print >> stream if value is None: print >> stream, "#%s=" % optname else: value = _encode(value, encoding).strip() print >> stream, "%s=%s" % (optname, value)
def get_message_help(self, msgid, checkerref=False): """return the help string for the given message id""" msg = self.check_message_id(msgid) desc = normalize_text(' '.join(msg.descr.split()), indent=' ') if checkerref: desc += ' This message belongs to the %s checker.' % \ msg.checker.name title = msg.msg if msg.symbol: symbol_part = ' (%s)' % msg.symbol else: symbol_part = '' if title != '%s': title = title.splitlines()[0] return ':%s%s: *%s*\n%s' % (msg.msgid, symbol_part, title, desc) return ':%s%s:\n%s' % (msg.msgid, symbol_part, desc)
def ini_format(stream, options, encoding): """format options using the INI format""" for optname, optdict, value in options: value = format_option_value(optdict, value) help = optdict.get('help') if help: help = normalize_text(help, line_len=79, indent='# ') print >> stream print >> stream, _encode(help, encoding) else: print >> stream if value is None: print >> stream, '#%s=' % optname else: value = _encode(value, encoding).strip() print >> stream, '%s=%s' % (optname, value)
def ini_format(stream, options, encoding): """format options using the INI format""" for optname, optdict, value in options: value = format_option_value(optdict, value) help = optdict.get('help') if help: help = normalize_text(help, line_len=79, indent='# ') print(file=stream) print(_encode(help, encoding), file=stream) else: print(file=stream) if value is None: print('#%s=' % optname, file=stream) else: value = _encode(value, encoding).strip() print('%s=%s' % (optname, value), file=stream)
def ini_format(stream, options, encoding): """format options using the INI format""" for optname, optdict, value in options: value = format_option_value(optdict, value) help = optdict.get('help') if help: help = normalize_text(help, line_len=79, indent='# ') print(file=stream) print(_encode(help, encoding), file=stream) else: print(file=stream) if value is None: print('#%s=' % optname, file=stream) else: value = _encode(value, encoding).strip() if optdict.get('type') == 'string' and '\n' in value: prefix = '\n ' value = prefix + prefix.join(value.split('\n')) print('%s=%s' % (optname, value), file=stream)
def __call__(self): entity = self.entity if not entity.from_state: # not a transition return rset = entity.related('wf_info_for') view = self.select_view('notif_status_change', rset=rset, row=0) if view is None: return comment = entity.printable_value('comment', format='text/plain') # XXX don't try to wrap rest until we've a proper transformation (see # #103822) if comment and entity.comment_format != 'text/rest': comment = normalize_text(comment, 80) viewargs = { 'comment': comment, 'previous_state': entity.previous_state.name, 'current_state': entity.new_state.name } notify_on_commit(self._cw, view, viewargs=viewargs)
def ini_format_section(stream, section, options, encoding=None, doc=None): """format an options section using the INI format""" encoding = _get_encoding(encoding, stream) if doc: print >> stream, _encode(comment(doc), encoding) print >> stream, '[%s]' % section for optname, optdict, value in options: value = format_option_value(optdict, value) help = optdict.get('help') if help: help = normalize_text(help, line_len=79, indent='# ') print >> stream print >> stream, _encode(help, encoding) else: print >> stream if value is None: print >> stream, '#%s=' % optname else: value = _encode(value, encoding).strip() print >> stream, '%s=%s' % (optname, value)
def ini_format(stream: Union[StringIO, TextIOWrapper], options: Any, encoding: str) -> None: """format options using the INI format""" for optname, optdict, value in options: value = format_option_value(optdict, value) help = optdict.get("help") if help: help = normalize_text(help, line_len=79, indent="# ") print(file=stream) print(_encode(help, encoding), file=stream) else: print(file=stream) if value is None: print("#%s=" % optname, file=stream) else: value = _encode(value, encoding).strip() if optdict.get("type") == "string" and "\n" in value: prefix = "\n " value = prefix + prefix.join(value.split("\n")) print("%s=%s" % (optname, value), file=stream)
def cell_call(self, row, col, indentlevel=0, withauthor=True): e = self.cw_rset.get_entity(row,col) if indentlevel: indentstr = '>'*indentlevel + ' ' else: indentstr = '' if withauthor: _ = self._cw._ author = e.created_by and e.created_by[0].login or _("Unknown author") head = u'%s%s - %s :' % (indentstr, _('On %s') % self._cw.format_date(e.creation_date, time=True), _('%s wrote') % author) lines = [head] else: lines = [] content = e.printable_value('content', format='text/plain') lines.append(normalize_text(content, 80, indentstr, rest=e.content_format=='text/rest')) lines.append(indentstr[:-2]) self.w(u'\n'.join(lines))
def test_nonregr_rest_normalize(self): self.assertEqual(ulines(tu.normalize_text("""... Il est donc evident que tout le monde doit lire le compte-rendu de RSH et aller discuter avec les autres si c'est utile ou necessaire. """, rest=True)), """... Il est donc evident que tout le monde doit lire le compte-rendu de RSH et aller discuter avec les autres si c'est utile ou necessaire.""")