• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python util.escape函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: add_message

 def add_message(self, cursor, forum, topic, replyto, author, body):
     sql = "INSERT INTO message (forum, topic, replyto, time, author," \
       " body) VALUES (%s, %s, %s, %s, %s, %s)"
     self.log.debug(sql % (forum, topic, replyto, int(time.time()),
       author, body))
     cursor.execute(sql, (forum, topic, replyto, int(time.time()),
       escape(author), escape(body)))
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:7,代码来源:api.py


示例2: render

 def render(self, env, req):
     out = StringIO()
     can_vote = req.perm.has_permission('POLL_VOTE')
     if can_vote:
         out.write('<form id="%(id)s" method="get" action="%(href)s#%(id)s">\n'
                   '<input type="hidden" name="poll" value="%(id)s"/>\n'
                   % {'id': self.key, 'href': env.href(req.path_info)})
     out.write('<fieldset class="poll">\n'
               ' <legend>%s</legend>\n'
               ' <ul>\n'
               % escape(self.title))
     username = req.authname or 'anonymous'
     for id, style, vote in self.vote_defs:
         hid = escape(str(id))
         out.write('<li%s>\n' % (style and ' class="%s"' % style or ''))
         if can_vote:
             checked = username in self.votes[id]
             out.write('<input type="radio" name="vote" id="%(pvid)s" value="%(vid)s"%(checked)s/>\n'
                       '<label for="%(pvid)s">%(vote)s</label>\n'
                       % {'vid': hid,
                          'pvid': self.key + hid,
                          'vote': vote,
                          'checked': checked and ' checked="checked"' or ''})
         else:
             out.write(vote)
         if self.votes[id]:
             out.write(' <span class="voters">(<span class="voter">' +
                       '</span>, <span class="voter">'.join(self.votes[id]) +
                       '</span>)</span>')
         out.write('</li>\n')
     can_vote and out.write('<input type="submit" value="Vote"/>')
     out.write(' </ul>\n</fieldset>\n')
     can_vote and out.write('</form>\n')
     return out.getvalue()
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:34,代码来源:tracpoll.py


示例3: _get_font

    def _get_font(self):
        # Load the narcissus trac.ini font configuration into an instance variable
        buf = StringIO()
        trouble = False

        if 'narcissus' not in self.config.sections():
            msg = 'The narcissus section was not found in the trac configuration file.'
            buf.write(escape(msg))
            self.log.error(msg)
            trouble = True
        else:
            # check for the ttf_path entry
            self._ttf_path = self.config.get('narcissus', 'ttf_path')
            if not self._ttf_path:
                self._ttf = None # PIL will use default system font
                return None, None
            if not self._ttf_path[-4:].lower() == '.ttf':
                msg = 'The ttf_path is set to %s which is not a truetype font file.'\
                    % self._ttf_path
                buf.write(escape(msg))
                self.log.error(msg)
                trouble = True
            if not os.path.exists(self._ttf_path):
                msg = 'The ttf_path is set to %s but that path does not exist.'\
                    % self._ttf_path
                buf.write(escape(msg))
                self.log.error(msg)
                trouble = True
            self._ttf = ImageFont.truetype(self._ttf_path, 12)
        return trouble, buf
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:30,代码来源:narcissus.py


示例4: get_navigation_items

 def get_navigation_items(self, req):
     if req.authname and req.authname != 'anonymous':
         yield 'metanav', 'login', 'logged in as %s' % req.authname
         yield 'metanav', 'logout', Markup( '<a href="%s">Logout</a>' \
               % escape(self.env.href.logout()) )
     else:
         yield 'metanav', 'login', Markup( '<a href="%s">Login</a>' \
               % escape(self.env.href.login()) )
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:8,代码来源:auth.py


