本文整理汇总了Python中trac.util.text.to_unicode函数的典型用法代码示例。如果您正苦于以下问题:Python to_unicode函数的具体用法?Python to_unicode怎么用?Python to_unicode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了to_unicode函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: add_value
def add_value(prefix, value):
if value is None:
return
if value in (True, False):
set_str(prefix, int(value))
elif isinstance(value, (Markup, Fragment)):
set_unicode(prefix, unicode(value))
elif isinstance(value, str):
if do_escape:
# Assume UTF-8 here, for backward compatibility reasons
set_unicode(prefix, escape(to_unicode(value)))
else:
set_str(prefix, value)
elif isinstance(value, unicode):
if do_escape:
set_unicode(prefix, escape(value))
else:
set_unicode(prefix, value)
elif isinstance(value, dict):
for k in value.keys():
add_value('%s.%s' % (prefix, to_unicode(k)), value[k])
else:
if hasattr(value, '__iter__') or \
isinstance(value, (list, tuple)):
for idx, item in enumerate(value):
add_value('%s.%d' % (prefix, idx), item)
else:
set_str(prefix, value)
开发者ID:gdgkyoto,项目名称:kyoto-gtug,代码行数:28,代码来源:clearsilver.py
示例17: validate_blog_post
def validate_blog_post(self, req, postname, version, fields):
if 'blog-preview' in req.args:
return []
blog_res = Resource('blog', postname, version)
if req.perm(blog_res).has_permission('BLOG_ADMIN'):
return []
if version > 1:
bp = BlogPost(self.env, postname, version)
last_post_fields = bp._fetch_fields(version=version-1)
else:
last_post_fields = {}
field_names = set(fields).union(last_post_fields)
changes = []
for field in field_names:
old = to_unicode(last_post_fields.get(field, ''))
new = to_unicode(fields.get(field, ''))
if new and old != new:
changes.append((old, new))
author = fields.get('author', '')
if arity(FilterSystem.test) == 4:
# 0.11 compatible method signature
FilterSystem(self.env).test(req, author, changes)
else:
# 0.12+ compatible that adds an 'ip' argument
FilterSystem(self.env).test(req, author, changes, req.remote_addr)
return []
开发者ID:kzhamaji,项目名称:TracFullBlogPlugin,代码行数:29,代码来源:spamfilter.py
示例18: send
def send(self, torcpts, ccrcpts):
header = {}
# Add item specific e-mail header fields.
if self.message:
# Get this messge ID.
header['Message-ID'] = self.get_message_id(self.forum['id'],
self.topic['id'], self.message['id'])
header['X-Trac-Message-ID'] = to_unicode(self.message['id'])
header['X-Trac-Discussion-URL'] = self.message['link']
# Get replied message ID.
reply_id = self.get_message_id(self.forum['id'], self.topic['id'],
self.message['replyto'])
header['In-Reply-To'] = reply_id
header['References'] = reply_id
else:
# Get this message ID.
header['Message-ID'] = self.get_message_id(self.forum['id'],
self.topic['id'], 0)
header['X-Trac-Topic-ID'] = to_unicode(self.topic['id'])
header['X-Trac-Discussion-URL'] = self.topic['link']
# Send e-mail.
NotifyEmail.send(self, torcpts, ccrcpts, header)
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:25,代码来源:notification.py
示例19: get
def get(self, key, default=''):
"""Return the value of the specified option.
Valid default input is a string. Returns a string.
"""
key = self.optionxform(key)
cached = self._cache.get(key, _use_default)
if cached is not _use_default:
return cached
name_str = self.name
key_str = to_unicode(key)
settings = ProductSetting.select(self.env,
where={'product':self.product, 'section':name_str,
'option':key_str})
if len(settings) > 0:
value = settings[0].value
else:
for parent in self.config.parents:
value = parent[self.name].get(key, _use_default)
if value is not _use_default:
break
else:
if default is not _use_default:
option = Option.registry.get((self.name, key))
value = option.default if option else _use_default
else:
value = _use_default
if value is _use_default:
return default
if not value:
value = u''
elif isinstance(value, basestring):
value = to_unicode(value)
self._cache[key] = value
return value
开发者ID:Stackato-Apps,项目名称:bloodhound,代码行数:35,代码来源:config.py
示例20: parse_rpc_request
def parse_rpc_request(self, req, content_type):
""" Parse XML-RPC requests."""
try:
args, method = xmlrpclib.loads(req.read(int(req.get_header("Content-Length"))))
except Exception, e:
self.log.debug("RPC(xml) parse error: %s", to_unicode(e))
raise ProtocolException(xmlrpclib.Fault(-32700, to_unicode(e)))
开发者ID:nextview,项目名称:tracxmlrpc,代码行数:7,代码来源:xml_rpc.py
注:本文中的trac.util.text.to_unicode函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论