mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 08:11:00 +00:00
We don't need 3 slightly different implementations of Data
This commit is contained in:
parent
84144ca0c6
commit
123e3b130c
@ -7,6 +7,9 @@ import json
|
||||
import importlib
|
||||
import inspect
|
||||
|
||||
import netlib.utils
|
||||
|
||||
|
||||
def timestamp():
|
||||
"""
|
||||
Returns a serializable UTC timestamp.
|
||||
@ -73,25 +76,7 @@ def pretty_duration(secs):
|
||||
return "{:.0f}ms".format(secs * 1000)
|
||||
|
||||
|
||||
class Data:
|
||||
|
||||
def __init__(self, name):
|
||||
m = importlib.import_module(name)
|
||||
dirname = os.path.dirname(inspect.getsourcefile(m))
|
||||
self.dirname = os.path.abspath(dirname)
|
||||
|
||||
def path(self, path):
|
||||
"""
|
||||
Returns a path to the package data housed at 'path' under this
|
||||
module.Path can be a path to a file, or to a directory.
|
||||
|
||||
This function will raise ValueError if the path does not exist.
|
||||
"""
|
||||
fullpath = os.path.join(self.dirname, path)
|
||||
if not os.path.exists(fullpath):
|
||||
raise ValueError("dataPath: %s does not exist." % fullpath)
|
||||
return fullpath
|
||||
pkg_data = Data(__name__)
|
||||
pkg_data = netlib.utils.Data(__name__)
|
||||
|
||||
|
||||
class LRUCache:
|
||||
|
@ -1,5 +1,6 @@
|
||||
import os
|
||||
import sys
|
||||
import netlib.utils
|
||||
|
||||
|
||||
SIZE_UNITS = dict(
|
||||
@ -75,27 +76,7 @@ def escape_unprintables(s):
|
||||
return s
|
||||
|
||||
|
||||
class Data(object):
|
||||
|
||||
def __init__(self, name):
|
||||
m = __import__(name)
|
||||
dirname, _ = os.path.split(m.__file__)
|
||||
self.dirname = os.path.abspath(dirname)
|
||||
|
||||
def path(self, path):
|
||||
"""
|
||||
Returns a path to the package data housed at 'path' under this
|
||||
module.Path can be a path to a file, or to a directory.
|
||||
|
||||
This function will raise ValueError if the path does not exist.
|
||||
"""
|
||||
fullpath = os.path.join(self.dirname, path)
|
||||
if not os.path.exists(fullpath):
|
||||
raise ValueError("dataPath: %s does not exist." % fullpath)
|
||||
return fullpath
|
||||
|
||||
|
||||
data = Data(__name__)
|
||||
data = netlib.utils.Data(__name__)
|
||||
|
||||
|
||||
def daemonize(stdin='/dev/null', stdout='/dev/null', stderr='/dev/null'): # pragma: no cover
|
||||
|
@ -5,11 +5,12 @@ from contextlib import contextmanager
|
||||
|
||||
from mitmproxy import utils, script
|
||||
from mitmproxy.proxy import config
|
||||
import netlib.utils
|
||||
from netlib import tutils as netutils
|
||||
from netlib.http import Headers
|
||||
from . import tservers, tutils
|
||||
|
||||
example_dir = utils.Data(__name__).path("../../examples")
|
||||
example_dir = netlib.utils.Data(__name__).path("../../examples")
|
||||
|
||||
|
||||
class DummyContext(object):
|
||||
|
@ -8,6 +8,7 @@ from contextlib import contextmanager
|
||||
|
||||
from unittest.case import SkipTest
|
||||
|
||||
import netlib.utils
|
||||
import netlib.tutils
|
||||
from mitmproxy import utils, controller
|
||||
from mitmproxy.models import (
|
||||
@ -163,4 +164,4 @@ def capture_stderr(command, *args, **kwargs):
|
||||
sys.stderr = out
|
||||
|
||||
|
||||
test_data = utils.Data(__name__)
|
||||
test_data = netlib.utils.Data(__name__)
|
||||
|
@ -116,7 +116,7 @@ tmpdir = netlib.tutils.tmpdir
|
||||
|
||||
raises = netlib.tutils.raises
|
||||
|
||||
test_data = utils.Data(__name__)
|
||||
test_data = netlib.utils.Data(__name__)
|
||||
|
||||
|
||||
def render(r, settings=language.Settings()):
|
||||
|
Loading…
Reference in New Issue
Block a user