示例5: _load_config

    def _load_config(self):
        # Load the narcissus trac.ini configuration into object instance variables.
        # The code in this function is modified from the graphviz plugin, (c) Peter Kropf
        buf = StringIO()
        trouble = False
        self.exe_suffix = ""
        if sys.platform == "win32":
            self.exe_suffix = ".exe"

        if "narcissus" not in self.config.sections():
            msg = "The narcissus section was not found in the trac configuration file."
            buf.write(escape(msg))
            self.log.error(msg)
            trouble = True
        else:
            # check for the cache_dir entry
            self.cache_dir = self.config.get("narcissus", "cache_dir")
            if not self.cache_dir:
                msg = "The narcissus section is missing the cache_dir field."
                buf.write(escape(msg))
                self.log.error(msg)
                trouble = True
            else:
                if not os.path.exists(self.cache_dir):
                    msg = "The cache_dir is set to %s but that path does not exist." % self.cache_dir
                    buf.write(escape(msg))
                    self.log.error(msg)
                    trouble = True

            # check for the cmd_path entry
            self.cmd_path = None
            if sys.platform in _CMD_PATHS:
                self.cmd_path = _CMD_PATHS[sys.platform]
            self.cmd_path = self.config.get("narcissus", "cmd_path", self.cmd_path)
            if not self.cmd_path:
                msg = (
                    """The narcissus section is missing the cmd_path field and
                    there is no default for %s."""
                    % sys.platform
                )
                buf.write(escape(msg))
                self.log.error(msg)
                trouble = True
            elif not os.path.exists(self.cmd_path):
                msg = "The cmd_path is set to %s but that path does not exist." % self.cmd_path
                buf.write(escape(msg))
                self.log.error(msg)
                trouble = True

            # check if we should run the cache manager
            self.cache_manager = self._boolean(self.config.get("narcissus", "cache_manager", False))
            if self.cache_manager:
                self.cache_max_size = int(self.config.get("narcissus", "cache_max_size", 10000000))
                self.cache_min_size = int(self.config.get("narcissus", "cache_min_size", 5000000))
                self.cache_max_count = int(self.config.get("narcissus", "cache_max_count", 2000))
                self.cache_min_count = int(self.config.get("narcissus", "cache_min_count", 1500))

        return trouble, buf
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:58,代码来源:narcissus.py


示例6: add_screenshot

 def add_screenshot(self, cursor, name, description, time, author, tags,
   large_file, medium_file, small_file):
     sql = "INSERT INTO screenshot (name, description, time, author, tags," \
       " large_file, medium_file, small_file) VALUES (%s, %s, %s, %s, %s," \
       " %s, %s, %s)"
     self.log.debug(sql % (name, description, time, author, tags, large_file,
       medium_file, small_file))
     cursor.execute(sql, (escape(name), escape(description), time,
       escape(author), tags, large_file, medium_file, small_file))
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:9,代码来源:api.py


示例7: get_navigation_items

 def get_navigation_items(self, req):
     if req.authname and req.authname != 'anonymous':
         yield 'metanav', 'login', Markup('logged in as <b>%s</b>' \
                 % req.authname)
         yield 'metanav', 'password', Markup('<a href="%s">Password</a>' \
               % escape(self.env.href.password()))
         yield 'metanav', 'logout', Markup('<a href="%s">Logout</a>' \
               % escape(self.env.href.logout()))
     else:
         yield 'metanav', 'login', Markup('<a href="%s">Login</a>' \
               % escape(self.env.href.login()))
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:11,代码来源:auth.py


示例8: _add_tags_and_branches

 def _add_tags_and_branches(self, req, repos, rev):
     # TODO: consider pushing that in BrowserModule.process_request and
     #       extend the API with Repository.get_tags and Repository.get_branches
     tags = []
     for t, rev in repos.get_tags():
         tags.append({"name": escape(t), "rev": rev})
     branches = []
     for b, rev in repos.get_branches():
         branches.append({"name": escape(b), "rev": rev})
     req.hdf["browser.tags"] = tags
     req.hdf["browser.branches"] = branches
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:11,代码来源:p4trac.py


示例9: edit_forum

 def edit_forum(self, cursor, forum, name, subject, description, moderators,
   group):
     moderators = ' '.join(moderators)
     if not group:
         group = '0'
     sql = "UPDATE forum SET name = %s, subject = %s, description = %s," \
       " moderators = %s, forum_group = %s WHERE id = %s"
     self.log.debug(sql % (name, subject, description, moderators,
       group, forum))
     cursor.execute(sql, (escape(name), escape(subject),
       escape(description), escape(moderators), group, forum))
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:11,代码来源:api.py


