Changeset 78


Ignore:
Timestamp:
06/02/15 13:33:02 (9 years ago)
Author:
tim
Message:

hack to handle binary data in responses for probe_bytes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/bletchley/chosenct.py

    r71 r78  
    2424import queue
    2525import hashlib
     26import codecs
     27
     28
     29def escape_handler(error):
     30    ret_val = ''
     31    for b in error.object[error.start:error.end]:
     32        ret_val += "\\x%.2X" % b
     33
     34    return (ret_val,error.end)
     35
     36codecs.register_error('decode_escape',escape_handler)
     37
    2638
    2739# Wish Python had a better function for this that escaped more characters
    2840_html_escape_table = {
    29     "&": "&",
    30     '"': """,
    31     "'": "'",
    32     ">": ">",
    33     "<": "&lt;",
    34     "\n": "&#x0a",
    35     "\r": "&#x0d",
     41    "&":  "&amp;",
     42    '"':  "&quot;",
     43    "'":  "&apos;",
     44    ">":  "&gt;",
     45    "<":  "&lt;",
     46    "\n": "&#x0a;",
     47    "\r": "&#x0d;",
    3648    }
    3749
     
    99111                bg,fg = self._generate_colors(message)
    100112                if not isinstance(message, str):
    101                     message = message.decode('utf-8')
     113                    message = message.decode('utf-8', 'decode_escape')
    102114
    103115                truncated = message[0:maxlen]
Note: See TracChangeset for help on using the changeset viewer.