当前位置: 首页>>代码示例>>Python>>正文


Python text.to_unicode函数代码示例

本文整理汇总了Python中trac.util.text.to_unicode函数的典型用法代码示例。如果您正苦于以下问题:Python to_unicode函数的具体用法?Python to_unicode怎么用?Python to_unicode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了to_unicode函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _ticket_links

def _ticket_links(env, formatter, t, a_class=""):
    """Build links to tickets."""
    tkt_id = str(t.get("id"))
    status = t.get("status")
    summary = to_unicode(t.get("summary"))
    owner = to_unicode(t.get("owner"))
    description = to_unicode(t.get("description"))
    url = t.get("href")

    if status == "closed":
        a_class = a_class + "closed"
    else:
        a_class = a_class + "open"

    # Reduce content for tooltips.
    markup = format_to_html(env, formatter.context, description)
    extractor = TextExtractor()
    extractor.feed(markup)
    tip = tag.span(shorten_line(extractor.getvalue()))

    ticket = tag.a("#" + tkt_id, href=url)
    ticket(tip, class_="tip", target="_blank")
    ticket = tag.div(ticket, class_=a_class, align="left")
    # Fix stripping of regular leading space in IE.
    blank = " "
    ticket(Markup(blank), summary, " (", owner, ")")

    summary = tag(summary, " (", owner, ")")
    ticket_short = tag.span(tag.a("#" + tkt_id, href=url, target="_blank", title_=summary), class_=a_class)
    return ticket, ticket_short
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:30,代码来源:macros.py

示例2: __init__

    def __init__(self, path, params, log):
        self.log = log
        self.pool = Pool()

        # Remove any trailing slash or else subversion might abort
        if isinstance(path, unicode):
            path_utf8 = path.encode('utf-8')
        else: # note that this should usually not happen (unicode arg expected)
            path_utf8 = to_unicode(path).encode('utf-8')

        path_utf8 = core.svn_path_canonicalize(
                                os.path.normpath(path_utf8).replace('\\', '/'))
        self.path = path_utf8.decode('utf-8')

        root_path_utf8 = repos.svn_repos_find_root_path(path_utf8, self.pool())
        if root_path_utf8 is None:
            raise TracError(_("%(path)s does not appear to be a Subversion "
                              "repository.", path=to_unicode(path_utf8)))

        try:
            self.repos = repos.svn_repos_open(root_path_utf8, self.pool())
        except core.SubversionException, e:
            raise TracError(_("Couldn't open Subversion repository %(path)s: "
                              "%(svn_error)s", path=to_unicode(path_utf8),
                              svn_error=exception_to_unicode(e)))
开发者ID:dafrito,项目名称:trac-mirror,代码行数:25,代码来源:svn_fs.py

示例3: handle_commit

def handle_commit(commit, env):
    from trac.ticket.notification import TicketNotifyEmail
    from trac.ticket import Ticket
    from trac.util.text import to_unicode
    from trac.util.datefmt import utc

    msg = to_unicode(call_git('rev-list', ['-n', '1', commit, '--pretty=medium']).rstrip())
    eml = to_unicode(call_git('rev-list', ['-n', '1', commit, '--pretty=format:%ae']).splitlines()[1])
    now = datetime.now(utc)

    tickets = {}
    for cmd, tkts in command_re.findall(msg.split('\n\n', 1)[1]):
        action = COMMANDS.get(cmd.lower())
        if action:
            for tkt_id in ticket_re.findall(tkts):
                tickets.setdefault(tkt_id, []).append(action)

    for tkt_id, actions in tickets.iteritems():
        try:
            db = env.get_db_cnx()
            ticket = Ticket(env, int(tkt_id), db)

            if 'close' in actions:
                ticket['status'] = 'closed'
                ticket['resolution'] = 'fixed'

            # trac 1.0: `db` parameter is no longer needed and will be removed in 1.1.1
            # trac 1.0: `cnum` parameter is deprecated
            ticket.save_changes(eml, msg, now)
            db.commit()

            tn = TicketNotifyEmail(env)
            tn.notify(ticket, newticket=0, modtime=now)
        except Exception, e:
            print >>sys.stderr, 'Unexpected error while processing ticket ID %s: %s' % (tkt_id, e)