示例10: add_forum

 def add_forum(self, cursor, name, author, subject, description, moderators,
   group):
     moderators = ' '.join(moderators)
     if not group:
         group = '0'
     sql = "INSERT INTO forum (name, author, time, moderators, subject," \
       " description, forum_group) VALUES (%s, %s, %s, %s, %s, %s, %s)"
     self.log.debug(sql % (name, author, str(int(time.time())), moderators,
       subject, description, group))
     cursor.execute(sql, (escape(name), escape(author),
       str(int(time.time())), escape(moderators), escape(subject),
       escape(description), group))
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:12,代码来源:api.py


示例11: _update_acronyms

 def _update_acronyms(self):
     page = WikiPage(self.env, self.acronym_page)
     self.env.log.debug('Updating acronym database')
     self.acronyms = {}
     if not page.exists:
         return
     for line in page.text.splitlines():
         if line.startswith('||') and line.endswith('||') and line[3] != "'":
             try:
                 a, d, u, s = ([i.strip() for i in line.strip('||').split('||')] + ['', ''])[0:4]
                 assert self.valid_acronym.match(a), "Invalid acronym %s" % a
                 self.acronyms[a] = (escape(d), escape(u), escape(s))
             except Exception, e:
                 self.env.log.warning("Invalid acronym line: %s (%s)", line, e)
开发者ID:lkraav,项目名称:trachacks,代码行数:14,代码来源:acronyms.py


示例12: render_table

def render_table(items, colspec, render_item):
    try:
        columns = max(int(colspec), 1)
    except:
        columns = 3
    buf = StringIO()
    buf.write('<table class="wiki">'
              ' <tr>')
    headers = ['<th>Markup&nbsp;</th><th>&nbsp;Display</th>'] * columns
    buf.write('  <th>&nbsp;</th>'.join(headers))
    buf.write(' </tr>')
    items = items[:]
    items.sort()
    rows = []
    while items:
        rows.append(items[0:columns])
        items[0:columns] = []
    for r in rows:
        buf.write('<tr>')
        buf.write('<td>&nbsp;</td>'.join(['<td>%s</td><td>%s</td>' % \
                                          (escape(s), render_item(s))
                                          for s in r]))
        buf.write('</tr>')
    buf.write('</table>')
    return buf.getvalue()
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:25,代码来源:util.py


示例13: render

    def render(self, req, mimetype, content, filename=None, url=None):
        if hasattr(content, 'read'):
            content = content.read()
	fd, path = tempfile.mkstemp(suffix='.xlsx', text=True)
	os.write(fd, content)
	os.close(fd)
	book = openpyxl.load_workbook(path)
        buf = []
	for sheetName in book.get_sheet_names():
	    sheet = book.get_sheet_by_name(sheetName)
	    if len(sheet.get_cell_collection()) == 0:
	        continue # Skip empty sheet
	    buf.append(u'<table class="listing"><caption>%s</caption>\n' % escape(sheetName))
            buf.append(u'<tbody>')
	    sheet.get_highest_row()
	    rowIdx = 0
	    for row in sheet.range(sheet.calculate_dimension()):
                buf.append(u'<tr class="%s">' % (rowIdx % 2 and 'odd' or 'even'))
		for cell in row:
		    if cell.value == None:
		        val = u''
	            else:
		        val = cell.value
                    buf.append(u'<td>%s</td>' % val)
                buf.append(u'</tr>\n')
		rowIdx = rowIdx + 1
            buf.append(u'</tbody>')
            buf.append(u'</table>\n')
	os.unlink(path)
        return u''.join(buf)
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:30,代码来源:__init__.py


