-
Notifications
You must be signed in to change notification settings - Fork 47
/
test.py
55 lines (47 loc) · 1.19 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#! /usr/bin/python
# -*- coding: utf-8 -*-
__author__ = 'linkerlin'
import sys
import struct
try:
from dns import message as m
except ImportError as ex:
print "cannot find dnspython"
from dnsserver import bytetodomain
from caches import *
import collections
import functools
from itertools import ifilterfalse
from heapq import nsmallest
from operator import itemgetter
import threading
import cPickle as p
import datetime as dt
import base64
import random
from random import choice
def testSqliteCache():
@sqlite_cache()
def f2(x, y):
return 3 * x + y
domain = range(50)
for i in range(1000):
r = f2(choice(domain), y=choice(domain))
print(f2.hits, f2.misses)
assert f2.hits>0
class R(object):
def __init__(self, name):
if isinstance(name, str):
self.name = unicode(name)
else:
self.name = name
def __str__(self):
return self.name.decode("utf-8")
def __unicode__(self):
return self.name
def __enter__(self):
print "enter:",self
def __exit__(self, exc_type, exc_val, exc_tb):
print "exit:",self
with R("A") as a, R("B") as b: # require A then require B
print "..."