示例#1
0
    def __call__(self, hdrs, content, limit):
        v = hdrs.get_first("content-type")
        if v:
            v = utils.parse_content_type(v)
            if not v:
                return
            boundary = v[2].get("boundary")
            if not boundary:
                return

            rx = re.compile(r'\bname="([^"]+)"')
            keys = []
            vals = []

            for i in content.split("--" + boundary):
                parts = i.splitlines()
                if len(parts) > 1 and parts[0][0:2] != "--":
                    match = rx.search(parts[1])
                    if match:
                        keys.append(match.group(1) + ":")
                        vals.append(
                            netlib.utils.cleanBin("\n".join(
                                parts[3 + parts[2:].index(""):])))
            r = [
                urwid.Text(("highlight", "Form data:\n")),
            ]
            r.extend(
                common.format_keyvals(zip(keys, vals),
                                      key="header",
                                      val="text"))
            return "Multipart form", r
示例#2
0
    def __call__(self, hdrs, content, limit):
        v = hdrs.get_first("content-type")
        if v:
            v = utils.parse_content_type(v)
            if not v:
                return
            boundary = v[2].get("boundary")
            if not boundary:
                return

            rx = re.compile(r'\bname="([^"]+)"')
            keys = []
            vals = []

            for i in content.split("--" + boundary):
                parts = i.splitlines()
                if len(parts) > 1 and parts[0][0:2] != "--":
                    match = rx.search(parts[1])
                    if match:
                        keys.append(match.group(1) + ":")
                        vals.append(netlib.utils.cleanBin(
                            "\n".join(parts[3 + parts[2:].index(""):])
                        ))
            r = [
                urwid.Text(("highlight", "Form data:\n")),
            ]
            r.extend(common.format_keyvals(
                zip(keys, vals),
                key="header",
                val="text"
            ))
            return "Multipart form", r
示例#3
0
def is_json(headers, content):
    if headers:
        ct = parse_content_type(headers.get("content-type", ""))
        if ct and "%s/%s" % (ct[0], ct[1]) == "application/json":
            try:
                return json.loads(content)
            except ValueError:
                return False
    return False
示例#4
0
def is_json(headers, content):
    if headers:
        ct = parse_content_type(headers.get("content-type", ""))
        if ct and "%s/%s" % (ct[0], ct[1]) == "application/json":
            try:
                return json.loads(content)
            except ValueError:
                return False
    return False
示例#5
0
 def __call__(self, hdrs, content, limit):
     ctype = hdrs.get_first("content-type")
     if ctype:
         ct = utils.parse_content_type(ctype) if ctype else None
         ct = "%s/%s" % (ct[0], ct[1])
         if ct in content_types_map:
             return content_types_map[ct][0](hdrs, content, limit)
         elif utils.isXML(content):
             return get("XML")(hdrs, content, limit)
     return get("Raw")(hdrs, content, limit)
示例#6
0
 def __call__(self, hdrs, content, limit):
     ctype = hdrs.get_first("content-type")
     if ctype:
         ct = utils.parse_content_type(ctype) if ctype else None
         ct = "%s/%s" % (ct[0], ct[1])
         if ct in content_types_map:
             return content_types_map[ct][0](hdrs, content, limit)
         elif utils.isXML(content):
             return get("XML")(hdrs, content, limit)
     return get("Raw")(hdrs, content, limit)
示例#7
0
 def __call__(self, data, **metadata):
     headers = metadata.get("headers", {})
     ctype = headers.get("content-type")
     if ctype:
         ct = parse_content_type(ctype) if ctype else None
         ct = "%s/%s" % (ct[0], ct[1])
         if ct in content_types_map:
             return content_types_map[ct][0](data, **metadata)
         elif utils.isXML(data):
             return get("XML")(data, **metadata)
     if utils.isMostlyBin(data):
         return get("Hex")(data)
     return get("Raw")(data)
示例#8
0
 def __call__(self, data, **metadata):
     headers = metadata.get("headers", {})
     ctype = headers.get("content-type")
     if ctype:
         ct = parse_content_type(ctype) if ctype else None
         ct = "%s/%s" % (ct[0], ct[1])
         if ct in content_types_map:
             return content_types_map[ct][0](data, **metadata)
         elif utils.isXML(data):
             return get("XML")(data, **metadata)
     if utils.isMostlyBin(data):
         return get("Hex")(data)
     return get("Raw")(data)