示例14: render_macro

	def render_macro(self, req, name, content):
		content = content and REGEX_CRLF.sub("\n", escape(content).replace('&#34;', '"')) or ''

		def inputstringcallback(match):
			if match.group('ur'):
				return '<span class="se-input-userreplacement">' + match.group('ur') + '</span>'
			if match.group('sq'):
				m = REGEXP_UR.sub(r'<span class="se-input-userreplacement">\1</span>', match.group('sq'))
				return '<span class="se-input-string">' + m + '</span>'
			if match.group('dq'):
				m = REGEXP_UR.sub(r'<span class="se-input-userreplacement">\1</span>', match.group('dq'))
				return '<span class="se-input-string">' + m + '</span>'
			if match.group('ct'):
				return '<span class="se-input-continuation">' + match.group('ct') + '</span>'
			if match.group('op'):
				return '<span class="se-input-option">' + match.group('op') + '</span>'
			return match.group(0)

		def linematcher_callback(match):
			if match.group('preinput'):
				s = ''
				if match.group('ps1'):
					if match.group('ps1start'):
						s += '<span class="se-prompt-start">' + match.group('ps1start') + '</span>'
					if match.group('user'):
						s += '<span class="se-prompt-user">' + match.group('user') + '</span>'
					if match.group('userhostsep'):
						s += '<span class="se-prompt-userhostseparator">' + match.group('userhostsep') + '</span>'
					if match.group('host'):
						s += '<span class="se-prompt-host">' + match.group('host') + '</span>'
					if match.group('userpathspace'):
						s += match.group('userpathspace')
					if match.group('path'):
						s += '<span class="se-prompt-path">' + match.group('path') + '</span>'
					if match.group('ps1end'):
						s += '<span class="se-prompt-end">' + match.group('ps1end') + '</span>'
					s = '<span class="se-prompt">' + s + '</span>';
				if match.group('cli'):
					if match.group('cli') == '# ':
						s += '<span class="se-root">' + match.group('cli') + '</span>'
					else:
						s += '<span class="se-unprivileged">' + match.group('cli') + '</span>'
					input = REGEXP_TAGS.sub(inputstringcallback, match.group('input'))
					s += '<span class="se-input">' + input + '</span>'
				return s;
			if match.group('note'):
				return '<span class="se-note">' + match.group('note') + '</span>'
			if match.group('delayedinput'):
				inputdelayed = REGEXP_TAGS.sub(inputstringcallback, match.group('delayedinput')[3:])
				return '<span class="se-input"><span class="se-input-delayed">' + inputdelayed + '</span></span>'
			if match.group('snippedoutput'):
				m = match.group('snippedoutput')
				sniptext = "&lt;Output Snipped&gt;" if len(m) == 5 else m[6:]
				return '<span class="se-output"><span class="se-output-snipped">' + sniptext + '</span></span>'
			if match.group('output'):
				return '<span class="se-output">' + match.group('output') + '</span>'
			return match.group(0)

		return Markup('<div class="code"><pre>' + REGEXP_LINE_MATCHER.sub(linematcher_callback, content) + '</pre></div>');
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:59,代码来源:module.py


示例15: show_err

 def show_err(self, msg):
     """Display msg in an error box, using Trac style."""
     buf = StringIO()
     buf.write('<div id="content" class="error"><div class="message"> \n\
                <strong>Graphviz macro processor has detected an error. Please fix the problem before continuing.</strong> \n\
                <pre>%s</pre> \n\
                </div></div>' % escape(msg))
     self.log.error(msg)
     return buf
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:9,代码来源:graphviz.py


示例16: render_timeline_event

    def render_timeline_event(self, context, field, event):
        id_, config, label, rev, platform, status, errors = event[3]

        if field == 'url':
            return context.href.build(config, id_)

        elif field == 'title':
            return tag('Build of ', tag.em('%s [%s]' % (label, rev)),
                        ' on %s %s' % (platform, _status_label[status]))

        elif field == 'description':
            message = ''
            if context.req.args.get('format') == 'rss':
                if errors:
                    buf = StringIO()
                    prev_step = None
                    for step, error in errors:
                        if step != prev_step:
                            if prev_step is not None:
                                buf.write('</ul>')
                            buf.write('<p>Step %s failed:</p><ul>' \
                                      % escape(step))
                            prev_step = step
                        buf.write('<li>%s</li>' % escape(error))
                    buf.write('</ul>')
                    message = Markup(buf.getvalue())
            else:
                if errors:
                    steps = []
                    for step, error in errors:
                        if step not in steps:
                            steps.append(step)
                    steps = [Markup('<em>%s</em>') % step for step in steps]
                    if len(steps) < 2:
                        message = steps[0]
                    elif len(steps) == 2:
                        message = Markup(' and ').join(steps)
                    elif len(steps) > 2:
                        message = Markup(', ').join(steps[:-1]) + ', and ' + \
                                  steps[-1]
                    message = Markup('Step%s %s failed') % (
                                    len(steps) != 1 and 's' or '', message)
            return message
