小编Ali*_*han的帖子

如何在python中使用带有装饰函数的doctest?

我正在使用装饰器:

class Memoized(object):

    __cache = {}

    def __init__(self, func):
        self.func = func
        key = (func.__module__, func.__name__)
        # print key
        if key not in self.__cache:
            self.__cache[key] = {}
        self.mycache = self.__cache[key]

    def __call__(self, *args):
        try:
            return self.mycache[args]
        except KeyError:
            value = self.func(*args)
            self.mycache[args] = value
            return value
        except TypeError:
            return self.func(*args)

    def __get__(self, obj, objtype):
       return functools.partial(self.__call__, obj)

    def reset(self):
        for v in self.__cache.itervalues():
            v.clear()
Run Code Online (Sandbox Code Playgroud)

和功能:

@Memoized
def is_tile_inside_border(x, y, z, border):
    '''Checks if a tile is inside border or not …
Run Code Online (Sandbox Code Playgroud)

python doctest python-decorators python-unittest

5
推荐指数
1
解决办法
458
查看次数

鱿鱼代理错误 403 tcp 如何修复

大家好,我正在安装 squid 作为 HTTP 代理,用于使用工具从 google 抓取 url 我已经配置了所有东西,但是当我连接到 squid 时,它给出了 tcp 403 错误我有 ubuntu14.04 并且我没有更改其默认设置只是更改HTTP_access 拒绝所有允许并且所有都相同我想使用该代理进行抓取目的应该是它的配置文件,请帮助我搜索超过 2 天的内容。

http_port 3128

refresh_pattern ^ftp:           1440    20%     10080
refresh_pattern ^gopher:        1440    0%      1440
refresh_pattern -i (/cgi-bin/|\?) 0     0%      0
refresh_pattern .               0       20%     4320

acl localnet src 10.0.0.0/8     # RFC 1918 possible internal network
acl localnet src 172.16.0.0/12  # RFC 1918 possible internal network
acl localnet src 192.168.0.0/16 # RFC 1918 possible internal network
acl localnet src fc00::/7       # RFC 4193 local …
Run Code Online (Sandbox Code Playgroud)

ubuntu proxy squid http-proxy ubuntu-14.04

5
推荐指数
1
解决办法
2万
查看次数