當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。