开发者ID:kroman0,项目名称:bitten,代码行数:43,代码来源:web_ui.py


示例17: _format_link

 def _format_link(self, formatter, ns, target, label):
     cursor = formatter.db.cursor()
     cursor.execute("SELECT subject,id FROM mailarc WHERE messageid = %s" , (target,))
     row = cursor.fetchone()
     if row:
         subject = util.escape(util.shorten_line(row[0]))
         return '<a href="%s" title="%s">%s</a>' \
                % (formatter.href.mailarchive(row[1]), subject, label)
     else:
         return label
开发者ID:okamototk,项目名称:kanonconductor,代码行数:10,代码来源:wikisyntax.py


示例18: _render_directory

    def _render_directory(self, req, repos, node, rev=None):
        req.perm.assert_permission('BROWSER_VIEW')

        order = req.args.get('order', 'name').lower()
        req.hdf['browser.order'] = order
        desc = req.args.has_key('desc')
        req.hdf['browser.desc'] = desc and 1 or 0

        info = []
        for entry in node.get_entries():
            entry_rev = rev and entry.rev
            info.append({
                'name': entry.name,
                'fullpath': entry.path,
                'is_dir': int(entry.isdir),
                'content_length': entry.content_length,
                'size': util.pretty_size(entry.content_length),
                'rev': entry.rev,
                'permission': 1, # FIXME
                'log_href': util.escape(self.env.href.log(entry.path, rev=rev)),
                'browser_href': util.escape(self.env.href.peerReviewBrowser(entry.path,
                                                                  rev=rev))
            })
        changes = get_changes(self.env, repos, [i['rev'] for i in info])

        def cmp_func(a, b):
            dir_cmp = (a['is_dir'] and -1 or 0) + (b['is_dir'] and 1 or 0)
            if dir_cmp:
                return dir_cmp
            neg = desc and -1 or 1
            if order == 'date':
                return neg * cmp(changes[b['rev']]['date_seconds'],
                                 changes[a['rev']]['date_seconds'])
            elif order == 'size':
                return neg * cmp(a['content_length'], b['content_length'])
            else:
                return neg * _natural_order(a['name'].lower(),
                                            b['name'].lower())
        info.sort(cmp_func)

        req.hdf['browser.items'] = info
        req.hdf['browser.changes'] = changes
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:42,代码来源:peerReviewBrowser.py


示例19: _error_div

 def _error_div(self, msg):
     """Display msg in an error box, using Trac style."""
     if isinstance(msg, str):
         msg = to_unicode(msg)
     self.log.error(msg)
     if isinstance(msg, unicode):
         msg = tag.pre(escape(msg))
     return tag.div(
             tag.strong(_("Canviz macro processor has detected an error. "
                          "Please fix the problem before continuing.")),
             msg, class_="system-message")
开发者ID:lkraav,项目名称:trachacks,代码行数:11,代码来源:canviz.py


示例20: _format_link

 def _format_link(self, formatter, ns, rev, label):
     cursor = formatter.db.cursor()
     cursor.execute('SELECT message FROM revision WHERE rev=%s', (rev,))
     row = cursor.fetchone()
     if row:
         return '<a class="changeset" title="%s" href="%s">%s</a>' \
                % (util.escape(util.shorten_line(row[0])),
                   formatter.href.changeset(rev), label)
     else:
         return '<a class="missing changeset" href="%s" rel="nofollow">%s</a>' \
                % (formatter.href.changeset(rev), label)
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:11,代码来源:setchangeset.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python util.format_datetime函数代码示例发布时间:2022-05-27
下一篇:
Python util.embedded_numbers函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap