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


Python cgi.escape方法代码示例

本文整理汇总了Python中cgi.escape方法的典型用法代码示例。如果您正苦于以下问题:Python cgi.escape方法的具体用法?Python cgi.escape怎么用?Python cgi.escape使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cgi的用法示例。


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

示例1: annotated_file

# 需要导入模块: import cgi [as 别名]
# 或者: from cgi import escape [as 别名]
def annotated_file(self, filename, statements, excluded, missing):
        source = open(filename, 'r')
        buffer = []
        for lineno, line in enumerate(source.readlines()):
            lineno += 1
            line = line.strip('\n\r')
            empty_the_buffer = True
            if lineno in excluded:
                template = TEMPLATE_LOC_EXCLUDED
            elif lineno in missing:
                template = TEMPLATE_LOC_NOT_COVERED
            elif lineno in statements:
                template = TEMPLATE_LOC_COVERED
            else:
                empty_the_buffer = False
                buffer.append((lineno, line))
            if empty_the_buffer:
                for lno, pastline in buffer:
                    yield template % (lno, cgi.escape(pastline))
                buffer = []
                yield template % (lineno, cgi.escape(line)) 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:23,代码来源:covercp.py

示例2: post_analysis_stuff

# 需要导入模块: import cgi [as 别名]
# 或者: from cgi import escape [as 别名]
def post_analysis_stuff(self, results):
        if results.has_formula():
            self.action_selector.addItem(self.parent.HIGHLIGHT_CODE)
            self.action_selector.addItem(self.parent.GRAPH_DEPENDENCY)
            self.formula_area.setText(self.parent.results.formula)
        if results.has_values():
            self.action_selector.addItem(self.parent.DISASS_UNKNOWN_TARGET)
        self.action_selector.setEnabled(True)
        self.action_button.setEnabled(True)

        report = HTMLReport()
        report.add_title("Results", size=3)
        report.add_table_header(["address", "assertion", "status", "values"])
        addr = make_cell("%x" % results.target)
        status = make_cell(results.get_status(), color=results.color, bold=True)
        vals = ""
        for value in results.values:
            flag = idc.GetFlags(value)
            typ = self.type_to_string(flag)
            vals += "%x type:%s seg:%s fun:%s<br/>" % (value, typ, idc.SegName(value), idc.GetFunctionName(value))
        report.add_table_line([addr, make_cell(cgi.escape(results.query)), status, make_cell(vals)])
        report.end_table()
        data = report.generate()
        self.result_area.setHtml(data) 
开发者ID:RobinDavid,项目名称:idasec,代码行数:26,代码来源:generic_analysis.py

示例3: app_dump

# 需要导入模块: import cgi [as 别名]
# 或者: from cgi import escape [as 别名]
def app_dump():
    lines = ['<table>']

    for attr in sorted(dir(app)):
        attrval = getattr(app, attr)
        lines.append('<tr>')
        lines.append('<td><a href="{url}">{attr}</a></td>'.format(
            url=url_for('debug.app_dump_attr', attr=attr),
            attr=attr))
        lines.append('<td>{_type}</td>'.format(
            _type=cgi.escape(str(type(attrval)))))
        lines.append('<td>{callable}</td>'.format(
            callable=callable(attrval)))
        lines.append('</tr>')

    lines.append('</table>')
    return '\n'.join(lines) 
开发者ID:dmsimard,项目名称:ara-archive,代码行数:19,代码来源:debug.py

示例4: _wrap_for_html

# 需要导入模块: import cgi [as 别名]
# 或者: from cgi import escape [as 别名]
def _wrap_for_html(self, lines):
        """Wrap the lines in HTML <pre> tag when using HTML format.

        Escape special HTML characters and add <pre> and </pre> tags around
        the given lines if we should be generating HTML as indicated by
        self._contains_html_diff being set to true.
        """
        if self._contains_html_diff:
            yield "<pre style='margin:0'>\n"

            for line in lines:
                yield cgi.escape(line)

            yield "</pre>\n"
        else:
            for line in lines:
                yield line 
开发者ID:Pagure,项目名称:pagure,代码行数:19,代码来源:git_multimail_upstream.py

示例5: django_test_runner

# 需要导入模块: import cgi [as 别名]
# 或者: from cgi import escape [as 别名]
def django_test_runner(request):
    unknown_args = [arg for (arg, v) in request.REQUEST.items()
                    if arg not in ("format", "package", "name")]
    if len(unknown_args) > 0:
        errors = []
        for arg in unknown_args:
            errors.append(_log_error("The request parameter '%s' is not valid." % arg))
        from django.http import HttpResponseNotFound
        return HttpResponseNotFound(" ".join(errors))

    format = request.REQUEST.get("format", "html")
    package_name = request.REQUEST.get("package")
    test_name = request.REQUEST.get("name")
    if format == "html":
        return _render_html(package_name, test_name)
    elif format == "plain":
        return _render_plain(package_name, test_name)
    else:
        error = _log_error("The format '%s' is not valid." % cgi.escape(format))
        from django.http import HttpResponseServerError
        return HttpResponseServerError(error) 
