MCPcopy
hub / github.com/cherrypy/cherrypy / encode

Method encode

cherrypy/lib/httputil.py:468–487  ·  view source on GitHub ↗

Return the given header name or value, encoded for HTTP output.

(cls, v)

Source from the content-addressed store, hash-verified

466
467 @classmethod
468 def encode(cls, v):
469 """Return the given header name or value, encoded for HTTP output."""
470 for enc in cls.encodings:
471 try:
472 return v.encode(enc)
473 except UnicodeEncodeError:
474 continue
475
476 if cls.protocol == (1, 1) and cls.use_rfc_2047:
477 # Encode RFC-2047 TEXT
478 # (e.g. u"\u8200" -> "=?utf-8?b?6IiA?=").
479 # We do our own here instead of using the email module
480 # because we never want to fold lines--folding has
481 # been deprecated by the HTTP working group.
482 v = b2a_base64(v.encode('utf-8'))
483 return (b'=?utf-8?b?' + v.strip(b'\n') + b'?=')
484
485 raise ValueError('Could not encode header part %r using '
486 'any of the encodings %r.' %
487 (v, cls.encodings))
488
489
490class Host(object):

Callers 15

encodeFunction · 0.80
downgrade_wsgi_ux_to_1xFunction · 0.80
recode_path_qsMethod · 0.80
ntobFunction · 0.80
accessMethod · 0.80
emitMethod · 0.80
process_multipartFunction · 0.80
get_error_pageFunction · 0.80
bare_errorFunction · 0.80
finalizeMethod · 0.80
__next__Method · 0.80
encoderMethod · 0.80

Calls

no outgoing calls

Tested by 15

testCombinedToolsMethod · 0.64
markLogMethod · 0.64
_read_marked_regionMethod · 0.64
assertLogMethod · 0.64
is_asciiFunction · 0.64
test_post_multipartMethod · 0.64
custom_clMethod · 0.64
test_HTTP11_TimeoutMethod · 0.64
reqparamsMethod · 0.64