be more strict about module namespaces

This commit is contained in:
Maximilian Hils 2016-05-31 14:05:57 -07:00
parent a7abf8b731
commit 30fff1fb32
5 changed files with 13 additions and 14 deletions

View File

@ -26,9 +26,8 @@ from PIL.ExifTags import TAGS
import html2text import html2text
import six import six
from netlib.odict import ODict from netlib.odict import ODict
from netlib import encoding from netlib import encoding, http
import netlib.http.headers from netlib.http import url
from netlib.http import url, multipart
from netlib.utils import clean_bin, hexdump from netlib.utils import clean_bin, hexdump
from . import utils from . import utils
from .exceptions import ContentViewException from .exceptions import ContentViewException
@ -122,7 +121,7 @@ class ViewAuto(View):
headers = metadata.get("headers", {}) headers = metadata.get("headers", {})
ctype = headers.get("content-type") ctype = headers.get("content-type")
if data and ctype: if data and ctype:
ct = netlib.http.headers.parse_content_type(ctype) if ctype else None ct = http.parse_content_type(ctype) if ctype else None
ct = "%s/%s" % (ct[0], ct[1]) ct = "%s/%s" % (ct[0], ct[1])
if ct in content_types_map: if ct in content_types_map:
return content_types_map[ct][0](data, **metadata) return content_types_map[ct][0](data, **metadata)
@ -276,7 +275,7 @@ class ViewMultipart(View):
def __call__(self, data, **metadata): def __call__(self, data, **metadata):
headers = metadata.get("headers", {}) headers = metadata.get("headers", {})
v = multipart.decode(headers, data) v = http.multipart.decode(headers, data)
if v: if v:
return "Multipart form", self._format(v) return "Multipart form", self._format(v)

View File

@ -5,7 +5,6 @@ from textwrap import dedent
from six.moves.urllib.parse import quote, quote_plus from six.moves.urllib.parse import quote, quote_plus
import netlib.http import netlib.http
import netlib.http.headers
def curl_command(flow): def curl_command(flow):
@ -88,7 +87,7 @@ def raw_request(flow):
def is_json(headers, content): def is_json(headers, content):
if headers: if headers:
ct = netlib.http.headers.parse_content_type(headers.get("content-type", "")) ct = netlib.http.parse_content_type(headers.get("content-type", ""))
if ct and "%s/%s" % (ct[0], ct[1]) == "application/json": if ct and "%s/%s" % (ct[0], ct[1]) == "application/json":
try: try:
return json.loads(content) return json.loads(content)

View File

@ -65,5 +65,7 @@ def migrate_flow(flow_data):
flow_data = converters[flow_version](flow_data) flow_data = converters[flow_version](flow_data)
else: else:
v = ".".join(str(i) for i in flow_data["version"]) v = ".".join(str(i) for i in flow_data["version"])
raise ValueError("Incompatible serialized data version: {}".format(v)) raise ValueError(
"{} cannot read files serialized with version {}.".format(version.NAMEVERSION, v)
)
return flow_data return flow_data

View File

@ -1,14 +1,14 @@
from __future__ import absolute_import, print_function, division from __future__ import absolute_import, print_function, division
from .request import Request from .request import Request
from .response import Response from .response import Response
from .headers import Headers from .headers import Headers, parse_content_type
from .message import decoded from .message import decoded
from . import http1, http2, status_codes from . import http1, http2, status_codes, multipart
__all__ = [ __all__ = [
"Request", "Request",
"Response", "Response",
"Headers", "Headers", "parse_content_type",
"decoded", "decoded",
"http1", "http2", "status_codes", "http1", "http2", "status_codes", "multipart",
] ]

View File

@ -1,5 +1,4 @@
from netlib.http import Headers from netlib.http import Headers, parse_content_type
from netlib.http.headers import parse_content_type
from netlib.tutils import raises from netlib.tutils import raises