开发者ID:elsigh,项目名称:browserscope,代码行数:23,代码来源:gaeunit.py

示例6: get

# 需要导入模块: import cgi [as 别名]
# 或者: from cgi import escape [as 别名]
def get(self):
        unknown_args = [arg for arg in self.request.arguments()
                        if arg not in ("format", "package", "name")]
        if len(unknown_args) > 0:
            errors = []
            for arg in unknown_args:
                errors.append(_log_error("The request parameter '%s' is not valid." % arg))
            self.error(404)
            self.response.out.write(" ".join(errors))
            return

        format = self.request.get("format", "html")
        package_name = self.request.get("package")
        test_name = self.request.get("name")
        if format == "html":
            self._render_html(package_name, test_name)
        elif format == "plain":
            self._render_plain(package_name, test_name)
        else:
            error = _log_error("The format '%s' is not valid." % cgi.escape(format))
            self.error(404)
            self.response.out.write(error) 
开发者ID:elsigh,项目名称:browserscope,代码行数:24,代码来源:gaeunit.py

示例7: run

# 需要导入模块: import cgi [as 别名]
# 或者: from cgi import escape [as 别名]
def run(self, **kwargs):
    random_token = kwargs.pop('random_token')
    kwargs.pop('approve_html', '')
    kwargs.pop('disapprove_html', '')

    approve_url = self.get_callback_url(
        random_token=random_token, choice='approve')
    disapprove_url = self.get_callback_url(
        random_token=random_token, choice='disapprove')

    mail_args = kwargs.copy()
    mail_args['body'] = mail_args['body'] % {
        'approve_url': approve_url,
        'disapprove_url': disapprove_url,
    }
    if 'html' in mail_args:
      mail_args['html'] = mail_args['html'] % {
        'approve_url': cgi.escape(approve_url),
        'disapprove_url': cgi.escape(disapprove_url),
      }
    EmailToContinue._email_message.im_func(**mail_args).send() 
开发者ID:elsigh,项目名称:browserscope,代码行数:23,代码来源:common.py

示例8: input_field

# 需要导入模块: import cgi [as 别名]
# 或者: from cgi import escape [as 别名]
def input_field(self, name, value, sample_values, back_uri):
    string_value = self.format(value) if value else ''
    sample_values = [self.format(s) for s in sample_values]
    multiline = False
    if value:
      multiline = len(string_value) > 255 or string_value.find('\n') >= 0
    if not multiline:
      for sample_value in sample_values:
        if sample_value and (len(sample_value) > 255 or
                             sample_value.find('\n') >= 0):
          multiline = True
          break
    if multiline:
      return '<textarea name="%s" rows="5" cols="50" %s>%s</textarea>' % (
          cgi.escape(name),
          self.get_placholder_attribute(),
          cgi.escape(string_value))
    else:
      return DataType.input_field(self, name, value, sample_values, back_uri) 
开发者ID:elsigh,项目名称:browserscope,代码行数:21,代码来源:datastore_viewer.py

示例9: generateunmatched

# 需要导入模块: import cgi [as 别名]
# 或者: from cgi import escape [as 别名]
def generateunmatched((picklefile, pickledir, filehash, reportdir, compressed)):

	unmatched_pickle = open(os.path.join(pickledir, picklefile), 'rb')
	unmatches = cPickle.load(unmatched_pickle)
        unmatched_pickle.close()

	htmlfilename = "%s/%s-unmatched.html" % (reportdir, filehash)
	unmatchedhtmlfile = codecs.open(htmlfilename, encoding='utf-8', mode='wb')
	unmatchedhtmlfile.write(u"<html><body><h1>Unmatched strings (%d strings)</h1><p>" % (len(unmatches),))
	for u in unmatches:
		decoded = False
		for i in ['utf-8','ascii','latin-1','euc_jp', 'euc_jis_2004', 'jisx0213', 'iso2022_jp', 'iso2022_jp_1', 'iso2022_jp_2', 'iso2022_jp_2004', 'iso2022_jp_3', 'iso2022_jp_ext', 'iso2022_kr','shift_jis','shift_jis_2004','shift_jisx0213']:
			try:
				decodeline = u.decode(i)
				decoded = True
				break
			except Exception, e:
				pass
			if decoded:
				unmatchedhtmlfile.write("u%s<br>\n" % cgi.escape(decodedline))
			else:
				pass 
开发者ID:armijnhemel,项目名称:binaryanalysis,代码行数:24,代码来源:generatereports.py

示例10: write_error