开发者ID:Kurt-P,项目名称:auto-trac,代码行数:35,代码来源:trac-post-receive-hook.4.py

示例4: get_lines_from_file

def get_lines_from_file(filename, lineno, context=0):
    """Return `content` number of lines before and after the specified
    `lineno` from the file identified by `filename`.
    
    Returns a `(lines_before, line, lines_after)` tuple.
    """
    if os.path.isfile(filename):
        fileobj = open(filename, "U")
        try:
            lines = fileobj.readlines()
            lbound = max(0, lineno - context)
            ubound = lineno + 1 + context

            charset = None
            rep = re.compile("coding[=:]\s*([-\w.]+)")
            for linestr in lines[0], lines[1]:
                match = rep.search(linestr)
                if match:
                    charset = match.group(1)
                    break

            before = [to_unicode(l.rstrip("\n"), charset) for l in lines[lbound:lineno]]
            line = to_unicode(lines[lineno].rstrip("\n"), charset)
            after = [to_unicode(l.rstrip("\n"), charset) for l in lines[lineno + 1 : ubound]]

            return before, line, after
        finally:
            fileobj.close()
    return (), None, ()
开发者ID:gdgkyoto,项目名称:kyoto-gtug,代码行数:29,代码来源:__init__.py

示例5: handle_commit

def handle_commit(commit, env):
    from trac.ticket import Ticket
    from trac.ticket.web_ui import TicketModule
    from trac.util.text import to_unicode
    from trac.util.datefmt import utc

    msg = to_unicode(call_git('rev-list', ['-n', '1', commit, '--pretty=medium']).rstrip())
    eml = to_unicode(call_git('rev-list', ['-n', '1', commit, '--pretty=format:%ae']).splitlines()[1])

    tickets = {}
    comtkts = command_re.findall(msg.split('\n\n', 1)[1])
    if not comtkts:
         print "no 'refs' or 'closes' in commitmessage for commit %s, aborting push" % commit
	 sys.exit(1)
    for cmd, tkts in comtkts:
        action = COMMANDS.get(cmd.lower())
        if action:
            for tkt_id in ticket_re.findall(tkts):
                tickets.setdefault(tkt_id, []).append(action)
	else: #no action specified, bad commit message!
	    print "no 'refs' or 'closes' in commitmessage for commit %s, aborting push" % commit
	    sys.exit(1)
	
    for tkt_id, actions in tickets.iteritems():
        try:
            db = env.get_db_cnx()
            ticket = Ticket(env, int(tkt_id), db)
	    if not ticket['status'] in ACCEPTED_STATUSSES:
		print "commiting to non-open ticket in commit %s, aborting push" % commit
		sys.exit(2)

        except Exception, e:
            print 'Unexpected error while processing commit %s :' % commit
	    print 'ticket ID %s: %s' % (tkt_id, e)
	    sys.exit(3)
开发者ID:JensTimmerman,项目名称:TRAC-SVN-to-GIT-migration,代码行数:35,代码来源:trac-pre-receive-hook.py

示例6: process

 def process(self, m):
     self.updated = True
     op, argstr = m.groups()
     op = op or self.default_op
     self.formatter.env.log.debug('Converting TracForms op: ' + str(op))
     kw = {}
     args = tuple(self.getargs(argstr, kw))
     fn = self.env.get('op:' + op.lower())
     if fn is None:
         fn = getattr(self, 'op_' + op.lower(), None)
     if fn is None:
         raise FormTooManyValuesError(str(op))
     else:
         try:
             if op[:5] == 'wikiop_':
                 self.formatter.env.log.debug(
                     'TracForms wiki value: ' + self.wiki(str(fn(*args))))
                 return self.wiki(str(fn(*args)))
             else:
                 self.formatter.env.log.debug(
                     'TracForms value: ' + to_unicode(fn(*args, **kw)))
                 return to_unicode(fn(*args, **kw))
         except FormError, e:
             return '<PRE>' + str(e) + '</PRE>'
         except Exception, e:
             return '<PRE>' + traceback.format_exc() + '</PRE>'
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:26,代码来源:macros.py

示例7: send

    def send(self, to_recipients, cc_recipients):
        header = {}

        # Add item specific e-mail header fields.
        if self.message:
            # ID of the message.
            header["Message-ID"] = self.get_message_email_id(self.message["id"])
            header["X-Trac-Message-ID"] = to_unicode(self.message["id"])
            header["X-Trac-Discussion-URL"] = self.message["link"]

            # ID of replied message.
            if self.message["replyto"] != -1:
                reply_id = self.get_message_email_id(self.message["replyto"])
            else:
                reply_id = self.get_topic_email_id(self.message["topic"])
            header["In-Reply-To"] = reply_id
            header["References"] = reply_id
        elif self.topic:
            # ID of the message.
            header["Message-ID"] = self.get_topic_email_id(self.topic["id"])
            header["X-Trac-Topic-ID"] = to_unicode(self.topic["id"])
            header["X-Trac-Discussion-URL"] = self.topic["link"]
        elif self.forum:
            # ID of the message.
            header["Message-ID"] = self.get_forum_email_id(self.forum["id"])
            header["X-Trac-Forum-ID"] = to_unicode(self.forum["id"])
            header["X-Trac-Discussion-URL"] = self.forum["link"]
        else:
            # Should not happen.
            raise TracError("DiscussionPlugin internal error.")

        # Send e-mail.
        self.template = Chrome(self.env).load_template(self.template_name, method="text")
        self.env.log.debug("to_recipients: %s cc_recipients: %s" % (to_recipients, cc_recipients))
        NotifyEmail.send(self, to_recipients, cc_recipients, header)
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:35,代码来源:notification.py

示例8: _save

 def _save(self, timestamp, value, update=False, db=None):
     """Saves a remaining time value to the database. The update parameter
     decides if the value should be updated (True) or inserted (False)"""
     params = {
         Key.TABLE : BURNDOWN_TABLE,
         Key.TASK_ID : self.task.id,
         Key.DATE : timestamp,
         Key.REMAINING_TIME : value,
     }
     if update:
         sql_query = "UPDATE %(table)s SET remaining_time=%(remaining_time)d " \
                     "WHERE task_id=%(task_id)d AND date=%(date)f" % params
     else:
         sql_query = "INSERT INTO %(table)s (task_id, date, remaining_time) " \
                     "VALUES (%(task_id)s, %(date)s, %(remaining_time)s)" % params
     
     db, handle_ta = get_db_for_write(self.env, db)
     try:
         cursor = db.cursor()
         cursor.execute(sql_query)
         if handle_ta:
             db.commit()
             debug(self, 
                   "DB Committed, saved remaining time (%s) for task %d" % \
                   (params[Key.REMAINING_TIME], self.task.id))
     except Exception, e:
         error(self, to_unicode(e))
         if handle_ta:
             db.rollback()
         raise TracError("Error while saving remaining time: %s" % \
                         to_unicode(e))
开发者ID:djangsters,项目名称:agilo,代码行数:31,代码来源:burndown.py

示例9: process_request

    def process_request(self, req):
        data = {'systeminfo': None, 'plugins': None, 'config': None}

        if 'CONFIG_VIEW' in req.perm('config', 'systeminfo'):
            # Collect system information
            data['systeminfo'] = self.env.get_systeminfo()

        if 'CONFIG_VIEW' in req.perm('config', 'plugins'):
            # Collect plugin information
            data['plugins'] = get_plugin_info(self.env)

        if 'CONFIG_VIEW' in req.perm('config', 'ini'):
            # Collect config information
            defaults = self.config.defaults(self.compmgr)
            sections = []
            for section in self.config.sections(self.compmgr):
                options = []
                default_options = defaults.get(section, {})
                for name, value in self.config.options(section, self.compmgr):
                    default = default_options.get(name) or ''
                    options.append({
                        'name': name, 'value': value,
                        'modified': to_unicode(value) != to_unicode(default)
                    })
                options.sort(key=lambda o: o['name'])
                sections.append({'name': section, 'options': options})
            sections.sort(key=lambda s: s['name'])
            data['config'] = sections

        return 'about.html', data, None
开发者ID:trac-ja,项目名称:trac-ja,代码行数:30,代码来源:about.py

示例10: _do_import

 def _do_import(self, filename=None):
     permsys = PermissionSystem(self.env)
     try:
         with file_or_std(filename, 'rb') as f:
             encoding = stream_encoding(f)
             linesep = os.linesep if filename else '\n'
             reader = csv.reader(f, lineterminator=linesep)
             for row in reader:
                 if len(row) < 2:
                     raise AdminCommandError(
                         _("Invalid row %(line)d. Expected <user>, "
                           "<action>, [action], [...]",
                           line=reader.line_num))
                 user = to_unicode(row[0], encoding)
                 actions = [to_unicode(action, encoding)
                            for action in row[1:]]
                 if user.isupper():
                     raise AdminCommandError(
                         _("Invalid user %(user)s on line %(line)d: All "
                           "upper-cased tokens are reserved for permission "
                           "names.", user=user, line=reader.line_num))
                 old_actions = self.get_user_perms(user)
                 for action in set(actions) - set(old_actions):
                     permsys.grant_permission(user, action)
     except csv.Error as e:
         raise AdminCommandError(
             _("Cannot import from %(filename)s line %(line)d: %(error)s ",
               filename=path_to_unicode(filename or 'stdin'),
               line=reader.line_num, error=e))
     except IOError as e:
         raise AdminCommandError(
             _("Cannot import from %(filename)s: %(error)s",
               filename=path_to_unicode(filename or 'stdin'),
               error=e.strerror))
开发者ID:pkdevbox,项目名称:trac,代码行数:34,代码来源:perm.py

示例11: send_rpc_error

    def send_rpc_error(self, req, e):
        """Send an XML-RPC fault message back to the caller"""
        rpcreq = req.rpc
        fault = None
        if isinstance(e, ProtocolException):
            fault = e._exc
        elif isinstance(e, ServiceException):
            e = e._exc
        elif isinstance(e, MethodNotFound):
            fault = xmlrpclib.Fault(-32601, to_unicode(e))
        elif isinstance(e, PermissionError):
            fault = xmlrpclib.Fault(403, to_unicode(e))
        elif isinstance(e, ResourceNotFound):
            fault = xmlrpclib.Fault(404, to_unicode(e))

        if fault is not None :
            self._send_response(req, xmlrpclib.dumps(fault), rpcreq['mimetype'])
        else :
            self.log.error(e)
            import traceback
            from tracrpc.util import StringIO
            out = StringIO()
            traceback.print_exc(file = out)
            self.log.error(out.getvalue())
            err_code = hasattr(e, 'code') and e.code or 1
            method = rpcreq.get('method')
            self._send_response(req,
                    xmlrpclib.dumps(
                        xmlrpclib.Fault(err_code,
                            "'%s' while executing '%s()'" % (str(e), method))))
开发者ID:hexenxp14,项目名称:tracxmlrpc,代码行数:30,代码来源:xml_rpc.py

示例12: _normalize_xml_output

 def _normalize_xml_output(self, result):
     """ Normalizes and converts output (traversing it):
     1. None => ''
     2. datetime => xmlrpclib.DateTime
     3. Binary => xmlrpclib.Binary
     4. genshi.builder.Fragment|genshi.core.Markup => unicode
     """
     new_result = []
     for res in result:
         if isinstance(res, datetime.datetime):
             new_result.append(to_xmlrpc_datetime(res))
         elif isinstance(res, Binary):
             res.__class__ = xmlrpclib.Binary
             new_result.append(res)
         elif res is None or res is empty:
             new_result.append('')
         elif isinstance(res, (genshi.builder.Fragment, \
                               genshi.core.Markup)):
             new_result.append(to_unicode(res))
         elif babel and isinstance(res, babel.support.LazyProxy):
             new_result.append(to_unicode(res))
         elif isinstance(res, dict):
             for key, val in res.items():
                 res[key], = self._normalize_xml_output([val])
             new_result.append(res)
         elif isinstance(res, list) or isinstance(res, tuple):
             new_result.append(self._normalize_xml_output(res))
         else:
             new_result.append(res)
     return new_result
开发者ID:hexenxp14,项目名称:tracxmlrpc,代码行数:30,代码来源:xml_rpc.py

示例13: __init__

    def __init__(self, path, authz, log, options={}):
        self.log = log
        self.options = options
        self.pool = Pool()

        # Remove any trailing slash or else subversion might abort
        if isinstance(path, unicode):
            self.path = path
            path_utf8 = path.encode("utf-8")
        else:  # note that this should usually not happen (unicode arg expected)
            self.path = to_unicode(path)
            path_utf8 = self.path.encode("utf-8")
        path_utf8 = os.path.normpath(path_utf8).replace("\\", "/")
        root_path_utf8 = repos.svn_repos_find_root_path(path_utf8, self.pool())
        if root_path_utf8 is None:
            raise TracError(_("%(path)s does not appear to be a Subversion " "repository.", path=to_unicode(path_utf8)))

        try:
            self.repos = repos.svn_repos_open(root_path_utf8, self.pool())
        except core.SubversionException, e:
            raise TracError(
                _(
                    "Couldn't open Subversion repository %(path)s: " "%(svn_error)s",
                    path=to_unicode(path_utf8),
                    svn_error=exception_to_unicode(e),
                )
            )
开发者ID:gdgkyoto,项目名称:kyoto-gtug,代码行数:27,代码来源:svn_fs.py

示例14: get_macro_descr

 def get_macro_descr():
     for macro_provider in formatter.wiki.macro_providers:
         names = list(macro_provider.get_macros() or [])
         if name_filter and not any(name.startswith(name_filter)
                                    for name in names):
             continue
         try:
             name_descriptions = [
                 (name, macro_provider.get_macro_description(name))
                 for name in names]
         except Exception, e:
             yield system_message(
                 _("Error: Can't get description for macro %(name)s",
                   name=names[0]), e), names
         else:
             for descr, pairs in groupby(name_descriptions,
                                         key=lambda p: p[1]):
                 if descr:
                     if isinstance(descr, (tuple, list)):
                         descr = dgettext(descr[0],
                                          to_unicode(descr[1])) \
                                 if descr[1] else ''
                     else:
                         descr = to_unicode(descr) or ''
                     if content == '*':
                         descr = format_to_oneliner(
                             self.env, formatter.context, descr,
                             shorten=True)
                     else:
                         descr = format_to_html(
                             self.env, formatter.context, descr)
                 yield descr, [name for name, descr in pairs]
开发者ID:exocad,项目名称:exotrac,代码行数:32,代码来源:macros.py

示例15: get_changes

        def get_changes(self):
                paths_seen = set()
                for parent in self.props.get('parent', [None]):
                        for mode1,mode2,obj1,obj2,action,path1,path2 in \
                                    self.git.diff_tree(parent, self.rev, find_renames=True):
                                path = path2 or path1
                                p_path, p_rev = path1, parent

                                kind = Node.FILE
                                if mode2.startswith('04') or mode1.startswith('04'):
                                        kind = Node.DIRECTORY

                                action = GitChangeset.action_map[action[0]]

                                if action == Changeset.ADD:
                                        p_path = ''
                                        p_rev = None

                                # CachedRepository expects unique (rev, path, change_type) key
                                # this is only an issue in case of merges where files required editing
                                if path in paths_seen:
                                        continue

                                paths_seen.add(path)

                                yield (to_unicode(path), kind, action, to_unicode(p_path), p_rev)
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:26,代码来源:git_fs.py


注:本文中的trac.util.text.to_unicode函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。