# 需要导入模块: import cgi [as 别名]
# 或者: from cgi import escape [as 别名]
def write_error(sock, status_int, reason, mesg):
    html = textwrap.dedent("""\
    <html>
      <head>
        <title>%(reason)s</title>
      </head>
      <body>
        <h1><p>%(reason)s</p></h1>
        %(mesg)s
      </body>
    </html>
    """) % {"reason": reason, "mesg": cgi.escape(mesg)}

    http = textwrap.dedent("""\
    HTTP/1.1 %s %s\r
    Connection: close\r
    Content-Type: text/html\r
    Content-Length: %d\r
    \r
    %s""") % (str(status_int), reason, len(html), html)
    write_nonblock(sock, http.encode('latin1')) 
开发者ID:jpush,项目名称:jbox,代码行数:23,代码来源:util.py

示例11: format_environ

# 需要导入模块: import cgi [as 别名]
# 或者: from cgi import escape [as 别名]
def format_environ(environ):
    if environ is None:
        return environ_template.substitute(
            key='---',
            value='No environment registered for this thread yet')
    environ_rows = []
    for key, value in sorted(environ.items()):
        if key in hide_keys:
            continue
        try:
            if key.upper() != key:
                value = repr(value)
            environ_rows.append(
                environ_template.substitute(
                key=cgi.escape(str(key)),
                value=cgi.escape(str(value))))
        except Exception, e:
            environ_rows.append(
                environ_template.substitute(
                key=cgi.escape(str(key)),
                value='Error in <code>repr()</code>: %s' % e)) 
开发者ID:linuxscout,项目名称:mishkal,代码行数:23,代码来源:watchthreads.py

示例12: send_report

# 需要导入模块: import cgi [as 别名]
# 或者: from cgi import escape [as 别名]
def send_report(rep, exc_data, html=True):
    try:
        rep.report(exc_data)
    except:
        output = StringIO()
        traceback.print_exc(file=output)
        if html:
            return """
            <p>Additionally an error occurred while sending the %s report:

            <pre>%s</pre>
            </p>""" % (
                cgi.escape(str(rep)), output.getvalue())
        else:
            return (
                "Additionally an error occurred while sending the "
                "%s report:\n%s" % (str(rep), output.getvalue()))
    else:
        return '' 
开发者ID:linuxscout,项目名称:mishkal,代码行数:21,代码来源:errormiddleware.py

示例13: html_quote

# 需要导入模块: import cgi [as 别名]
# 或者: from cgi import escape [as 别名]
def html_quote(v, encoding=None):
    r"""
    Quote the value (turned to a string) as HTML.  This quotes <, >,
    and quotes:

    >>> html_quote(1)
    '1'
    >>> html_quote(None)
    ''
    >>> html_quote('<hey!>')
    '&lt;hey!&gt;'
    >>> html_quote(u'\u1029')
    '\xe1\x80\xa9'
    """
    encoding = encoding or default_encoding
    if v is None:
        return ''
    elif isinstance(v, str):
        return cgi.escape(v, 1)
    elif isinstance(v, unicode):
        return cgi.escape(v.encode(encoding), 1)
    else:
        return cgi.escape(unicode(v).encode(encoding), 1) 
开发者ID:linuxscout,项目名称:mishkal,代码行数:25,代码来源:quoting.py

示例14: send_error

# 需要导入模块: import cgi [as 别名]
# 或者: from cgi import escape [as 别名]
def send_error(self, code, message=None, close=True):
        try:
            short, int = self.responses[code]
        except KeyError:
            short, int = '???', '???'
        if message is None:
            message = short
        explain = int
        content = (self.error_message_format %
                   {'code': code, 'message': cgi.escape(message),
                    'explain': explain})
        self.send_response(code, message)
        self.send_header("Content-Type", self.error_content_type)
        self.send_header('Content-Length', str(len(content)))
        if close:
            self.send_header('Connection', "close")

        self.end_headers()
        if self.command != 'HEAD' and code >= 200 and code not in (204, 304):
            self.wfile.write(content) 
开发者ID:google,项目名称:rekall,代码行数:22,代码来源:http_server.py

示例15: run

# 需要导入模块: import cgi [as 别名]
# 或者: from cgi import escape [as 别名]
def run(self, params={}):
        text = params.get('text')

        html_template = """
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title></title></head>
<body><pre>{}</pre></body>
</html>"""
        # Wrap text preserving existing newlines
        text = '\n'.join(
            wrapped for line in text.splitlines() for wrapped in wrap(
                line, width=70, expand_tabs=False,
                replace_whitespace=False, drop_whitespace=False
            )
        )
        text = escape(text)
        html_content = html_template.format(text)
        pdf_content = HTML(string=html_content).write_pdf()

        b64_content = b64encode(pdf_content).decode()

        return {'pdf': b64_content} 
开发者ID:rapid7,项目名称:insightconnect-plugins,代码行数:25,代码来源:action.py


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