repo_name
stringlengths 6
100
| path
stringlengths 4
294
| copies
stringclasses 981
values | size
stringlengths 4
6
| content
stringlengths 606
896k
| license
stringclasses 15
values | input_ids
listlengths 1.02k
1.02k
| labels
listlengths 1.02k
1.02k
| attention_mask
listlengths 1.02k
1.02k
|
|---|---|---|---|---|---|---|---|---|
alwayskidd/LRB
|
.waf-1.7.13-5a064c2686fe54de4e11018d22148cfc/waflib/Tools/ccroot.py
|
19
|
13272
|
#! /usr/bin/env python
# encoding: utf-8
# WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file
import os,re
from waflib import Task,Utils,Node,Errors
from waflib.TaskGen import after_method,before_method,feature,taskgen_method,extension
from waflib.Tools import c_aliases,c_preproc,c_config,c_osx,c_tests
from waflib.Configure import conf
SYSTEM_LIB_PATHS=['/usr/lib64','/usr/lib','/usr/local/lib64','/usr/local/lib']
USELIB_VARS=Utils.defaultdict(set)
USELIB_VARS['c']=set(['INCLUDES','FRAMEWORKPATH','DEFINES','CPPFLAGS','CCDEPS','CFLAGS','ARCH'])
USELIB_VARS['cxx']=set(['INCLUDES','FRAMEWORKPATH','DEFINES','CPPFLAGS','CXXDEPS','CXXFLAGS','ARCH'])
USELIB_VARS['d']=set(['INCLUDES','DFLAGS'])
USELIB_VARS['includes']=set(['INCLUDES','FRAMEWORKPATH','ARCH'])
USELIB_VARS['cprogram']=USELIB_VARS['cxxprogram']=set(['LIB','STLIB','LIBPATH','STLIBPATH','LINKFLAGS','RPATH','LINKDEPS','FRAMEWORK','FRAMEWORKPATH','ARCH'])
USELIB_VARS['cshlib']=USELIB_VARS['cxxshlib']=set(['LIB','STLIB','LIBPATH','STLIBPATH','LINKFLAGS','RPATH','LINKDEPS','FRAMEWORK','FRAMEWORKPATH','ARCH'])
USELIB_VARS['cstlib']=USELIB_VARS['cxxstlib']=set(['ARFLAGS','LINKDEPS'])
USELIB_VARS['dprogram']=set(['LIB','STLIB','LIBPATH','STLIBPATH','LINKFLAGS','RPATH','LINKDEPS'])
USELIB_VARS['dshlib']=set(['LIB','STLIB','LIBPATH','STLIBPATH','LINKFLAGS','RPATH','LINKDEPS'])
USELIB_VARS['dstlib']=set(['ARFLAGS','LINKDEPS'])
USELIB_VARS['asm']=set(['ASFLAGS'])
@taskgen_method
def create_compiled_task(self,name,node):
out='%s.%d.o'%(node.name,self.idx)
task=self.create_task(name,node,node.parent.find_or_declare(out))
try:
self.compiled_tasks.append(task)
except AttributeError:
self.compiled_tasks=[task]
return task
@taskgen_method
def to_incnodes(self,inlst):
lst=[]
seen=set([])
for x in self.to_list(inlst):
if x in seen or not x:
continue
seen.add(x)
if isinstance(x,Node.Node):
lst.append(x)
else:
if os.path.isabs(x):
lst.append(self.bld.root.make_node(x)or x)
else:
if x[0]=='#':
p=self.bld.bldnode.make_node(x[1:])
v=self.bld.srcnode.make_node(x[1:])
else:
p=self.path.get_bld().make_node(x)
v=self.path.make_node(x)
if p.is_child_of(self.bld.bldnode):
p.mkdir()
lst.append(p)
lst.append(v)
return lst
@feature('c','cxx','d','asm','fc','includes')
@after_method('propagate_uselib_vars','process_source')
def apply_incpaths(self):
lst=self.to_incnodes(self.to_list(getattr(self,'includes',[]))+self.env['INCLUDES'])
self.includes_nodes=lst
self.env['INCPATHS']=[x.abspath()for x in lst]
class link_task(Task.Task):
color='YELLOW'
inst_to=None
chmod=Utils.O755
def add_target(self,target):
if isinstance(target,str):
pattern=self.env[self.__class__.__name__+'_PATTERN']
if not pattern:
pattern='%s'
folder,name=os.path.split(target)
if self.__class__.__name__.find('shlib')>0 and getattr(self.generator,'vnum',None):
nums=self.generator.vnum.split('.')
if self.env.DEST_BINFMT=='pe':
name=name+'-'+nums[0]
elif self.env.DEST_OS=='openbsd':
pattern='%s.%s.%s'%(pattern,nums[0],nums[1])
tmp=folder+os.sep+pattern%name
target=self.generator.path.find_or_declare(tmp)
self.set_outputs(target)
class stlink_task(link_task):
run_str='${AR} ${ARFLAGS} ${AR_TGT_F}${TGT} ${AR_SRC_F}${SRC}'
def rm_tgt(cls):
old=cls.run
def wrap(self):
try:os.remove(self.outputs[0].abspath())
except OSError:pass
return old(self)
setattr(cls,'run',wrap)
rm_tgt(stlink_task)
@feature('c','cxx','d','fc','asm')
@after_method('process_source')
def apply_link(self):
for x in self.features:
if x=='cprogram'and'cxx'in self.features:
x='cxxprogram'
elif x=='cshlib'and'cxx'in self.features:
x='cxxshlib'
if x in Task.classes:
if issubclass(Task.classes[x],link_task):
link=x
break
else:
return
objs=[t.outputs[0]for t in getattr(self,'compiled_tasks',[])]
self.link_task=self.create_task(link,objs)
self.link_task.add_target(self.target)
try:
inst_to=self.install_path
except AttributeError:
inst_to=self.link_task.__class__.inst_to
if inst_to:
self.install_task=self.bld.install_files(inst_to,self.link_task.outputs[:],env=self.env,chmod=self.link_task.chmod)
@taskgen_method
def use_rec(self,name,**kw):
if name in self.tmp_use_not or name in self.tmp_use_seen:
return
try:
y=self.bld.get_tgen_by_name(name)
except Errors.WafError:
self.uselib.append(name)
self.tmp_use_not.add(name)
return
self.tmp_use_seen.append(name)
y.post()
y.tmp_use_objects=objects=kw.get('objects',True)
y.tmp_use_stlib=stlib=kw.get('stlib',True)
try:
link_task=y.link_task
except AttributeError:
y.tmp_use_var=''
else:
objects=False
if not isinstance(link_task,stlink_task):
stlib=False
y.tmp_use_var='LIB'
else:
y.tmp_use_var='STLIB'
p=self.tmp_use_prec
for x in self.to_list(getattr(y,'use',[])):
try:
p[x].append(name)
except KeyError:
p[x]=[name]
self.use_rec(x,objects=objects,stlib=stlib)
@feature('c','cxx','d','use','fc')
@before_method('apply_incpaths','propagate_uselib_vars')
@after_method('apply_link','process_source')
def process_use(self):
use_not=self.tmp_use_not=set([])
self.tmp_use_seen=[]
use_prec=self.tmp_use_prec={}
self.uselib=self.to_list(getattr(self,'uselib',[]))
self.includes=self.to_list(getattr(self,'includes',[]))
names=self.to_list(getattr(self,'use',[]))
for x in names:
self.use_rec(x)
for x in use_not:
if x in use_prec:
del use_prec[x]
out=[]
tmp=[]
for x in self.tmp_use_seen:
for k in use_prec.values():
if x in k:
break
else:
tmp.append(x)
while tmp:
e=tmp.pop()
out.append(e)
try:
nlst=use_prec[e]
except KeyError:
pass
else:
del use_prec[e]
for x in nlst:
for y in use_prec:
if x in use_prec[y]:
break
else:
tmp.append(x)
if use_prec:
raise Errors.WafError('Cycle detected in the use processing %r'%use_prec)
out.reverse()
link_task=getattr(self,'link_task',None)
for x in out:
y=self.bld.get_tgen_by_name(x)
var=y.tmp_use_var
if var and link_task:
if var=='LIB'or y.tmp_use_stlib:
self.env.append_value(var,[y.target[y.target.rfind(os.sep)+1:]])
self.link_task.dep_nodes.extend(y.link_task.outputs)
tmp_path=y.link_task.outputs[0].parent.path_from(self.bld.bldnode)
self.env.append_value(var+'PATH',[tmp_path])
else:
if y.tmp_use_objects:
self.add_objects_from_tgen(y)
if getattr(y,'export_includes',None):
self.includes.extend(y.to_incnodes(y.export_includes))
if getattr(y,'export_defines',None):
self.env.append_value('DEFINES',self.to_list(y.export_defines))
for x in names:
try:
y=self.bld.get_tgen_by_name(x)
except Exception:
if not self.env['STLIB_'+x]and not x in self.uselib:
self.uselib.append(x)
else:
for k in self.to_list(getattr(y,'uselib',[])):
if not self.env['STLIB_'+k]and not k in self.uselib:
self.uselib.append(k)
@taskgen_method
def accept_node_to_link(self,node):
return not node.name.endswith('.pdb')
@taskgen_method
def add_objects_from_tgen(self,tg):
try:
link_task=self.link_task
except AttributeError:
pass
else:
for tsk in getattr(tg,'compiled_tasks',[]):
for x in tsk.outputs:
if self.accept_node_to_link(x):
link_task.inputs.append(x)
@taskgen_method
def get_uselib_vars(self):
_vars=set([])
for x in self.features:
if x in USELIB_VARS:
_vars|=USELIB_VARS[x]
return _vars
@feature('c','cxx','d','fc','javac','cs','uselib','asm')
@after_method('process_use')
def propagate_uselib_vars(self):
_vars=self.get_uselib_vars()
env=self.env
for x in _vars:
y=x.lower()
env.append_unique(x,self.to_list(getattr(self,y,[])))
for x in self.features:
for var in _vars:
compvar='%s_%s'%(var,x)
env.append_value(var,env[compvar])
for x in self.to_list(getattr(self,'uselib',[])):
for v in _vars:
env.append_value(v,env[v+'_'+x])
@feature('cshlib','cxxshlib','fcshlib')
@after_method('apply_link')
def apply_implib(self):
if not self.env.DEST_BINFMT=='pe':
return
dll=self.link_task.outputs[0]
if isinstance(self.target,Node.Node):
name=self.target.name
else:
name=os.path.split(self.target)[1]
implib=self.env['implib_PATTERN']%name
implib=dll.parent.find_or_declare(implib)
self.env.append_value('LINKFLAGS',self.env['IMPLIB_ST']%implib.bldpath())
self.link_task.outputs.append(implib)
if getattr(self,'defs',None)and self.env.DEST_BINFMT=='pe':
node=self.path.find_resource(self.defs)
if not node:
raise Errors.WafError('invalid def file %r'%self.defs)
if'msvc'in(self.env.CC_NAME,self.env.CXX_NAME):
self.env.append_value('LINKFLAGS','/def:%s'%node.path_from(self.bld.bldnode))
self.link_task.dep_nodes.append(node)
else:
self.link_task.inputs.append(node)
try:
inst_to=self.install_path
except AttributeError:
inst_to=self.link_task.__class__.inst_to
if not inst_to:
return
self.implib_install_task=self.bld.install_as('${LIBDIR}/%s'%implib.name,implib,self.env)
re_vnum=re.compile('^([1-9]\\d*|0)[.]([1-9]\\d*|0)[.]([1-9]\\d*|0)$')
@feature('cshlib','cxxshlib','dshlib','fcshlib','vnum')
@after_method('apply_link','propagate_uselib_vars')
def apply_vnum(self):
if not getattr(self,'vnum','')or os.name!='posix'or self.env.DEST_BINFMT not in('elf','mac-o'):
return
link=self.link_task
if not re_vnum.match(self.vnum):
raise Errors.WafError('Invalid version %r for %r'%(self.vnum,self))
nums=self.vnum.split('.')
node=link.outputs[0]
libname=node.name
if libname.endswith('.dylib'):
name3=libname.replace('.dylib','.%s.dylib'%self.vnum)
name2=libname.replace('.dylib','.%s.dylib'%nums[0])
else:
name3=libname+'.'+self.vnum
name2=libname+'.'+nums[0]
if self.env.SONAME_ST:
v=self.env.SONAME_ST%name2
self.env.append_value('LINKFLAGS',v.split())
if self.env.DEST_OS!='openbsd':
self.create_task('vnum',node,[node.parent.find_or_declare(name2),node.parent.find_or_declare(name3)])
if getattr(self,'install_task',None):
self.install_task.hasrun=Task.SKIP_ME
bld=self.bld
path=self.install_task.dest
if self.env.DEST_OS=='openbsd':
libname=self.link_task.outputs[0].name
t1=bld.install_as('%s%s%s'%(path,os.sep,libname),node,env=self.env,chmod=self.link_task.chmod)
self.vnum_install_task=(t1,)
else:
t1=bld.install_as(path+os.sep+name3,node,env=self.env,chmod=self.link_task.chmod)
t2=bld.symlink_as(path+os.sep+name2,name3)
t3=bld.symlink_as(path+os.sep+libname,name3)
self.vnum_install_task=(t1,t2,t3)
if'-dynamiclib'in self.env['LINKFLAGS']:
try:
inst_to=self.install_path
except AttributeError:
inst_to=self.link_task.__class__.inst_to
if inst_to:
p=Utils.subst_vars(inst_to,self.env)
path=os.path.join(p,self.link_task.outputs[0].name)
self.env.append_value('LINKFLAGS',['-install_name',path])
class vnum(Task.Task):
color='CYAN'
quient=True
ext_in=['.bin']
def run(self):
for x in self.outputs:
path=x.abspath()
try:
os.remove(path)
except OSError:
pass
try:
os.symlink(self.inputs[0].name,path)
except OSError:
return 1
class fake_shlib(link_task):
def runnable_status(self):
for t in self.run_after:
if not t.hasrun:
return Task.ASK_LATER
for x in self.outputs:
x.sig=Utils.h_file(x.abspath())
return Task.SKIP_ME
class fake_stlib(stlink_task):
def runnable_status(self):
for t in self.run_after:
if not t.hasrun:
return Task.ASK_LATER
for x in self.outputs:
x.sig=Utils.h_file(x.abspath())
return Task.SKIP_ME
@conf
def read_shlib(self,name,paths=[],export_includes=[],export_defines=[]):
return self(name=name,features='fake_lib',lib_paths=paths,lib_type='shlib',export_includes=export_includes,export_defines=export_defines)
@conf
def read_stlib(self,name,paths=[],export_includes=[],export_defines=[]):
return self(name=name,features='fake_lib',lib_paths=paths,lib_type='stlib',export_includes=export_includes,export_defines=export_defines)
lib_patterns={'shlib':['lib%s.so','%s.so','lib%s.dylib','lib%s.dll','%s.dll'],'stlib':['lib%s.a','%s.a','lib%s.dll','%s.dll','lib%s.lib','%s.lib'],}
@feature('fake_lib')
def process_lib(self):
node=None
names=[x%self.name for x in lib_patterns[self.lib_type]]
for x in self.lib_paths+[self.path]+SYSTEM_LIB_PATHS:
if not isinstance(x,Node.Node):
x=self.bld.root.find_node(x)or self.path.find_node(x)
if not x:
continue
for y in names:
node=x.find_node(y)
if node:
node.sig=Utils.h_file(node.abspath())
break
else:
continue
break
else:
raise Errors.WafError('could not find library %r'%self.name)
self.link_task=self.create_task('fake_%s'%self.lib_type,[],[node])
self.target=self.name
class fake_o(Task.Task):
def runnable_status(self):
return Task.SKIP_ME
@extension('.o','.obj')
def add_those_o_files(self,node):
tsk=self.create_task('fake_o',[],node)
try:
self.compiled_tasks.append(tsk)
except AttributeError:
self.compiled_tasks=[tsk]
@feature('fake_obj')
@before_method('process_source')
def process_objs(self):
for node in self.to_nodes(self.source):
self.add_those_o_files(node)
self.source=[]
@conf
def read_object(self,obj):
if not isinstance(obj,self.path.__class__):
obj=self.path.find_resource(obj)
return self(features='fake_obj',source=obj,name=obj.name)
|
gpl-2.0
|
[
3168,
1182,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
2644,
26,
2774,
13,
24,
199,
3,
14750,
1,
4226,
440,
5283,
1,
1455,
921,
21500,
14,
31864,
14,
957,
15,
3187,
15,
4757,
15,
21500,
2706,
15,
4780,
14,
1360,
20930,
2873,
24522,
63,
1589,
63,
21500,
63,
493,
199,
199,
646,
747,
12,
264,
199,
504,
31380,
492,
8495,
12,
7535,
12,
1716,
12,
9298,
199,
504,
31380,
14,
4476,
8168,
492,
2410,
63,
765,
12,
5182,
63,
765,
12,
4445,
12,
1765,
2268,
63,
765,
12,
3435,
199,
504,
31380,
14,
11654,
492,
286,
63,
8602,
12,
67,
63,
657,
4687,
12,
67,
63,
888,
12,
67,
63,
28197,
12,
67,
63,
2219,
199,
504,
31380,
14,
17324,
492,
3743,
199,
12711,
63,
5617,
63,
20202,
2968,
15,
2647,
15,
773,
772,
32381,
2647,
15,
773,
32381,
2647,
15,
1832,
15,
773,
772,
32381,
2647,
15,
1832,
15,
773,
418,
199,
4701,
5617,
63,
21367,
29,
7535,
14,
21501,
8,
409,
9,
199,
4701,
5617,
63,
21367,
459,
67,
13784,
409,
2941,
568,
29992,
1673,
12683,
8406,
3243,
1673,
27196,
1673,
14533,
4831,
1673,
2571,
1093,
5067,
1673,
14804,
1673,
7762,
1105,
199,
4701,
5617,
63,
21367,
459,
9634,
13784,
409,
2941,
568,
29992,
1673,
12683,
8406,
3243,
1673,
27196,
1673,
14533,
4831,
1673,
12206,
1093,
5067,
1673,
26180,
1673,
7762,
1105,
199,
4701,
5617,
63,
21367,
459,
68,
13784,
409,
2941,
568,
29992,
1673,
36,
4831,
1105,
199,
4701,
5617,
63,
21367,
459,
9441,
13784,
409,
2941,
568,
29992,
1673,
12683,
8406,
3243,
1673,
7762,
1105,
199,
4701,
5617,
63,
21367,
459,
67,
6815,
13784,
4701,
5617,
63,
21367,
459,
9634,
6815,
13784,
409,
2941,
5617,
1673,
840,
5617,
1673,
32119,
1673,
840,
32119,
1673,
30388,
1673,
50,
3243,
1673,
7916,
1093,
5067,
1673,
12683,
8406,
1673,
12683,
8406,
3243,
1673,
7762,
1105,
199,
4701,
5617,
63,
21367,
459,
28736,
773,
13784,
4701,
5617,
63,
21367,
459,
9634,
609,
773,
13784,
409,
2941,
5617,
1673,
840,
5617,
1673,
32119,
1673,
840,
32119,
1673,
30388,
1673,
50,
3243,
1673,
7916,
1093,
5067,
1673,
12683,
8406,
1673,
12683,
8406,
3243,
1673,
7762,
1105,
199,
4701,
5617,
63,
21367,
459,
67,
270,
773,
13784,
4701,
5617,
63,
21367,
459,
9634,
270,
773,
13784,
409,
2941,
689,
4831,
1673,
7916,
1093,
5067,
1105,
199,
4701,
5617,
63,
21367,
459,
68,
6815,
13784,
409,
2941,
5617,
1673,
840,
5617,
1673,
32119,
1673,
840,
32119,
1673,
30388,
1673,
50,
3243,
1673,
7916,
1093,
5067,
1105,
199,
4701,
5617,
63,
21367,
459,
68,
609,
773,
13784,
409,
2941,
5617,
1673,
840,
5617,
1673,
32119,
1673,
840,
32119,
1673,
30388,
1673,
50,
3243,
1673,
7916,
1093,
5067,
1105,
199,
4701,
5617,
63,
21367,
459,
5119,
773,
13784,
409,
2941,
689,
4831,
1673,
7916,
1093,
5067,
1105,
199,
4701,
5617,
63,
21367,
459,
11374,
13784,
409,
2941,
1179,
4831,
1105,
199,
32,
1765,
2268,
63,
765,
199,
318,
1218,
63,
8427,
63,
1765,
8,
277,
12,
354,
12,
932,
304,
199,
198,
548,
9569,
83,
4111,
68,
14,
79,
13328,
932,
14,
354,
12,
277,
14,
2996,
9,
199,
198,
1765,
29,
277,
14,
981,
63,
1765,
8,
354,
12,
932,
12,
932,
14,
1708,
14,
1623,
63,
269,
63,
16536,
8,
548,
430,
199,
198,
893,
26,
507,
198,
277,
14,
8427,
63,
5054,
14,
740,
8,
1765,
9,
199,
198,
2590,
4281,
26,
507,
198,
277,
14,
8427,
63,
5054,
1524,
1765,
61,
199,
198,
1107,
2120,
199,
32,
1765,
2268,
63,
765,
199,
318,
370,
63,
6559,
2415,
8,
277,
12,
262,
6916,
304,
199,
198,
6916,
9811,
199,
198,
8606,
29,
409,
4157,
199,
198,
509,
671,
315,
291,
14,
475,
63,
513,
8,
262,
6916,
304,
507,
198,
692,
671,
315,
6775,
503,
440,
671,
26,
686,
198,
6958,
507,
198,
8606,
14,
525,
8,
88,
9,
507,
198,
692,
1228,
8,
88,
12,
1716,
14,
1716,
304,
686,
198,
6916,
14,
740,
8,
88,
9,
507,
198,
2836,
26,
686,
198,
692,
747,
14,
515,
14,
17896,
8,
88,
304,
1585,
198,
6916,
14,
740,
8,
277,
14,
14341,
14,
1231,
14,
1875,
63,
932,
8,
88,
9,
269,
671,
9,
686,
198,
2836,
26,
1585,
198,
692,
671,
59,
16,
22954,
24397,
1871,
198,
80,
29,
277,
14,
14341,
14,
14341,
932,
14,
1875,
63,
932,
8,
88,
59,
17,
5728,
1871,
198,
86,
29,
277,
14,
14341,
14,
2164,
932,
14,
1875,
63,
932,
8,
88,
59,
17,
5728,
1585,
198,
2836,
26,
1871,
198,
80,
29,
277,
14,
515,
14,
362,
63,
14341,
1252,
1875,
63,
932,
8,
88,
9,
1871,
198,
86,
29,
277,
14,
515,
14,
1875,
63,
932,
8,
88,
9,
1585,
198,
692,
299,
14,
374,
63,
1739,
63,
1618,
8,
277,
14,
14341,
14,
14341,
932,
304,
1871,
198,
80,
14,
8215,
342,
1585,
198,
6916,
14,
740,
8,
80,
9,
1585,
198,
6916,
14,
740,
8,
86,
9,
199,
198,
1107,
9877,
199,
32,
4445,
360,
67,
1673,
9634,
1673,
68,
1673,
11374,
1673,
3003,
1673,
9441,
358,
199,
32,
4399,
63,
765,
360,
19432,
63,
1180,
773,
63,
2936,
1673,
1412,
63,
1365,
358,
199,
318,
4838,
63,
6559,
3771,
8,
277,
304,
199,
198,
6916,
29,
277,
14,
475,
63,
6559,
2415,
8,
277,
14,
475,
63,
513,
8,
5675,
8,
277,
2584,
9441,
23993,
2459,
11,
277,
14,
1813,
459,
568,
29992,
1105,
199,
198,
277,
14,
9441,
63,
2415,
29,
6916,
199,
198,
277,
14,
1813,
459,
25205,
20202,
418,
1524,
88,
14,
4832,
342,
509,
671,
315,
9877,
61,
199,
533,
2142,
63,
1765,
8,
4476,
14,
4476,
304,
199,
198,
2326,
534,
57,
23575,
7,
199,
198,
3615,
63,
475,
29,
403,
199,
198,
11693,
29,
7535,
14,
47,
12315,
199,
198,
318,
1050,
63,
1375,
8,
277,
12,
1375,
304,
507,
198,
692,
1228,
8,
1375,
12,
495,
304,
686,
198,
3401,
29,
277,
14,
1813,
59,
277,
855,
533,
4914,
354,
363,
28323,
10764,
418,
686,
198,
692,
440,
3851,
26,
1585,
198,
3401,
9569,
83,
7,
686,
198,
3741,
12,
354,
29,
736,
14,
515,
14,
1294,
8,
1375,
9,
686,
198,
692,
291,
855
] |
[
1182,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
2644,
26,
2774,
13,
24,
199,
3,
14750,
1,
4226,
440,
5283,
1,
1455,
921,
21500,
14,
31864,
14,
957,
15,
3187,
15,
4757,
15,
21500,
2706,
15,
4780,
14,
1360,
20930,
2873,
24522,
63,
1589,
63,
21500,
63,
493,
199,
199,
646,
747,
12,
264,
199,
504,
31380,
492,
8495,
12,
7535,
12,
1716,
12,
9298,
199,
504,
31380,
14,
4476,
8168,
492,
2410,
63,
765,
12,
5182,
63,
765,
12,
4445,
12,
1765,
2268,
63,
765,
12,
3435,
199,
504,
31380,
14,
11654,
492,
286,
63,
8602,
12,
67,
63,
657,
4687,
12,
67,
63,
888,
12,
67,
63,
28197,
12,
67,
63,
2219,
199,
504,
31380,
14,
17324,
492,
3743,
199,
12711,
63,
5617,
63,
20202,
2968,
15,
2647,
15,
773,
772,
32381,
2647,
15,
773,
32381,
2647,
15,
1832,
15,
773,
772,
32381,
2647,
15,
1832,
15,
773,
418,
199,
4701,
5617,
63,
21367,
29,
7535,
14,
21501,
8,
409,
9,
199,
4701,
5617,
63,
21367,
459,
67,
13784,
409,
2941,
568,
29992,
1673,
12683,
8406,
3243,
1673,
27196,
1673,
14533,
4831,
1673,
2571,
1093,
5067,
1673,
14804,
1673,
7762,
1105,
199,
4701,
5617,
63,
21367,
459,
9634,
13784,
409,
2941,
568,
29992,
1673,
12683,
8406,
3243,
1673,
27196,
1673,
14533,
4831,
1673,
12206,
1093,
5067,
1673,
26180,
1673,
7762,
1105,
199,
4701,
5617,
63,
21367,
459,
68,
13784,
409,
2941,
568,
29992,
1673,
36,
4831,
1105,
199,
4701,
5617,
63,
21367,
459,
9441,
13784,
409,
2941,
568,
29992,
1673,
12683,
8406,
3243,
1673,
7762,
1105,
199,
4701,
5617,
63,
21367,
459,
67,
6815,
13784,
4701,
5617,
63,
21367,
459,
9634,
6815,
13784,
409,
2941,
5617,
1673,
840,
5617,
1673,
32119,
1673,
840,
32119,
1673,
30388,
1673,
50,
3243,
1673,
7916,
1093,
5067,
1673,
12683,
8406,
1673,
12683,
8406,
3243,
1673,
7762,
1105,
199,
4701,
5617,
63,
21367,
459,
28736,
773,
13784,
4701,
5617,
63,
21367,
459,
9634,
609,
773,
13784,
409,
2941,
5617,
1673,
840,
5617,
1673,
32119,
1673,
840,
32119,
1673,
30388,
1673,
50,
3243,
1673,
7916,
1093,
5067,
1673,
12683,
8406,
1673,
12683,
8406,
3243,
1673,
7762,
1105,
199,
4701,
5617,
63,
21367,
459,
67,
270,
773,
13784,
4701,
5617,
63,
21367,
459,
9634,
270,
773,
13784,
409,
2941,
689,
4831,
1673,
7916,
1093,
5067,
1105,
199,
4701,
5617,
63,
21367,
459,
68,
6815,
13784,
409,
2941,
5617,
1673,
840,
5617,
1673,
32119,
1673,
840,
32119,
1673,
30388,
1673,
50,
3243,
1673,
7916,
1093,
5067,
1105,
199,
4701,
5617,
63,
21367,
459,
68,
609,
773,
13784,
409,
2941,
5617,
1673,
840,
5617,
1673,
32119,
1673,
840,
32119,
1673,
30388,
1673,
50,
3243,
1673,
7916,
1093,
5067,
1105,
199,
4701,
5617,
63,
21367,
459,
5119,
773,
13784,
409,
2941,
689,
4831,
1673,
7916,
1093,
5067,
1105,
199,
4701,
5617,
63,
21367,
459,
11374,
13784,
409,
2941,
1179,
4831,
1105,
199,
32,
1765,
2268,
63,
765,
199,
318,
1218,
63,
8427,
63,
1765,
8,
277,
12,
354,
12,
932,
304,
199,
198,
548,
9569,
83,
4111,
68,
14,
79,
13328,
932,
14,
354,
12,
277,
14,
2996,
9,
199,
198,
1765,
29,
277,
14,
981,
63,
1765,
8,
354,
12,
932,
12,
932,
14,
1708,
14,
1623,
63,
269,
63,
16536,
8,
548,
430,
199,
198,
893,
26,
507,
198,
277,
14,
8427,
63,
5054,
14,
740,
8,
1765,
9,
199,
198,
2590,
4281,
26,
507,
198,
277,
14,
8427,
63,
5054,
1524,
1765,
61,
199,
198,
1107,
2120,
199,
32,
1765,
2268,
63,
765,
199,
318,
370,
63,
6559,
2415,
8,
277,
12,
262,
6916,
304,
199,
198,
6916,
9811,
199,
198,
8606,
29,
409,
4157,
199,
198,
509,
671,
315,
291,
14,
475,
63,
513,
8,
262,
6916,
304,
507,
198,
692,
671,
315,
6775,
503,
440,
671,
26,
686,
198,
6958,
507,
198,
8606,
14,
525,
8,
88,
9,
507,
198,
692,
1228,
8,
88,
12,
1716,
14,
1716,
304,
686,
198,
6916,
14,
740,
8,
88,
9,
507,
198,
2836,
26,
686,
198,
692,
747,
14,
515,
14,
17896,
8,
88,
304,
1585,
198,
6916,
14,
740,
8,
277,
14,
14341,
14,
1231,
14,
1875,
63,
932,
8,
88,
9,
269,
671,
9,
686,
198,
2836,
26,
1585,
198,
692,
671,
59,
16,
22954,
24397,
1871,
198,
80,
29,
277,
14,
14341,
14,
14341,
932,
14,
1875,
63,
932,
8,
88,
59,
17,
5728,
1871,
198,
86,
29,
277,
14,
14341,
14,
2164,
932,
14,
1875,
63,
932,
8,
88,
59,
17,
5728,
1585,
198,
2836,
26,
1871,
198,
80,
29,
277,
14,
515,
14,
362,
63,
14341,
1252,
1875,
63,
932,
8,
88,
9,
1871,
198,
86,
29,
277,
14,
515,
14,
1875,
63,
932,
8,
88,
9,
1585,
198,
692,
299,
14,
374,
63,
1739,
63,
1618,
8,
277,
14,
14341,
14,
14341,
932,
304,
1871,
198,
80,
14,
8215,
342,
1585,
198,
6916,
14,
740,
8,
80,
9,
1585,
198,
6916,
14,
740,
8,
86,
9,
199,
198,
1107,
9877,
199,
32,
4445,
360,
67,
1673,
9634,
1673,
68,
1673,
11374,
1673,
3003,
1673,
9441,
358,
199,
32,
4399,
63,
765,
360,
19432,
63,
1180,
773,
63,
2936,
1673,
1412,
63,
1365,
358,
199,
318,
4838,
63,
6559,
3771,
8,
277,
304,
199,
198,
6916,
29,
277,
14,
475,
63,
6559,
2415,
8,
277,
14,
475,
63,
513,
8,
5675,
8,
277,
2584,
9441,
23993,
2459,
11,
277,
14,
1813,
459,
568,
29992,
1105,
199,
198,
277,
14,
9441,
63,
2415,
29,
6916,
199,
198,
277,
14,
1813,
459,
25205,
20202,
418,
1524,
88,
14,
4832,
342,
509,
671,
315,
9877,
61,
199,
533,
2142,
63,
1765,
8,
4476,
14,
4476,
304,
199,
198,
2326,
534,
57,
23575,
7,
199,
198,
3615,
63,
475,
29,
403,
199,
198,
11693,
29,
7535,
14,
47,
12315,
199,
198,
318,
1050,
63,
1375,
8,
277,
12,
1375,
304,
507,
198,
692,
1228,
8,
1375,
12,
495,
304,
686,
198,
3401,
29,
277,
14,
1813,
59,
277,
855,
533,
4914,
354,
363,
28323,
10764,
418,
686,
198,
692,
440,
3851,
26,
1585,
198,
3401,
9569,
83,
7,
686,
198,
3741,
12,
354,
29,
736,
14,
515,
14,
1294,
8,
1375,
9,
686,
198,
692,
291,
855,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
kenorb/BitTorrent
|
twisted/scripts/tkmktap.py
|
16
|
17390
|
# Copyright (c) 2001-2004 Twisted Matrix Laboratories.
# See LICENSE for details.
#
"""Implementation module for the graphical version of the `mktap` command.
"""
# System imports
import Tkinter, tkMessageBox, tkFileDialog, StringIO, os
import traceback
# Twisted imports
from twisted.application import service
from twisted.internet import tksupport, reactor
from twisted.scripts import mktap
from twisted.python import usage, reflect
from twisted.copyright import version
class TkMkAppFrame(Tkinter.Frame):
"""
A frame with all the necessary widgets to configure a Twisted Application.
"""
# Plugin currently selected
coil = None
# Options instance currently displayed
options = None
# Frame options are displayed in
optFrame = None
def __init__(self, master, coil):
Tkinter.Frame.__init__(self, master)
self.setupMkTap()
self.reset(coil)
def setupMkTap(self):
# Create all of the "mktap" option widgets
appFrame = Tkinter.Frame(self)
f = Tkinter.Frame(appFrame)
listLabel = Tkinter.Label(f, text='TAp Format')
self.typeList = Tkinter.Listbox(f, background='white')
self.typeList['height'] = 3
for t in ('pickle', 'xml', 'source'):
self.typeList.insert(Tkinter.END, t)
self.typeList.selection_set(0)
listLabel.pack(side=Tkinter.TOP)
self.typeList.pack(side=Tkinter.TOP)
f.pack(side=Tkinter.LEFT, anchor=Tkinter.N)
f = Tkinter.Frame(appFrame)
tapLabel = Tkinter.Label(f, text='TAp Filename')
tapButton = Tkinter.Button(f, text="Choose", command=self.pickTapFile)
self.tapfile = Tkinter.Entry(f, background='white')
tapLabel.pack(side=Tkinter.LEFT)
self.tapfile.pack(side=Tkinter.LEFT)
tapButton.pack(side=Tkinter.LEFT)
f.pack(side=Tkinter.TOP, anchor=Tkinter.E)
f = Tkinter.Frame(appFrame)
nameLabel = Tkinter.Label(f, text='Application Process Name')
self.appname = Tkinter.Entry(f, background='white')
nameLabel.pack(side=Tkinter.LEFT)
self.appname.pack(side=Tkinter.LEFT)
f.pack(side=Tkinter.TOP, anchor=Tkinter.E)
f = Tkinter.Frame(appFrame)
encLabel = Tkinter.Label(f, text='Passphrase')
self.passphrase = Tkinter.Entry(f, background='white')
encLabel.pack(side=Tkinter.LEFT)
self.passphrase.pack(side=Tkinter.LEFT)
f.pack(side=Tkinter.TOP, anchor=Tkinter.E)
f = Tkinter.Frame(appFrame)
self.append = Tkinter.BooleanVar()
appLabel = Tkinter.Label(f, text='Append')
appButton = Tkinter.Checkbutton(f, variable=self.append)
appLabel.pack(side=Tkinter.LEFT)
appButton.pack(side=Tkinter.LEFT)
f.pack(side=Tkinter.LEFT, anchor=Tkinter.E)
f = Tkinter.Frame(appFrame)
s = Tkinter.StringVar()
s.set(not hasattr(os, 'getuid') and '0' or str(os.getuid()))
uidLabel = Tkinter.Label(f, text='UID')
self.uid = Tkinter.Entry(f, text=s, background='white')
uidLabel.pack(side=Tkinter.LEFT)
self.uid.pack(side=Tkinter.LEFT)
f.pack(side=Tkinter.BOTTOM)
f = Tkinter.Frame(appFrame)
s = Tkinter.StringVar()
s.set(not hasattr(os, 'getgid') and '0' or str(os.getgid()))
gidLabel = Tkinter.Label(f, text='GID')
self.gid = Tkinter.Entry(f, text=s, background='white')
gidLabel.pack(side=Tkinter.LEFT)
self.gid.pack(side=Tkinter.LEFT)
f.pack(side=Tkinter.BOTTOM)
appFrame.grid(row=0, column=0, columnspan=3, sticky=Tkinter.N + Tkinter.S)
def pickTapFile(self):
r = tkFileDialog.askopenfilename()
if r:
self.tapfile.delete(0, Tkinter.END)
self.tapfile.insert(Tkinter.END, r)
def reset(self, coil):
"""
Remove the existing coil-specific widgets and then create and add
new ones based on the given plugin object.
"""
if coil is self.coil:
return
try:
opt = coil.load().Options()
except:
f = StringIO.StringIO()
traceback.print_exc(file=f)
# XXX - Why is this so narrow?
tkMessageBox.showerror(title="Options Error", message=f.getvalue(), parent=self)
return
if self.optFrame:
self.optFrame.forget()
self.optFrame.destroy()
self.optFrame = None
self.coil = coil
self.options = opt
self.optFrame = TkConfigFrame(self, self.options)
self.optFrame.grid(row=1, column=0)
# self.tapfile.delete(0, Tkinter.END)
# try:
# self.tapfile.insert(Tkinter.END, self.coil.tapname)
# except AttributeError:
# self.tapfile.insert(Tkinter.END, self.coil.name)
def copyOptions(self):
# Snarf the data out of the widgets and place them into the Options
# instance.
extra = self.optFrame.updateConfig(self.options)
self.options['filename'] = self.tapfile.get()
self.options['appname'] = self.appname.get()
self.options['passphrase'] = self.passphrase.get()
self.options['append'] = self.append.get()
self.options['encrypted'] = len(self.options['passphrase'])
self.options['uid'] = int(self.uid.get())
self.options['gid'] = int(self.gid.get())
try:
self.options['type'] = self.typeList.curselection()[0]
except IndexError:
raise usage.UsageError("Select a TAp Format")
self.options['help'] = 0
if extra:
try:
# XXX - this is wrong. It needs to respect quotes, etc.
self.options.parseArgs(extra.split())
except TypeError:
raise usage.UsageError("Wrong number of extra arguments")
self.options.postOptions()
def createApplication(self):
if not self.options:
tkMessageBox.showerror(message="Select an Application first")
return
try:
self.copyOptions()
except usage.UsageError, e:
tkMessageBox.showerror(message=str(e))
return
exists = os.path.exists(self.options['filename'])
if self.options['append'] and exists:
a = service.loadApplication(
self.options['filename'],
self.options['type'],
self.options['passphrase']
)
else:
if exists:
overwrite = tkMessageBox.askyesno(title='File Exists', message='Overwrite?')
if not overwrite:
return
a = service.Application(self.coil.name, self.options['uid'], self.options['gid'])
try:
s = mktap.makeService(
self.coil.load(),
self.options['appname'],
self.options
)
except usage.UsageError:
f = StringIO.StringIO()
traceback.print_stack(file=f)
tkMessageBox.showerror(title="Usage Error", message=f.getvalue(), parent=self)
else:
try:
mktap.addToApplication(
s, self.coil.name, self.options['append'],
self.options['appname'], self.options['type'],
self.options['encrypted'], self.options['uid'],
self.options['gid'],
)
except:
f = StringIO.StringIO()
traceback.print_exc(file=f)
print f.getvalue()
tkMessageBox.showerror(title="Usage Error", message=f.getvalue(), parent=self)
else:
filename = self.options['filename']
if not filename:
filename = self.coil.name
tkMessageBox.showinfo(message="Wrote " + filename)
def destroy(self):
reactor.crash()
Tkinter.Frame.destroy(self)
#
# This class was written based on code from Drew "drewp" Pertulla
# (<drewp (at) bigasterisk (dot) com>) - without his help, tkmktap
# would be an ugly POS.
#
class ParameterLine(Tkinter.Frame):
def __init__(self, master, lines, label, desc, default, cmd, **kw):
Tkinter.Frame.__init__(self, master, relief='raised', bd=1, **kw)
self.lines = lines
l = Tkinter.Label(
self, text=label, wraplen=200,
width=30, anchor='w', justify='left'
)
s = Tkinter.StringVar()
if default:
s.set(default)
self.entry = Tkinter.Entry(self, text=s, background='white')
self.flag = label
more = Tkinter.Button(
self, text='+',
command=lambda f = cmd, a = label, b = default, c = desc: f(a, b, c)
)
l.pack(side=Tkinter.LEFT, fill='y')
self.entry.pack(side=Tkinter.LEFT)
more.pack(side=Tkinter.LEFT)
l.bind("<Enter>", self.highlight)
l.bind("<Leave>", self.unhighlight)
l.bind("<ButtonPress-1>", self.press)
l.bind("<B1-ButtonRelease>", self.release)
l.bind("<B1-Motion>", self.motion)
def highlight(self, ev, hicolor = 'gray90'):
# make the label light up when you mouseover
ev.widget._oldcolor = self.cget('bg')
ev.widget.config(bg=hicolor)
def unhighlight(self, ev):
# make the label return to its old setting
try:
ev.widget.config(bg=ev.widget._oldcolor)
del ev.widget._oldcolor
except:
pass
# make the frame change order when you drag it (by its label)
def press(self, ev):
# save old attrs
self._oldrelief = self.cget('relief'), self.cget('bd')
# thicken the border
self.config(relief='raised', bd=3)
def motion(self, ev):
this = self.lines.index(self)
framey = ev.y + self.winfo_y() # get mouse y coord in parent frame
replace = this # replace will be the index of the row to swap with
for i, l in zip(range(len(self.lines)), self.lines):
y1 = l.winfo_y()
y2 = y1 + l.winfo_height()
if y1 < framey < y2:
replace = i
if replace != this:
# we moved over another row-- swap them
self.lines[replace], self.lines[this] = self.lines[this], self.lines[replace]
# and re-assign all rows in the new order
for i, l in zip(range(len(self.lines)), self.lines):
l.grid(row=i, column=0)
def release(self, ev):
# restore the old border width
try:
rel, bd = self._oldrelief
self.config(relief=rel, bd=bd)
del self._oldrelief
except:
pass
class TkConfigFrame(Tkinter.Frame):
optFrame = None
paramFrame = None
commandFrame = None
subCmdFrame = None
previousCommand = None
optFlags = None
paramLines = None
def __init__(self, master, options):
Tkinter.Frame.__init__(self, master)
self.options = options
self.setupOptFlags()
self.setupOptParameters()
self.setupSubCommands()
self.setupExtra()
def getOptFlags(self):
return self.optFlags
def getOptParameters(self):
r = []
for p in self.paramLines:
r.append((p.flag, p.entry.get()))
return r
def updateConfig(self, options):
for (opt, var) in self.getOptFlags():
var = var.get()
if not var:
continue # XXX - this is poor - add a '-' button to remove options
f = getattr(options, 'opt_' + opt, None)
if f:
f()
else:
options[opt] = var
for (opt, var) in self.getOptParameters():
if not var:
continue # XXX - this is poor - add a '-' button to remove options
f = getattr(options, 'opt_' + opt, None)
if f:
f(var)
else:
options[opt] = var
return self.extra.get()
def setupOptFlags(self):
self.optFlags = []
flags = []
if hasattr(self.options, 'optFlags'):
flags.extend(self.options.optFlags)
d = {}
soFar = {}
for meth in reflect.prefixedMethodNames(self.options.__class__, 'opt_'):
full = 'opt_' + meth
func = getattr(self.options, full)
if not usage.flagFunction(func) or meth in ('help', 'version'):
continue
if soFar.has_key(func):
continue
soFar[func] = 1
existing = d.setdefault(func, meth)
if existing != meth:
if len(existing) < len(meth):
d[func] = meth
for (func, name) in d.items():
flags.append((name, None, func.__doc__))
if len(flags):
self.optFrame = f = Tkinter.Frame(self)
for (flag, _, desc) in flags:
b = Tkinter.BooleanVar()
c = Tkinter.Checkbutton(f, text=desc, variable=b, wraplen=200)
c.pack(anchor=Tkinter.W)
self.optFlags.append((flag, b))
f.grid(row=1, column=1)
def setupOptParameters(self):
params = []
if hasattr(self.options, 'optParameters'):
params.extend(self.options.optParameters)
d = {}
soFar = {}
for meth in reflect.prefixedMethodNames(self.options.__class__, 'opt_'):
full = 'opt_' + meth
func = getattr(self.options, full)
if usage.flagFunction(func) or soFar.has_key(func):
continue
soFar[func] = 1
existing = d.setdefault(func, meth)
if existing != meth:
if len(existing) < len(meth):
d[func] = meth
for (func, name) in d.items():
params.append((name, None, None, func.__doc__))
if len(params):
self.paramFrame = Tkinter.Frame(self)
self.paramLines = []
for (flag, _, default, desc) in params:
try:
default = self.options[flag]
except KeyError:
pass
self.makeField(flag, default, desc)
self.paramFrame.grid(row=1, column=2)
def makeField(self, flag, default, desc):
line = ParameterLine(
self.paramFrame, self.paramLines, flag, desc, default,
cmd=self.makeField
)
self.paramLines.append(line)
line.grid(row=len(self.paramLines), column=0)
def setupSubCommands(self):
self.optMap = {}
if hasattr(self.options, 'subCommands'):
self.commandFrame = f = Tkinter.Frame(self)
self.cmdList = Tkinter.Listbox(f)
for (cmd, _, opt, desc) in self.options.subCommands:
self.cmdList.insert(Tkinter.END, cmd)
self.optMap[cmd] = opt()
self.cmdList.pack()
self.subCmdPoll = reactor.callLater(0.1, self.pollSubCommands)
f.grid(row=1, column=3)
def setupExtra(self):
f = Tkinter.Frame(self)
l = Tkinter.Label(f, text='Extra Options')
self.extra = Tkinter.Entry(f, background='white')
l.pack()
self.extra.pack(fill='y')
f.grid(row=2, column=1, columnspan=2)
def pollSubCommands(self):
s = self.cmdList.curselection()
if len(s):
s = s[0]
if s != self.previousCommand:
if self.subOptFrame:
self.subOptFrame.forget()
self.subOptFrame.destroy()
self.subOptFrame = TkConfigFrame(self.commandFrame, self.optMap[s])
self.subOptFrame.pack()
self.subCmdPoll = reactor.callLater(0.1, self.pollSubCommands)
class TkAppMenu(Tkinter.Menu):
def __init__(self, master, create, callback, items):
Tkinter.Menu.__init__(self, master)
cmdMenu = Tkinter.Menu(self)
self.add_cascade(label="Actions", menu=cmdMenu)
cmdMenu.add_command(label='Create', command=create)
cmdMenu.add_separator()
cmdMenu.add_command(label='Quit', command=reactor.crash)
tapMenu = Tkinter.Menu(self)
self.add_cascade(label="Applications", menu=tapMenu)
for item in items:
tapMenu.add_command(
label=item, command=lambda i=item, c = callback: c(i)
)
def run():
taps = mktap.loadPlugins()
r = Tkinter.Tk()
r.withdraw()
keyList = taps.keys()
keyList.sort()
config = TkMkAppFrame(r, None)
menu = TkAppMenu(
r,
config.createApplication,
lambda i, d = taps, c = config: c.reset(d[i]),
keyList
)
config.pack()
r['menu'] = menu
r.title('Twisted Application Maker ' + version)
r.deiconify()
tksupport.install(r)
reactor.run()
if __name__ == '__main__':
run()
|
gpl-3.0
|
[
199,
3,
1898,
334,
67,
9,
12521,
13,
15431,
17078,
8449,
26640,
14,
199,
3,
1666,
5113,
367,
2436,
14,
199,
199,
3,
199,
199,
624,
7921,
859,
367,
314,
3343,
2652,
1015,
402,
314,
658,
3880,
16609,
64,
1414,
14,
199,
624,
199,
199,
3,
6187,
8925,
199,
646,
16826,
12,
10157,
13695,
12,
10157,
25213,
12,
5228,
12,
747,
199,
646,
5190,
199,
199,
3,
17078,
8925,
199,
504,
7390,
14,
3578,
492,
2435,
199,
504,
7390,
14,
4901,
492,
10157,
4058,
12,
9655,
199,
504,
7390,
14,
6429,
492,
21825,
439,
199,
504,
7390,
14,
1548,
492,
4503,
12,
16806,
199,
504,
7390,
14,
7307,
492,
1015,
421,
199,
533,
12435,
31506,
2640,
3160,
8,
15189,
1058,
14,
3160,
304,
272,
408,
272,
437,
2787,
543,
1006,
314,
5784,
11114,
370,
7908,
282,
17078,
13515,
14,
272,
408,
339,
327,
11349,
5544,
4895,
272,
512,
382,
275,
488,
2286,
327,
8394,
1256,
5544,
9080,
272,
1511,
275,
488,
339,
327,
11726,
1511,
787,
9080,
315,
272,
2450,
3160,
275,
488,
339,
347,
636,
826,
721,
277,
12,
5288,
12,
512,
382,
304,
267,
16826,
14,
3160,
855,
826,
721,
277,
12,
5288,
9,
398,
291,
14,
2758,
31506,
27746,
342,
267,
291,
14,
3958,
8,
331,
382,
9,
2378,
347,
3272,
31506,
27746,
8,
277,
304,
267,
327,
2790,
1006,
402,
314,
298,
3880,
16609,
2,
945,
11114,
267,
1145,
3160,
275,
16826,
14,
3160,
8,
277,
9,
398,
289,
275,
16826,
14,
3160,
8,
571,
3160,
9,
267,
769,
4314,
275,
16826,
14,
4314,
8,
70,
12,
1318,
534,
6166,
80,
9701,
358,
267,
291,
14,
466,
1296,
275,
16826,
14,
1296,
1977,
8,
70,
12,
8020,
534,
7510,
358,
267,
291,
14,
466,
1296,
459,
3333,
418,
275,
650,
267,
367,
307,
315,
661,
8092,
297,
283,
1652,
297,
283,
1365,
735,
288,
291,
14,
466,
1296,
14,
3176,
8,
15189,
1058,
14,
3902,
12,
307,
9,
267,
291,
14,
466,
1296,
14,
5592,
63,
409,
8,
16,
9,
398,
769,
4314,
14,
1389,
8,
2441,
29,
15189,
1058,
14,
11422,
9,
267,
291,
14,
466,
1296,
14,
1389,
8,
2441,
29,
15189,
1058,
14,
11422,
9,
267,
289,
14,
1389,
8,
2441,
29,
15189,
1058,
14,
9894,
12,
12514,
29,
15189,
1058,
14,
46,
9,
398,
289,
275,
16826,
14,
3160,
8,
571,
3160,
9,
267,
24410,
4314,
275,
16826,
14,
4314,
8,
70,
12,
1318,
534,
6166,
80,
31167,
358,
267,
24410,
4259,
275,
16826,
14,
4259,
8,
70,
12,
1318,
628,
23932,
401,
1414,
29,
277,
14,
4510,
27746,
1173,
9,
267,
291,
14,
16609,
493,
275,
16826,
14,
3900,
8,
70,
12,
8020,
534,
7510,
358,
398,
24410,
4314,
14,
1389,
8,
2441,
29,
15189,
1058,
14,
9894,
9,
267,
291,
14,
16609,
493,
14,
1389,
8,
2441,
29,
15189,
1058,
14,
9894,
9,
267,
24410,
4259,
14,
1389,
8,
2441,
29,
15189,
1058,
14,
9894,
9,
267,
289,
14,
1389,
8,
2441,
29,
15189,
1058,
14,
11422,
12,
12514,
29,
15189,
1058,
14,
37,
9,
398,
289,
275,
16826,
14,
3160,
8,
571,
3160,
9,
267,
536,
4314,
275,
16826,
14,
4314,
8,
70,
12,
1318,
534,
5039,
7132,
2812,
358,
267,
291,
14,
21653,
275,
16826,
14,
3900,
8,
70,
12,
8020,
534,
7510,
358,
398,
536,
4314,
14,
1389,
8,
2441,
29,
15189,
1058,
14,
9894,
9,
267,
291,
14,
21653,
14,
1389,
8,
2441,
29,
15189,
1058,
14,
9894,
9,
267,
289,
14,
1389,
8,
2441,
29,
15189,
1058,
14,
11422,
12,
12514,
29,
15189,
1058,
14,
37,
9,
398,
289,
275,
16826,
14,
3160,
8,
571,
3160,
9,
267,
12011,
4314,
275,
16826,
14,
4314,
8,
70,
12,
1318,
534,
4986,
10906,
358,
267,
291,
14,
25173,
275,
16826,
14,
3900,
8,
70,
12,
8020,
534,
7510,
358,
398,
12011,
4314,
14,
1389,
8,
2441,
29,
15189,
1058,
14,
9894,
9,
267,
291,
14,
25173,
14,
1389,
8,
2441,
29,
15189,
1058,
14,
9894,
9,
267,
289,
14,
1389,
8,
2441,
29,
15189,
1058,
14,
11422,
12,
12514,
29,
15189,
1058,
14,
37,
9,
398,
289,
275,
16826,
14,
3160,
8,
571,
3160,
9,
267,
291,
14,
740,
275,
16826,
14,
4082,
5894,
342,
267,
1145,
4314,
275,
16826,
14,
4314,
8,
70,
12,
1318,
534,
8310,
358,
267,
1145,
4259,
275,
16826,
14,
1799,
3887,
8,
70,
12,
1750,
29,
277,
14,
740,
9,
398,
1145,
4314,
14,
1389,
8,
2441,
29,
15189,
1058,
14,
9894,
9,
267,
1145,
4259,
14,
1389,
8,
2441,
29,
15189,
1058,
14,
9894,
9,
267,
289,
14,
1389,
8,
2441,
29,
15189,
1058,
14,
9894,
12,
12514,
29,
15189,
1058,
14,
37,
9,
398,
289,
275,
16826,
14,
3160,
8,
571,
3160,
9,
267,
308,
275,
16826,
14,
1558,
5894,
342,
267,
308,
14,
409,
8,
1397,
2688,
8,
736,
12,
283,
362,
1535,
358,
436,
283,
16,
7,
503,
620,
8,
736,
14,
362,
1535,
4059,
267,
1747,
4314,
275,
16826,
14,
4314,
8,
70,
12,
1318,
534,
6685,
358,
267,
291,
14,
1535,
275,
16826,
14,
3900,
8,
70,
12,
1318,
29,
83,
12,
8020,
534,
7510,
358,
398,
1747,
4314,
14,
1389,
8,
2441,
29,
15189,
1058,
14,
9894,
9,
267,
291,
14,
1535,
14,
1389,
8,
2441,
29,
15189,
1058,
14,
9894,
9,
267,
289,
14,
1389,
8,
2441,
29,
15189,
1058,
14,
27838,
9,
398,
289,
275,
16826,
14,
3160,
8,
571,
3160,
9,
267,
308,
275,
16826,
14,
1558,
5894,
342,
267,
308,
14,
409,
8,
1397,
2688,
8,
736,
12,
283,
362,
8787,
358,
436,
283,
16,
7,
503,
620,
8,
736,
14,
362,
8787,
4059,
267,
15122,
4314,
275,
16826,
14,
4314,
8,
70,
12,
1318,
534,
39,
998,
358,
267,
291,
14,
8787,
275,
16826,
14,
3900,
8,
70,
12,
1318,
29,
83,
12,
8020,
534,
7510,
358,
398,
15122,
4314,
14,
1389,
8,
2441,
29,
15189,
1058,
14,
9894,
9,
267,
291,
14,
8787,
14,
1389,
8,
2441,
29,
15189,
1058,
14,
9894,
9,
267,
289,
14,
1389,
8,
2441,
29,
15189,
1058,
14,
27838,
9,
398,
1145,
3160,
14,
3825,
8,
1143,
29,
16,
12,
2763,
29,
16,
12,
4362,
10384,
29
] |
[
3,
1898,
334,
67,
9,
12521,
13,
15431,
17078,
8449,
26640,
14,
199,
3,
1666,
5113,
367,
2436,
14,
199,
199,
3,
199,
199,
624,
7921,
859,
367,
314,
3343,
2652,
1015,
402,
314,
658,
3880,
16609,
64,
1414,
14,
199,
624,
199,
199,
3,
6187,
8925,
199,
646,
16826,
12,
10157,
13695,
12,
10157,
25213,
12,
5228,
12,
747,
199,
646,
5190,
199,
199,
3,
17078,
8925,
199,
504,
7390,
14,
3578,
492,
2435,
199,
504,
7390,
14,
4901,
492,
10157,
4058,
12,
9655,
199,
504,
7390,
14,
6429,
492,
21825,
439,
199,
504,
7390,
14,
1548,
492,
4503,
12,
16806,
199,
504,
7390,
14,
7307,
492,
1015,
421,
199,
533,
12435,
31506,
2640,
3160,
8,
15189,
1058,
14,
3160,
304,
272,
408,
272,
437,
2787,
543,
1006,
314,
5784,
11114,
370,
7908,
282,
17078,
13515,
14,
272,
408,
339,
327,
11349,
5544,
4895,
272,
512,
382,
275,
488,
2286,
327,
8394,
1256,
5544,
9080,
272,
1511,
275,
488,
339,
327,
11726,
1511,
787,
9080,
315,
272,
2450,
3160,
275,
488,
339,
347,
636,
826,
721,
277,
12,
5288,
12,
512,
382,
304,
267,
16826,
14,
3160,
855,
826,
721,
277,
12,
5288,
9,
398,
291,
14,
2758,
31506,
27746,
342,
267,
291,
14,
3958,
8,
331,
382,
9,
2378,
347,
3272,
31506,
27746,
8,
277,
304,
267,
327,
2790,
1006,
402,
314,
298,
3880,
16609,
2,
945,
11114,
267,
1145,
3160,
275,
16826,
14,
3160,
8,
277,
9,
398,
289,
275,
16826,
14,
3160,
8,
571,
3160,
9,
267,
769,
4314,
275,
16826,
14,
4314,
8,
70,
12,
1318,
534,
6166,
80,
9701,
358,
267,
291,
14,
466,
1296,
275,
16826,
14,
1296,
1977,
8,
70,
12,
8020,
534,
7510,
358,
267,
291,
14,
466,
1296,
459,
3333,
418,
275,
650,
267,
367,
307,
315,
661,
8092,
297,
283,
1652,
297,
283,
1365,
735,
288,
291,
14,
466,
1296,
14,
3176,
8,
15189,
1058,
14,
3902,
12,
307,
9,
267,
291,
14,
466,
1296,
14,
5592,
63,
409,
8,
16,
9,
398,
769,
4314,
14,
1389,
8,
2441,
29,
15189,
1058,
14,
11422,
9,
267,
291,
14,
466,
1296,
14,
1389,
8,
2441,
29,
15189,
1058,
14,
11422,
9,
267,
289,
14,
1389,
8,
2441,
29,
15189,
1058,
14,
9894,
12,
12514,
29,
15189,
1058,
14,
46,
9,
398,
289,
275,
16826,
14,
3160,
8,
571,
3160,
9,
267,
24410,
4314,
275,
16826,
14,
4314,
8,
70,
12,
1318,
534,
6166,
80,
31167,
358,
267,
24410,
4259,
275,
16826,
14,
4259,
8,
70,
12,
1318,
628,
23932,
401,
1414,
29,
277,
14,
4510,
27746,
1173,
9,
267,
291,
14,
16609,
493,
275,
16826,
14,
3900,
8,
70,
12,
8020,
534,
7510,
358,
398,
24410,
4314,
14,
1389,
8,
2441,
29,
15189,
1058,
14,
9894,
9,
267,
291,
14,
16609,
493,
14,
1389,
8,
2441,
29,
15189,
1058,
14,
9894,
9,
267,
24410,
4259,
14,
1389,
8,
2441,
29,
15189,
1058,
14,
9894,
9,
267,
289,
14,
1389,
8,
2441,
29,
15189,
1058,
14,
11422,
12,
12514,
29,
15189,
1058,
14,
37,
9,
398,
289,
275,
16826,
14,
3160,
8,
571,
3160,
9,
267,
536,
4314,
275,
16826,
14,
4314,
8,
70,
12,
1318,
534,
5039,
7132,
2812,
358,
267,
291,
14,
21653,
275,
16826,
14,
3900,
8,
70,
12,
8020,
534,
7510,
358,
398,
536,
4314,
14,
1389,
8,
2441,
29,
15189,
1058,
14,
9894,
9,
267,
291,
14,
21653,
14,
1389,
8,
2441,
29,
15189,
1058,
14,
9894,
9,
267,
289,
14,
1389,
8,
2441,
29,
15189,
1058,
14,
11422,
12,
12514,
29,
15189,
1058,
14,
37,
9,
398,
289,
275,
16826,
14,
3160,
8,
571,
3160,
9,
267,
12011,
4314,
275,
16826,
14,
4314,
8,
70,
12,
1318,
534,
4986,
10906,
358,
267,
291,
14,
25173,
275,
16826,
14,
3900,
8,
70,
12,
8020,
534,
7510,
358,
398,
12011,
4314,
14,
1389,
8,
2441,
29,
15189,
1058,
14,
9894,
9,
267,
291,
14,
25173,
14,
1389,
8,
2441,
29,
15189,
1058,
14,
9894,
9,
267,
289,
14,
1389,
8,
2441,
29,
15189,
1058,
14,
11422,
12,
12514,
29,
15189,
1058,
14,
37,
9,
398,
289,
275,
16826,
14,
3160,
8,
571,
3160,
9,
267,
291,
14,
740,
275,
16826,
14,
4082,
5894,
342,
267,
1145,
4314,
275,
16826,
14,
4314,
8,
70,
12,
1318,
534,
8310,
358,
267,
1145,
4259,
275,
16826,
14,
1799,
3887,
8,
70,
12,
1750,
29,
277,
14,
740,
9,
398,
1145,
4314,
14,
1389,
8,
2441,
29,
15189,
1058,
14,
9894,
9,
267,
1145,
4259,
14,
1389,
8,
2441,
29,
15189,
1058,
14,
9894,
9,
267,
289,
14,
1389,
8,
2441,
29,
15189,
1058,
14,
9894,
12,
12514,
29,
15189,
1058,
14,
37,
9,
398,
289,
275,
16826,
14,
3160,
8,
571,
3160,
9,
267,
308,
275,
16826,
14,
1558,
5894,
342,
267,
308,
14,
409,
8,
1397,
2688,
8,
736,
12,
283,
362,
1535,
358,
436,
283,
16,
7,
503,
620,
8,
736,
14,
362,
1535,
4059,
267,
1747,
4314,
275,
16826,
14,
4314,
8,
70,
12,
1318,
534,
6685,
358,
267,
291,
14,
1535,
275,
16826,
14,
3900,
8,
70,
12,
1318,
29,
83,
12,
8020,
534,
7510,
358,
398,
1747,
4314,
14,
1389,
8,
2441,
29,
15189,
1058,
14,
9894,
9,
267,
291,
14,
1535,
14,
1389,
8,
2441,
29,
15189,
1058,
14,
9894,
9,
267,
289,
14,
1389,
8,
2441,
29,
15189,
1058,
14,
27838,
9,
398,
289,
275,
16826,
14,
3160,
8,
571,
3160,
9,
267,
308,
275,
16826,
14,
1558,
5894,
342,
267,
308,
14,
409,
8,
1397,
2688,
8,
736,
12,
283,
362,
8787,
358,
436,
283,
16,
7,
503,
620,
8,
736,
14,
362,
8787,
4059,
267,
15122,
4314,
275,
16826,
14,
4314,
8,
70,
12,
1318,
534,
39,
998,
358,
267,
291,
14,
8787,
275,
16826,
14,
3900,
8,
70,
12,
1318,
29,
83,
12,
8020,
534,
7510,
358,
398,
15122,
4314,
14,
1389,
8,
2441,
29,
15189,
1058,
14,
9894,
9,
267,
291,
14,
8787,
14,
1389,
8,
2441,
29,
15189,
1058,
14,
9894,
9,
267,
289,
14,
1389,
8,
2441,
29,
15189,
1058,
14,
27838,
9,
398,
1145,
3160,
14,
3825,
8,
1143,
29,
16,
12,
2763,
29,
16,
12,
4362,
10384,
29,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
google/trax
|
trax/models/rnn.py
|
1
|
9301
|
# coding=utf-8
# Copyright 2021 The Trax Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Lint as: python3
"""RNNs (recursive neural networks)."""
from trax import layers as tl
from trax.fastmath import numpy as jnp
def RNNLM(vocab_size,
d_model=512,
n_layers=2,
rnn_cell=tl.LSTMCell,
rnn_cell_d_state_multiplier=2,
dropout=0.1,
mode='train'):
"""Returns an RNN language model.
This model performs autoregressive language modeling:
- input: rank 2 tensor representing a batch of text strings via token IDs
plus padding markers; shape is (batch_size, sequence_length). The tensor
elements are integers in `range(vocab_size)`, and `0` values mark padding
positions.
- output: rank 3 tensor representing a batch of log-probability
distributions for each sequence position over possible token IDs;
shape is (batch_size, sequence_length, `vocab_size`).
Args:
vocab_size: Input vocabulary size -- each element of the input tensor
should be an integer in `range(vocab_size)`. These integers typically
represent token IDs from a vocabulary-based tokenizer.
d_model: Embedding depth throughout the model.
n_layers: Number of RNN layers.
rnn_cell: Type of RNN cell; must be a subclass of `Layer`.
rnn_cell_d_state_multiplier: Multiplier for feature depth of RNN cell
state.
dropout: Stochastic rate (probability) for dropping an activation value
when applying dropout.
mode: If `'predict'`, use fast inference; if `'train'` apply dropout.
Returns:
An RNN language model as a layer that maps from a tensor of tokens
to activations over a vocab set.
"""
if n_layers != 2: # TODO(jonni): Remove n_layers arg, if it can't vary?
raise ValueError(f'Number of layers must be set to 2; instead got'
f' {n_layers}.')
def MultiRNNCell():
"""Multi-layer RNN cell."""
return tl.Serial(
tl.Parallel([], tl.Split(n_items=n_layers)),
tl.SerialWithSideOutputs(
[rnn_cell(n_units=d_model) for _ in range(n_layers)]),
tl.Parallel([], tl.Concatenate(n_items=n_layers))
)
zero_state = tl.MakeZeroState( # pylint: disable=no-value-for-parameter
depth_multiplier=n_layers * rnn_cell_d_state_multiplier
)
return tl.Serial(
tl.ShiftRight(mode=mode),
tl.Embedding(vocab_size, d_model),
tl.Dropout(rate=dropout, mode=mode),
tl.Branch([], zero_state),
tl.Scan(MultiRNNCell(), axis=1, mode=mode),
tl.Select([0], n_in=2), # Drop RNN state.
tl.Dense(vocab_size),
)
def GRULM(vocab_size=256,
d_model=512,
n_layers=1,
mode='train'):
"""Returns a GRU (gated recurrent unit) language model.
This model performs autoregressive language modeling:
- input: rank 2 tensor representing a batch of text strings via token IDs
plus padding markers; shape is (batch_size, sequence_length). The tensor
elements are integers in `range(vocab_size)`, and `0` values mark padding
positions.
- output: rank 3 tensor representing a batch of log-probability
distributions for each sequence position over possible token IDs;
shape is (batch_size, sequence_length, `vocab_size`).
Args:
vocab_size: Input vocabulary size -- each element of the input tensor
should be an integer in `range(vocab_size)`. These integers typically
represent token IDs from a vocabulary-based tokenizer.
d_model: Embedding depth throughout the model.
n_layers: Number of GRU layers.
mode: If `'predict'`, use fast inference (and omit the right shift).
Returns:
A GRU language model as a layer that maps from a tensor of tokens
to activations over a vocab set.
"""
return tl.Serial(
tl.ShiftRight(mode=mode),
tl.Embedding(vocab_size, d_model),
[tl.GRU(d_model, mode=mode) for _ in range(n_layers)],
tl.Dense(vocab_size),
)
# TODO(jonni): Decide names (here and Transformer): input/source, output/target
# TODO(jonni): Align with Transfomer: (attention-)dropout, n-(attention-)heads
def LSTMSeq2SeqAttn(input_vocab_size=256,
target_vocab_size=256,
d_model=512,
n_encoder_layers=2,
n_decoder_layers=2,
n_attention_heads=1,
attention_dropout=0.0,
mode='train'):
"""Returns an LSTM sequence-to-sequence model with attention.
This model is an encoder-decoder that performs tokenized string-to-string
("source"-to-"target") transduction:
- inputs (2):
- source: rank 2 tensor representing a batch of text strings via token
IDs plus padding markers; shape is (batch_size, sequence_length). The
tensor elements are integers in `range(input_vocab_size)`, and `0`
values mark padding positions.
- target: rank 2 tensor representing a batch of text strings via token
IDs plus padding markers; shape is (batch_size, sequence_length). The
tensor elements are integers in `range(output_vocab_size)`, and `0`
values mark padding positions.
- output: rank 3 tensor representing a batch of log-probability
distributions for each sequence position over possible token IDs;
shape is (batch_size, sequence_length, `vocab_size`).
An example use would be to translate (tokenized) sentences from English to
German.
The model works as follows:
* Input encoder runs on the input tokens and creates activations that
are used as both keys and values in attention.
* Pre-attention decoder runs on the targets and creates
activations that are used as queries in attention.
* Attention runs on the queries, keys and values masking out input padding.
* Decoder runs on the result, followed by a cross-entropy loss.
Args:
input_vocab_size: Input vocabulary size -- each element of the input tensor
should be an integer in `range(vocab_size)`. These integers typically
represent token IDs from a vocabulary-based tokenizer.
target_vocab_size: Target vocabulary size.
d_model: Final dimension of tensors at most points in the model, including
the initial embedding output.
n_encoder_layers: Number of LSTM layers in the encoder.
n_decoder_layers: Number of LSTM layers in the decoder after attention.
n_attention_heads: Number of attention heads.
attention_dropout: Stochastic rate (probability) for dropping an activation
value when applying dropout within an attention block.
mode: If `'predict'`, use fast inference. If `'train'`, each attention block
will include dropout; else, it will pass all values through unaltered.
Returns:
An LSTM sequence-to-sequence model as a layer that maps from a
source-target tokenized text pair to activations over a vocab set.
"""
input_encoder = tl.Serial(
tl.Embedding(input_vocab_size, d_model),
[tl.LSTM(d_model) for _ in range(n_encoder_layers)],
)
pre_attention_decoder = tl.Serial(
tl.ShiftRight(mode=mode),
tl.Embedding(target_vocab_size, d_model),
tl.LSTM(d_model, mode=mode),
)
def PrepareAttentionInputs():
"""Layer that prepares queries, keys, values and mask for attention."""
def F(encoder_activations, decoder_activations, input_tokens):
keys = values = encoder_activations
queries = decoder_activations
# Mask is 1 where inputs are not padding (0) and 0 where they are padding.
mask = (input_tokens != 0)
# We need to add axes to the mask for attention heads and decoder length.
mask = jnp.reshape(mask, (mask.shape[0], 1, 1, mask.shape[1]))
# Broadcast so mask is [batch, 1 for heads, decoder-len, encoder-len].
mask = mask + jnp.zeros((1, 1, decoder_activations.shape[1], 1))
mask = mask.astype(jnp.float32)
return queries, keys, values, mask
return tl.Fn('PrepareAttentionInputs', F, n_out=4)
return tl.Serial( # in-toks, target-toks
tl.Select([0, 1, 0, 1]), # in-toks, target-toks, in-toks, target-toks
tl.Parallel(input_encoder, pre_attention_decoder),
PrepareAttentionInputs(), # q, k, v, mask, target-toks
tl.Residual(
tl.AttentionQKV(d_model, n_heads=n_attention_heads,
dropout=attention_dropout, mode=mode,
cache_KV_in_predict=True)
), # decoder-vecs, mask, target-toks
tl.Select([0, 2]), # decoder-vecs, target-toks
[tl.LSTM(d_model, mode=mode) for _ in range(n_decoder_layers)],
tl.Dense(target_vocab_size),
tl.LogSoftmax()
)
|
apache-2.0
|
[
3,
2803,
29,
1624,
13,
24,
199,
3,
1898,
499,
15385,
710,
12643,
88,
6642,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
3,
491,
442,
465,
26,
2366,
19,
199,
624,
15303,
2438,
334,
9931,
1279,
4889,
11759,
10477,
199,
199,
504,
1468,
88,
492,
9393,
465,
25168,
199,
504,
1468,
88,
14,
7015,
3442,
492,
2680,
465,
1335,
1590,
421,
199,
318,
26009,
25526,
8,
9953,
63,
890,
12,
881,
366,
63,
1238,
29,
7736,
12,
881,
302,
63,
4359,
29,
18,
12,
881,
19433,
63,
3890,
29,
5019,
14,
29805,
7608,
1697,
12,
881,
19433,
63,
3890,
63,
68,
63,
929,
63,
15812,
29,
18,
12,
881,
19795,
29,
16,
14,
17,
12,
881,
818,
534,
2834,
735,
523,
408,
3407,
376,
26009,
2637,
1402,
14,
819,
961,
1402,
18628,
28589,
25787,
2637,
1402,
316,
26,
339,
446,
1324,
26,
6915,
499,
2345,
6144,
282,
3522,
402,
1318,
3326,
4799,
1526,
11449,
489,
12254,
6273,
14327,
27,
2215,
365,
334,
2912,
63,
890,
12,
3414,
63,
1267,
680,
710,
2345,
489,
4008,
787,
9446,
315,
658,
1842,
8,
9953,
63,
890,
32124,
436,
658,
16,
64,
1338,
2216,
6273,
489,
12266,
14,
339,
446,
1072,
26,
6915,
650,
2345,
6144,
282,
3522,
402,
943,
13,
17210,
489,
10208,
367,
1924,
3414,
3421,
1806,
3962,
1526,
11449,
27,
489,
2215,
365,
334,
2912,
63,
890,
12,
3414,
63,
1267,
12,
658,
9953,
63,
890,
14963,
819,
3033,
26,
272,
11181,
63,
890,
26,
6924,
17515,
1568,
1553,
1924,
1819,
402,
314,
1324,
2345,
267,
1077,
506,
376,
3000,
315,
658,
1842,
8,
9953,
63,
890,
20414,
5723,
9446,
13609,
267,
2954,
1526,
11449,
687,
282,
17515,
13,
6788,
14803,
14,
272,
366,
63,
1238,
26,
24297,
1098,
5818,
23088,
314,
1402,
14,
272,
302,
63,
4359,
26,
4860,
402,
26009,
9393,
14,
272,
19433,
63,
3890,
26,
2434,
402,
26009,
4917,
27,
1471,
506,
282,
5516,
402,
658,
5003,
2313,
272,
19433,
63,
3890,
63,
68,
63,
929,
63,
15812,
26,
603,
2092,
5697,
367,
3878,
5818,
402,
26009,
4917,
267,
1174,
14,
272,
19795,
26,
9785,
21913,
6634,
334,
17210,
9,
367,
366,
20148,
376,
10361,
574,
267,
1380,
18876,
19795,
14,
272,
818,
26,
982,
658,
7,
6892,
7,
3559,
675,
7377,
17353,
27,
340,
658,
7,
2834,
7,
64,
4838,
19795,
14,
819,
1803,
26,
272,
1626,
26009,
2637,
1402,
465,
282,
4045,
626,
9033,
687,
282,
2345,
402,
4645,
272,
370,
32038,
1806,
282,
11181,
663,
14,
523,
408,
819,
340,
302,
63,
4359,
1137,
499,
26,
221,
327,
3254,
8,
74,
265,
8445,
304,
5852,
302,
63,
4359,
1680,
12,
340,
652,
883,
1133,
17083,
31,
272,
746,
1722,
8,
70,
7,
3259,
402,
9393,
1471,
506,
663,
370,
499,
27,
3140,
4788,
7,
2151,
289,
7,
469,
78,
63,
4359,
93,
2659,
819,
347,
6879,
32675,
837,
272,
408,
3947,
13,
1897,
26009,
4917,
1041,
272,
372,
25168,
14,
3571,
8,
267,
25168,
14,
25721,
8798,
25168,
14,
8862,
8,
78,
63,
1744,
29,
78,
63,
4359,
1826,
267,
25168,
14,
3571,
3007,
15414,
18669,
8,
288,
359,
12845,
63,
3890,
8,
78,
63,
5260,
29,
68,
63,
1238,
9,
367,
485,
315,
1425,
8,
78,
63,
4359,
16636,
267,
25168,
14,
25721,
8798,
25168,
14,
714,
10592,
8,
78,
63,
1744,
29,
78,
63,
4359,
430,
272,
776,
819,
4697,
63,
929,
275,
25168,
14,
5483,
8681,
2223,
8,
221,
327,
4287,
26,
3507,
29,
889,
13,
585,
13,
509,
13,
5329,
489,
5818,
63,
15812,
29,
78,
63,
4359,
627,
19433,
63,
3890,
63,
68,
63,
929,
63,
15812,
523,
776,
819,
372,
25168,
14,
3571,
8,
489,
25168,
14,
14379,
9121,
8,
632,
29,
632,
395,
489,
25168,
14,
27907,
8,
9953,
63,
890,
12,
366,
63,
1238,
395,
489,
25168,
14,
30662,
8,
1866,
29,
17953,
12,
818,
29,
632,
395,
489,
25168,
14,
12526,
8798,
4697,
63,
929,
395,
489,
25168,
14,
15936,
8,
3947,
32675,
1062,
3114,
29,
17,
12,
818,
29,
632,
395,
489,
25168,
14,
5446,
779,
16,
467,
302,
63,
262,
29,
18,
395,
221,
327,
18110,
26009,
1174,
14,
489,
25168,
14,
15327,
8,
9953,
63,
890,
395,
523,
776,
421,
199,
318,
21772,
1293,
45,
8,
9953,
63,
890,
29,
3912,
12,
881,
366,
63,
1238,
29,
7736,
12,
881,
302,
63,
4359,
29,
17,
12,
881,
818,
534,
2834,
735,
523,
408,
3407,
282,
598,
9500,
334,
71,
972,
295,
1818,
4137,
9,
2637,
1402,
14,
819,
961,
1402,
18628,
28589,
25787,
2637,
1402,
316,
26,
339,
446,
1324,
26,
6915,
499,
2345,
6144,
282,
3522,
402,
1318,
3326,
4799,
1526,
11449,
489,
12254,
6273,
14327,
27,
2215,
365,
334,
2912,
63,
890,
12,
3414,
63,
1267,
680,
710,
2345,
489,
4008,
787,
9446,
315,
658,
1842,
8,
9953,
63,
890,
32124,
436,
658,
16,
64,
1338,
2216,
6273,
489,
12266,
14,
339,
446,
1072,
26,
6915,
650,
2345,
6144,
282,
3522,
402,
943,
13,
17210,
489,
10208,
367,
1924,
3414,
3421,
1806,
3962,
1526,
11449,
27,
489,
2215,
365,
334,
2912,
63,
890,
12,
3414,
63,
1267,
12,
658,
9953,
63,
890,
14963,
819,
3033,
26,
272,
11181,
63,
890,
26,
6924,
17515,
1568,
1553,
1924,
1819,
402,
314,
1324,
2345,
267,
1077,
506,
376,
3000,
315,
658,
1842,
8,
9953,
63,
890,
20414,
5723,
9446,
13609,
267,
2954,
1526,
11449,
687,
282,
17515,
13,
6788,
14803
] |
[
2803,
29,
1624,
13,
24,
199,
3,
1898,
499,
15385,
710,
12643,
88,
6642,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
3,
491,
442,
465,
26,
2366,
19,
199,
624,
15303,
2438,
334,
9931,
1279,
4889,
11759,
10477,
199,
199,
504,
1468,
88,
492,
9393,
465,
25168,
199,
504,
1468,
88,
14,
7015,
3442,
492,
2680,
465,
1335,
1590,
421,
199,
318,
26009,
25526,
8,
9953,
63,
890,
12,
881,
366,
63,
1238,
29,
7736,
12,
881,
302,
63,
4359,
29,
18,
12,
881,
19433,
63,
3890,
29,
5019,
14,
29805,
7608,
1697,
12,
881,
19433,
63,
3890,
63,
68,
63,
929,
63,
15812,
29,
18,
12,
881,
19795,
29,
16,
14,
17,
12,
881,
818,
534,
2834,
735,
523,
408,
3407,
376,
26009,
2637,
1402,
14,
819,
961,
1402,
18628,
28589,
25787,
2637,
1402,
316,
26,
339,
446,
1324,
26,
6915,
499,
2345,
6144,
282,
3522,
402,
1318,
3326,
4799,
1526,
11449,
489,
12254,
6273,
14327,
27,
2215,
365,
334,
2912,
63,
890,
12,
3414,
63,
1267,
680,
710,
2345,
489,
4008,
787,
9446,
315,
658,
1842,
8,
9953,
63,
890,
32124,
436,
658,
16,
64,
1338,
2216,
6273,
489,
12266,
14,
339,
446,
1072,
26,
6915,
650,
2345,
6144,
282,
3522,
402,
943,
13,
17210,
489,
10208,
367,
1924,
3414,
3421,
1806,
3962,
1526,
11449,
27,
489,
2215,
365,
334,
2912,
63,
890,
12,
3414,
63,
1267,
12,
658,
9953,
63,
890,
14963,
819,
3033,
26,
272,
11181,
63,
890,
26,
6924,
17515,
1568,
1553,
1924,
1819,
402,
314,
1324,
2345,
267,
1077,
506,
376,
3000,
315,
658,
1842,
8,
9953,
63,
890,
20414,
5723,
9446,
13609,
267,
2954,
1526,
11449,
687,
282,
17515,
13,
6788,
14803,
14,
272,
366,
63,
1238,
26,
24297,
1098,
5818,
23088,
314,
1402,
14,
272,
302,
63,
4359,
26,
4860,
402,
26009,
9393,
14,
272,
19433,
63,
3890,
26,
2434,
402,
26009,
4917,
27,
1471,
506,
282,
5516,
402,
658,
5003,
2313,
272,
19433,
63,
3890,
63,
68,
63,
929,
63,
15812,
26,
603,
2092,
5697,
367,
3878,
5818,
402,
26009,
4917,
267,
1174,
14,
272,
19795,
26,
9785,
21913,
6634,
334,
17210,
9,
367,
366,
20148,
376,
10361,
574,
267,
1380,
18876,
19795,
14,
272,
818,
26,
982,
658,
7,
6892,
7,
3559,
675,
7377,
17353,
27,
340,
658,
7,
2834,
7,
64,
4838,
19795,
14,
819,
1803,
26,
272,
1626,
26009,
2637,
1402,
465,
282,
4045,
626,
9033,
687,
282,
2345,
402,
4645,
272,
370,
32038,
1806,
282,
11181,
663,
14,
523,
408,
819,
340,
302,
63,
4359,
1137,
499,
26,
221,
327,
3254,
8,
74,
265,
8445,
304,
5852,
302,
63,
4359,
1680,
12,
340,
652,
883,
1133,
17083,
31,
272,
746,
1722,
8,
70,
7,
3259,
402,
9393,
1471,
506,
663,
370,
499,
27,
3140,
4788,
7,
2151,
289,
7,
469,
78,
63,
4359,
93,
2659,
819,
347,
6879,
32675,
837,
272,
408,
3947,
13,
1897,
26009,
4917,
1041,
272,
372,
25168,
14,
3571,
8,
267,
25168,
14,
25721,
8798,
25168,
14,
8862,
8,
78,
63,
1744,
29,
78,
63,
4359,
1826,
267,
25168,
14,
3571,
3007,
15414,
18669,
8,
288,
359,
12845,
63,
3890,
8,
78,
63,
5260,
29,
68,
63,
1238,
9,
367,
485,
315,
1425,
8,
78,
63,
4359,
16636,
267,
25168,
14,
25721,
8798,
25168,
14,
714,
10592,
8,
78,
63,
1744,
29,
78,
63,
4359,
430,
272,
776,
819,
4697,
63,
929,
275,
25168,
14,
5483,
8681,
2223,
8,
221,
327,
4287,
26,
3507,
29,
889,
13,
585,
13,
509,
13,
5329,
489,
5818,
63,
15812,
29,
78,
63,
4359,
627,
19433,
63,
3890,
63,
68,
63,
929,
63,
15812,
523,
776,
819,
372,
25168,
14,
3571,
8,
489,
25168,
14,
14379,
9121,
8,
632,
29,
632,
395,
489,
25168,
14,
27907,
8,
9953,
63,
890,
12,
366,
63,
1238,
395,
489,
25168,
14,
30662,
8,
1866,
29,
17953,
12,
818,
29,
632,
395,
489,
25168,
14,
12526,
8798,
4697,
63,
929,
395,
489,
25168,
14,
15936,
8,
3947,
32675,
1062,
3114,
29,
17,
12,
818,
29,
632,
395,
489,
25168,
14,
5446,
779,
16,
467,
302,
63,
262,
29,
18,
395,
221,
327,
18110,
26009,
1174,
14,
489,
25168,
14,
15327,
8,
9953,
63,
890,
395,
523,
776,
421,
199,
318,
21772,
1293,
45,
8,
9953,
63,
890,
29,
3912,
12,
881,
366,
63,
1238,
29,
7736,
12,
881,
302,
63,
4359,
29,
17,
12,
881,
818,
534,
2834,
735,
523,
408,
3407,
282,
598,
9500,
334,
71,
972,
295,
1818,
4137,
9,
2637,
1402,
14,
819,
961,
1402,
18628,
28589,
25787,
2637,
1402,
316,
26,
339,
446,
1324,
26,
6915,
499,
2345,
6144,
282,
3522,
402,
1318,
3326,
4799,
1526,
11449,
489,
12254,
6273,
14327,
27,
2215,
365,
334,
2912,
63,
890,
12,
3414,
63,
1267,
680,
710,
2345,
489,
4008,
787,
9446,
315,
658,
1842,
8,
9953,
63,
890,
32124,
436,
658,
16,
64,
1338,
2216,
6273,
489,
12266,
14,
339,
446,
1072,
26,
6915,
650,
2345,
6144,
282,
3522,
402,
943,
13,
17210,
489,
10208,
367,
1924,
3414,
3421,
1806,
3962,
1526,
11449,
27,
489,
2215,
365,
334,
2912,
63,
890,
12,
3414,
63,
1267,
12,
658,
9953,
63,
890,
14963,
819,
3033,
26,
272,
11181,
63,
890,
26,
6924,
17515,
1568,
1553,
1924,
1819,
402,
314,
1324,
2345,
267,
1077,
506,
376,
3000,
315,
658,
1842,
8,
9953,
63,
890,
20414,
5723,
9446,
13609,
267,
2954,
1526,
11449,
687,
282,
17515,
13,
6788,
14803,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
umitproject/tease-o-matic
|
django/contrib/gis/gdal/prototypes/errcheck.py
|
404
|
4207
|
"""
This module houses the error-checking routines used by the GDAL
ctypes prototypes.
"""
from ctypes import c_void_p, string_at
from django.contrib.gis.gdal.error import check_err, OGRException, SRSException
from django.contrib.gis.gdal.libgdal import lgdal
# Helper routines for retrieving pointers and/or values from
# arguments passed in by reference.
def arg_byref(args, offset=-1):
"Returns the pointer argument's by-refernece value."
return args[offset]._obj.value
def ptr_byref(args, offset=-1):
"Returns the pointer argument passed in by-reference."
return args[offset]._obj
def check_bool(result, func, cargs):
"Returns the boolean evaluation of the value."
if bool(result): return True
else: return False
### String checking Routines ###
def check_const_string(result, func, cargs, offset=None):
"""
Similar functionality to `check_string`, but does not free the pointer.
"""
if offset:
check_err(result)
ptr = ptr_byref(cargs, offset)
return ptr.value
else:
return result
def check_string(result, func, cargs, offset=-1, str_result=False):
"""
Checks the string output returned from the given function, and frees
the string pointer allocated by OGR. The `str_result` keyword
may be used when the result is the string pointer, otherwise
the OGR error code is assumed. The `offset` keyword may be used
to extract the string pointer passed in by-reference at the given
slice offset in the function arguments.
"""
if str_result:
# For routines that return a string.
ptr = result
if not ptr: s = None
else: s = string_at(result)
else:
# Error-code return specified.
check_err(result)
ptr = ptr_byref(cargs, offset)
# Getting the string value
s = ptr.value
# Correctly freeing the allocated memory beind GDAL pointer
# w/the VSIFree routine.
if ptr: lgdal.VSIFree(ptr)
return s
### DataSource, Layer error-checking ###
### Envelope checking ###
def check_envelope(result, func, cargs, offset=-1):
"Checks a function that returns an OGR Envelope by reference."
env = ptr_byref(cargs, offset)
return env
### Geometry error-checking routines ###
def check_geom(result, func, cargs):
"Checks a function that returns a geometry."
# OGR_G_Clone may return an integer, even though the
# restype is set to c_void_p
if isinstance(result, (int, long)):
result = c_void_p(result)
if not result:
raise OGRException('Invalid geometry pointer returned from "%s".' % func.__name__)
return result
def check_geom_offset(result, func, cargs, offset=-1):
"Chcks the geometry at the given offset in the C parameter list."
check_err(result)
geom = ptr_byref(cargs, offset=offset)
return check_geom(geom, func, cargs)
### Spatial Reference error-checking routines ###
def check_srs(result, func, cargs):
if isinstance(result, (int, long)):
result = c_void_p(result)
if not result:
raise SRSException('Invalid spatial reference pointer returned from "%s".' % func.__name__)
return result
### Other error-checking routines ###
def check_arg_errcode(result, func, cargs):
"""
The error code is returned in the last argument, by reference.
Check its value with `check_err` before returning the result.
"""
check_err(arg_byref(cargs))
return result
def check_errcode(result, func, cargs):
"""
Check the error code returned (c_int).
"""
check_err(result)
return
def check_pointer(result, func, cargs):
"Makes sure the result pointer is valid."
if isinstance(result, (int, long)):
result = c_void_p(result)
if bool(result):
return result
else:
raise OGRException('Invalid pointer returned from "%s"' % func.__name__)
def check_str_arg(result, func, cargs):
"""
This is for the OSRGet[Angular|Linear]Units functions, which
require that the returned string pointer not be freed. This
returns both the double and tring values.
"""
dbl = result
ptr = cargs[-1]._obj
return dbl, ptr.value
|
bsd-3-clause
|
[
624,
199,
961,
859,
394,
810,
874,
314,
1125,
13,
19527,
14975,
1202,
701,
314,
15801,
199,
5577,
19393,
83,
14,
199,
624,
199,
504,
5577,
492,
286,
63,
1647,
63,
80,
12,
1059,
63,
292,
199,
504,
1639,
14,
2828,
14,
5668,
14,
11600,
14,
705,
492,
1104,
63,
1508,
12,
19746,
907,
16010,
12,
12765,
21686,
199,
504,
1639,
14,
2828,
14,
5668,
14,
11600,
14,
773,
11600,
492,
634,
11600,
199,
199,
3,
11642,
14975,
367,
23812,
21116,
436,
15,
269,
1338,
687,
221,
199,
3,
2368,
3032,
315,
701,
3659,
14,
221,
199,
318,
1680,
63,
20447,
8,
589,
12,
3268,
4022,
17,
304,
272,
298,
3407,
314,
7849,
1423,
1159,
701,
13,
21928,
685,
301,
574,
2122,
272,
372,
1249,
59,
2743,
18289,
1113,
14,
585,
199,
199,
318,
12448,
63,
20447,
8,
589,
12,
3268,
4022,
17,
304,
272,
298,
3407,
314,
7849,
1423,
3032,
315,
701,
13,
4443,
2122,
272,
372,
1249,
59,
2743,
18289,
1113,
199,
199,
318,
1104,
63,
2245,
8,
1099,
12,
2562,
12,
286,
589,
304,
272,
298,
3407,
314,
5046,
11735,
402,
314,
574,
2122,
272,
340,
2155,
8,
1099,
304,
372,
715,
272,
587,
26,
372,
756,
199,
199,
5680,
2624,
7907,
30790,
3746,
6754,
199,
318,
1104,
63,
1297,
63,
875,
8,
1099,
12,
2562,
12,
286,
589,
12,
3268,
29,
403,
304,
272,
408,
272,
20046,
9330,
370,
658,
1074,
63,
875,
3559,
1325,
1630,
440,
2867,
314,
7849,
14,
272,
408,
272,
340,
3268,
26,
267,
1104,
63,
1508,
8,
1099,
9,
267,
12448,
275,
12448,
63,
20447,
8,
67,
589,
12,
3268,
9,
267,
372,
12448,
14,
585,
272,
587,
26,
267,
372,
754,
199,
199,
318,
1104,
63,
875,
8,
1099,
12,
2562,
12,
286,
589,
12,
3268,
4022,
17,
12,
620,
63,
1099,
29,
797,
304,
272,
408,
272,
13813,
314,
1059,
1072,
2138,
687,
314,
1627,
805,
12,
436,
289,
5710,
272,
314,
1059,
7849,
17659,
701,
10904,
14,
221,
710,
658,
495,
63,
1099,
64,
4252,
272,
1443,
506,
1202,
1380,
314,
754,
365,
314,
1059,
7849,
12,
4257,
272,
314,
10904,
1125,
1233,
365,
10826,
14,
221,
710,
658,
2743,
64,
4252,
1443,
506,
1202,
272,
370,
5536,
314,
1059,
7849,
3032,
315,
701,
13,
4443,
737,
314,
1627,
272,
6014,
3268,
315,
314,
805,
2368,
14,
272,
408,
272,
340,
620,
63,
1099,
26,
267,
327,
2104,
14975,
626,
372,
282,
1059,
14,
267,
12448,
275,
754,
267,
340,
440,
12448,
26,
308,
275,
488,
267,
587,
26,
308,
275,
1059,
63,
292,
8,
1099,
9,
272,
587,
26,
267,
327,
4520,
13,
600,
372,
2013,
14,
267,
1104,
63,
1508,
8,
1099,
9,
267,
12448,
275,
12448,
63,
20447,
8,
67,
589,
12,
3268,
9,
267,
327,
20703,
314,
1059,
574,
267,
308,
275,
12448,
14,
585,
272,
327,
31057,
590,
2867,
316,
314,
17659,
4402,
506,
688,
15801,
7849,
5591,
327,
336,
15,
1589,
812,
2684,
10146,
12981,
14,
272,
340,
12448,
26,
634,
11600,
14,
54,
2684,
10146,
8,
4695,
9,
272,
372,
308,
199,
199,
5680,
24300,
12,
11915,
1125,
13,
19527,
6754,
199,
199,
5680,
29143,
7907,
6754,
199,
318,
1104,
63,
19707,
8,
1099,
12,
2562,
12,
286,
589,
12,
3268,
4022,
17,
304,
272,
298,
11834,
282,
805,
626,
2529,
376,
10904,
29143,
701,
3659,
2122,
272,
2589,
275,
12448,
63,
20447,
8,
67,
589,
12,
3268,
9,
272,
372,
2589,
199,
199,
5680,
10579,
1125,
13,
19527,
14975,
6754,
199,
318,
1104,
63,
6481,
8,
1099,
12,
2562,
12,
286,
589,
304,
272,
298,
11834,
282,
805,
626,
2529,
282,
3400,
2122,
272,
327,
10904,
63,
39,
63,
21222,
1443,
372,
376,
3000,
12,
2755,
10617,
314,
272,
327,
4618,
514,
365,
663,
370,
286,
63,
1647,
63,
80,
272,
340,
1228,
8,
1099,
12,
334,
442,
12,
1846,
2298,
267,
754,
275,
286,
63,
1647,
63,
80,
8,
1099,
9,
272,
340,
440,
754,
26,
4960,
746,
19746,
907,
16010,
360,
3364,
3400,
7849,
2138,
687,
2071,
83,
24217,
450,
2562,
855,
354,
3368,
272,
372,
754,
199,
199,
318,
1104,
63,
6481,
63,
2743,
8,
1099,
12,
2562,
12,
286,
589,
12,
3268,
4022,
17,
304,
272,
298,
1049,
5618,
314,
3400,
737,
314,
1627,
3268,
315,
314,
445,
2725,
769,
2122,
272,
1104,
63,
1508,
8,
1099,
9,
272,
9671,
275,
12448,
63,
20447,
8,
67,
589,
12,
3268,
29,
2743,
9,
272,
372,
1104,
63,
6481,
8,
6481,
12,
2562,
12,
286,
589,
9,
199,
199,
5680,
13423,
10944,
1125,
13,
19527,
14975,
6754,
199,
318,
1104,
63,
12722,
8,
1099,
12,
2562,
12,
286,
589,
304,
272,
340,
1228,
8,
1099,
12,
334,
442,
12,
1846,
2298,
267,
754,
275,
286,
63,
1647,
63,
80,
8,
1099,
9,
272,
340,
440,
754,
26,
267,
746,
12765,
21686,
360,
3364,
11469,
3659,
7849,
2138,
687,
2071,
83,
24217,
450,
2562,
855,
354,
3368,
272,
372,
754,
199,
199,
5680,
5439,
1125,
13,
19527,
14975,
6754,
199,
318,
1104,
63,
1273,
63,
1508,
600,
8,
1099,
12,
2562,
12,
286,
589,
304,
272,
408,
272,
710,
1125,
1233,
365,
2138,
315,
314,
2061,
1423,
12,
701,
3659,
14,
272,
2670,
2399,
574,
543,
658,
1074,
63,
1508,
64,
2544,
8152,
314,
754,
14,
272,
408,
272,
1104,
63,
1508,
8,
1273,
63,
20447,
8,
67,
589,
430,
272,
372,
754,
199,
199,
318,
1104,
63,
1508,
600,
8,
1099,
12,
2562,
12,
286,
589,
304,
272,
408,
272,
2670,
314,
1125,
1233,
2138,
334,
67,
63,
442,
680,
272,
408,
272,
1104,
63,
1508,
8,
1099,
9,
272,
372,
199,
199,
318,
1104,
63,
3929,
8,
1099,
12,
2562,
12,
286,
589,
304,
272,
298,
27142,
3238,
314,
754,
7849,
365,
1686,
2122,
272,
340,
1228,
8,
1099,
12,
334,
442,
12,
1846,
2298,
267,
754,
275,
286,
63,
1647,
63,
80,
8,
1099,
9,
272,
340,
2155,
8,
1099,
304,
4960,
372,
754,
272,
587,
26,
4960,
746,
19746,
907,
16010,
360,
3364,
7849,
2138,
687,
2071,
83,
4507,
450,
2562,
855,
354,
3368,
199,
199,
318,
1104,
63,
495,
63,
1273,
8,
1099,
12,
2562,
12,
286,
589
] |
[
199,
961,
859,
394,
810,
874,
314,
1125,
13,
19527,
14975,
1202,
701,
314,
15801,
199,
5577,
19393,
83,
14,
199,
624,
199,
504,
5577,
492,
286,
63,
1647,
63,
80,
12,
1059,
63,
292,
199,
504,
1639,
14,
2828,
14,
5668,
14,
11600,
14,
705,
492,
1104,
63,
1508,
12,
19746,
907,
16010,
12,
12765,
21686,
199,
504,
1639,
14,
2828,
14,
5668,
14,
11600,
14,
773,
11600,
492,
634,
11600,
199,
199,
3,
11642,
14975,
367,
23812,
21116,
436,
15,
269,
1338,
687,
221,
199,
3,
2368,
3032,
315,
701,
3659,
14,
221,
199,
318,
1680,
63,
20447,
8,
589,
12,
3268,
4022,
17,
304,
272,
298,
3407,
314,
7849,
1423,
1159,
701,
13,
21928,
685,
301,
574,
2122,
272,
372,
1249,
59,
2743,
18289,
1113,
14,
585,
199,
199,
318,
12448,
63,
20447,
8,
589,
12,
3268,
4022,
17,
304,
272,
298,
3407,
314,
7849,
1423,
3032,
315,
701,
13,
4443,
2122,
272,
372,
1249,
59,
2743,
18289,
1113,
199,
199,
318,
1104,
63,
2245,
8,
1099,
12,
2562,
12,
286,
589,
304,
272,
298,
3407,
314,
5046,
11735,
402,
314,
574,
2122,
272,
340,
2155,
8,
1099,
304,
372,
715,
272,
587,
26,
372,
756,
199,
199,
5680,
2624,
7907,
30790,
3746,
6754,
199,
318,
1104,
63,
1297,
63,
875,
8,
1099,
12,
2562,
12,
286,
589,
12,
3268,
29,
403,
304,
272,
408,
272,
20046,
9330,
370,
658,
1074,
63,
875,
3559,
1325,
1630,
440,
2867,
314,
7849,
14,
272,
408,
272,
340,
3268,
26,
267,
1104,
63,
1508,
8,
1099,
9,
267,
12448,
275,
12448,
63,
20447,
8,
67,
589,
12,
3268,
9,
267,
372,
12448,
14,
585,
272,
587,
26,
267,
372,
754,
199,
199,
318,
1104,
63,
875,
8,
1099,
12,
2562,
12,
286,
589,
12,
3268,
4022,
17,
12,
620,
63,
1099,
29,
797,
304,
272,
408,
272,
13813,
314,
1059,
1072,
2138,
687,
314,
1627,
805,
12,
436,
289,
5710,
272,
314,
1059,
7849,
17659,
701,
10904,
14,
221,
710,
658,
495,
63,
1099,
64,
4252,
272,
1443,
506,
1202,
1380,
314,
754,
365,
314,
1059,
7849,
12,
4257,
272,
314,
10904,
1125,
1233,
365,
10826,
14,
221,
710,
658,
2743,
64,
4252,
1443,
506,
1202,
272,
370,
5536,
314,
1059,
7849,
3032,
315,
701,
13,
4443,
737,
314,
1627,
272,
6014,
3268,
315,
314,
805,
2368,
14,
272,
408,
272,
340,
620,
63,
1099,
26,
267,
327,
2104,
14975,
626,
372,
282,
1059,
14,
267,
12448,
275,
754,
267,
340,
440,
12448,
26,
308,
275,
488,
267,
587,
26,
308,
275,
1059,
63,
292,
8,
1099,
9,
272,
587,
26,
267,
327,
4520,
13,
600,
372,
2013,
14,
267,
1104,
63,
1508,
8,
1099,
9,
267,
12448,
275,
12448,
63,
20447,
8,
67,
589,
12,
3268,
9,
267,
327,
20703,
314,
1059,
574,
267,
308,
275,
12448,
14,
585,
272,
327,
31057,
590,
2867,
316,
314,
17659,
4402,
506,
688,
15801,
7849,
5591,
327,
336,
15,
1589,
812,
2684,
10146,
12981,
14,
272,
340,
12448,
26,
634,
11600,
14,
54,
2684,
10146,
8,
4695,
9,
272,
372,
308,
199,
199,
5680,
24300,
12,
11915,
1125,
13,
19527,
6754,
199,
199,
5680,
29143,
7907,
6754,
199,
318,
1104,
63,
19707,
8,
1099,
12,
2562,
12,
286,
589,
12,
3268,
4022,
17,
304,
272,
298,
11834,
282,
805,
626,
2529,
376,
10904,
29143,
701,
3659,
2122,
272,
2589,
275,
12448,
63,
20447,
8,
67,
589,
12,
3268,
9,
272,
372,
2589,
199,
199,
5680,
10579,
1125,
13,
19527,
14975,
6754,
199,
318,
1104,
63,
6481,
8,
1099,
12,
2562,
12,
286,
589,
304,
272,
298,
11834,
282,
805,
626,
2529,
282,
3400,
2122,
272,
327,
10904,
63,
39,
63,
21222,
1443,
372,
376,
3000,
12,
2755,
10617,
314,
272,
327,
4618,
514,
365,
663,
370,
286,
63,
1647,
63,
80,
272,
340,
1228,
8,
1099,
12,
334,
442,
12,
1846,
2298,
267,
754,
275,
286,
63,
1647,
63,
80,
8,
1099,
9,
272,
340,
440,
754,
26,
4960,
746,
19746,
907,
16010,
360,
3364,
3400,
7849,
2138,
687,
2071,
83,
24217,
450,
2562,
855,
354,
3368,
272,
372,
754,
199,
199,
318,
1104,
63,
6481,
63,
2743,
8,
1099,
12,
2562,
12,
286,
589,
12,
3268,
4022,
17,
304,
272,
298,
1049,
5618,
314,
3400,
737,
314,
1627,
3268,
315,
314,
445,
2725,
769,
2122,
272,
1104,
63,
1508,
8,
1099,
9,
272,
9671,
275,
12448,
63,
20447,
8,
67,
589,
12,
3268,
29,
2743,
9,
272,
372,
1104,
63,
6481,
8,
6481,
12,
2562,
12,
286,
589,
9,
199,
199,
5680,
13423,
10944,
1125,
13,
19527,
14975,
6754,
199,
318,
1104,
63,
12722,
8,
1099,
12,
2562,
12,
286,
589,
304,
272,
340,
1228,
8,
1099,
12,
334,
442,
12,
1846,
2298,
267,
754,
275,
286,
63,
1647,
63,
80,
8,
1099,
9,
272,
340,
440,
754,
26,
267,
746,
12765,
21686,
360,
3364,
11469,
3659,
7849,
2138,
687,
2071,
83,
24217,
450,
2562,
855,
354,
3368,
272,
372,
754,
199,
199,
5680,
5439,
1125,
13,
19527,
14975,
6754,
199,
318,
1104,
63,
1273,
63,
1508,
600,
8,
1099,
12,
2562,
12,
286,
589,
304,
272,
408,
272,
710,
1125,
1233,
365,
2138,
315,
314,
2061,
1423,
12,
701,
3659,
14,
272,
2670,
2399,
574,
543,
658,
1074,
63,
1508,
64,
2544,
8152,
314,
754,
14,
272,
408,
272,
1104,
63,
1508,
8,
1273,
63,
20447,
8,
67,
589,
430,
272,
372,
754,
199,
199,
318,
1104,
63,
1508,
600,
8,
1099,
12,
2562,
12,
286,
589,
304,
272,
408,
272,
2670,
314,
1125,
1233,
2138,
334,
67,
63,
442,
680,
272,
408,
272,
1104,
63,
1508,
8,
1099,
9,
272,
372,
199,
199,
318,
1104,
63,
3929,
8,
1099,
12,
2562,
12,
286,
589,
304,
272,
298,
27142,
3238,
314,
754,
7849,
365,
1686,
2122,
272,
340,
1228,
8,
1099,
12,
334,
442,
12,
1846,
2298,
267,
754,
275,
286,
63,
1647,
63,
80,
8,
1099,
9,
272,
340,
2155,
8,
1099,
304,
4960,
372,
754,
272,
587,
26,
4960,
746,
19746,
907,
16010,
360,
3364,
7849,
2138,
687,
2071,
83,
4507,
450,
2562,
855,
354,
3368,
199,
199,
318,
1104,
63,
495,
63,
1273,
8,
1099,
12,
2562,
12,
286,
589,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
AkihikoITOH/capybara
|
capybara/virtualenv/lib/python2.7/site-packages/pip/req/req_install.py
|
30
|
43196
|
from __future__ import absolute_import
import logging
import os
import re
import shutil
import sys
import tempfile
import warnings
import zipfile
from distutils.util import change_root
from distutils import sysconfig
from email.parser import FeedParser
from pip._vendor import pkg_resources, six
from pip._vendor.distlib.markers import interpret as markers_interpret
from pip._vendor.six.moves import configparser
import pip.wheel
from pip.compat import native_str, WINDOWS
from pip.download import is_url, url_to_path, path_to_url, is_archive_file
from pip.exceptions import (
InstallationError, UninstallationError, UnsupportedWheel,
)
from pip.locations import (
bin_py, running_under_virtualenv, PIP_DELETE_MARKER_FILENAME, bin_user,
)
from pip.utils import (
display_path, rmtree, ask_path_exists, backup_dir, is_installable_dir,
dist_in_usersite, dist_in_site_packages, egg_link_path, make_path_relative,
call_subprocess, read_text_file, FakeFile, _make_build_dir, ensure_dir,
)
from pip.utils.deprecation import RemovedInPip8Warning
from pip.utils.logging import indent_log
from pip.req.req_uninstall import UninstallPathSet
from pip.vcs import vcs
from pip.wheel import move_wheel_files, Wheel
from pip._vendor.packaging.version import Version
logger = logging.getLogger(__name__)
def _strip_extras(path):
m = re.match(r'^(.+)(\[[^\]]+\])$', path)
extras = None
if m:
path_no_extras = m.group(1)
extras = m.group(2)
else:
path_no_extras = path
return path_no_extras, extras
class InstallRequirement(object):
def __init__(self, req, comes_from, source_dir=None, editable=False,
link=None, as_egg=False, update=True, editable_options=None,
pycompile=True, markers=None, isolated=False, options=None,
wheel_cache=None):
self.extras = ()
if isinstance(req, six.string_types):
req = pkg_resources.Requirement.parse(req)
self.extras = req.extras
self.req = req
self.comes_from = comes_from
self.source_dir = source_dir
self.editable = editable
if editable_options is None:
editable_options = {}
self.editable_options = editable_options
self._wheel_cache = wheel_cache
self.link = link
self.as_egg = as_egg
self.markers = markers
self._egg_info_path = None
# This holds the pkg_resources.Distribution object if this requirement
# is already available:
self.satisfied_by = None
# This hold the pkg_resources.Distribution object if this requirement
# conflicts with another installed distribution:
self.conflicts_with = None
# Temporary build location
self._temp_build_dir = None
# Used to store the global directory where the _temp_build_dir should
# have been created. Cf _correct_build_location method.
self._ideal_global_dir = None
# True if the editable should be updated:
self.update = update
# Set to True after successful installation
self.install_succeeded = None
# UninstallPathSet of uninstalled distribution (for possible rollback)
self.uninstalled = None
self.use_user_site = False
self.target_dir = None
self.options = options if options else {}
self.pycompile = pycompile
self.isolated = isolated
@classmethod
def from_editable(cls, editable_req, comes_from=None, default_vcs=None,
isolated=False, options=None, wheel_cache=None):
from pip.index import Link
name, url, extras_override, editable_options = parse_editable(
editable_req, default_vcs)
if url.startswith('file:'):
source_dir = url_to_path(url)
else:
source_dir = None
res = cls(name, comes_from, source_dir=source_dir,
editable=True,
link=Link(url),
editable_options=editable_options,
isolated=isolated,
options=options if options else {},
wheel_cache=wheel_cache)
if extras_override is not None:
res.extras = extras_override
return res
@classmethod
def from_line(
cls, name, comes_from=None, isolated=False, options=None,
wheel_cache=None):
"""Creates an InstallRequirement from a name, which might be a
requirement, directory containing 'setup.py', filename, or URL.
"""
from pip.index import Link
if is_url(name):
marker_sep = '; '
else:
marker_sep = ';'
if marker_sep in name:
name, markers = name.split(marker_sep, 1)
markers = markers.strip()
if not markers:
markers = None
else:
markers = None
name = name.strip()
req = None
path = os.path.normpath(os.path.abspath(name))
link = None
extras = None
if is_url(name):
link = Link(name)
else:
p, extras = _strip_extras(path)
if (os.path.isdir(p) and
(os.path.sep in name or name.startswith('.'))):
if not is_installable_dir(p):
raise InstallationError(
"Directory %r is not installable. File 'setup.py' "
"not found." % name
)
link = Link(path_to_url(p))
elif is_archive_file(p):
if not os.path.isfile(p):
logger.warning(
'Requirement %r looks like a filename, but the '
'file does not exist',
name
)
link = Link(path_to_url(p))
# it's a local file, dir, or url
if link:
# Handle relative file URLs
if link.scheme == 'file' and re.search(r'\.\./', link.url):
link = Link(
path_to_url(os.path.normpath(os.path.abspath(link.path))))
# wheel file
if link.is_wheel:
wheel = Wheel(link.filename) # can raise InvalidWheelFilename
if not wheel.supported():
raise UnsupportedWheel(
"%s is not a supported wheel on this platform." %
wheel.filename
)
req = "%s==%s" % (wheel.name, wheel.version)
else:
# set the req to the egg fragment. when it's not there, this
# will become an 'unnamed' requirement
req = link.egg_fragment
# a requirement specifier
else:
req = name
options = options if options else {}
res = cls(req, comes_from, link=link, markers=markers,
isolated=isolated, options=options,
wheel_cache=wheel_cache)
if extras:
res.extras = pkg_resources.Requirement.parse('__placeholder__' +
extras).extras
return res
def __str__(self):
if self.req:
s = str(self.req)
if self.link:
s += ' from %s' % self.link.url
else:
s = self.link.url if self.link else None
if self.satisfied_by is not None:
s += ' in %s' % display_path(self.satisfied_by.location)
if self.comes_from:
if isinstance(self.comes_from, six.string_types):
comes_from = self.comes_from
else:
comes_from = self.comes_from.from_path()
if comes_from:
s += ' (from %s)' % comes_from
return s
def __repr__(self):
return '<%s object: %s editable=%r>' % (
self.__class__.__name__, str(self), self.editable)
def populate_link(self, finder, upgrade):
"""Ensure that if a link can be found for this, that it is found.
Note that self.link may still be None - if Upgrade is False and the
requirement is already installed.
"""
if self.link is None:
self.link = finder.find_requirement(self, upgrade)
@property
def link(self):
return self._link
@link.setter
def link(self, link):
# Lookup a cached wheel, if possible.
if self._wheel_cache is None:
self._link = link
else:
self._link = self._wheel_cache.cached_wheel(link, self.name)
@property
def specifier(self):
return self.req.specifier
def from_path(self):
if self.req is None:
return None
s = str(self.req)
if self.comes_from:
if isinstance(self.comes_from, six.string_types):
comes_from = self.comes_from
else:
comes_from = self.comes_from.from_path()
if comes_from:
s += '->' + comes_from
return s
def build_location(self, build_dir):
if self._temp_build_dir is not None:
return self._temp_build_dir
if self.req is None:
# for requirement via a path to a directory: the name of the
# package is not available yet so we create a temp directory
# Once run_egg_info will have run, we'll be able
# to fix it via _correct_build_location
self._temp_build_dir = tempfile.mkdtemp('-build', 'pip-')
self._ideal_build_dir = build_dir
return self._temp_build_dir
if self.editable:
name = self.name.lower()
else:
name = self.name
# FIXME: Is there a better place to create the build_dir? (hg and bzr
# need this)
if not os.path.exists(build_dir):
logger.debug('Creating directory %s', build_dir)
_make_build_dir(build_dir)
return os.path.join(build_dir, name)
def _correct_build_location(self):
"""Move self._temp_build_dir to self._ideal_build_dir/self.req.name
For some requirements (e.g. a path to a directory), the name of the
package is not available until we run egg_info, so the build_location
will return a temporary directory and store the _ideal_build_dir.
This is only called by self.egg_info_path to fix the temporary build
directory.
"""
if self.source_dir is not None:
return
assert self.req is not None
assert self._temp_build_dir
assert self._ideal_build_dir
old_location = self._temp_build_dir
self._temp_build_dir = None
new_location = self.build_location(self._ideal_build_dir)
if os.path.exists(new_location):
raise InstallationError(
'A package already exists in %s; please remove it to continue'
% display_path(new_location))
logger.debug(
'Moving package %s from %s to new location %s',
self, display_path(old_location), display_path(new_location),
)
shutil.move(old_location, new_location)
self._temp_build_dir = new_location
self._ideal_build_dir = None
self.source_dir = new_location
self._egg_info_path = None
@property
def name(self):
if self.req is None:
return None
return native_str(self.req.project_name)
@property
def setup_py(self):
assert self.source_dir, "No source dir for %s" % self
try:
import setuptools # noqa
except ImportError:
# Setuptools is not available
raise InstallationError(
"setuptools must be installed to install from a source "
"distribution"
)
setup_file = 'setup.py'
if self.editable_options and 'subdirectory' in self.editable_options:
setup_py = os.path.join(self.source_dir,
self.editable_options['subdirectory'],
setup_file)
else:
setup_py = os.path.join(self.source_dir, setup_file)
# Python2 __file__ should not be unicode
if six.PY2 and isinstance(setup_py, six.text_type):
setup_py = setup_py.encode(sys.getfilesystemencoding())
return setup_py
def run_egg_info(self):
assert self.source_dir
if self.name:
logger.debug(
'Running setup.py (path:%s) egg_info for package %s',
self.setup_py, self.name,
)
else:
logger.debug(
'Running setup.py (path:%s) egg_info for package from %s',
self.setup_py, self.link,
)
with indent_log():
script = self._run_setup_py
script = script.replace('__SETUP_PY__', repr(self.setup_py))
script = script.replace('__PKG_NAME__', repr(self.name))
base_cmd = [sys.executable, '-c', script]
if self.isolated:
base_cmd += ["--no-user-cfg"]
egg_info_cmd = base_cmd + ['egg_info']
# We can't put the .egg-info files at the root, because then the
# source code will be mistaken for an installed egg, causing
# problems
if self.editable:
egg_base_option = []
else:
egg_info_dir = os.path.join(self.source_dir, 'pip-egg-info')
ensure_dir(egg_info_dir)
egg_base_option = ['--egg-base', 'pip-egg-info']
cwd = self.source_dir
if self.editable_options and \
'subdirectory' in self.editable_options:
cwd = os.path.join(cwd, self.editable_options['subdirectory'])
call_subprocess(
egg_info_cmd + egg_base_option,
cwd=cwd,
show_stdout=False,
command_level=logging.DEBUG,
command_desc='python setup.py egg_info')
if not self.req:
if isinstance(
pkg_resources.parse_version(self.pkg_info()["Version"]),
Version):
op = "=="
else:
op = "==="
self.req = pkg_resources.Requirement.parse(
"".join([
self.pkg_info()["Name"],
op,
self.pkg_info()["Version"],
]))
self._correct_build_location()
# FIXME: This is a lame hack, entirely for PasteScript which has
# a self-provided entry point that causes this awkwardness
_run_setup_py = """
__file__ = __SETUP_PY__
from setuptools.command import egg_info
import pkg_resources
import os
import tokenize
def replacement_run(self):
self.mkpath(self.egg_info)
installer = self.distribution.fetch_build_egg
for ep in pkg_resources.iter_entry_points('egg_info.writers'):
# require=False is the change we're making:
writer = ep.load(require=False)
if writer:
writer(self, ep.name, os.path.join(self.egg_info,ep.name))
self.find_sources()
egg_info.egg_info.run = replacement_run
exec(compile(
getattr(tokenize, 'open', open)(__file__).read().replace('\\r\\n', '\\n'),
__file__,
'exec'
))
"""
def egg_info_data(self, filename):
if self.satisfied_by is not None:
if not self.satisfied_by.has_metadata(filename):
return None
return self.satisfied_by.get_metadata(filename)
assert self.source_dir
filename = self.egg_info_path(filename)
if not os.path.exists(filename):
return None
data = read_text_file(filename)
return data
def egg_info_path(self, filename):
if self._egg_info_path is None:
if self.editable:
base = self.source_dir
else:
base = os.path.join(self.source_dir, 'pip-egg-info')
filenames = os.listdir(base)
if self.editable:
filenames = []
for root, dirs, files in os.walk(base):
for dir in vcs.dirnames:
if dir in dirs:
dirs.remove(dir)
# Iterate over a copy of ``dirs``, since mutating
# a list while iterating over it can cause trouble.
# (See https://github.com/pypa/pip/pull/462.)
for dir in list(dirs):
# Don't search in anything that looks like a virtualenv
# environment
if (
os.path.exists(
os.path.join(root, dir, 'bin', 'python')
) or
os.path.exists(
os.path.join(
root, dir, 'Scripts', 'Python.exe'
)
)):
dirs.remove(dir)
# Also don't search through tests
elif dir == 'test' or dir == 'tests':
dirs.remove(dir)
filenames.extend([os.path.join(root, dir)
for dir in dirs])
filenames = [f for f in filenames if f.endswith('.egg-info')]
if not filenames:
raise InstallationError(
'No files/directories in %s (from %s)' % (base, filename)
)
assert filenames, \
"No files/directories in %s (from %s)" % (base, filename)
# if we have more than one match, we pick the toplevel one. This
# can easily be the case if there is a dist folder which contains
# an extracted tarball for testing purposes.
if len(filenames) > 1:
filenames.sort(
key=lambda x: x.count(os.path.sep) +
(os.path.altsep and x.count(os.path.altsep) or 0)
)
self._egg_info_path = os.path.join(base, filenames[0])
return os.path.join(self._egg_info_path, filename)
def pkg_info(self):
p = FeedParser()
data = self.egg_info_data('PKG-INFO')
if not data:
logger.warning(
'No PKG-INFO file found in %s',
display_path(self.egg_info_path('PKG-INFO')),
)
p.feed(data or '')
return p.close()
_requirements_section_re = re.compile(r'\[(.*?)\]')
@property
def installed_version(self):
# Create a requirement that we'll look for inside of setuptools.
req = pkg_resources.Requirement.parse(self.name)
# We want to avoid having this cached, so we need to construct a new
# working set each time.
working_set = pkg_resources.WorkingSet()
# Get the installed distribution from our working set
dist = working_set.find(req)
# Check to see if we got an installed distribution or not, if we did
# we want to return it's version.
if dist:
return dist.version
def assert_source_matches_version(self):
assert self.source_dir
version = self.pkg_info()['version']
if version not in self.req:
logger.warning(
'Requested %s, but installing version %s',
self,
self.installed_version,
)
else:
logger.debug(
'Source in %s has version %s, which satisfies requirement %s',
display_path(self.source_dir),
version,
self,
)
def update_editable(self, obtain=True):
if not self.link:
logger.debug(
"Cannot update repository at %s; repository location is "
"unknown",
self.source_dir,
)
return
assert self.editable
assert self.source_dir
if self.link.scheme == 'file':
# Static paths don't get updated
return
assert '+' in self.link.url, "bad url: %r" % self.link.url
if not self.update:
return
vc_type, url = self.link.url.split('+', 1)
backend = vcs.get_backend(vc_type)
if backend:
vcs_backend = backend(self.link.url)
if obtain:
vcs_backend.obtain(self.source_dir)
else:
vcs_backend.export(self.source_dir)
else:
assert 0, (
'Unexpected version control type (in %s): %s'
% (self.link, vc_type))
def uninstall(self, auto_confirm=False):
"""
Uninstall the distribution currently satisfying this requirement.
Prompts before removing or modifying files unless
``auto_confirm`` is True.
Refuses to delete or modify files outside of ``sys.prefix`` -
thus uninstallation within a virtual environment can only
modify that virtual environment, even if the virtualenv is
linked to global site-packages.
"""
if not self.check_if_exists():
raise UninstallationError(
"Cannot uninstall requirement %s, not installed" % (self.name,)
)
dist = self.satisfied_by or self.conflicts_with
paths_to_remove = UninstallPathSet(dist)
develop_egg_link = egg_link_path(dist)
develop_egg_link_egg_info = '{0}.egg-info'.format(
pkg_resources.to_filename(dist.project_name))
egg_info_exists = dist.egg_info and os.path.exists(dist.egg_info)
# Special case for distutils installed package
distutils_egg_info = getattr(dist._provider, 'path', None)
# Uninstall cases order do matter as in the case of 2 installs of the
# same package, pip needs to uninstall the currently detected version
if (egg_info_exists and dist.egg_info.endswith('.egg-info') and
not dist.egg_info.endswith(develop_egg_link_egg_info)):
# if dist.egg_info.endswith(develop_egg_link_egg_info), we
# are in fact in the develop_egg_link case
paths_to_remove.add(dist.egg_info)
if dist.has_metadata('installed-files.txt'):
for installed_file in dist.get_metadata(
'installed-files.txt').splitlines():
path = os.path.normpath(
os.path.join(dist.egg_info, installed_file)
)
paths_to_remove.add(path)
# FIXME: need a test for this elif block
# occurs with --single-version-externally-managed/--record outside
# of pip
elif dist.has_metadata('top_level.txt'):
if dist.has_metadata('namespace_packages.txt'):
namespaces = dist.get_metadata('namespace_packages.txt')
else:
namespaces = []
for top_level_pkg in [
p for p
in dist.get_metadata('top_level.txt').splitlines()
if p and p not in namespaces]:
path = os.path.join(dist.location, top_level_pkg)
paths_to_remove.add(path)
paths_to_remove.add(path + '.py')
paths_to_remove.add(path + '.pyc')
elif distutils_egg_info:
warnings.warn(
"Uninstalling a distutils installed project ({0}) has been "
"deprecated and will be removed in a future version. This is "
"due to the fact that uninstalling a distutils project will "
"only partially uninstall the project.".format(self.name),
RemovedInPip8Warning,
)
paths_to_remove.add(distutils_egg_info)
elif dist.location.endswith('.egg'):
# package installed by easy_install
# We cannot match on dist.egg_name because it can slightly vary
# i.e. setuptools-0.6c11-py2.6.egg vs setuptools-0.6rc11-py2.6.egg
paths_to_remove.add(dist.location)
easy_install_egg = os.path.split(dist.location)[1]
easy_install_pth = os.path.join(os.path.dirname(dist.location),
'easy-install.pth')
paths_to_remove.add_pth(easy_install_pth, './' + easy_install_egg)
elif develop_egg_link:
# develop egg
with open(develop_egg_link, 'r') as fh:
link_pointer = os.path.normcase(fh.readline().strip())
assert (link_pointer == dist.location), (
'Egg-link %s does not match installed location of %s '
'(at %s)' % (link_pointer, self.name, dist.location)
)
paths_to_remove.add(develop_egg_link)
easy_install_pth = os.path.join(os.path.dirname(develop_egg_link),
'easy-install.pth')
paths_to_remove.add_pth(easy_install_pth, dist.location)
elif egg_info_exists and dist.egg_info.endswith('.dist-info'):
for path in pip.wheel.uninstallation_paths(dist):
paths_to_remove.add(path)
else:
logger.debug(
'Not sure how to uninstall: %s - Check: %s',
dist, dist.location)
# find distutils scripts= scripts
if dist.has_metadata('scripts') and dist.metadata_isdir('scripts'):
for script in dist.metadata_listdir('scripts'):
if dist_in_usersite(dist):
bin_dir = bin_user
else:
bin_dir = bin_py
paths_to_remove.add(os.path.join(bin_dir, script))
if WINDOWS:
paths_to_remove.add(os.path.join(bin_dir, script) + '.bat')
# find console_scripts
if dist.has_metadata('entry_points.txt'):
config = configparser.SafeConfigParser()
config.readfp(
FakeFile(dist.get_metadata_lines('entry_points.txt'))
)
if config.has_section('console_scripts'):
for name, value in config.items('console_scripts'):
if dist_in_usersite(dist):
bin_dir = bin_user
else:
bin_dir = bin_py
paths_to_remove.add(os.path.join(bin_dir, name))
if WINDOWS:
paths_to_remove.add(
os.path.join(bin_dir, name) + '.exe'
)
paths_to_remove.add(
os.path.join(bin_dir, name) + '.exe.manifest'
)
paths_to_remove.add(
os.path.join(bin_dir, name) + '-script.py'
)
paths_to_remove.remove(auto_confirm)
self.uninstalled = paths_to_remove
def rollback_uninstall(self):
if self.uninstalled:
self.uninstalled.rollback()
else:
logger.error(
"Can't rollback %s, nothing uninstalled.", self.project_name,
)
def commit_uninstall(self):
if self.uninstalled:
self.uninstalled.commit()
else:
logger.error(
"Can't commit %s, nothing uninstalled.", self.project_name,
)
def archive(self, build_dir):
assert self.source_dir
create_archive = True
archive_name = '%s-%s.zip' % (self.name, self.pkg_info()["version"])
archive_path = os.path.join(build_dir, archive_name)
if os.path.exists(archive_path):
response = ask_path_exists(
'The file %s exists. (i)gnore, (w)ipe, (b)ackup ' %
display_path(archive_path), ('i', 'w', 'b'))
if response == 'i':
create_archive = False
elif response == 'w':
logger.warning('Deleting %s', display_path(archive_path))
os.remove(archive_path)
elif response == 'b':
dest_file = backup_dir(archive_path)
logger.warning(
'Backing up %s to %s',
display_path(archive_path),
display_path(dest_file),
)
shutil.move(archive_path, dest_file)
if create_archive:
zip = zipfile.ZipFile(
archive_path, 'w', zipfile.ZIP_DEFLATED,
allowZip64=True
)
dir = os.path.normcase(os.path.abspath(self.source_dir))
for dirpath, dirnames, filenames in os.walk(dir):
if 'pip-egg-info' in dirnames:
dirnames.remove('pip-egg-info')
for dirname in dirnames:
dirname = os.path.join(dirpath, dirname)
name = self._clean_zip_name(dirname, dir)
zipdir = zipfile.ZipInfo(self.name + '/' + name + '/')
zipdir.external_attr = 0x1ED << 16 # 0o755
zip.writestr(zipdir, '')
for filename in filenames:
if filename == PIP_DELETE_MARKER_FILENAME:
continue
filename = os.path.join(dirpath, filename)
name = self._clean_zip_name(filename, dir)
zip.write(filename, self.name + '/' + name)
zip.close()
logger.info('Saved %s', display_path(archive_path))
def _clean_zip_name(self, name, prefix):
assert name.startswith(prefix + os.path.sep), (
"name %r doesn't start with prefix %r" % (name, prefix)
)
name = name[len(prefix) + 1:]
name = name.replace(os.path.sep, '/')
return name
def match_markers(self):
if self.markers is not None:
return markers_interpret(self.markers)
else:
return True
def install(self, install_options, global_options=[], root=None):
if self.editable:
self.install_editable(install_options, global_options)
return
if self.is_wheel:
version = pip.wheel.wheel_version(self.source_dir)
pip.wheel.check_compatibility(version, self.name)
self.move_wheel_files(self.source_dir, root=root)
self.install_succeeded = True
return
# Extend the list of global and install options passed on to
# the setup.py call with the ones from the requirements file.
# Options specified in requirements file override those
# specified on the command line, since the last option given
# to setup.py is the one that is used.
global_options += self.options.get('global_options', [])
install_options += self.options.get('install_options', [])
if self.isolated:
global_options = list(global_options) + ["--no-user-cfg"]
temp_location = tempfile.mkdtemp('-record', 'pip-')
record_filename = os.path.join(temp_location, 'install-record.txt')
try:
install_args = [sys.executable]
install_args.append('-c')
install_args.append(
"import setuptools, tokenize;__file__=%r;"
"exec(compile(getattr(tokenize, 'open', open)(__file__).read()"
".replace('\\r\\n', '\\n'), __file__, 'exec'))" % self.setup_py
)
install_args += list(global_options) + \
['install', '--record', record_filename]
if not self.as_egg:
install_args += ['--single-version-externally-managed']
if root is not None:
install_args += ['--root', root]
if self.pycompile:
install_args += ["--compile"]
else:
install_args += ["--no-compile"]
if running_under_virtualenv():
py_ver_str = 'python' + sysconfig.get_python_version()
install_args += ['--install-headers',
os.path.join(sys.prefix, 'include', 'site',
py_ver_str, self.name)]
logger.info('Running setup.py install for %s', self.name)
with indent_log():
call_subprocess(
install_args + install_options,
cwd=self.source_dir,
show_stdout=False,
)
if not os.path.exists(record_filename):
logger.debug('Record file %s not found', record_filename)
return
self.install_succeeded = True
if self.as_egg:
# there's no --always-unzip option we can pass to install
# command so we unable to save the installed-files.txt
return
def prepend_root(path):
if root is None or not os.path.isabs(path):
return path
else:
return change_root(root, path)
with open(record_filename) as f:
for line in f:
directory = os.path.dirname(line)
if directory.endswith('.egg-info'):
egg_info_dir = prepend_root(directory)
break
else:
logger.warning(
'Could not find .egg-info directory in install record'
' for %s',
self,
)
# FIXME: put the record somewhere
# FIXME: should this be an error?
return
new_lines = []
with open(record_filename) as f:
for line in f:
filename = line.strip()
if os.path.isdir(filename):
filename += os.path.sep
new_lines.append(
make_path_relative(
prepend_root(filename), egg_info_dir)
)
inst_files_path = os.path.join(egg_info_dir, 'installed-files.txt')
with open(inst_files_path, 'w') as f:
f.write('\n'.join(new_lines) + '\n')
finally:
if os.path.exists(record_filename):
os.remove(record_filename)
rmtree(temp_location)
def ensure_has_source_dir(self, parent_dir):
"""Ensure that a source_dir is set.
This will create a temporary build dir if the name of the requirement
isn't known yet.
:param parent_dir: The ideal pip parent_dir for the source_dir.
Generally src_dir for editables and build_dir for sdists.
:return: self.source_dir
"""
if self.source_dir is None:
self.source_dir = self.build_location(parent_dir)
return self.source_dir
def remove_temporary_source(self):
"""Remove the source files from this requirement, if they are marked
for deletion"""
if self.source_dir and os.path.exists(
os.path.join(self.source_dir, PIP_DELETE_MARKER_FILENAME)):
logger.debug('Removing source in %s', self.source_dir)
rmtree(self.source_dir)
self.source_dir = None
if self._temp_build_dir and os.path.exists(self._temp_build_dir):
rmtree(self._temp_build_dir)
self._temp_build_dir = None
def install_editable(self, install_options, global_options=()):
logger.info('Running setup.py develop for %s', self.name)
if self.isolated:
global_options = list(global_options) + ["--no-user-cfg"]
with indent_log():
# FIXME: should we do --install-headers here too?
cwd = self.source_dir
if self.editable_options and \
'subdirectory' in self.editable_options:
cwd = os.path.join(cwd, self.editable_options['subdirectory'])
call_subprocess(
[
sys.executable,
'-c',
"import setuptools, tokenize; __file__=%r; exec(compile("
"getattr(tokenize, 'open', open)(__file__).read().replace"
"('\\r\\n', '\\n'), __file__, 'exec'))" % self.setup_py
] +
list(global_options) +
['develop', '--no-deps'] +
list(install_options),
cwd=cwd,
show_stdout=False)
self.install_succeeded = True
def check_if_exists(self):
"""Find an installed distribution that satisfies or conflicts
with this requirement, and set self.satisfied_by or
self.conflicts_with appropriately.
"""
if self.req is None:
return False
try:
self.satisfied_by = pkg_resources.get_distribution(self.req)
except pkg_resources.DistributionNotFound:
return False
except pkg_resources.VersionConflict:
existing_dist = pkg_resources.get_distribution(
self.req.project_name
)
if self.use_user_site:
if dist_in_usersite(existing_dist):
self.conflicts_with = existing_dist
elif (running_under_virtualenv() and
dist_in_site_packages(existing_dist)):
raise InstallationError(
"Will not install to the user site because it will "
"lack sys.path precedence to %s in %s" %
(existing_dist.project_name, existing_dist.location)
)
else:
self.conflicts_with = existing_dist
return True
@property
def is_wheel(self):
return self.link and self.link.is_wheel
def move_wheel_files(self, wheeldir, root=None):
move_wheel_files(
self.name, self.req, wheeldir,
user=self.use_user_site,
home=self.target_dir,
root=root,
pycompile=self.pycompile,
isolated=self.isolated,
)
def get_dist(self):
"""Return a pkg_resources.Distribution built from self.egg_info_path"""
egg_info = self.egg_info_path('').rstrip('/')
base_dir = os.path.dirname(egg_info)
metadata = pkg_resources.PathMetadata(base_dir, egg_info)
dist_name = os.path.splitext(os.path.basename(egg_info))[0]
return pkg_resources.Distribution(
os.path.dirname(egg_info),
project_name=dist_name,
metadata=metadata)
def _strip_postfix(req):
"""
Strip req postfix ( -dev, 0.2, etc )
"""
# FIXME: use package_to_requirement?
match = re.search(r'^(.*?)(?:-dev|-\d.*)$', req)
if match:
# Strip off -dev, -0.2, etc.
req = match.group(1)
return req
def _build_req_from_url(url):
parts = [p for p in url.split('#', 1)[0].split('/') if p]
req = None
if parts[-2] in ('tags', 'branches', 'tag', 'branch'):
req = parts[-3]
elif parts[-1] == 'trunk':
req = parts[-2]
return req
def _build_editable_options(req):
"""
This method generates a dictionary of the query string
parameters contained in a given editable URL.
"""
regexp = re.compile(r"[\?#&](?P<name>[^&=]+)=(?P<value>[^&=]+)")
matched = regexp.findall(req)
if matched:
ret = dict()
for option in matched:
(name, value) = option
if name in ret:
raise Exception("%s option already defined" % name)
ret[name] = value
return ret
return None
def parse_editable(editable_req, default_vcs=None):
"""Parses an editable requirement into:
- a requirement name
- an URL
- extras
- editable options
Accepted requirements:
svn+http://blahblah@rev#egg=Foobar[baz]&subdirectory=version_subdir
.[some_extra]
"""
url = editable_req
extras = None
# If a file path is specified with extras, strip off the extras.
m = re.match(r'^(.+)(\[[^\]]+\])$', url)
if m:
url_no_extras = m.group(1)
extras = m.group(2)
else:
url_no_extras = url
if os.path.isdir(url_no_extras):
if not os.path.exists(os.path.join(url_no_extras, 'setup.py')):
raise InstallationError(
"Directory %r is not installable. File 'setup.py' not found." %
url_no_extras
)
# Treating it as code that has already been checked out
url_no_extras = path_to_url(url_no_extras)
if url_no_extras.lower().startswith('file:'):
if extras:
return (
None,
url_no_extras,
pkg_resources.Requirement.parse(
'__placeholder__' + extras
).extras,
{},
)
else:
return None, url_no_extras, None, {}
for version_control in vcs:
if url.lower().startswith('%s:' % version_control):
url = '%s+%s' % (version_control, url)
break
if '+' not in url:
if default_vcs:
url = default_vcs + '+' + url
else:
raise InstallationError(
'%s should either be a path to a local project or a VCS url '
'beginning with svn+, git+, hg+, or bzr+' %
editable_req
)
vc_type = url.split('+', 1)[0].lower()
if not vcs.get_backend(vc_type):
error_message = 'For --editable=%s only ' % editable_req + \
', '.join([backend.name + '+URL' for backend in vcs.backends]) + \
' is currently supported'
raise InstallationError(error_message)
try:
options = _build_editable_options(editable_req)
except Exception as exc:
raise InstallationError(
'--editable=%s error in editable options:%s' % (editable_req, exc)
)
if not options or 'egg' not in options:
req = _build_req_from_url(editable_req)
if not req:
raise InstallationError(
'--editable=%s is not the right format; it must have '
'#egg=Package' % editable_req
)
else:
req = options['egg']
package = _strip_postfix(req)
return package, url, None, options
|
mit
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
646,
2050,
199,
646,
747,
199,
646,
295,
199,
646,
5145,
199,
646,
984,
199,
646,
5549,
199,
646,
3598,
199,
646,
10392,
199,
199,
504,
7065,
14,
1974,
492,
1570,
63,
1231,
199,
504,
7065,
492,
22381,
199,
504,
3031,
14,
2087,
492,
16261,
2842,
199,
199,
504,
7305,
423,
9884,
492,
5496,
63,
4435,
12,
3816,
199,
504,
7305,
423,
9884,
14,
2686,
773,
14,
16835,
492,
15579,
465,
14327,
63,
21533,
199,
504,
7305,
423,
9884,
14,
4174,
14,
4912,
492,
21230,
199,
199,
646,
7305,
14,
11798,
199,
199,
504,
7305,
14,
5819,
492,
5438,
63,
495,
12,
20896,
1649,
5035,
199,
504,
7305,
14,
4249,
492,
365,
63,
633,
12,
1166,
63,
475,
63,
515,
12,
931,
63,
475,
63,
633,
12,
365,
63,
6404,
63,
493,
199,
504,
7305,
14,
3924,
492,
334,
272,
26866,
547,
12,
1910,
23048,
547,
12,
19022,
25663,
12,
199,
9,
199,
504,
7305,
14,
8022,
492,
334,
272,
2517,
63,
647,
12,
3879,
63,
7138,
63,
21611,
12,
510,
1772,
63,
7014,
63,
18997,
63,
15440,
12,
2517,
63,
751,
12,
199,
9,
199,
504,
7305,
14,
1208,
492,
334,
272,
2929,
63,
515,
12,
20978,
12,
7198,
63,
515,
63,
2444,
12,
6902,
63,
694,
12,
365,
63,
21762,
63,
694,
12,
272,
2917,
63,
262,
63,
30178,
12,
2917,
63,
262,
63,
2124,
63,
5154,
12,
11393,
63,
1073,
63,
515,
12,
1852,
63,
515,
63,
6188,
12,
272,
1240,
63,
5781,
12,
1586,
63,
505,
63,
493,
12,
7777,
1173,
12,
485,
1875,
63,
1506,
63,
694,
12,
4868,
63,
694,
12,
199,
9,
199,
504,
7305,
14,
1208,
14,
15383,
492,
799,
17920,
32457,
24,
3849,
199,
504,
7305,
14,
1208,
14,
4806,
492,
4363,
63,
793,
199,
504,
7305,
14,
2103,
14,
2103,
63,
19502,
492,
1910,
3174,
2042,
1084,
199,
504,
7305,
14,
15525,
492,
19827,
199,
504,
7305,
14,
11798,
492,
4057,
63,
11798,
63,
1725,
12,
26161,
199,
504,
7305,
423,
9884,
14,
27796,
14,
1023,
492,
3394,
421,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
318,
485,
1913,
63,
9975,
8,
515,
304,
272,
333,
275,
295,
14,
1431,
8,
82,
31996,
6977,
10127,
59,
16045,
2677,
7896,
566,
4268,
931,
9,
272,
13751,
275,
488,
272,
340,
333,
26,
267,
931,
63,
889,
63,
9975,
275,
333,
14,
923,
8,
17,
9,
267,
13751,
275,
333,
14,
923,
8,
18,
9,
272,
587,
26,
267,
931,
63,
889,
63,
9975,
275,
931,
339,
372,
931,
63,
889,
63,
9975,
12,
13751,
421,
199,
533,
13276,
17947,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
2648,
12,
12477,
63,
504,
12,
1350,
63,
694,
29,
403,
12,
14783,
29,
797,
12,
326,
2142,
29,
403,
12,
465,
63,
5799,
29,
797,
12,
1678,
29,
549,
12,
14783,
63,
1419,
29,
403,
12,
326,
1134,
2014,
29,
549,
12,
14327,
29,
403,
12,
23348,
29,
797,
12,
1511,
29,
403,
12,
326,
9989,
63,
1637,
29,
403,
304,
267,
291,
14,
9975,
275,
6248,
267,
340,
1228,
8,
2103,
12,
3816,
14,
875,
63,
1313,
304,
288,
2648,
275,
5496,
63,
4435,
14,
17947,
14,
1122,
8,
2103,
9,
288,
291,
14,
9975,
275,
2648,
14,
9975,
398,
291,
14,
2103,
275,
2648,
267,
291,
14,
31430,
63,
504,
275,
12477,
63,
504,
267,
291,
14,
1365,
63,
694,
275,
1350,
63,
694,
267,
291,
14,
10820,
275,
14783,
398,
340,
14783,
63,
1419,
365,
488,
26,
288,
14783,
63,
1419,
275,
1052,
398,
291,
14,
10820,
63,
1419,
275,
14783,
63,
1419,
267,
291,
423,
11798,
63,
1637,
275,
9989,
63,
1637,
267,
291,
14,
1073,
275,
2142,
267,
291,
14,
305,
63,
5799,
275,
465,
63,
5799,
267,
291,
14,
16835,
275,
14327,
267,
291,
423,
5799,
63,
815,
63,
515,
275,
488,
267,
327,
961,
15164,
314,
5496,
63,
4435,
14,
8580,
909,
340,
642,
10685,
267,
327,
365,
2575,
2808,
26,
267,
291,
14,
22878,
63,
991,
275,
488,
267,
327,
961,
10266,
314,
5496,
63,
4435,
14,
8580,
909,
340,
642,
10685,
267,
327,
18511,
543,
4573,
4903,
4084,
26,
267,
291,
14,
22654,
63,
1045,
275,
488,
267,
327,
21791,
1900,
2909,
267,
291,
423,
808,
63,
1506,
63,
694,
275,
488,
267,
327,
8051,
370,
3877,
314,
2288,
2082,
2382,
314,
485,
808,
63,
1506,
63,
694,
1077,
267,
327,
1172,
2757,
2737,
14,
445,
70,
485,
4525,
63,
1506,
63,
1985,
1083,
14,
267,
291,
423,
32564,
63,
2966,
63,
694,
275,
488,
267,
327,
715,
340,
314,
14783,
1077,
506,
4588,
26,
267,
291,
14,
873,
275,
1678,
267,
327,
2494,
370,
715,
2410,
9512,
12096,
267,
291,
14,
3174,
63,
20003,
275,
488,
267,
327,
1910,
3174,
2042,
1084,
402,
625,
7657,
4084,
334,
509,
3962,
16475,
9,
267,
291,
14,
324,
7657,
275,
488,
267,
291,
14,
1180,
63,
751,
63,
2124,
275,
756,
267,
291,
14,
1375,
63,
694,
275,
488,
267,
291,
14,
1419,
275,
1511,
340,
1511,
587,
1052,
267,
291,
14,
647,
2014,
275,
1134,
2014,
398,
291,
14,
21748,
275,
23348,
339,
768,
3744,
272,
347,
687,
63,
10820,
8,
1886,
12,
14783,
63,
2103,
12,
12477,
63,
504,
29,
403,
12,
849,
63,
15525,
29,
403,
12,
1993,
23348,
29,
797,
12,
1511,
29,
403,
12,
9989,
63,
1637,
29,
403,
304,
267,
687,
7305,
14,
1080,
492,
10967,
398,
536,
12,
1166,
12,
13751,
63,
4415,
12,
14783,
63,
1419,
275,
2198,
63,
10820,
8,
288,
14783,
63,
2103,
12,
849,
63,
15525,
9,
267,
340,
1166,
14,
2460,
360,
493,
23117,
288,
1350,
63,
694,
275,
1166,
63,
475,
63,
515,
8,
633,
9,
267,
587,
26,
288,
1350,
63,
694,
275,
488,
398,
522,
275,
843,
8,
354,
12,
12477,
63,
504,
12,
1350,
63,
694,
29,
1365,
63,
694,
12,
2116,
14783,
29,
549,
12,
2116,
2142,
29,
3834,
8,
633,
395,
2116,
14783,
63,
1419,
29,
10820,
63,
1419,
12,
2116,
23348,
29,
21748,
12,
2116,
1511,
29,
1419,
340,
1511,
587,
5479,
2116,
9989,
63
] |
[
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
646,
2050,
199,
646,
747,
199,
646,
295,
199,
646,
5145,
199,
646,
984,
199,
646,
5549,
199,
646,
3598,
199,
646,
10392,
199,
199,
504,
7065,
14,
1974,
492,
1570,
63,
1231,
199,
504,
7065,
492,
22381,
199,
504,
3031,
14,
2087,
492,
16261,
2842,
199,
199,
504,
7305,
423,
9884,
492,
5496,
63,
4435,
12,
3816,
199,
504,
7305,
423,
9884,
14,
2686,
773,
14,
16835,
492,
15579,
465,
14327,
63,
21533,
199,
504,
7305,
423,
9884,
14,
4174,
14,
4912,
492,
21230,
199,
199,
646,
7305,
14,
11798,
199,
199,
504,
7305,
14,
5819,
492,
5438,
63,
495,
12,
20896,
1649,
5035,
199,
504,
7305,
14,
4249,
492,
365,
63,
633,
12,
1166,
63,
475,
63,
515,
12,
931,
63,
475,
63,
633,
12,
365,
63,
6404,
63,
493,
199,
504,
7305,
14,
3924,
492,
334,
272,
26866,
547,
12,
1910,
23048,
547,
12,
19022,
25663,
12,
199,
9,
199,
504,
7305,
14,
8022,
492,
334,
272,
2517,
63,
647,
12,
3879,
63,
7138,
63,
21611,
12,
510,
1772,
63,
7014,
63,
18997,
63,
15440,
12,
2517,
63,
751,
12,
199,
9,
199,
504,
7305,
14,
1208,
492,
334,
272,
2929,
63,
515,
12,
20978,
12,
7198,
63,
515,
63,
2444,
12,
6902,
63,
694,
12,
365,
63,
21762,
63,
694,
12,
272,
2917,
63,
262,
63,
30178,
12,
2917,
63,
262,
63,
2124,
63,
5154,
12,
11393,
63,
1073,
63,
515,
12,
1852,
63,
515,
63,
6188,
12,
272,
1240,
63,
5781,
12,
1586,
63,
505,
63,
493,
12,
7777,
1173,
12,
485,
1875,
63,
1506,
63,
694,
12,
4868,
63,
694,
12,
199,
9,
199,
504,
7305,
14,
1208,
14,
15383,
492,
799,
17920,
32457,
24,
3849,
199,
504,
7305,
14,
1208,
14,
4806,
492,
4363,
63,
793,
199,
504,
7305,
14,
2103,
14,
2103,
63,
19502,
492,
1910,
3174,
2042,
1084,
199,
504,
7305,
14,
15525,
492,
19827,
199,
504,
7305,
14,
11798,
492,
4057,
63,
11798,
63,
1725,
12,
26161,
199,
504,
7305,
423,
9884,
14,
27796,
14,
1023,
492,
3394,
421,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
318,
485,
1913,
63,
9975,
8,
515,
304,
272,
333,
275,
295,
14,
1431,
8,
82,
31996,
6977,
10127,
59,
16045,
2677,
7896,
566,
4268,
931,
9,
272,
13751,
275,
488,
272,
340,
333,
26,
267,
931,
63,
889,
63,
9975,
275,
333,
14,
923,
8,
17,
9,
267,
13751,
275,
333,
14,
923,
8,
18,
9,
272,
587,
26,
267,
931,
63,
889,
63,
9975,
275,
931,
339,
372,
931,
63,
889,
63,
9975,
12,
13751,
421,
199,
533,
13276,
17947,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
2648,
12,
12477,
63,
504,
12,
1350,
63,
694,
29,
403,
12,
14783,
29,
797,
12,
326,
2142,
29,
403,
12,
465,
63,
5799,
29,
797,
12,
1678,
29,
549,
12,
14783,
63,
1419,
29,
403,
12,
326,
1134,
2014,
29,
549,
12,
14327,
29,
403,
12,
23348,
29,
797,
12,
1511,
29,
403,
12,
326,
9989,
63,
1637,
29,
403,
304,
267,
291,
14,
9975,
275,
6248,
267,
340,
1228,
8,
2103,
12,
3816,
14,
875,
63,
1313,
304,
288,
2648,
275,
5496,
63,
4435,
14,
17947,
14,
1122,
8,
2103,
9,
288,
291,
14,
9975,
275,
2648,
14,
9975,
398,
291,
14,
2103,
275,
2648,
267,
291,
14,
31430,
63,
504,
275,
12477,
63,
504,
267,
291,
14,
1365,
63,
694,
275,
1350,
63,
694,
267,
291,
14,
10820,
275,
14783,
398,
340,
14783,
63,
1419,
365,
488,
26,
288,
14783,
63,
1419,
275,
1052,
398,
291,
14,
10820,
63,
1419,
275,
14783,
63,
1419,
267,
291,
423,
11798,
63,
1637,
275,
9989,
63,
1637,
267,
291,
14,
1073,
275,
2142,
267,
291,
14,
305,
63,
5799,
275,
465,
63,
5799,
267,
291,
14,
16835,
275,
14327,
267,
291,
423,
5799,
63,
815,
63,
515,
275,
488,
267,
327,
961,
15164,
314,
5496,
63,
4435,
14,
8580,
909,
340,
642,
10685,
267,
327,
365,
2575,
2808,
26,
267,
291,
14,
22878,
63,
991,
275,
488,
267,
327,
961,
10266,
314,
5496,
63,
4435,
14,
8580,
909,
340,
642,
10685,
267,
327,
18511,
543,
4573,
4903,
4084,
26,
267,
291,
14,
22654,
63,
1045,
275,
488,
267,
327,
21791,
1900,
2909,
267,
291,
423,
808,
63,
1506,
63,
694,
275,
488,
267,
327,
8051,
370,
3877,
314,
2288,
2082,
2382,
314,
485,
808,
63,
1506,
63,
694,
1077,
267,
327,
1172,
2757,
2737,
14,
445,
70,
485,
4525,
63,
1506,
63,
1985,
1083,
14,
267,
291,
423,
32564,
63,
2966,
63,
694,
275,
488,
267,
327,
715,
340,
314,
14783,
1077,
506,
4588,
26,
267,
291,
14,
873,
275,
1678,
267,
327,
2494,
370,
715,
2410,
9512,
12096,
267,
291,
14,
3174,
63,
20003,
275,
488,
267,
327,
1910,
3174,
2042,
1084,
402,
625,
7657,
4084,
334,
509,
3962,
16475,
9,
267,
291,
14,
324,
7657,
275,
488,
267,
291,
14,
1180,
63,
751,
63,
2124,
275,
756,
267,
291,
14,
1375,
63,
694,
275,
488,
267,
291,
14,
1419,
275,
1511,
340,
1511,
587,
1052,
267,
291,
14,
647,
2014,
275,
1134,
2014,
398,
291,
14,
21748,
275,
23348,
339,
768,
3744,
272,
347,
687,
63,
10820,
8,
1886,
12,
14783,
63,
2103,
12,
12477,
63,
504,
29,
403,
12,
849,
63,
15525,
29,
403,
12,
1993,
23348,
29,
797,
12,
1511,
29,
403,
12,
9989,
63,
1637,
29,
403,
304,
267,
687,
7305,
14,
1080,
492,
10967,
398,
536,
12,
1166,
12,
13751,
63,
4415,
12,
14783,
63,
1419,
275,
2198,
63,
10820,
8,
288,
14783,
63,
2103,
12,
849,
63,
15525,
9,
267,
340,
1166,
14,
2460,
360,
493,
23117,
288,
1350,
63,
694,
275,
1166,
63,
475,
63,
515,
8,
633,
9,
267,
587,
26,
288,
1350,
63,
694,
275,
488,
398,
522,
275,
843,
8,
354,
12,
12477,
63,
504,
12,
1350,
63,
694,
29,
1365,
63,
694,
12,
2116,
14783,
29,
549,
12,
2116,
2142,
29,
3834,
8,
633,
395,
2116,
14783,
63,
1419,
29,
10820,
63,
1419,
12,
2116,
23348,
29,
21748,
12,
2116,
1511,
29,
1419,
340,
1511,
587,
5479,
2116,
9989,
63,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
kingthorin/zaproxy
|
docker/zap-api-scan.py
|
6
|
25656
|
#!/usr/bin/env python
# Zed Attack Proxy (ZAP) and its related class files.
#
# ZAP is an HTTP/HTTPS proxy for assessing web application security.
#
# Copyright 2017 ZAP Development Team
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# This script runs a full scan against an API defined by OpenAPI/Swagger, SOAP
# or GraphQL using ZAP.
#
# It can either be run 'standalone', in which case depends on
# https://pypi.python.org/pypi/python-owasp-zap-v2.4 and Docker, or it can be run
# inside one of the ZAP docker containers. It automatically detects if it is
# running in docker so the parameters are the same.
#
# It currently support APIS defined by:
# OpenAPI/Swagger URL
# OpenAPI/Swagger file
# SOAP URL
# SOAP File
# GraphQL URL
# GraphQL File
# It will exit with codes of:
# 0: Success
# 1: At least 1 FAIL
# 2: At least one WARN and no FAILs
# 3: Any other failure
# By default all alerts found by ZAP will be treated as WARNings.
# You can use the -c or -u parameters to specify a configuration file to override
# this.
# You can generate a template configuration file using the -g parameter. You will
# then need to change 'WARN' to 'FAIL', 'INFO' or 'IGNORE' for the rules you want
# to be handled differently.
# You can also add your own messages for the rules by appending them after a tab
# at the end of each line.
# By default the active scan rules run are hardcoded in the API-Minimal.policy
# file but you can change them by supplying a configuration file with the rules
# you dont want to be run set to IGNORE.
import getopt
import json
import logging
import os
import os.path
import subprocess
import sys
import time
from datetime import datetime
from six.moves.urllib.parse import urljoin
from zapv2 import ZAPv2
from zap_common import *
class NoUrlsException(Exception):
pass
config_dict = {}
config_msg = {}
out_of_scope_dict = {}
min_level = 0
# Scan rules that aren't really relevant, e.g. the examples rules in the alpha set
ignore_scan_rules = ['-1', '50003', '60000', '60001']
# Scan rules that are being addressed
in_progress_issues = {}
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(message)s')
# Hide "Starting new HTTP connection" messages
logging.getLogger("requests").setLevel(logging.WARNING)
def usage():
print('Usage: zap-api-scan.py -t <target> -f <format> [options]')
print(' -t target target API definition, OpenAPI or SOAP, local file or URL, e.g. https://www.example.com/openapi.json')
print(' or target endpoint URL, GraphQL, e.g. https://www.example.com/graphql')
print(' -f format openapi, soap, or graphql')
print('Options:')
print(' -h print this help message')
print(' -c config_file config file to use to INFO, IGNORE or FAIL warnings')
print(' -u config_url URL of config file to use to INFO, IGNORE or FAIL warnings')
print(' -g gen_file generate default config file(all rules set to WARN)')
print(' -r report_html file to write the full ZAP HTML report')
print(' -w report_md file to write the full ZAP Wiki(Markdown) report')
print(' -x report_xml file to write the full ZAP XML report')
print(' -J report_json file to write the full ZAP JSON document')
print(' -a include the alpha passive scan rules as well')
print(' -d show debug messages')
print(' -P specify listen port')
print(' -D delay in seconds to wait for passive scanning ')
print(' -i default rules not in the config file to INFO')
print(' -I do not return failure on warning')
print(' -l level minimum level to show: PASS, IGNORE, INFO, WARN or FAIL, use with -s to hide example URLs')
print(' -n context_file context file which will be loaded prior to scanning the target')
print(' -p progress_file progress file which specifies issues that are being addressed')
print(' -s short output format - dont show PASSes or example URLs')
print(' -S safe mode this will skip the active scan and perform a baseline scan')
print(' -T max time in minutes to wait for ZAP to start and the passive scan to run')
print(' -U user username to use for authenticated scans - must be defined in the given context file')
print(' -O the hostname to override in the (remote) OpenAPI spec')
print(' -z zap_options ZAP command line options e.g. -z "-config aaa=bbb -config ccc=ddd"')
print(' --hook path to python file that define your custom hooks')
print(' --schema GraphQL schema location, URL or file, e.g. https://www.example.com/schema.graphqls')
print('')
print('For more details see https://www.zaproxy.org/docs/docker/api-scan/')
def main(argv):
global min_level
global in_progress_issues
cid = ''
context_file = ''
progress_file = ''
config_file = ''
config_url = ''
generate = ''
port = 0
detailed_output = True
report_html = ''
report_md = ''
report_xml = ''
report_json = ''
target = ''
target_url = ''
host_override = ''
format = ''
zap_alpha = False
baseline = False
info_unspecified = False
base_dir = ''
zap_ip = 'localhost'
zap_options = ''
delay = 0
timeout = 0
ignore_warn = False
hook_file = None
schema = ''
schema_url = ''
user = ''
pass_count = 0
warn_count = 0
fail_count = 0
info_count = 0
ignore_count = 0
warn_inprog_count = 0
fail_inprog_count = 0
exception_raised = False
try:
opts, args = getopt.getopt(argv, "t:f:c:u:g:m:n:r:J:w:x:l:hdaijSp:sz:P:D:T:IO:U:", ["hook=", "schema="])
except getopt.GetoptError as exc:
logging.warning('Invalid option ' + exc.opt + ' : ' + exc.msg)
usage()
sys.exit(3)
for opt, arg in opts:
if opt == '-h':
usage()
sys.exit(0)
elif opt == '-t':
target = arg
logging.debug('Target: ' + target)
elif opt == '-f':
format = arg
elif opt == '-c':
config_file = arg
elif opt == '-u':
config_url = arg
elif opt == '-g':
generate = arg
elif opt == '-d':
logging.getLogger().setLevel(logging.DEBUG)
elif opt == '-P':
port = int(arg)
elif opt == '-D':
delay = int(arg)
elif opt == '-n':
context_file = arg
elif opt == '-p':
progress_file = arg
elif opt == '-r':
report_html = arg
elif opt == '-J':
report_json = arg
elif opt == '-w':
report_md = arg
elif opt == '-x':
report_xml = arg
elif opt == '-a':
zap_alpha = True
elif opt == '-i':
info_unspecified = True
elif opt == '-I':
ignore_warn = True
elif opt == '-l':
try:
min_level = zap_conf_lvls.index(arg)
except ValueError:
logging.warning('Level must be one of ' + str(zap_conf_lvls))
usage()
sys.exit(3)
elif opt == '-z':
zap_options = arg
elif opt == '-s':
detailed_output = False
elif opt == '-S':
baseline = True
elif opt == '-T':
timeout = int(arg)
elif opt == '-O':
host_override = arg
elif opt == '-U':
user = arg
elif opt == '--hook':
hook_file = arg
elif opt == '--schema':
schema = arg
logging.debug('Schema: ' + schema)
check_zap_client_version()
load_custom_hooks(hook_file)
trigger_hook('cli_opts', opts)
# Check target supplied and ok
if len(target) == 0:
usage()
sys.exit(3)
if format != 'openapi' and format != 'soap' and format != 'graphql':
logging.warning('Format must be either \'openapi\', \'soap\', or \'graphql\'')
usage()
sys.exit(3)
if running_in_docker():
base_dir = '/zap/wrk/'
if config_file or generate or report_html or report_xml or report_json or report_md or progress_file or context_file:
# Check directory has been mounted
if not os.path.exists(base_dir):
logging.warning('A file based option has been specified but the directory \'/zap/wrk\' is not mounted ')
usage()
sys.exit(3)
if user and not context_file:
logging.warning('A context file must be specified (and include the user) if the user option is selected')
usage()
sys.exit(3)
target_file = ''
if target.startswith('http://') or target.startswith('https://'):
target_url = target
elif format == 'graphql':
logging.warning('Target must start with \'http://\' or \'https://\' and be a valid GraphQL endpoint.')
usage()
sys.exit(3)
else:
# assume its a file
if not os.path.exists(base_dir + target):
logging.warning('Target must either start with \'http://\' or \'https://\' or be a local file')
logging.warning('File does not exist: ' + base_dir + target)
usage()
sys.exit(3)
else:
target_file = target
schema_file = ''
if schema and format == 'graphql':
if schema.startswith('http://') or schema.startswith('https://'):
schema_url = schema
else:
# assume its a file
if not os.path.exists(base_dir + schema):
logging.warning('GraphQL schema must either start with \'http://\' or \'https://\' or be a local file')
logging.warning('File does not exist: ' + base_dir + schema)
usage()
sys.exit(3)
else:
schema_file = schema
# Choose a random 'ephemeral' port and check its available if it wasn't specified with -P option
if port == 0:
port = get_free_port()
logging.debug('Using port: ' + str(port))
if config_file:
# load config file from filestore
with open(base_dir + config_file) as f:
try:
load_config(f, config_dict, config_msg, out_of_scope_dict)
except ValueError as e:
logging.warning("Failed to load config file " + base_dir + config_file + " " + str(e))
sys.exit(3)
elif config_url:
# load config file from url
try:
config_data = urlopen(config_url).read().decode('UTF-8').splitlines()
load_config(config_data, config_dict, config_msg, out_of_scope_dict)
except ValueError as e:
logging.warning("Failed to read configs from " + config_url + " " + str(e))
sys.exit(3)
except:
logging.warning('Failed to read configs from ' + config_url)
sys.exit(3)
if progress_file:
# load progress file from filestore
with open(base_dir + progress_file) as f:
progress = json.load(f)
# parse into something more useful...
# in_prog_issues = map of vulnid -> {object with everything in}
for issue in progress["issues"]:
if issue["state"] == "inprogress":
in_progress_issues[issue["id"]] = issue
if running_in_docker():
try:
params = [
'-addonupdate',
'-addoninstall', 'pscanrulesBeta'] # In case we're running in the stable container
if zap_alpha:
params.append('-addoninstall')
params.append('pscanrulesAlpha')
add_zap_options(params, zap_options)
start_zap(port, params)
except OSError:
logging.warning('Failed to start ZAP :(')
sys.exit(3)
else:
# Not running in docker, so start one
mount_dir = ''
if context_file:
mount_dir = os.path.dirname(os.path.abspath(context_file))
params = ['-addonupdate']
if (zap_alpha):
params.extend(['-addoninstall', 'pscanrulesAlpha'])
add_zap_options(params, zap_options)
try:
cid = start_docker_zap('owasp/zap2docker-weekly', port, params, mount_dir)
zap_ip = ipaddress_for_cid(cid)
logging.debug('Docker ZAP IP Addr: ' + zap_ip)
# Copy across the files that may not be in all of the docker images
try:
subprocess.check_output(['docker', 'exec', '-t', cid, 'mkdir', '-p', '/home/zap/.ZAP_D/scripts/scripts/httpsender/'])
cp_to_docker(cid, 'scripts/scripts/httpsender/Alert_on_HTTP_Response_Code_Errors.js', '/home/zap/.ZAP_D/')
cp_to_docker(cid, 'scripts/scripts/httpsender/Alert_on_Unexpected_Content_Types.js', '/home/zap/.ZAP_D/')
cp_to_docker(cid, 'policies/API-Minimal.policy', '/home/zap/.ZAP_D/')
if target_file:
cp_to_docker(cid, target_file, '/zap/')
except OSError:
logging.warning('Failed to copy one of the required files')
sys.exit(3)
except OSError:
logging.warning('Failed to start ZAP in docker :(')
sys.exit(3)
try:
zap = ZAPv2(proxies={'http': 'http://' + zap_ip + ':' + str(port), 'https': 'http://' + zap_ip + ':' + str(port)})
wait_for_zap_start(zap, timeout * 60)
trigger_hook('zap_started', zap, target)
# Make suitable performance tweaks for running in this environment
zap_tune(zap)
trigger_hook('zap_tuned', zap)
if context_file:
# handle the context file, cant use base_dir as it might not have been set up
zap_import_context(zap, '/zap/wrk/' + os.path.basename(context_file))
if (user):
zap_set_scan_user(zap, user)
# Enable scripts
zap.script.load('Alert_on_HTTP_Response_Code_Errors.js', 'httpsender', 'Oracle Nashorn', '/home/zap/.ZAP_D/scripts/scripts/httpsender/Alert_on_HTTP_Response_Code_Errors.js')
zap.script.enable('Alert_on_HTTP_Response_Code_Errors.js')
zap.script.load('Alert_on_Unexpected_Content_Types.js', 'httpsender', 'Oracle Nashorn', '/home/zap/.ZAP_D/scripts/scripts/httpsender/Alert_on_Unexpected_Content_Types.js')
zap.script.enable('Alert_on_Unexpected_Content_Types.js')
# Import the API defn
if format == 'openapi':
trigger_hook('importing_openapi', target_url, target_file)
if target_url:
logging.debug('Import OpenAPI URL ' + target_url)
res = zap.openapi.import_url(target, host_override)
urls = zap.core.urls()
if host_override:
target = urljoin(target_url, '//' + host_override)
logging.info('Using host override, new target: {0}'.format(target))
else:
logging.debug('Import OpenAPI File ' + target_file)
res = zap.openapi.import_file(base_dir + target_file)
urls = zap.core.urls()
if len(urls) > 0:
# Choose the first one - will be striping off the path below
target = urls[0]
logging.debug('Using target from imported file: {0}'.format(target))
logging.info('Number of Imported URLs: ' + str(len(urls)))
elif format == 'soap':
trigger_hook('importing_soap', target_url, target_file)
if target_url:
logging.debug('Import SOAP URL ' + target_url)
res = zap._request(zap.base + 'soap/action/importUrl/', {'url':target})
urls = zap.core.urls()
else:
logging.debug('Import SOAP File ' + target_file)
res = zap._request(zap.base + 'soap/action/importFile/', {'file': base_dir + target_file})
urls = zap.core.urls()
if len(urls) > 0:
# Choose the first one - will be striping off the path below
target = urls[0]
logging.debug('Using target from imported file: {0}'.format(target))
logging.info('Number of Imported URLs: ' + str(len(urls)))
elif format == 'graphql':
trigger_hook('importing_graphql', target, schema)
logging.debug('GraphQL Endpoint URL ' + target)
logging.info('Begin sending GraphQL requests...')
if schema:
logging.debug('Import GraphQL Schema ' + schema)
res = zap.graphql.import_file(target, base_dir + schema) if schema_file else zap.graphql.import_url(target, schema_url)
else:
res = zap.graphql.import_url(target)
logging.info('About ' + str(zap.core.number_of_messages()) + ' requests sent.')
urls = zap.core.urls()
logging.debug('Import warnings: ' + str(res))
if len(urls) == 0:
logging.warning('Failed to import any URLs')
# No point continue, there's nothing to scan.
raise NoUrlsException()
if target.count('/') > 2:
old_target = target
# The url can include a valid path, but always reset to scan the host
target = target[0:target.index('/', 8)+1]
logging.debug('Normalised target from {0} to {1}'.format(old_target, target))
# Wait for a delay if specified with -D option
if (delay):
start_scan = datetime.now()
while((datetime.now() - start_scan).seconds < delay ):
time.sleep(5)
logging.debug('Delay active scan ' + str(delay -(datetime.now() - start_scan).seconds) + ' seconds')
# Set up the scan policy
scan_policy = 'API-Minimal'
if config_dict:
# They have supplied a config file, use this to define the ascan rules
# Use the default one as the script might not have write access to the one just copied across
scan_policy = 'Default Policy'
zap.ascan.enable_all_scanners(scanpolicyname=scan_policy)
for scanner, state in config_dict.items():
if state == 'IGNORE':
# Dont bother checking the result - this will fail for pscan rules
zap.ascan.set_scanner_alert_threshold(id=scanner, alertthreshold='OFF', scanpolicyname=scan_policy)
if not baseline:
zap_active_scan(zap, target, scan_policy)
zap_wait_for_passive_scan(zap, timeout * 60)
# Print out a count of the number of urls
num_urls = len(zap.core.urls())
if num_urls == 0:
logging.warning('No URLs found - is the target URL accessible? Local services may not be accessible from the Docker container')
else:
if detailed_output:
print('Total of ' + str(num_urls) + ' URLs')
alert_dict = zap_get_alerts(zap, target, ignore_scan_rules, out_of_scope_dict)
all_ascan_rules = zap.ascan.scanners('Default Policy')
all_pscan_rules = zap.pscan.scanners
all_dict = {}
for rule in all_pscan_rules:
plugin_id = rule.get('id')
if plugin_id in ignore_scan_rules:
continue
all_dict[plugin_id] = rule.get('name') + ' - Passive/' + rule.get('quality')
for rule in all_ascan_rules:
plugin_id = rule.get('id')
if plugin_id in ignore_scan_rules:
continue
all_dict[plugin_id] = rule.get('name') + ' - Active/' + rule.get('quality')
if generate:
# Create the config file
with open(base_dir + generate, 'w') as f:
f.write('# zap-api-scan rule configuration file\n')
f.write('# Change WARN to IGNORE to ignore rule or FAIL to fail if rule matches\n')
f.write('# Active scan rules set to IGNORE will not be run which will speed up the scan\n')
f.write('# Only the rule identifiers are used - the names are just for info\n')
f.write('# You can add your own messages to each rule by appending them after a tab on each line.\n')
for key, rule in sorted(all_dict.items()):
f.write(key + '\tWARN\t(' + rule + ')\n')
# print out the passing rules
pass_dict = {}
for rule in all_pscan_rules:
plugin_id = rule.get('id')
if plugin_id in ignore_scan_rules:
continue
if plugin_id not in alert_dict:
pass_dict[plugin_id] = rule.get('name')
for rule in all_ascan_rules:
plugin_id = rule.get('id')
if plugin_id in ignore_scan_rules:
continue
if plugin_id not in alert_dict and not(plugin_id in config_dict and config_dict[plugin_id] == 'IGNORE'):
pass_dict[plugin_id] = rule.get('name')
if min_level == zap_conf_lvls.index("PASS") and detailed_output:
for key, rule in sorted(pass_dict.items()):
print('PASS: ' + rule + ' [' + key + ']')
pass_count = len(pass_dict)
if detailed_output:
# print out the ignored ascan rules(there will be no alerts for these as they were not run)
for rule in all_ascan_rules:
plugin_id = rule.get('id')
if plugin_id in ignore_scan_rules:
continue
if plugin_id in config_dict and config_dict[plugin_id] == 'IGNORE':
print('SKIP: ' + rule.get('name') + ' [' + plugin_id + ']')
# print out the ignored rules
ignore_count, not_used = print_rules(zap, alert_dict, 'IGNORE', config_dict, config_msg, min_level,
inc_ignore_rules, True, detailed_output, {})
# print out the info rules
info_count, not_used = print_rules(zap, alert_dict, 'INFO', config_dict, config_msg, min_level,
inc_info_rules, info_unspecified, detailed_output, in_progress_issues)
# print out the warning rules
warn_count, warn_inprog_count = print_rules(zap, alert_dict, 'WARN', config_dict, config_msg, min_level,
inc_warn_rules, not info_unspecified, detailed_output, in_progress_issues)
# print out the failing rules
fail_count, fail_inprog_count = print_rules(zap, alert_dict, 'FAIL', config_dict, config_msg, min_level,
inc_fail_rules, True, detailed_output, in_progress_issues)
if report_html:
# Save the report
write_report(base_dir + report_html, zap.core.htmlreport())
if report_json:
# Save the report
write_report(base_dir + report_json, zap.core.jsonreport())
if report_md:
# Save the report
write_report(base_dir + report_md, zap.core.mdreport())
if report_xml:
# Save the report
write_report(base_dir + report_xml, zap.core.xmlreport())
print('FAIL-NEW: ' + str(fail_count) + '\tFAIL-INPROG: ' + str(fail_inprog_count) +
'\tWARN-NEW: ' + str(warn_count) + '\tWARN-INPROG: ' + str(warn_inprog_count) +
'\tINFO: ' + str(info_count) + '\tIGNORE: ' + str(ignore_count) + '\tPASS: ' + str(pass_count))
trigger_hook('zap_pre_shutdown', zap)
# Stop ZAP
zap.core.shutdown()
except UserInputException as e:
exception_raised = True
print("ERROR %s" % e)
except (NoUrlsException, ScanNotStartedException):
exception_raised = True
dump_log_file(cid)
except IOError as e:
exception_raised = True
print("ERROR %s" % e)
logging.warning('I/O error: ' + str(e))
dump_log_file(cid)
except:
exception_raised = True
print("ERROR " + str(sys.exc_info()[0]))
logging.warning('Unexpected error: ' + str(sys.exc_info()[0]))
dump_log_file(cid)
if not running_in_docker():
stop_docker(cid)
trigger_hook('pre_exit', fail_count, warn_count, pass_count)
if exception_raised:
sys.exit(3)
elif fail_count > 0:
sys.exit(1)
elif (not ignore_warn) and warn_count > 0:
sys.exit(2)
elif pass_count > 0:
sys.exit(0)
else:
sys.exit(3)
if __name__ == "__main__":
main(sys.argv[1:])
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
3107,
379,
2854,
13058,
12373,
334,
58,
1282,
9,
436,
2399,
4048,
1021,
1584,
14,
199,
3,
199,
3,
3107,
1282,
365,
376,
3101,
15,
14921,
4566,
367,
465,
5480,
316,
3330,
4223,
6391,
14,
199,
3,
199,
3,
1898,
9708,
3107,
1282,
15290,
11682,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
257,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
3,
961,
2884,
7858,
282,
2615,
8000,
6169,
376,
3261,
3247,
701,
3232,
3735,
15,
10941,
16267,
12,
26805,
199,
3,
503,
11513,
2940,
1808,
3107,
1282,
14,
199,
3,
199,
3,
2779,
883,
1902,
506,
1255,
283,
20323,
297,
315,
1314,
1930,
8350,
641,
199,
3,
4178,
921,
17343,
14,
1548,
14,
1308,
15,
17343,
15,
1548,
13,
583,
20222,
13,
24568,
13,
86,
18,
14,
20,
436,
22067,
12,
503,
652,
883,
506,
1255,
199,
3,
6272,
1373,
402,
314,
3107,
1282,
12424,
15333,
14,
2779,
5847,
477,
28853,
340,
652,
365,
199,
3,
3879,
315,
12424,
880,
314,
2633,
787,
314,
2011,
14,
199,
3,
199,
3,
2779,
5544,
2291,
10319,
1311,
3247,
701,
26,
199,
3,
198,
4299,
3735,
15,
10941,
16267,
2851,
199,
3,
198,
4299,
3735,
15,
10941,
16267,
570,
199,
3,
198,
4118,
1282,
2851,
199,
3,
198,
4118,
1282,
3814,
199,
3,
198,
4578,
2940,
2851,
199,
3,
198,
4578,
2940,
3814,
199,
3,
2779,
911,
4458,
543,
9479,
402,
26,
199,
3,
198,
16,
26,
198,
8300,
199,
3,
198,
17,
26,
198,
1271,
5210,
413,
10341,
199,
3,
198,
18,
26,
198,
1271,
5210,
1373,
13253,
46,
436,
949,
10341,
83,
199,
3,
198,
19,
26,
198,
9874,
1163,
5988,
199,
3,
4885,
849,
1006,
31529,
1911,
701,
3107,
1282,
911,
506,
10184,
465,
13253,
46,
780,
14,
199,
3,
2047,
883,
675,
314,
446,
67,
503,
446,
85,
2633,
370,
4165,
282,
2897,
570,
370,
4278,
199,
3,
642,
14,
199,
3,
2047,
883,
3550,
282,
1978,
2897,
570,
1808,
314,
446,
71,
2725,
14,
2047,
911,
199,
3,
2066,
1929,
370,
1570,
283,
17449,
7,
370,
283,
8784,
297,
283,
4531,
7,
503,
283,
11209,
7,
367,
314,
4713,
1265,
2934,
199,
3,
370,
506,
8860,
23142,
14,
199,
3,
2047,
883,
2597,
1050,
2195,
5705,
3788,
367,
314,
4713,
701,
24373,
3062,
2410,
282,
5174,
199,
3,
737,
314,
1284,
402,
1924,
1004,
14,
199,
3,
4885,
849,
314,
4702,
8000,
4713,
1255,
787,
7508,
15282,
315,
314,
3261,
13,
4649,
7265,
14,
3185,
199,
3,
570,
1325,
1265,
883,
1570,
3062,
701,
4973,
6670,
282,
2897,
570,
543,
314,
4713,
199,
3,
1265,
21542,
2934,
370,
506,
1255,
663,
370,
27499,
5788,
14,
199,
199,
646,
12733,
199,
646,
2022,
199,
646,
2050,
199,
646,
747,
199,
646,
747,
14,
515,
199,
646,
3873,
199,
646,
984,
199,
646,
900,
199,
504,
2197,
492,
2197,
199,
504,
3816,
14,
4912,
14,
4078,
14,
1122,
492,
20818,
199,
504,
1315,
439,
86,
18,
492,
3107,
1282,
86,
18,
199,
504,
1315,
439,
63,
2330,
492,
627,
421,
199,
533,
3091,
21867,
478,
1726,
8,
1726,
304,
272,
986,
421,
199,
888,
63,
807,
275,
1052,
199,
888,
63,
1328,
275,
1052,
199,
548,
63,
1618,
63,
2645,
63,
807,
275,
1052,
199,
827,
63,
1896,
275,
378,
199,
199,
3,
24833,
4713,
626,
10621,
1133,
7710,
12082,
12,
325,
14,
71,
14,
314,
7251,
4713,
315,
314,
5131,
663,
199,
4247,
63,
6282,
63,
4423,
275,
11573,
17,
297,
283,
13128,
19,
297,
283,
22,
993,
297,
283,
22,
4183,
418,
199,
199,
3,
24833,
4713,
626,
787,
3769,
1050,
5111,
199,
262,
63,
5734,
63,
10115,
275,
1052,
199,
199,
4806,
14,
19602,
8,
1896,
29,
4806,
14,
4531,
12,
1475,
29342,
18331,
9,
83,
2818,
1188,
9,
83,
358,
199,
3,
869,
2655,
298,
14139,
892,
3101,
1950,
2,
3788,
199,
4806,
14,
5572,
480,
6615,
3471,
13548,
8,
4806,
14,
9171,
9,
421,
199,
318,
4503,
837,
272,
870,
360,
7692,
26,
1315,
439,
13,
1246,
13,
6282,
14,
647,
446,
84,
665,
1375,
30,
446,
70,
665,
908,
30,
359,
1419,
10374,
272,
870,
360,
259,
446,
84,
1347,
260,
1347,
3261,
5492,
12,
3232,
3735,
503,
26805,
12,
2257,
570,
503,
2851,
12,
325,
14,
71,
14,
4178,
921,
1544,
14,
2694,
14,
957,
15,
1490,
1246,
14,
1001,
358,
272,
870,
360,
10473,
503,
1347,
6037,
2851,
12,
11513,
2940,
12,
325,
14,
71,
14,
4178,
921,
1544,
14,
2694,
14,
957,
15,
2180,
1710,
358,
272,
870,
360,
259,
446,
70,
1475,
260,
1551,
1246,
12,
880,
439,
12,
503,
3343,
1710,
358,
272,
870,
360,
4558,
10993,
272,
870,
360,
259,
446,
72,
4483,
870,
642,
1720,
1245,
358,
272,
870,
360,
259,
446,
67,
1101,
63,
493,
259,
1101,
570,
370,
675,
370,
24008,
12,
27499,
5788,
503,
10341,
3598,
358,
272,
870,
360,
259,
446,
85,
1101,
63,
633,
258,
2851,
402,
1101,
570,
370,
675,
370,
24008,
12,
27499,
5788,
503,
10341,
3598,
358,
272,
870,
360,
259,
446,
71,
3805,
63,
493,
755,
3550,
849,
1101,
570,
8,
452,
4713,
663,
370,
13253,
46,
5942,
272,
870,
360,
259,
446,
82,
3622,
63,
1360,
259,
570,
370,
2218,
314,
2615,
3107,
1282,
4163,
3622,
358,
272,
870,
360,
259,
446,
87,
3622,
63,
1064,
420,
570,
370,
2218,
314,
2615,
3107,
1282,
644,
11545,
8,
30916,
9,
3622,
358,
272,
870,
360
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
3107,
379,
2854,
13058,
12373,
334,
58,
1282,
9,
436,
2399,
4048,
1021,
1584,
14,
199,
3,
199,
3,
3107,
1282,
365,
376,
3101,
15,
14921,
4566,
367,
465,
5480,
316,
3330,
4223,
6391,
14,
199,
3,
199,
3,
1898,
9708,
3107,
1282,
15290,
11682,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
257,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
3,
961,
2884,
7858,
282,
2615,
8000,
6169,
376,
3261,
3247,
701,
3232,
3735,
15,
10941,
16267,
12,
26805,
199,
3,
503,
11513,
2940,
1808,
3107,
1282,
14,
199,
3,
199,
3,
2779,
883,
1902,
506,
1255,
283,
20323,
297,
315,
1314,
1930,
8350,
641,
199,
3,
4178,
921,
17343,
14,
1548,
14,
1308,
15,
17343,
15,
1548,
13,
583,
20222,
13,
24568,
13,
86,
18,
14,
20,
436,
22067,
12,
503,
652,
883,
506,
1255,
199,
3,
6272,
1373,
402,
314,
3107,
1282,
12424,
15333,
14,
2779,
5847,
477,
28853,
340,
652,
365,
199,
3,
3879,
315,
12424,
880,
314,
2633,
787,
314,
2011,
14,
199,
3,
199,
3,
2779,
5544,
2291,
10319,
1311,
3247,
701,
26,
199,
3,
198,
4299,
3735,
15,
10941,
16267,
2851,
199,
3,
198,
4299,
3735,
15,
10941,
16267,
570,
199,
3,
198,
4118,
1282,
2851,
199,
3,
198,
4118,
1282,
3814,
199,
3,
198,
4578,
2940,
2851,
199,
3,
198,
4578,
2940,
3814,
199,
3,
2779,
911,
4458,
543,
9479,
402,
26,
199,
3,
198,
16,
26,
198,
8300,
199,
3,
198,
17,
26,
198,
1271,
5210,
413,
10341,
199,
3,
198,
18,
26,
198,
1271,
5210,
1373,
13253,
46,
436,
949,
10341,
83,
199,
3,
198,
19,
26,
198,
9874,
1163,
5988,
199,
3,
4885,
849,
1006,
31529,
1911,
701,
3107,
1282,
911,
506,
10184,
465,
13253,
46,
780,
14,
199,
3,
2047,
883,
675,
314,
446,
67,
503,
446,
85,
2633,
370,
4165,
282,
2897,
570,
370,
4278,
199,
3,
642,
14,
199,
3,
2047,
883,
3550,
282,
1978,
2897,
570,
1808,
314,
446,
71,
2725,
14,
2047,
911,
199,
3,
2066,
1929,
370,
1570,
283,
17449,
7,
370,
283,
8784,
297,
283,
4531,
7,
503,
283,
11209,
7,
367,
314,
4713,
1265,
2934,
199,
3,
370,
506,
8860,
23142,
14,
199,
3,
2047,
883,
2597,
1050,
2195,
5705,
3788,
367,
314,
4713,
701,
24373,
3062,
2410,
282,
5174,
199,
3,
737,
314,
1284,
402,
1924,
1004,
14,
199,
3,
4885,
849,
314,
4702,
8000,
4713,
1255,
787,
7508,
15282,
315,
314,
3261,
13,
4649,
7265,
14,
3185,
199,
3,
570,
1325,
1265,
883,
1570,
3062,
701,
4973,
6670,
282,
2897,
570,
543,
314,
4713,
199,
3,
1265,
21542,
2934,
370,
506,
1255,
663,
370,
27499,
5788,
14,
199,
199,
646,
12733,
199,
646,
2022,
199,
646,
2050,
199,
646,
747,
199,
646,
747,
14,
515,
199,
646,
3873,
199,
646,
984,
199,
646,
900,
199,
504,
2197,
492,
2197,
199,
504,
3816,
14,
4912,
14,
4078,
14,
1122,
492,
20818,
199,
504,
1315,
439,
86,
18,
492,
3107,
1282,
86,
18,
199,
504,
1315,
439,
63,
2330,
492,
627,
421,
199,
533,
3091,
21867,
478,
1726,
8,
1726,
304,
272,
986,
421,
199,
888,
63,
807,
275,
1052,
199,
888,
63,
1328,
275,
1052,
199,
548,
63,
1618,
63,
2645,
63,
807,
275,
1052,
199,
827,
63,
1896,
275,
378,
199,
199,
3,
24833,
4713,
626,
10621,
1133,
7710,
12082,
12,
325,
14,
71,
14,
314,
7251,
4713,
315,
314,
5131,
663,
199,
4247,
63,
6282,
63,
4423,
275,
11573,
17,
297,
283,
13128,
19,
297,
283,
22,
993,
297,
283,
22,
4183,
418,
199,
199,
3,
24833,
4713,
626,
787,
3769,
1050,
5111,
199,
262,
63,
5734,
63,
10115,
275,
1052,
199,
199,
4806,
14,
19602,
8,
1896,
29,
4806,
14,
4531,
12,
1475,
29342,
18331,
9,
83,
2818,
1188,
9,
83,
358,
199,
3,
869,
2655,
298,
14139,
892,
3101,
1950,
2,
3788,
199,
4806,
14,
5572,
480,
6615,
3471,
13548,
8,
4806,
14,
9171,
9,
421,
199,
318,
4503,
837,
272,
870,
360,
7692,
26,
1315,
439,
13,
1246,
13,
6282,
14,
647,
446,
84,
665,
1375,
30,
446,
70,
665,
908,
30,
359,
1419,
10374,
272,
870,
360,
259,
446,
84,
1347,
260,
1347,
3261,
5492,
12,
3232,
3735,
503,
26805,
12,
2257,
570,
503,
2851,
12,
325,
14,
71,
14,
4178,
921,
1544,
14,
2694,
14,
957,
15,
1490,
1246,
14,
1001,
358,
272,
870,
360,
10473,
503,
1347,
6037,
2851,
12,
11513,
2940,
12,
325,
14,
71,
14,
4178,
921,
1544,
14,
2694,
14,
957,
15,
2180,
1710,
358,
272,
870,
360,
259,
446,
70,
1475,
260,
1551,
1246,
12,
880,
439,
12,
503,
3343,
1710,
358,
272,
870,
360,
4558,
10993,
272,
870,
360,
259,
446,
72,
4483,
870,
642,
1720,
1245,
358,
272,
870,
360,
259,
446,
67,
1101,
63,
493,
259,
1101,
570,
370,
675,
370,
24008,
12,
27499,
5788,
503,
10341,
3598,
358,
272,
870,
360,
259,
446,
85,
1101,
63,
633,
258,
2851,
402,
1101,
570,
370,
675,
370,
24008,
12,
27499,
5788,
503,
10341,
3598,
358,
272,
870,
360,
259,
446,
71,
3805,
63,
493,
755,
3550,
849,
1101,
570,
8,
452,
4713,
663,
370,
13253,
46,
5942,
272,
870,
360,
259,
446,
82,
3622,
63,
1360,
259,
570,
370,
2218,
314,
2615,
3107,
1282,
4163,
3622,
358,
272,
870,
360,
259,
446,
87,
3622,
63,
1064,
420,
570,
370,
2218,
314,
2615,
3107,
1282,
644,
11545,
8,
30916,
9,
3622,
358,
272,
870,
360,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
Priyansh2/test
|
web2py/taskmanagement/languages/id.py
|
148
|
11233
|
# coding: utf8
{
'!langcode!': 'id',
'!langname!': 'Indonesian',
'%d days ago': '%d hari yang lalu',
'%d hours ago': '%d jam yang lalu',
'%d minutes ago': '%d menit yang lalu',
'%d months ago': '%d bulan yang lalu',
'%d seconds ago': '%d detik yang lalu',
'%d seconds from now': '%d detik dari sekarang',
'%d weeks ago': '%d minggu yang lalu',
'%d years ago': '%d tahun yang lalu',
'%s %%{row} deleted': '%s %%{row} dihapus',
'%s %%{row} updated': '%s %%{row} diperbarui',
'%s selected': '%s dipilih',
'%Y-%m-%d': '%d-%m-%Y',
'%Y-%m-%d %H:%M:%S': '%d-%m-%Y %H:%M:%S',
'(requires internet access, experimental)': '(membutuhkan akses internet, eksperimental)',
'(something like "it-it")': '(sesuatu seperti "it-it")',
'1 day ago': '1 hari yang lalu',
'1 hour ago': '1 jam yang lalu',
'1 minute ago': '1 menit yang lalu',
'1 month ago': '1 bulan yang lalu',
'1 second ago': '1 detik yang lalu',
'1 week ago': '1 minggu yang lalu',
'1 year ago': '1 tahun yang lalu',
'< Previous': '< Sebelumnya',
'About': 'Tentang',
'About application': 'Tentang Aplikasi',
'Add': 'Tambah',
'Additional code for your application': 'Tambahan kode untuk aplikasi Anda',
'Address': 'Alamat',
'Admin language': 'Bahasa Admin',
'administrative interface': 'antarmuka administrative',
'Administrator Password:': 'Administrator Kata Sandi:',
'Ajax Recipes': 'Resep Ajax',
'An error occured, please %s the page': 'Terjadi kesalahan, silakan %s halaman',
'And': 'Dan',
'and rename it:': 'dan memberi nama baru itu:',
'Answer': 'Jawaban',
'appadmin is disabled because insecure channel': 'AppAdmin dinonaktifkan karena kanal tidak aman',
'application "%s" uninstalled': 'applikasi "%s" dihapus',
'application compiled': 'aplikasi dikompilasi',
'Application name:': 'Nama Applikasi:',
'are not used yet': 'tidak digunakan lagi',
'Are you sure you want to delete this object?': 'Apakah Anda yakin ingin menghapus ini?',
'Are you sure you want to uninstall application "%s"?': 'Apakah Anda yakin ingin menghapus aplikasi "%s"?',
'Available Databases and Tables': 'Database dan Tabel yang tersedia',
'Back': 'Kembali',
'Buy this book': 'Beli buku ini',
'cache, errors and sessions cleaned': 'cache, kesalahan dan sesi dibersihkan',
'can be a git repo': 'bisa menjadi repo git',
'Cancel': 'Batalkan',
'Cannot be empty': 'Tidak boleh kosong',
'Change admin password': 'Ubah kata sandi admin',
'Change password': 'Ubah kata sandi',
'Check for upgrades': 'Periksa upgrade',
'Check to delete': 'Centang untuk menghapus',
'Checking for upgrades...': 'Memeriksa untuk upgrade...',
'Clean': 'Bersih',
'Clear': 'Hapus',
'Clear CACHE?': 'Hapus CACHE?',
'Clear DISK': 'Hapus DISK',
'Clear RAM': 'Hapus RAM',
'Click row to expand traceback': 'Klik baris untuk memperluas traceback',
'Close': 'Tutup',
'collapse/expand all': 'kempis / memperluas semua',
'Community': 'Komunitas',
'Compile': 'Kompilasi',
'compiled application removed': 'aplikasi yang dikompilasi dihapus',
'Components and Plugins': 'Komponen dan Plugin',
'contains': 'mengandung',
'Controllers': 'Kontrolir',
'controllers': 'kontrolir',
'Copyright': 'Hak Cipta',
'Count': 'Hitung',
'Create': 'Buat',
'create file with filename:': 'buat file dengan nama:',
'created by': 'dibuat oleh',
'CSV (hidden cols)': 'CSV (kolom tersembunyi)',
'currently running': 'sedang berjalan',
'data uploaded': 'data diunggah',
'Database %s select': 'Memilih Database %s',
'database administration': 'administrasi database',
'defines tables': 'mendefinisikan tabel',
'Delete': 'Hapus',
'delete all checked': 'menghapus semua yang di centang',
'Delete this file (you will be asked to confirm deletion)': 'Hapus file ini (Anda akan diminta untuk mengkonfirmasi penghapusan)',
'Delete:': 'Hapus:',
'Description': 'Keterangan',
'design': 'disain',
'direction: ltr': 'petunjuk: ltr',
'Disk Cleared': 'Disk Dihapus',
'Documentation': 'Dokumentasi',
"Don't know what to do?": 'Tidak tahu apa yang harus dilakukan?',
'done!': 'selesai!',
'Download': 'Unduh',
'Download .w2p': 'Unduh .w2p',
'download layouts': 'unduh layouts',
'download plugins': 'unduh plugins',
'Duration': 'Durasi',
'Edit': 'Mengedit',
'Edit application': 'Mengedit Aplikasi',
'Email sent': 'Email dikirim',
'enter a valid email address': 'masukkan alamat email yang benar',
'enter a valid URL': 'masukkan URL yang benar',
'enter a value': 'masukkan data',
'Error': 'Kesalahan',
'Error logs for "%(app)s"': 'Catatan kesalahan untuk "%(app)s"',
'Errors': 'Kesalahan',
'export as csv file': 'ekspor sebagai file csv',
'Export:': 'Ekspor:',
'exposes': 'menghadapkan',
'extends': 'meluaskan',
'filter': 'menyaring',
'First Name': 'Nama Depan',
'Forgot username?': 'Lupa nama pengguna?',
'Free Applications': 'Aplikasi Gratis',
'Gender': 'Jenis Kelamin',
'Group %(group_id)s created': 'Grup %(group_id)s dibuat',
'Group uniquely assigned to user %(id)s': 'Grup unik yang diberikan kepada pengguna %(id)s',
'Groups': 'Grup',
'Guest': 'Tamu',
'Hello World': 'Halo Dunia',
'Help': 'Bantuan',
'Home': 'Halaman Utama',
'How did you get here?': 'Bagaimana kamu bisa di sini?',
'Image': 'Gambar',
'import': 'impor',
'Import/Export': 'Impor/Ekspor',
'includes': 'termasuk',
'Install': 'Memasang',
'Installation': 'Instalasi',
'Installed applications': 'Aplikasi yang diinstal',
'Introduction': 'Pengenalan',
'Invalid email': 'Email tidak benar',
'Language': 'Bahasa',
'languages': 'bahasa',
'Languages': 'Bahasa',
'Last Name': 'Nama Belakang',
'License for': 'Lisensi untuk',
'loading...': 'sedang memuat...',
'Logged in': 'Masuk',
'Logged out': 'Keluar',
'Login': 'Masuk',
'Login to the Administrative Interface': 'Masuk ke antarmuka Administrasi',
'Logout': 'Keluar',
'Lost Password': 'Lupa Kata Sandi',
'Lost password?': 'Lupa kata sandi?',
'Maintenance': 'Pemeliharaan',
'Manage': 'Mengelola',
'Manage Cache': 'Mengelola Cache',
'models': 'model',
'Models': 'Model',
'Modules': 'Modul',
'modules': 'modul',
'My Sites': 'Situs Saya',
'New': 'Baru',
'new application "%s" created': 'aplikasi baru "%s" dibuat',
'New password': 'Kata sandi baru',
'New simple application': 'Aplikasi baru sederhana',
'News': 'Berita',
'next 100 rows': '100 baris berikutnya',
'Next >': 'Berikutnya >',
'Next Page': 'Halaman Berikutnya',
'No databases in this application': 'Tidak ada database dalam aplikasi ini',
'No ticket_storage.txt found under /private folder': 'Tidak ditemukan ticket_storage.txt dalam folder /private',
'not a Zip Code': 'bukan Kode Pos',
'Note': 'Catatan',
'Old password': 'Kata sandi lama',
'Online examples': 'Contoh Online',
'Or': 'Atau',
'or alternatively': 'atau alternatif',
'Or Get from URL:': 'Atau Dapatkan dari URL:',
'or import from csv file': 'atau impor dari file csv',
'Other Plugins': 'Plugin Lainnya',
'Other Recipes': 'Resep Lainnya',
'Overview': 'Ikhtisar',
'Overwrite installed app': 'Ikhtisar app yang terinstall',
'Pack all': 'Pak semua',
'Pack compiled': 'Pak yang telah dikompilasi',
'Pack custom': 'Pak secara kustomisasi',
'Password': 'Kata sandi',
'Password changed': 'Kata sandi berubah',
"Password fields don't match": 'Kata sandi tidak sama',
'please input your password again': 'silahkan masukan kata sandi anda lagi',
'plugins': 'plugin',
'Plugins': 'Plugin',
'Plural-Forms:': 'Bentuk-Jamak:',
'Powered by': 'Didukung oleh',
'Preface': 'Pendahuluan',
'previous 100 rows': '100 baris sebelumnya',
'Previous Page': 'Halaman Sebelumnya',
'private files': 'file pribadi',
'Private files': 'File pribadi',
'Profile': 'Profil',
'Profile updated': 'Profil diperbarui',
'Project Progress': 'Perkembangan Proyek',
'Quick Examples': 'Contoh Cepat',
'Ram Cleared': 'Ram Dihapus',
'Recipes': 'Resep',
'Register': 'Daftar',
'Registration successful': 'Pendaftaran berhasil',
'reload': 'memuat kembali',
'Reload routes': 'Memuat rute kembali',
'Remember me (for 30 days)': 'Ingat saya (selama 30 hari)',
'Remove compiled': 'Hapus Kompilasi',
'Request reset password': 'Meminta reset kata sandi',
'Rows in Table': 'Baris dalam Tabel',
'Rows selected': 'Baris dipilih',
"Run tests in this file (to run all files, you may also use the button labelled 'test')": "Jalankan tes di file ini (untuk menjalankan semua file, Anda juga dapat menggunakan tombol berlabel 'test')",
'Running on %s': 'Berjalan di %s',
'Save model as...': 'Simpan model sebagai ...',
'Save profile': 'Simpan profil',
'Search': 'Cari',
'Select Files to Package': 'Pilih Berkas untuk Paket',
'Send Email': 'Kirim Email',
'Service': 'Layanan',
'Site': 'Situs',
'Size of cache:': 'Ukuran cache:',
'starts with': 'dimulai dengan',
'static': 'statis',
'Static': 'Statis',
'Statistics': 'Statistik',
'Support': 'Mendukung',
'Table': 'Tabel',
'test': 'tes',
'The application logic, each URL path is mapped in one exposed function in the controller': 'Logika aplikasi, setiap jalur URL dipetakan dalam satu fungsi terpapar di kontrolir',
'The data representation, define database tables and sets': 'Representasi data, mendefinisikan tabel database dan set',
'There are no plugins': 'Tidak ada plugin',
'There are no private files': 'Tidak ada file pribadi',
'These files are not served, they are only available from within your app': 'File-file ini tidak dilayani, mereka hanya tersedia dari dalam aplikasi Anda',
'These files are served without processing, your images go here': 'File-file ini disajikan tanpa pengolahan, gambar Anda di sini',
'This App': 'App Ini',
'Time in Cache (h:m:s)': 'Waktu di Cache (h: m: s)',
'To create a plugin, name a file/folder plugin_[name]': 'Untuk membuat sebuah plugin, nama file / folder plugin_ [nama]',
'too short': 'terlalu pendek',
'Translation strings for the application': 'Terjemahan string untuk aplikasi',
'Try the mobile interface': 'Coba antarmuka ponsel',
'Unable to download because:': 'Tidak dapat mengunduh karena:',
'unable to parse csv file': 'tidak mampu mengurai file csv',
'update all languages': 'memperbarui semua bahasa',
'Update:': 'Perbarui:',
'Upload': 'Unggah',
'Upload a package:': 'Unggah sebuah paket:',
'Upload and install packed application': 'Upload dan pasang aplikasi yang dikemas',
'upload file:': 'unggah file:',
'upload plugin file:': 'unggah file plugin:',
'User %(id)s Logged-in': 'Pengguna %(id)s Masuk',
'User %(id)s Logged-out': 'Pengguna %(id)s Keluar',
'User %(id)s Password changed': 'Pengguna %(id)s Kata Sandi berubah',
'User %(id)s Password reset': 'Pengguna %(id)s Kata Sandi telah direset',
'User %(id)s Profile updated': 'Pengguna %(id)s Profil diperbarui',
'User %(id)s Registered': 'Pengguna %(id)s Terdaftar',
'value already in database or empty': 'data sudah ada dalam database atau kosong',
'value not allowed': 'data tidak benar',
'value not in database': 'data tidak ada dalam database',
'Verify Password': 'Verifikasi Kata Sandi',
'Version': 'Versi',
'View': 'Lihat',
'Views': 'Lihat',
'views': 'lihat',
'Web Framework': 'Kerangka Web',
'web2py is up to date': 'web2py terbaru',
'web2py Recent Tweets': 'Tweet web2py terbaru',
'Website': 'Situs Web',
'Welcome': 'Selamat Datang',
'Welcome to web2py!': 'Selamat Datang di web2py!',
'You are successfully running web2py': 'Anda berhasil menjalankan web2py',
'You can modify this application and adapt it to your needs': 'Anda dapat memodifikasi aplikasi ini dan menyesuaikan dengan kebutuhan Anda',
'You visited the url %s': 'Anda mengunjungi url %s',
}
|
gpl-3.0
|
[
3,
2803,
26,
2774,
24,
199,
91,
199,
7,
1,
4159,
600,
27676,
283,
344,
297,
199,
7,
1,
4159,
354,
27676,
283,
607,
4456,
6214,
297,
199,
5956,
68,
7609,
20313,
356,
1543,
68,
394,
759,
31193,
634,
279,
85,
297,
199,
5956,
68,
10857,
20313,
356,
1543,
68,
1335,
455,
31193,
634,
279,
85,
297,
199,
5956,
68,
9395,
20313,
356,
1543,
68,
12953,
390,
31193,
634,
279,
85,
297,
199,
5956,
68,
20096,
20313,
356,
1543,
68,
330,
348,
290,
31193,
634,
279,
85,
297,
199,
5956,
68,
4696,
20313,
356,
1543,
68,
477,
30298,
31193,
634,
279,
85,
297,
199,
5956,
68,
4696,
687,
3063,
356,
1543,
68,
477,
30298,
366,
759,
542,
75,
285,
621,
297,
199,
5956,
68,
29540,
20313,
356,
1543,
68,
333,
316,
6051,
31193,
634,
279,
85,
297,
199,
5956,
68,
17399,
20313,
356,
1543,
68,
3052,
72,
324,
31193,
634,
279,
85,
297,
199,
5956,
83,
11539,
91,
1143,
93,
5463,
356,
1543,
83,
11539,
91,
1143,
93,
487,
72,
439,
527,
297,
199,
5956,
83,
11539,
91,
1143,
93,
4588,
356,
1543,
83,
11539,
91,
1143,
93,
487,
529,
1700,
1907,
297,
199,
5956,
83,
4895,
356,
1543,
83,
487,
1038,
317,
72,
297,
199,
5956,
57,
3295,
77,
3295,
68,
356,
1543,
68,
3295,
77,
3295,
57,
297,
199,
5956,
57,
3295,
77,
3295,
68,
450,
40,
2689,
45,
2689,
51,
356,
1543,
68,
3295,
77,
3295,
57,
450,
40,
2689,
45,
2689,
51,
297,
199,
6774,
6537,
21408,
2879,
12,
22820,
11862,
8189,
278,
887,
337,
85,
21557,
290,
282,
75,
874,
21408,
12,
325,
6080,
6306,
279,
3196,
199,
6774,
10297,
2839,
298,
390,
13,
390,
531,
356,
8189,
874,
85,
292,
85,
542,
529,
280,
298,
390,
13,
390,
30901,
199,
7,
17,
5382,
20313,
356,
283,
17,
394,
759,
31193,
634,
279,
85,
297,
199,
7,
17,
6925,
20313,
356,
283,
17,
1335,
455,
31193,
634,
279,
85,
297,
199,
7,
17,
12709,
20313,
356,
283,
17,
12953,
390,
31193,
634,
279,
85,
297,
199,
7,
17,
5794,
20313,
356,
283,
17,
330,
348,
290,
31193,
634,
279,
85,
297,
199,
7,
17,
3499,
20313,
356,
283,
17,
477,
30298,
31193,
634,
279,
85,
297,
199,
7,
17,
8620,
20313,
356,
283,
17,
333,
316,
6051,
31193,
634,
279,
85,
297,
199,
7,
17,
5361,
20313,
356,
283,
17,
3052,
72,
324,
31193,
634,
279,
85,
297,
199,
7601,
26902,
356,
2650,
428,
2871,
352,
1307,
11552,
297,
199,
7,
18816,
356,
283,
52,
484,
621,
297,
199,
7,
18816,
4223,
356,
283,
52,
484,
621,
13450,
317,
75,
24950,
297,
199,
7,
1123,
356,
283,
52,
14310,
72,
297,
199,
7,
8824,
1233,
367,
2195,
4223,
356,
283,
52,
14310,
19262,
1022,
380,
625,
84,
3210,
2771,
317,
75,
24950,
6061,
65,
297,
199,
7,
1476,
356,
283,
33,
416,
569,
297,
199,
7,
4880,
2637,
356,
283,
13864,
1989,
65,
9516,
297,
199,
7,
2113,
25124,
3217,
356,
283,
867,
5362,
3210,
65,
4628,
25124,
297,
199,
7,
31972,
13635,
25156,
283,
31972,
1804,
419,
29359,
328,
6536,
199,
7,
33,
15863,
799,
8233,
83,
356,
283,
497,
4127,
437,
15863,
297,
199,
7,
2493,
1125,
28408,
12,
8749,
450,
83,
314,
2034,
356,
283,
8600,
3387,
328,
1022,
397,
279,
11326,
290,
12,
24968,
1151,
290,
450,
83,
22939,
455,
290,
297,
199,
7,
3325,
356,
283,
29336,
297,
199,
7,
460,
11441,
652,
25156,
283,
24863,
3653,
73,
11802,
391,
4681,
85,
652,
85,
6536,
199,
7,
19104,
356,
283,
42,
10084,
371,
290,
297,
199,
7,
571,
2113,
365,
6980,
2952,
26097,
3623,
356,
283,
2640,
4880,
366,
262,
265,
1151,
280,
9010,
290,
1022,
65,
28359,
1022,
290,
279,
3367,
983,
75,
282,
1237,
297,
199,
7,
3578,
2071,
83,
2,
625,
7657,
356,
283,
571,
317,
75,
24950,
2071,
83,
2,
487,
72,
439,
527,
297,
199,
7,
3578,
10311,
356,
283,
439,
317,
75,
24950,
487,
7697,
311,
382,
24950,
297,
199,
7,
5039,
536,
25156,
283,
8565,
391,
4693,
317,
75,
24950,
6536,
199,
7,
1530,
440,
1202,
5966,
356,
283,
280,
983,
75,
487,
17924,
1151,
290,
1127,
6153,
297,
199,
7,
17683,
1265,
3238,
1265,
2934,
370,
3145,
642,
909,
28867,
283,
33,
387,
7351,
72,
6061,
65,
612,
1151,
262,
315,
903,
562,
2753,
72,
439,
527,
20364,
7044,
199,
7,
17683,
1265,
3238,
1265,
2934,
370,
22199,
4223,
2071,
83,
14863,
356,
283,
33,
387,
7351,
72,
6061,
65,
612,
1151,
262,
315,
903,
562,
2753,
72,
439,
527,
2771,
317,
75,
24950,
2071,
83,
2,
7044,
199,
7,
11464,
8692,
83,
436,
377,
5921,
356,
283,
7243,
366,
290,
377,
902,
31193,
2044,
261,
2391,
297,
199,
7,
4540,
356,
283,
1136,
887,
10874,
297,
199,
7,
1713,
89,
642,
6719,
356,
283,
3655,
317,
1032,
20661,
20364,
297,
199,
7,
1637,
12,
2552,
436,
12184,
12364,
356,
283,
1637,
12,
1022,
397,
279,
11326,
290,
366,
290,
542,
338,
487,
605,
338,
21557,
290,
297,
199,
7,
2425,
506,
282,
6135,
3831,
356,
283,
66,
13655,
12953,
3387,
328,
3831,
6135,
297,
199,
7,
9083,
356,
283,
34,
292,
4878,
290,
297,
199,
7,
6612,
506,
2701,
356,
283,
32487,
1151,
1234,
274,
72,
1022,
736,
951,
297,
199,
7,
4001,
4628,
2505,
356,
283,
53,
2470,
72,
1022,
419,
28698,
328,
4628,
297,
199,
7,
4001,
2505,
356,
283,
53,
2470,
72,
1022,
419,
28698,
328,
297,
199,
7,
1799,
367,
1536,
18050,
356,
283,
2623,
3258,
2231,
10754,
297,
199,
7,
1799,
370,
3145,
356,
283,
22744,
621,
625,
84,
3210,
562,
2753,
72,
439,
527,
297,
199,
7,
14740,
367,
1536,
18050,
1396,
356,
283,
1352,
278,
25844,
2231,
625,
84,
3210,
10754,
20833,
199,
7,
6580,
356,
283,
24947,
338,
72,
297,
199,
7,
9721,
356,
283,
40,
439,
527,
297,
199,
7,
9721,
7240,
4576,
28867,
283,
40,
439,
527,
7240,
4576,
7044,
199,
7,
9721,
7587,
43,
356,
283,
40,
439,
527,
7587,
43,
297,
199,
7,
9721,
30207,
356,
283,
40,
439,
527,
30207,
297,
199,
7,
12040,
1962,
370,
6544,
5190,
356,
283,
43,
317
] |
[
2803,
26,
2774,
24,
199,
91,
199,
7,
1,
4159,
600,
27676,
283,
344,
297,
199,
7,
1,
4159,
354,
27676,
283,
607,
4456,
6214,
297,
199,
5956,
68,
7609,
20313,
356,
1543,
68,
394,
759,
31193,
634,
279,
85,
297,
199,
5956,
68,
10857,
20313,
356,
1543,
68,
1335,
455,
31193,
634,
279,
85,
297,
199,
5956,
68,
9395,
20313,
356,
1543,
68,
12953,
390,
31193,
634,
279,
85,
297,
199,
5956,
68,
20096,
20313,
356,
1543,
68,
330,
348,
290,
31193,
634,
279,
85,
297,
199,
5956,
68,
4696,
20313,
356,
1543,
68,
477,
30298,
31193,
634,
279,
85,
297,
199,
5956,
68,
4696,
687,
3063,
356,
1543,
68,
477,
30298,
366,
759,
542,
75,
285,
621,
297,
199,
5956,
68,
29540,
20313,
356,
1543,
68,
333,
316,
6051,
31193,
634,
279,
85,
297,
199,
5956,
68,
17399,
20313,
356,
1543,
68,
3052,
72,
324,
31193,
634,
279,
85,
297,
199,
5956,
83,
11539,
91,
1143,
93,
5463,
356,
1543,
83,
11539,
91,
1143,
93,
487,
72,
439,
527,
297,
199,
5956,
83,
11539,
91,
1143,
93,
4588,
356,
1543,
83,
11539,
91,
1143,
93,
487,
529,
1700,
1907,
297,
199,
5956,
83,
4895,
356,
1543,
83,
487,
1038,
317,
72,
297,
199,
5956,
57,
3295,
77,
3295,
68,
356,
1543,
68,
3295,
77,
3295,
57,
297,
199,
5956,
57,
3295,
77,
3295,
68,
450,
40,
2689,
45,
2689,
51,
356,
1543,
68,
3295,
77,
3295,
57,
450,
40,
2689,
45,
2689,
51,
297,
199,
6774,
6537,
21408,
2879,
12,
22820,
11862,
8189,
278,
887,
337,
85,
21557,
290,
282,
75,
874,
21408,
12,
325,
6080,
6306,
279,
3196,
199,
6774,
10297,
2839,
298,
390,
13,
390,
531,
356,
8189,
874,
85,
292,
85,
542,
529,
280,
298,
390,
13,
390,
30901,
199,
7,
17,
5382,
20313,
356,
283,
17,
394,
759,
31193,
634,
279,
85,
297,
199,
7,
17,
6925,
20313,
356,
283,
17,
1335,
455,
31193,
634,
279,
85,
297,
199,
7,
17,
12709,
20313,
356,
283,
17,
12953,
390,
31193,
634,
279,
85,
297,
199,
7,
17,
5794,
20313,
356,
283,
17,
330,
348,
290,
31193,
634,
279,
85,
297,
199,
7,
17,
3499,
20313,
356,
283,
17,
477,
30298,
31193,
634,
279,
85,
297,
199,
7,
17,
8620,
20313,
356,
283,
17,
333,
316,
6051,
31193,
634,
279,
85,
297,
199,
7,
17,
5361,
20313,
356,
283,
17,
3052,
72,
324,
31193,
634,
279,
85,
297,
199,
7601,
26902,
356,
2650,
428,
2871,
352,
1307,
11552,
297,
199,
7,
18816,
356,
283,
52,
484,
621,
297,
199,
7,
18816,
4223,
356,
283,
52,
484,
621,
13450,
317,
75,
24950,
297,
199,
7,
1123,
356,
283,
52,
14310,
72,
297,
199,
7,
8824,
1233,
367,
2195,
4223,
356,
283,
52,
14310,
19262,
1022,
380,
625,
84,
3210,
2771,
317,
75,
24950,
6061,
65,
297,
199,
7,
1476,
356,
283,
33,
416,
569,
297,
199,
7,
4880,
2637,
356,
283,
13864,
1989,
65,
9516,
297,
199,
7,
2113,
25124,
3217,
356,
283,
867,
5362,
3210,
65,
4628,
25124,
297,
199,
7,
31972,
13635,
25156,
283,
31972,
1804,
419,
29359,
328,
6536,
199,
7,
33,
15863,
799,
8233,
83,
356,
283,
497,
4127,
437,
15863,
297,
199,
7,
2493,
1125,
28408,
12,
8749,
450,
83,
314,
2034,
356,
283,
8600,
3387,
328,
1022,
397,
279,
11326,
290,
12,
24968,
1151,
290,
450,
83,
22939,
455,
290,
297,
199,
7,
3325,
356,
283,
29336,
297,
199,
7,
460,
11441,
652,
25156,
283,
24863,
3653,
73,
11802,
391,
4681,
85,
652,
85,
6536,
199,
7,
19104,
356,
283,
42,
10084,
371,
290,
297,
199,
7,
571,
2113,
365,
6980,
2952,
26097,
3623,
356,
283,
2640,
4880,
366,
262,
265,
1151,
280,
9010,
290,
1022,
65,
28359,
1022,
290,
279,
3367,
983,
75,
282,
1237,
297,
199,
7,
3578,
2071,
83,
2,
625,
7657,
356,
283,
571,
317,
75,
24950,
2071,
83,
2,
487,
72,
439,
527,
297,
199,
7,
3578,
10311,
356,
283,
439,
317,
75,
24950,
487,
7697,
311,
382,
24950,
297,
199,
7,
5039,
536,
25156,
283,
8565,
391,
4693,
317,
75,
24950,
6536,
199,
7,
1530,
440,
1202,
5966,
356,
283,
280,
983,
75,
487,
17924,
1151,
290,
1127,
6153,
297,
199,
7,
17683,
1265,
3238,
1265,
2934,
370,
3145,
642,
909,
28867,
283,
33,
387,
7351,
72,
6061,
65,
612,
1151,
262,
315,
903,
562,
2753,
72,
439,
527,
20364,
7044,
199,
7,
17683,
1265,
3238,
1265,
2934,
370,
22199,
4223,
2071,
83,
14863,
356,
283,
33,
387,
7351,
72,
6061,
65,
612,
1151,
262,
315,
903,
562,
2753,
72,
439,
527,
2771,
317,
75,
24950,
2071,
83,
2,
7044,
199,
7,
11464,
8692,
83,
436,
377,
5921,
356,
283,
7243,
366,
290,
377,
902,
31193,
2044,
261,
2391,
297,
199,
7,
4540,
356,
283,
1136,
887,
10874,
297,
199,
7,
1713,
89,
642,
6719,
356,
283,
3655,
317,
1032,
20661,
20364,
297,
199,
7,
1637,
12,
2552,
436,
12184,
12364,
356,
283,
1637,
12,
1022,
397,
279,
11326,
290,
366,
290,
542,
338,
487,
605,
338,
21557,
290,
297,
199,
7,
2425,
506,
282,
6135,
3831,
356,
283,
66,
13655,
12953,
3387,
328,
3831,
6135,
297,
199,
7,
9083,
356,
283,
34,
292,
4878,
290,
297,
199,
7,
6612,
506,
2701,
356,
283,
32487,
1151,
1234,
274,
72,
1022,
736,
951,
297,
199,
7,
4001,
4628,
2505,
356,
283,
53,
2470,
72,
1022,
419,
28698,
328,
4628,
297,
199,
7,
4001,
2505,
356,
283,
53,
2470,
72,
1022,
419,
28698,
328,
297,
199,
7,
1799,
367,
1536,
18050,
356,
283,
2623,
3258,
2231,
10754,
297,
199,
7,
1799,
370,
3145,
356,
283,
22744,
621,
625,
84,
3210,
562,
2753,
72,
439,
527,
297,
199,
7,
14740,
367,
1536,
18050,
1396,
356,
283,
1352,
278,
25844,
2231,
625,
84,
3210,
10754,
20833,
199,
7,
6580,
356,
283,
24947,
338,
72,
297,
199,
7,
9721,
356,
283,
40,
439,
527,
297,
199,
7,
9721,
7240,
4576,
28867,
283,
40,
439,
527,
7240,
4576,
7044,
199,
7,
9721,
7587,
43,
356,
283,
40,
439,
527,
7587,
43,
297,
199,
7,
9721,
30207,
356,
283,
40,
439,
527,
30207,
297,
199,
7,
12040,
1962,
370,
6544,
5190,
356,
283,
43,
317,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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.hardware
class Stepper(component.Element):
def __init__(self,
size="GenericNEMA17",
negative=False,
negativeLength=10):
component.Element.__init__(self, name="stepper")
self.size = size
self.width = 0
self.length = 0
self.mountSpacing = 0
self.mountScrew = ""
self.flangeDiameter = 0
self.flangeHeight = 0
self.shaftLength = 0
self.shaftDiameter = 0
self.negative = negative
self.negativeLength = negativeLength
magpie.utility.get_dimensions(size=size, name="stepperMotor", obj=self)
self.holeLocations = [[self.mountSpacing/2, self.mountSpacing/2, 0],
[self.mountSpacing/2, -self.mountSpacing/2, 0],
[-self.mountSpacing/2, self.mountSpacing/2, 0],
[-self.mountSpacing/2, -self.mountSpacing/2, 0]]
self.screw = magpie.hardware.CapScrew(size=self.mountScrew)
self.location = [0, 0, 0]
self.color = [0.5, 0.5, 0.5]
self.construction = self._construction()
def _construction(self):
body = element.Cube([self.width, self.width, self.length])
body.center = [True, True, False]
body.location = [0, 0, -self.length]
flange = element.Cylinder(radius=self.flangeDiameter/2,
height=self.flangeHeight)
shaft = element.Cylinder(radius=self.shaftDiameter/2,
height=self.shaftLength+self.flangeHeight)
asm = body + flange + shaft
if self.negative:
# Flange
asm += element.Hole(radius=self.flangeDiameter/2,
height=self.negativeLength)
# Mount holes
for hole in self.holeLocations:
s = element.Hole(radius=self.screw.outerDiameter/2,
height=self.negativeLength)
s.location = hole
asm += s
return asm
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
504,
1318,
28806,
492,
627,
199,
646,
8127,
9890,
14,
16877,
199,
646,
8127,
9890,
14,
16529,
421,
199,
533,
13382,
529,
8,
3173,
14,
2162,
304,
339,
347,
636,
826,
721,
277,
12,
326,
1568,
628,
9417,
6388,
2054,
1196,
401,
326,
6946,
29,
797,
12,
326,
6946,
4625,
29,
709,
304,
267,
3931,
14,
2162,
855,
826,
721,
277,
12,
536,
628,
2926,
529,
531,
267,
291,
14,
890,
275,
1568,
267,
291,
14,
2063,
275,
378,
267,
291,
14,
1267,
275,
378,
267,
291,
14,
3956,
24052,
275,
378,
267,
291,
14,
3956,
51,
1353,
87,
275,
3087,
267,
291,
14,
2327,
618,
1341,
1787,
275,
378,
267,
291,
14,
2327,
618,
8436,
275,
378,
267,
291,
14,
4835,
856,
4625,
275,
378,
267,
291,
14,
4835,
856,
1341,
1787,
275,
378,
267,
291,
14,
7371,
275,
6946,
267,
291,
14,
7371,
4625,
275,
6946,
4625,
267,
8127,
9890,
14,
16877,
14,
362,
63,
13320,
8,
890,
29,
890,
12,
536,
628,
2926,
529,
31642,
401,
1559,
29,
277,
9,
267,
291,
14,
16668,
27727,
275,
3474,
277,
14,
3956,
24052,
15,
18,
12,
291,
14,
3956,
24052,
15,
18,
12,
378,
467,
2892,
359,
277,
14,
3956,
24052,
15,
18,
12,
446,
277,
14,
3956,
24052,
15,
18,
12,
378,
467,
2892,
5243,
277,
14,
3956,
24052,
15,
18,
12,
291,
14,
3956,
24052,
15,
18,
12,
378,
467,
2892,
5243,
277,
14,
3956,
24052,
15,
18,
12,
446,
277,
14,
3956,
24052,
15,
18,
12,
378,
2677,
267,
291,
14,
551,
5257,
275,
8127,
9890,
14,
16529,
14,
9155,
51,
1353,
87,
8,
890,
29,
277,
14,
3956,
51,
1353,
87,
9,
267,
291,
14,
1985,
275,
359,
16,
12,
378,
12,
378,
61,
267,
291,
14,
2326,
275,
359,
16,
14,
21,
12,
378,
14,
21,
12,
378,
14,
21,
61,
267,
291,
14,
12708,
275,
291,
423,
12708,
342,
339,
347,
485,
12708,
8,
277,
304,
267,
2396,
275,
1819,
14,
25043,
779,
277,
14,
2063,
12,
291,
14,
2063,
12,
291,
14,
1267,
566,
267,
2396,
14,
4218,
275,
359,
549,
12,
715,
12,
756,
61,
267,
2396,
14,
1985,
275,
359,
16,
12,
378,
12,
446,
277,
14,
1267,
61,
267,
2717,
618,
275,
1819,
14,
9156,
24447,
8,
8017,
29,
277,
14,
2327,
618,
1341,
1787,
15,
18,
12,
3303,
4569,
29,
277,
14,
2327,
618,
8436,
9,
267,
7793,
856,
275,
1819,
14,
9156,
24447,
8,
8017,
29,
277,
14,
4835,
856,
1341,
1787,
15,
18,
12,
639,
4569,
29,
277,
14,
4835,
856,
4625,
11,
277,
14,
2327,
618,
8436,
9,
267,
21875,
275,
2396,
435,
2717,
618,
435,
7793,
856,
267,
340,
291,
14,
7371,
26,
288,
327,
11040,
618,
288,
21875,
847,
1819,
14,
40,
16721,
8,
8017,
29,
277,
14,
2327,
618,
1341,
1787,
15,
18,
12,
1816,
4569,
29,
277,
14,
7371,
4625,
9,
288,
327,
3930,
638,
2636,
2978,
288,
367,
2636,
274,
315,
291,
14,
16668,
27727,
26,
355,
308,
275,
1819,
14,
40,
16721,
8,
8017,
29,
277,
14,
551,
5257,
14,
7837,
1341,
1787,
15,
18,
12,
639,
4569,
29,
277,
14,
7371,
4625,
9,
355,
308,
14,
1985,
275,
2636,
274,
355,
21875,
847,
308,
267,
372,
21875,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
504,
1318,
28806,
492,
627,
199,
646,
8127,
9890,
14,
16877,
199,
646,
8127,
9890,
14,
16529,
421,
199,
533,
13382,
529,
8,
3173,
14,
2162,
304,
339,
347,
636,
826,
721,
277,
12,
326,
1568,
628,
9417,
6388,
2054,
1196,
401,
326,
6946,
29,
797,
12,
326,
6946,
4625,
29,
709,
304,
267,
3931,
14,
2162,
855,
826,
721,
277,
12,
536,
628,
2926,
529,
531,
267,
291,
14,
890,
275,
1568,
267,
291,
14,
2063,
275,
378,
267,
291,
14,
1267,
275,
378,
267,
291,
14,
3956,
24052,
275,
378,
267,
291,
14,
3956,
51,
1353,
87,
275,
3087,
267,
291,
14,
2327,
618,
1341,
1787,
275,
378,
267,
291,
14,
2327,
618,
8436,
275,
378,
267,
291,
14,
4835,
856,
4625,
275,
378,
267,
291,
14,
4835,
856,
1341,
1787,
275,
378,
267,
291,
14,
7371,
275,
6946,
267,
291,
14,
7371,
4625,
275,
6946,
4625,
267,
8127,
9890,
14,
16877,
14,
362,
63,
13320,
8,
890,
29,
890,
12,
536,
628,
2926,
529,
31642,
401,
1559,
29,
277,
9,
267,
291,
14,
16668,
27727,
275,
3474,
277,
14,
3956,
24052,
15,
18,
12,
291,
14,
3956,
24052,
15,
18,
12,
378,
467,
2892,
359,
277,
14,
3956,
24052,
15,
18,
12,
446,
277,
14,
3956,
24052,
15,
18,
12,
378,
467,
2892,
5243,
277,
14,
3956,
24052,
15,
18,
12,
291,
14,
3956,
24052,
15,
18,
12,
378,
467,
2892,
5243,
277,
14,
3956,
24052,
15,
18,
12,
446,
277,
14,
3956,
24052,
15,
18,
12,
378,
2677,
267,
291,
14,
551,
5257,
275,
8127,
9890,
14,
16529,
14,
9155,
51,
1353,
87,
8,
890,
29,
277,
14,
3956,
51,
1353,
87,
9,
267,
291,
14,
1985,
275,
359,
16,
12,
378,
12,
378,
61,
267,
291,
14,
2326,
275,
359,
16,
14,
21,
12,
378,
14,
21,
12,
378,
14,
21,
61,
267,
291,
14,
12708,
275,
291,
423,
12708,
342,
339,
347,
485,
12708,
8,
277,
304,
267,
2396,
275,
1819,
14,
25043,
779,
277,
14,
2063,
12,
291,
14,
2063,
12,
291,
14,
1267,
566,
267,
2396,
14,
4218,
275,
359,
549,
12,
715,
12,
756,
61,
267,
2396,
14,
1985,
275,
359,
16,
12,
378,
12,
446,
277,
14,
1267,
61,
267,
2717,
618,
275,
1819,
14,
9156,
24447,
8,
8017,
29,
277,
14,
2327,
618,
1341,
1787,
15,
18,
12,
3303,
4569,
29,
277,
14,
2327,
618,
8436,
9,
267,
7793,
856,
275,
1819,
14,
9156,
24447,
8,
8017,
29,
277,
14,
4835,
856,
1341,
1787,
15,
18,
12,
639,
4569,
29,
277,
14,
4835,
856,
4625,
11,
277,
14,
2327,
618,
8436,
9,
267,
21875,
275,
2396,
435,
2717,
618,
435,
7793,
856,
267,
340,
291,
14,
7371,
26,
288,
327,
11040,
618,
288,
21875,
847,
1819,
14,
40,
16721,
8,
8017,
29,
277,
14,
2327,
618,
1341,
1787,
15,
18,
12,
1816,
4569,
29,
277,
14,
7371,
4625,
9,
288,
327,
3930,
638,
2636,
2978,
288,
367,
2636,
274,
315,
291,
14,
16668,
27727,
26,
355,
308,
275,
1819,
14,
40,
16721,
8,
8017,
29,
277,
14,
551,
5257,
14,
7837,
1341,
1787,
15,
18,
12,
639,
4569,
29,
277,
14,
7371,
4625,
9,
355,
308,
14,
1985,
275,
2636,
274,
355,
21875,
847,
308,
267,
372,
21875,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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8 -*-
#
# This file is part of Invenio.
# Copyright (C) 2015-2018 CERN.
#
# Invenio is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.
"""Invenio application loader.
Quickstart
----------
Invenio-Base is taking advantage of advanced patterns for building Flask
application. It assumes you already have understanding of
`patterns for Flask <http://flask.pocoo.org/docs/dev/patterns/>`_.
Dependencies
~~~~~~~~~~~~
First we need to install and import dependencies:
.. code-block:: console
$ mkvirtualenv example
(example)$ pip install invenio-base
Now you can create new file ``app.py`` with following imports:
.. include:: ../examples/app.py
:start-after: # sphinxdoc-example-import-begin
:end-before: # sphinxdoc-example-import-end
:literal:
Configuration
~~~~~~~~~~~~~
Tell the application factory how to load configuration by creating
``config_loader`` function that accepts an application instance:
.. include:: ../examples/app.py
:start-after: # sphinxdoc-example-config-begin
:end-before: # sphinxdoc-example-config-end
:literal:
The recommended way is to use `Invenio-Config
<https://invenio-config.readthedocs.io/>`_ that provides a default
configuration loader :func:`invenio_config.utils.create_config_loader` which is
sufficient for most cases:
.. code-block:: python
from invenio_config import create_config_loader
config_loader = create_config_loader(config=Config, env_prefix='APP')
In the next step you should set an absolute path for the *instance folder* in
order to load configuration files and other data from deployment specific
location. The instance folder is also perfect place for dropping static files
if you do not serve them from CDN:
.. include:: ../examples/app.py
:start-after: # sphinxdoc-example-paths-begin
:end-before: # sphinxdoc-example-paths-end
:literal:
In our example the variables are read from environment variables first with the
purpose that they can be easily changed without modifying code for various
deployment usecases.
Combining Applications
~~~~~~~~~~~~~~~~~~~~~~
It is highly recommendended to separate Invenio UI and REST applications then
different exception handlers, URL converters and session management can be
installed on each application instance. You can even install your own WSGI
application side by side with Invenio ones.
Invenio packages provide apps (extensions), blueprints, and URL converters via
entry points ``invenio_base.[api_]<apps,blueprints,converters>``. You can
specify multiple entry point groups for each application factory (e.g.
``myservice.blueprints``):
.. include:: ../examples/app.py
:start-after: # sphinxdoc-example-factories-begin
:end-before: # sphinxdoc-example-factories-end
:literal:
You provide instances of your own apps, blueprints, or URL converters directly
to the factory:
.. code-block:: python
from flask import Blueprint
blueprint = Blueprint('example', __name__)
@blueprint.route('/')
def index():
return 'Hello from Example application.'
create_app = create_app_factory(
'example',
blueprints=[blueprint],
# other parameters as shown in previous example
)
Running
~~~~~~~
To run you application you need to first instantiate the application object:
.. include:: ../examples/app.py
:start-after: # sphinxdoc-example-objects-begin
:end-before: # sphinxdoc-example-objects-end
:literal:
Then you need to tell the **``flask``** command where is your file located
by setting environment variable ``FLASK_APP=app.py``:
.. code-block:: console
$ export FLASK_APP=app.py
$ flask run
If you prefer to make your own executable script then you can use following
pattern:
.. code-block:: python
from invenio_base.app import create_cli
cli = create_cli(create_app=create_app)
if __name__ == '__main__':
cli()
Do not worry, you do not have to write all this by yourself. Follow next steps
and use ``inveniomanage`` command that generates the scaffold code for you.
The ``inveniomanage`` command
-----------------------------
Invenio-Base installs the ``inveniomanage`` command. By default only three
subcommands are available:
.. code-block:: console
$ inveniomanage --help
Usage: inveniomanage [OPTIONS] COMMAND [ARGS]...
Command Line Interface for Invenio.
Options:
-a, --app TEXT The application to run.
--debug / --no-debug Enable or disable debug mode.
--help Show this message and exit.
Commands:
run Run development server.
shell Run shell in the app context.
The ``run`` and ``shell`` commands only works if you have specified the
``--app`` option or the ``FLASK_APP`` environment variable. See
`Flask <http://flask.pocoo.org/docs/dev/cli/>`_ documentation for further
information.
Listing all entrypoints of an Invenio instance
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The ``instance entrypoints`` subcommand helps you list all entrypoints of your
Invenio application:
.. code-block:: console
$ inveniomanage instance entrypoints
The output of the command will be in the below format:
.. code-block:: console
<entrypoint_group_name>
<entrypoint>
You can also restrict the output of the command to list all entrypoints for a
specific entrypoint group by passing the name via the `-e` option:
.. code-block:: console
$ inveniomanage instance entrypoints -e <entrypoint_group_name>
For further details about the available options run the `help` command:
.. code-block:: console
$ inveniomanage instance entrypoints --help
...
Migrating the application's old secret key
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The ``instance migrate_secret_key`` subcommand helps you migrate your
application's old secret key:
.. code-block:: console
$ inveniomanage instance migrate_secret_key --old-key <old_key>
The purpose of this command is to provide the administrator the capability to
change the Invenio application's secret_key and migrate that change in all
database's EncryptedType properties through an entrypoint group called
`invenio_base.secret_key'`. There you can specify your migration function that
will receive the old secret_key that can be used to decrypt the old properties
and encrypt them again with the application's new secret_key.
You can register your migration function as shown below in your package's
entrypoints in the setup.py:
.. code-block:: console
entrypoints= {
'invenio_base.secret_key': [
'<entrypoint_name> = <entrypoint_function>'
]
}
Also you can see an example of use in `invenio_oauthclient
<https://github.com/inveniosoftware/invenio-oauthclient>`_
package's setup.py.
.. note::
You should change your application's `secret_key` in the config before calling
the migration command.
For further details about the available options run the `help` command:
.. code-block:: console
$ inveniomanage instance migrate_secret_key --help
...
"""
from __future__ import absolute_import, print_function
from .app import create_app_factory, create_cli
from .version import __version__
from .wsgi import create_wsgi_factory
__all__ = (
'__version__',
'create_app_factory',
'create_cli',
'create_wsgi_factory',
)
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
12235,
14,
199,
3,
1898,
334,
35,
9,
6900,
13,
12682,
24354,
14,
199,
3,
199,
3,
12235,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
199,
3,
1334,
314,
2895,
402,
314,
10697,
844,
27,
1937,
5113,
570,
367,
1655,
2436,
14,
199,
199,
624,
607,
7597,
4223,
5077,
14,
199,
199,
19684,
928,
199,
9460,
199,
607,
7597,
13,
1563,
365,
16466,
30268,
402,
19472,
7970,
367,
10015,
16704,
199,
3578,
14,
2779,
15194,
1265,
2575,
1172,
1334,
18126,
402,
199,
64,
7435,
367,
16704,
665,
1014,
921,
15720,
14,
555,
22684,
14,
1308,
15,
4757,
15,
2374,
15,
7435,
3133,
32578,
199,
199,
11927,
199,
22935,
199,
7147,
781,
1929,
370,
3907,
436,
492,
5124,
26,
199,
199,
703,
1233,
13,
1457,
447,
8559,
8410,
2672,
9199,
21611,
2893,
2043,
334,
2694,
9,
4,
7305,
3907,
13640,
13,
1095,
199,
199,
14351,
1265,
883,
1218,
892,
570,
1124,
571,
14,
647,
1040,
543,
2569,
8925,
26,
199,
199,
703,
2387,
447,
24272,
8589,
15,
571,
14,
647,
2043,
520,
928,
13,
4399,
26,
327,
15882,
1301,
13,
2694,
13,
646,
13,
5037,
2043,
520,
500,
13,
5182,
26,
327,
15882,
1301,
13,
2694,
13,
646,
13,
500,
2043,
520,
8939,
26,
199,
199,
5688,
199,
22935,
94,
199,
52,
1697,
314,
4223,
6434,
4212,
370,
2248,
2897,
701,
6425,
199,
1040,
888,
63,
3422,
1040,
805,
626,
11479,
376,
4223,
1256,
26,
199,
199,
703,
2387,
447,
24272,
8589,
15,
571,
14,
647,
2043,
520,
928,
13,
4399,
26,
327,
15882,
1301,
13,
2694,
13,
888,
13,
5037,
2043,
520,
500,
13,
5182,
26,
327,
15882,
1301,
13,
2694,
13,
888,
13,
500,
2043,
520,
8939,
26,
199,
199,
1918,
14318,
4340,
365,
370,
675,
658,
607,
7597,
13,
2028,
199,
28,
2859,
921,
30628,
13,
888,
14,
25085,
14,
2308,
3133,
18417,
626,
6571,
282,
849,
199,
4758,
5077,
520,
1532,
1705,
30628,
63,
888,
14,
1208,
14,
981,
63,
888,
63,
3422,
64,
1314,
365,
199,
83,
12983,
367,
4750,
5560,
26,
199,
199,
703,
1233,
13,
1457,
447,
2366,
8410,
687,
13640,
63,
888,
492,
1218,
63,
888,
63,
3422,
2043,
1101,
63,
3422,
275,
1218,
63,
888,
63,
3422,
8,
888,
29,
2028,
12,
2589,
63,
1861,
534,
7121,
358,
199,
199,
607,
314,
2163,
3650,
1265,
1077,
663,
376,
3679,
931,
367,
314,
627,
842,
4922,
10,
315,
199,
1648,
370,
2248,
2897,
1584,
436,
1163,
666,
687,
14295,
2488,
199,
1985,
14,
710,
1256,
4922,
365,
2597,
23668,
4192,
367,
366,
20148,
2955,
1584,
199,
692,
1265,
886,
440,
14062,
3062,
687,
445,
10872,
26,
199,
199,
703,
2387,
447,
24272,
8589,
15,
571,
14,
647,
2043,
520,
928,
13,
4399,
26,
327,
15882,
1301,
13,
2694,
13,
3771,
13,
5037,
2043,
520,
500,
13,
5182,
26,
327,
15882,
1301,
13,
2694,
13,
3771,
13,
500,
2043,
520,
8939,
26,
199,
199,
607,
4154,
2893,
314,
2860,
787,
1586,
687,
3734,
2860,
1642,
543,
314,
199,
22615,
626,
2985,
883,
506,
16174,
2896,
1928,
24662,
1233,
367,
7750,
199,
13605,
675,
9403,
14,
199,
199,
17039,
316,
24636,
199,
9753,
2878,
1714,
199,
7940,
365,
4721,
590,
295,
9847,
848,
770,
370,
7396,
12235,
14041,
436,
14880,
13103,
2066,
199,
14020,
1919,
8297,
12,
2851,
23172,
436,
2351,
10041,
883,
506,
199,
7657,
641,
1924,
4223,
1256,
14,
2047,
883,
2755,
3907,
2195,
5705,
9279,
199,
3578,
5366,
701,
5366,
543,
12235,
7869,
14,
199,
199,
607,
7597,
6117,
5647,
8686,
334,
5359,
395,
16808,
83,
12,
436,
2851,
23172,
4799,
199,
2373,
4501,
1124,
30628,
63,
1095,
24097,
1246,
24601,
28,
5181,
12,
15918,
83,
12,
17911,
30,
4345,
2047,
883,
199,
26164,
3663,
2397,
2376,
4652,
367,
1924,
4223,
6434,
334,
69,
14,
71,
14,
199,
1040,
1662,
1364,
14,
15918,
83,
1040,
304,
199,
199,
703,
2387,
447,
24272,
8589,
15,
571,
14,
647,
2043,
520,
928,
13,
4399,
26,
327,
15882,
1301,
13,
2694,
13,
15406,
13,
5037,
2043,
520,
500,
13,
5182,
26,
327,
15882,
1301,
13,
2694,
13,
15406,
13,
500,
2043,
520,
8939,
26,
199,
199,
5556,
5647,
4454,
402,
2195,
5705,
8686,
12,
16808,
83,
12,
503,
2851,
23172,
5370,
199,
475,
314,
6434,
26,
199,
199,
703,
1233,
13,
1457,
447,
2366,
8410,
687,
7209,
492,
22447,
1361,
8410,
16808,
275,
22447,
1361,
360,
2694,
297,
636,
354,
3368,
8410,
768,
15918,
14,
4449,
7825,
2043,
347,
1478,
837,
2126,
372,
283,
6257,
687,
5679,
4223,
3530,
339,
1218,
63,
571,
275,
1218,
63,
571,
63,
3702,
8,
267,
283,
2694,
297,
267,
16808,
83,
1524,
15918,
467,
267,
327,
1163,
2633,
465,
9164,
315,
4136,
2893,
272,
776,
199,
199,
9602,
199,
2878,
23597,
199,
1378,
1255,
1265,
4223,
1265,
1929,
370,
1642,
17321,
314,
4223,
909,
26,
199,
199,
703,
2387,
447,
24272,
8589,
15,
571,
14,
647,
2043,
520,
928,
13,
4399,
26,
327,
15882,
1301,
13,
2694,
13,
1462,
13,
5037,
2043,
520,
500,
13,
5182,
26,
327,
15882,
1301,
13,
2694,
13,
1462,
13,
500,
2043,
520,
8939,
26,
199,
199,
28226,
1265,
1929,
370,
11480,
314,
1011,
1040,
15720,
1040,
538,
1414,
2382,
365,
2195,
570,
16180,
199,
991,
4260,
3734,
1750,
1124,
3143,
7946,
63,
7121,
29,
571,
14,
647,
18983,
199,
199,
703,
1233,
13,
1457,
447,
8559,
8410,
2672,
4843,
9821,
7946,
63,
7121,
29,
571,
14,
647,
2043,
2672,
7209,
1255,
199,
199,
3917,
1265,
16602,
370,
1852,
2195,
5705,
7286,
2884,
2066,
1265,
883,
675,
2569,
199,
3401,
26,
199,
199,
703,
1233,
13,
1457,
447,
2366,
8410,
687,
13640,
63,
1095,
14,
571,
492,
1218,
63,
2764,
8410,
5053,
275,
1218,
63,
2764,
8,
981,
63,
571,
29,
981,
63,
571,
9,
8410,
340,
636,
354,
363,
508,
2560,
973,
3706,
2126,
5053,
342,
199,
199,
2585,
440,
30944,
12,
1265,
886,
440,
1172,
370,
2218,
1006,
642,
701,
28225,
14,
21876,
2163,
7124,
199,
460,
675,
1124,
262,
1856,
73,
21604,
474,
1040,
1414,
626,
12821,
314,
32388,
1233,
367,
1265
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
12235,
14,
199,
3,
1898,
334,
35,
9,
6900,
13,
12682,
24354,
14,
199,
3,
199,
3,
12235,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
199,
3,
1334,
314,
2895,
402,
314,
10697,
844,
27,
1937,
5113,
570,
367,
1655,
2436,
14,
199,
199,
624,
607,
7597,
4223,
5077,
14,
199,
199,
19684,
928,
199,
9460,
199,
607,
7597,
13,
1563,
365,
16466,
30268,
402,
19472,
7970,
367,
10015,
16704,
199,
3578,
14,
2779,
15194,
1265,
2575,
1172,
1334,
18126,
402,
199,
64,
7435,
367,
16704,
665,
1014,
921,
15720,
14,
555,
22684,
14,
1308,
15,
4757,
15,
2374,
15,
7435,
3133,
32578,
199,
199,
11927,
199,
22935,
199,
7147,
781,
1929,
370,
3907,
436,
492,
5124,
26,
199,
199,
703,
1233,
13,
1457,
447,
8559,
8410,
2672,
9199,
21611,
2893,
2043,
334,
2694,
9,
4,
7305,
3907,
13640,
13,
1095,
199,
199,
14351,
1265,
883,
1218,
892,
570,
1124,
571,
14,
647,
1040,
543,
2569,
8925,
26,
199,
199,
703,
2387,
447,
24272,
8589,
15,
571,
14,
647,
2043,
520,
928,
13,
4399,
26,
327,
15882,
1301,
13,
2694,
13,
646,
13,
5037,
2043,
520,
500,
13,
5182,
26,
327,
15882,
1301,
13,
2694,
13,
646,
13,
500,
2043,
520,
8939,
26,
199,
199,
5688,
199,
22935,
94,
199,
52,
1697,
314,
4223,
6434,
4212,
370,
2248,
2897,
701,
6425,
199,
1040,
888,
63,
3422,
1040,
805,
626,
11479,
376,
4223,
1256,
26,
199,
199,
703,
2387,
447,
24272,
8589,
15,
571,
14,
647,
2043,
520,
928,
13,
4399,
26,
327,
15882,
1301,
13,
2694,
13,
888,
13,
5037,
2043,
520,
500,
13,
5182,
26,
327,
15882,
1301,
13,
2694,
13,
888,
13,
500,
2043,
520,
8939,
26,
199,
199,
1918,
14318,
4340,
365,
370,
675,
658,
607,
7597,
13,
2028,
199,
28,
2859,
921,
30628,
13,
888,
14,
25085,
14,
2308,
3133,
18417,
626,
6571,
282,
849,
199,
4758,
5077,
520,
1532,
1705,
30628,
63,
888,
14,
1208,
14,
981,
63,
888,
63,
3422,
64,
1314,
365,
199,
83,
12983,
367,
4750,
5560,
26,
199,
199,
703,
1233,
13,
1457,
447,
2366,
8410,
687,
13640,
63,
888,
492,
1218,
63,
888,
63,
3422,
2043,
1101,
63,
3422,
275,
1218,
63,
888,
63,
3422,
8,
888,
29,
2028,
12,
2589,
63,
1861,
534,
7121,
358,
199,
199,
607,
314,
2163,
3650,
1265,
1077,
663,
376,
3679,
931,
367,
314,
627,
842,
4922,
10,
315,
199,
1648,
370,
2248,
2897,
1584,
436,
1163,
666,
687,
14295,
2488,
199,
1985,
14,
710,
1256,
4922,
365,
2597,
23668,
4192,
367,
366,
20148,
2955,
1584,
199,
692,
1265,
886,
440,
14062,
3062,
687,
445,
10872,
26,
199,
199,
703,
2387,
447,
24272,
8589,
15,
571,
14,
647,
2043,
520,
928,
13,
4399,
26,
327,
15882,
1301,
13,
2694,
13,
3771,
13,
5037,
2043,
520,
500,
13,
5182,
26,
327,
15882,
1301,
13,
2694,
13,
3771,
13,
500,
2043,
520,
8939,
26,
199,
199,
607,
4154,
2893,
314,
2860,
787,
1586,
687,
3734,
2860,
1642,
543,
314,
199,
22615,
626,
2985,
883,
506,
16174,
2896,
1928,
24662,
1233,
367,
7750,
199,
13605,
675,
9403,
14,
199,
199,
17039,
316,
24636,
199,
9753,
2878,
1714,
199,
7940,
365,
4721,
590,
295,
9847,
848,
770,
370,
7396,
12235,
14041,
436,
14880,
13103,
2066,
199,
14020,
1919,
8297,
12,
2851,
23172,
436,
2351,
10041,
883,
506,
199,
7657,
641,
1924,
4223,
1256,
14,
2047,
883,
2755,
3907,
2195,
5705,
9279,
199,
3578,
5366,
701,
5366,
543,
12235,
7869,
14,
199,
199,
607,
7597,
6117,
5647,
8686,
334,
5359,
395,
16808,
83,
12,
436,
2851,
23172,
4799,
199,
2373,
4501,
1124,
30628,
63,
1095,
24097,
1246,
24601,
28,
5181,
12,
15918,
83,
12,
17911,
30,
4345,
2047,
883,
199,
26164,
3663,
2397,
2376,
4652,
367,
1924,
4223,
6434,
334,
69,
14,
71,
14,
199,
1040,
1662,
1364,
14,
15918,
83,
1040,
304,
199,
199,
703,
2387,
447,
24272,
8589,
15,
571,
14,
647,
2043,
520,
928,
13,
4399,
26,
327,
15882,
1301,
13,
2694,
13,
15406,
13,
5037,
2043,
520,
500,
13,
5182,
26,
327,
15882,
1301,
13,
2694,
13,
15406,
13,
500,
2043,
520,
8939,
26,
199,
199,
5556,
5647,
4454,
402,
2195,
5705,
8686,
12,
16808,
83,
12,
503,
2851,
23172,
5370,
199,
475,
314,
6434,
26,
199,
199,
703,
1233,
13,
1457,
447,
2366,
8410,
687,
7209,
492,
22447,
1361,
8410,
16808,
275,
22447,
1361,
360,
2694,
297,
636,
354,
3368,
8410,
768,
15918,
14,
4449,
7825,
2043,
347,
1478,
837,
2126,
372,
283,
6257,
687,
5679,
4223,
3530,
339,
1218,
63,
571,
275,
1218,
63,
571,
63,
3702,
8,
267,
283,
2694,
297,
267,
16808,
83,
1524,
15918,
467,
267,
327,
1163,
2633,
465,
9164,
315,
4136,
2893,
272,
776,
199,
199,
9602,
199,
2878,
23597,
199,
1378,
1255,
1265,
4223,
1265,
1929,
370,
1642,
17321,
314,
4223,
909,
26,
199,
199,
703,
2387,
447,
24272,
8589,
15,
571,
14,
647,
2043,
520,
928,
13,
4399,
26,
327,
15882,
1301,
13,
2694,
13,
1462,
13,
5037,
2043,
520,
500,
13,
5182,
26,
327,
15882,
1301,
13,
2694,
13,
1462,
13,
500,
2043,
520,
8939,
26,
199,
199,
28226,
1265,
1929,
370,
11480,
314,
1011,
1040,
15720,
1040,
538,
1414,
2382,
365,
2195,
570,
16180,
199,
991,
4260,
3734,
1750,
1124,
3143,
7946,
63,
7121,
29,
571,
14,
647,
18983,
199,
199,
703,
1233,
13,
1457,
447,
8559,
8410,
2672,
4843,
9821,
7946,
63,
7121,
29,
571,
14,
647,
2043,
2672,
7209,
1255,
199,
199,
3917,
1265,
16602,
370,
1852,
2195,
5705,
7286,
2884,
2066,
1265,
883,
675,
2569,
199,
3401,
26,
199,
199,
703,
1233,
13,
1457,
447,
2366,
8410,
687,
13640,
63,
1095,
14,
571,
492,
1218,
63,
2764,
8410,
5053,
275,
1218,
63,
2764,
8,
981,
63,
571,
29,
981,
63,
571,
9,
8410,
340,
636,
354,
363,
508,
2560,
973,
3706,
2126,
5053,
342,
199,
199,
2585,
440,
30944,
12,
1265,
886,
440,
1172,
370,
2218,
1006,
642,
701,
28225,
14,
21876,
2163,
7124,
199,
460,
675,
1124,
262,
1856,
73,
21604,
474,
1040,
1414,
626,
12821,
314,
32388,
1233,
367,
1265,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
foss-transportationmodeling/rettina-server
|
.env/local/lib/python2.7/encodings/big5hkscs.py
|
816
|
1039
|
#
# big5hkscs.py: Python Unicode Codec for BIG5HKSCS
#
# Written by Hye-Shik Chang <perky@FreeBSD.org>
#
import _codecs_hk, codecs
import _multibytecodec as mbc
codec = _codecs_hk.getcodec('big5hkscs')
class Codec(codecs.Codec):
encode = codec.encode
decode = codec.decode
class IncrementalEncoder(mbc.MultibyteIncrementalEncoder,
codecs.IncrementalEncoder):
codec = codec
class IncrementalDecoder(mbc.MultibyteIncrementalDecoder,
codecs.IncrementalDecoder):
codec = codec
class StreamReader(Codec, mbc.MultibyteStreamReader, codecs.StreamReader):
codec = codec
class StreamWriter(Codec, mbc.MultibyteStreamWriter, codecs.StreamWriter):
codec = codec
def getregentry():
return codecs.CodecInfo(
name='big5hkscs',
encode=Codec().encode,
decode=Codec().decode,
incrementalencoder=IncrementalEncoder,
incrementaldecoder=IncrementalDecoder,
streamreader=StreamReader,
streamwriter=StreamWriter,
)
|
apache-2.0
|
[
3,
199,
3,
7282,
21,
21557,
551,
83,
14,
647,
26,
2018,
6140,
13732,
367,
16524,
21,
40,
43,
14897,
199,
3,
199,
3,
27694,
701,
869,
8048,
13,
2662,
3258,
2799,
621,
665,
529,
10562,
32,
10146,
15400,
14,
1308,
30,
199,
3,
199,
199,
646,
485,
8933,
63,
21557,
12,
6010,
199,
646,
485,
3029,
4414,
9276,
465,
333,
3776,
199,
199,
9276,
275,
485,
8933,
63,
21557,
14,
362,
9276,
360,
5076,
21,
21557,
551,
83,
358,
199,
199,
533,
13732,
8,
8933,
14,
8818,
304,
272,
3752,
275,
9076,
14,
2143,
272,
4849,
275,
9076,
14,
2708,
199,
199,
533,
24350,
8,
887,
67,
14,
3947,
4414,
17016,
12,
586,
6010,
14,
17016,
304,
272,
9076,
275,
9076,
199,
199,
533,
24385,
8,
887,
67,
14,
3947,
4414,
16703,
12,
586,
6010,
14,
16703,
304,
272,
9076,
275,
9076,
199,
199,
533,
22970,
8,
8818,
12,
333,
3776,
14,
3947,
4414,
16132,
12,
6010,
14,
16132,
304,
272,
9076,
275,
9076,
199,
199,
533,
24163,
8,
8818,
12,
333,
3776,
14,
3947,
4414,
16551,
12,
6010,
14,
16551,
304,
272,
9076,
275,
9076,
199,
199,
318,
26116,
837,
272,
372,
6010,
14,
26375,
8,
267,
536,
534,
5076,
21,
21557,
551,
83,
297,
267,
3752,
29,
8818,
1252,
2143,
12,
267,
4849,
29,
8818,
1252,
2708,
12,
267,
26329,
29,
17016,
12,
267,
26317,
29,
16703,
12,
267,
26101,
29,
16132,
12,
267,
26112,
29,
16551,
12,
272,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
3,
7282,
21,
21557,
551,
83,
14,
647,
26,
2018,
6140,
13732,
367,
16524,
21,
40,
43,
14897,
199,
3,
199,
3,
27694,
701,
869,
8048,
13,
2662,
3258,
2799,
621,
665,
529,
10562,
32,
10146,
15400,
14,
1308,
30,
199,
3,
199,
199,
646,
485,
8933,
63,
21557,
12,
6010,
199,
646,
485,
3029,
4414,
9276,
465,
333,
3776,
199,
199,
9276,
275,
485,
8933,
63,
21557,
14,
362,
9276,
360,
5076,
21,
21557,
551,
83,
358,
199,
199,
533,
13732,
8,
8933,
14,
8818,
304,
272,
3752,
275,
9076,
14,
2143,
272,
4849,
275,
9076,
14,
2708,
199,
199,
533,
24350,
8,
887,
67,
14,
3947,
4414,
17016,
12,
586,
6010,
14,
17016,
304,
272,
9076,
275,
9076,
199,
199,
533,
24385,
8,
887,
67,
14,
3947,
4414,
16703,
12,
586,
6010,
14,
16703,
304,
272,
9076,
275,
9076,
199,
199,
533,
22970,
8,
8818,
12,
333,
3776,
14,
3947,
4414,
16132,
12,
6010,
14,
16132,
304,
272,
9076,
275,
9076,
199,
199,
533,
24163,
8,
8818,
12,
333,
3776,
14,
3947,
4414,
16551,
12,
6010,
14,
16551,
304,
272,
9076,
275,
9076,
199,
199,
318,
26116,
837,
272,
372,
6010,
14,
26375,
8,
267,
536,
534,
5076,
21,
21557,
551,
83,
297,
267,
3752,
29,
8818,
1252,
2143,
12,
267,
4849,
29,
8818,
1252,
2708,
12,
267,
26329,
29,
17016,
12,
267,
26317,
29,
16703,
12,
267,
26101,
29,
16132,
12,
267,
26112,
29,
16551,
12,
272,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
bodi000/odoo
|
addons/stock/report/product_stock.py
|
376
|
4868
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from datetime import datetime
from dateutil.relativedelta import relativedelta
import openerp
from openerp import osv
import time
from openerp.report.interface import report_int
from openerp.report.render import render
import stock_graph
import StringIO
import unicodedata
class external_pdf(render):
def __init__(self, pdf):
render.__init__(self)
self.pdf = pdf
self.output_type='pdf'
def _render(self):
return self.pdf
class report_stock(report_int):
def create(self, cr, uid, ids, datas, context=None):
if context is None:
context = {}
registry = openerp.registry(cr.dbname)
product_ids = ids
if 'location_id' in context:
location_id = context['location_id']
else:
warehouse_id = registry['stock.warehouse'].search(cr, uid, [])[0]
location_id = registry['stock.warehouse'].browse(cr, uid, warehouse_id).lot_stock_id.id
loc_ids = registry['stock.location'].search(cr, uid, [('location_id','child_of',[location_id])])
now = time.strftime('%Y-%m-%d')
dt_from = now
dt_to = now
names = dict(registry['product.product'].name_get(cr, uid, product_ids))
for name in names:
names[name] = names[name].encode('utf8')
products = {}
ctx = context.copy()
ctx['location_id'] = loc_ids
prods = registry['product.product']._product_available(cr, uid, product_ids, context=ctx)
for prod in prods.keys():
products[prod] = [(now, prods[prod]['qty_available'])]
prods[prod] = 0
if not loc_ids or not product_ids:
return (False, 'pdf')
cr.execute("select sum(r.product_qty * u.factor), r.date, r.product_id "
"from stock_move r left join product_uom u on (r.product_uom=u.id) "
"where state IN %s"
"and location_id IN %s"
"and product_id IN %s"
"group by date,product_id",(('confirmed','assigned','waiting'),tuple(loc_ids) ,tuple(product_ids),))
for (qty, dt, prod_id) in cr.fetchall():
if dt<=dt_from:
dt= (datetime.now() + relativedelta(days=1)).strftime('%Y-%m-%d')
else:
dt = dt[:10]
products.setdefault(prod_id, [])
products[prod_id].append((dt,-qty))
cr.execute("select sum(r.product_qty * u.factor), r.date, r.product_id "
"from stock_move r left join product_uom u on (r.product_uom=u.id) "
"where state IN %s"
"and location_dest_id IN %s"
"and product_id IN %s"
"group by date,product_id",(('confirmed','assigned','waiting'),tuple(loc_ids) ,tuple(product_ids),))
for (qty, dt, prod_id) in cr.fetchall():
if dt<=dt_from:
dt= (datetime.now() + relativedelta(days=1)).strftime('%Y-%m-%d')
else:
dt = dt[:10]
products.setdefault(prod_id, [])
products[prod_id].append((dt,qty))
dt = dt_from
qty = 0
io = StringIO.StringIO()
gt = stock_graph.stock_graph(io)
for prod_id in products:
prod_name = names.get(prod_id,'Unknown')
if isinstance(prod_name, str):
prod_name = prod_name.decode('utf-8')
prod_name = unicodedata.normalize('NFKD',prod_name)
prod_name = prod_name.encode('ascii','replace')
gt.add(prod_id, prod_name, products[prod_id])
gt.draw()
gt.close()
self.obj = external_pdf(io.getvalue())
self.obj.render()
return (self.obj.pdf, 'pdf')
report_stock('report.stock.product.history')
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
504,
2197,
492,
2197,
199,
504,
22208,
14,
32300,
492,
20599,
199,
199,
646,
5166,
199,
504,
5166,
492,
9506,
199,
646,
900,
199,
504,
5166,
14,
3070,
14,
3266,
492,
3622,
63,
442,
199,
504,
5166,
14,
3070,
14,
3352,
492,
3795,
199,
199,
646,
10952,
63,
2180,
199,
646,
5228,
199,
646,
23128,
199,
199,
533,
5957,
63,
5607,
8,
3352,
304,
272,
347,
636,
826,
721,
277,
12,
11249,
304,
267,
3795,
855,
826,
721,
277,
9,
267,
291,
14,
5607,
275,
11249,
267,
291,
14,
1199,
63,
466,
534,
5607,
7,
339,
347,
485,
3352,
8,
277,
304,
267,
372,
291,
14,
5607,
421,
199,
533,
3622,
63,
6088,
8,
3070,
63,
442,
304,
272,
347,
1218,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
15012,
12,
1067,
29,
403,
304,
267,
340,
1067,
365,
488,
26,
288,
1067,
275,
1052,
267,
7086,
275,
5166,
14,
5189,
8,
1556,
14,
13238,
9,
267,
3336,
63,
1580,
275,
2762,
267,
340,
283,
1985,
63,
344,
7,
315,
1067,
26,
288,
2909,
63,
344,
275,
1067,
459,
1985,
63,
344,
418,
267,
587,
26,
288,
13782,
63,
344,
275,
7086,
459,
6088,
14,
12806,
2278,
1733,
8,
1556,
12,
1747,
12,
3073,
59,
16,
61,
288,
2909,
63,
344,
275,
7086,
459,
6088,
14,
12806,
2278,
4570,
8,
1556,
12,
1747,
12,
13782,
63,
344,
680,
1653,
63,
6088,
63,
344,
14,
344,
398,
4355,
63,
1580,
275,
7086,
459,
6088,
14,
1985,
2278,
1733,
8,
1556,
12,
1747,
12,
4274,
1985,
63,
344,
1673,
1739,
63,
1618,
23993,
1985,
63,
344,
24310,
398,
3063,
275,
900,
14,
6205,
3508,
57,
3295,
77,
3295,
68,
358,
267,
4487,
63,
504,
275,
3063,
267,
4487,
63,
475,
275,
3063,
398,
1561,
275,
1211,
8,
5189,
459,
2558,
14,
2558,
2278,
354,
63,
362,
8,
1556,
12,
1747,
12,
3336,
63,
1580,
430,
267,
367,
536,
315,
1561,
26,
288,
1561,
59,
354,
61,
275,
1561,
59,
354,
1055,
2143,
360,
1624,
24,
358,
267,
7585,
275,
1052,
267,
4027,
275,
1067,
14,
1574,
342,
267,
4027,
459,
1985,
63,
344,
418,
275,
4355,
63,
1580,
267,
557,
795,
275,
7086,
459,
2558,
14,
2558,
26099,
2558,
63,
4561,
8,
1556,
12,
1747,
12,
3336,
63,
1580,
12,
1067,
29,
3799,
9,
267,
367,
12441,
315,
557,
795,
14,
1612,
837,
288,
7585,
59,
8788,
61,
275,
3842,
2131,
12,
557,
795,
59,
8788,
2733,
5643,
63,
4561,
24437,
288,
557,
795,
59,
8788,
61,
275,
378,
7318,
340,
440,
4355,
63,
1580,
503,
440,
3336,
63,
1580,
26,
288,
372,
334,
797,
12,
283,
5607,
358,
398,
2467,
14,
2526,
480,
2416,
3089,
8,
82,
14,
2558,
63,
5643,
627,
399,
14,
4778,
395,
519,
14,
602,
12,
519,
14,
2558,
63,
344,
298,
673,
298,
504,
10952,
63,
1185,
519,
3602,
4263,
3336,
63,
7519,
399,
641,
334,
82,
14,
2558,
63,
7519,
29,
85,
14,
344,
9,
298,
673,
298,
4509,
1174,
1621,
450,
83,
2,
673,
298,
460,
2909,
63,
344,
1621,
450,
83,
2,
673,
298,
460,
3336,
63,
344,
1621,
450,
83,
2,
673,
298,
923,
701,
1434,
12,
2558,
63,
344,
401,
4725,
16391,
1673,
12941,
1673,
14093,
659,
2960,
8,
2102,
63,
1580,
9,
2360,
2960,
8,
2558,
63,
1580,
18399,
267,
367,
334,
5643,
12,
4487,
12,
12441,
63,
344,
9,
315,
2467,
14,
10174,
837,
288,
340,
4487,
12932,
3583,
63,
504,
26,
355,
4487,
29,
334,
2083,
14,
2131,
342,
435,
20599,
8,
4899,
29,
17,
4992,
6205,
3508,
57,
3295,
77,
3295,
68,
358,
288,
587,
26,
355,
4487,
275,
4487,
1491,
709,
61,
288,
7585,
14,
5486,
8,
8788,
63,
344,
12,
3073,
288,
7585,
59,
8788,
63,
344,
1055,
740,
1332,
3583,
3057,
5643,
430,
398,
2467,
14,
2526,
480,
2416,
3089,
8,
82,
14,
2558,
63,
5643,
627,
399,
14,
4778,
395,
519,
14,
602,
12,
519,
14,
2558,
63,
344,
298,
673,
298,
504,
10952,
63,
1185,
519,
3602,
4263,
3336,
63,
7519,
399,
641,
334,
82,
14,
2558,
63,
7519,
29,
85,
14,
344,
9,
298,
673,
298,
4509,
1174,
1621,
450,
83,
2,
673,
298,
460,
2909,
63,
2614,
63,
344,
1621,
450,
83,
2,
673,
298,
460,
3336,
63,
344,
1621,
450,
83,
2,
673,
298,
923,
701,
1434,
12,
2558,
63,
344,
401,
4725,
16391,
1673,
12941,
1673,
14093,
659,
2960,
8,
2102,
63,
1580,
9,
2360,
2960,
8,
2558,
63,
1580,
18399,
398,
367,
334,
5643,
12,
4487,
12,
12441,
63,
344,
9,
315,
2467,
14,
10174,
837,
288,
340,
4487,
12932,
3583,
63,
504,
26,
355,
4487,
29,
334,
2083,
14,
2131,
342,
435,
20599,
8,
4899,
29,
17,
4992,
6205,
3508,
57,
3295,
77,
3295,
68,
358,
288,
587,
26,
355,
4487,
275,
4487,
1491,
709,
61,
288,
7585,
14,
5486,
8,
8788,
63,
344,
12,
3073,
288,
7585,
59
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
504,
2197,
492,
2197,
199,
504,
22208,
14,
32300,
492,
20599,
199,
199,
646,
5166,
199,
504,
5166,
492,
9506,
199,
646,
900,
199,
504,
5166,
14,
3070,
14,
3266,
492,
3622,
63,
442,
199,
504,
5166,
14,
3070,
14,
3352,
492,
3795,
199,
199,
646,
10952,
63,
2180,
199,
646,
5228,
199,
646,
23128,
199,
199,
533,
5957,
63,
5607,
8,
3352,
304,
272,
347,
636,
826,
721,
277,
12,
11249,
304,
267,
3795,
855,
826,
721,
277,
9,
267,
291,
14,
5607,
275,
11249,
267,
291,
14,
1199,
63,
466,
534,
5607,
7,
339,
347,
485,
3352,
8,
277,
304,
267,
372,
291,
14,
5607,
421,
199,
533,
3622,
63,
6088,
8,
3070,
63,
442,
304,
272,
347,
1218,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
15012,
12,
1067,
29,
403,
304,
267,
340,
1067,
365,
488,
26,
288,
1067,
275,
1052,
267,
7086,
275,
5166,
14,
5189,
8,
1556,
14,
13238,
9,
267,
3336,
63,
1580,
275,
2762,
267,
340,
283,
1985,
63,
344,
7,
315,
1067,
26,
288,
2909,
63,
344,
275,
1067,
459,
1985,
63,
344,
418,
267,
587,
26,
288,
13782,
63,
344,
275,
7086,
459,
6088,
14,
12806,
2278,
1733,
8,
1556,
12,
1747,
12,
3073,
59,
16,
61,
288,
2909,
63,
344,
275,
7086,
459,
6088,
14,
12806,
2278,
4570,
8,
1556,
12,
1747,
12,
13782,
63,
344,
680,
1653,
63,
6088,
63,
344,
14,
344,
398,
4355,
63,
1580,
275,
7086,
459,
6088,
14,
1985,
2278,
1733,
8,
1556,
12,
1747,
12,
4274,
1985,
63,
344,
1673,
1739,
63,
1618,
23993,
1985,
63,
344,
24310,
398,
3063,
275,
900,
14,
6205,
3508,
57,
3295,
77,
3295,
68,
358,
267,
4487,
63,
504,
275,
3063,
267,
4487,
63,
475,
275,
3063,
398,
1561,
275,
1211,
8,
5189,
459,
2558,
14,
2558,
2278,
354,
63,
362,
8,
1556,
12,
1747,
12,
3336,
63,
1580,
430,
267,
367,
536,
315,
1561,
26,
288,
1561,
59,
354,
61,
275,
1561,
59,
354,
1055,
2143,
360,
1624,
24,
358,
267,
7585,
275,
1052,
267,
4027,
275,
1067,
14,
1574,
342,
267,
4027,
459,
1985,
63,
344,
418,
275,
4355,
63,
1580,
267,
557,
795,
275,
7086,
459,
2558,
14,
2558,
26099,
2558,
63,
4561,
8,
1556,
12,
1747,
12,
3336,
63,
1580,
12,
1067,
29,
3799,
9,
267,
367,
12441,
315,
557,
795,
14,
1612,
837,
288,
7585,
59,
8788,
61,
275,
3842,
2131,
12,
557,
795,
59,
8788,
2733,
5643,
63,
4561,
24437,
288,
557,
795,
59,
8788,
61,
275,
378,
7318,
340,
440,
4355,
63,
1580,
503,
440,
3336,
63,
1580,
26,
288,
372,
334,
797,
12,
283,
5607,
358,
398,
2467,
14,
2526,
480,
2416,
3089,
8,
82,
14,
2558,
63,
5643,
627,
399,
14,
4778,
395,
519,
14,
602,
12,
519,
14,
2558,
63,
344,
298,
673,
298,
504,
10952,
63,
1185,
519,
3602,
4263,
3336,
63,
7519,
399,
641,
334,
82,
14,
2558,
63,
7519,
29,
85,
14,
344,
9,
298,
673,
298,
4509,
1174,
1621,
450,
83,
2,
673,
298,
460,
2909,
63,
344,
1621,
450,
83,
2,
673,
298,
460,
3336,
63,
344,
1621,
450,
83,
2,
673,
298,
923,
701,
1434,
12,
2558,
63,
344,
401,
4725,
16391,
1673,
12941,
1673,
14093,
659,
2960,
8,
2102,
63,
1580,
9,
2360,
2960,
8,
2558,
63,
1580,
18399,
267,
367,
334,
5643,
12,
4487,
12,
12441,
63,
344,
9,
315,
2467,
14,
10174,
837,
288,
340,
4487,
12932,
3583,
63,
504,
26,
355,
4487,
29,
334,
2083,
14,
2131,
342,
435,
20599,
8,
4899,
29,
17,
4992,
6205,
3508,
57,
3295,
77,
3295,
68,
358,
288,
587,
26,
355,
4487,
275,
4487,
1491,
709,
61,
288,
7585,
14,
5486,
8,
8788,
63,
344,
12,
3073,
288,
7585,
59,
8788,
63,
344,
1055,
740,
1332,
3583,
3057,
5643,
430,
398,
2467,
14,
2526,
480,
2416,
3089,
8,
82,
14,
2558,
63,
5643,
627,
399,
14,
4778,
395,
519,
14,
602,
12,
519,
14,
2558,
63,
344,
298,
673,
298,
504,
10952,
63,
1185,
519,
3602,
4263,
3336,
63,
7519,
399,
641,
334,
82,
14,
2558,
63,
7519,
29,
85,
14,
344,
9,
298,
673,
298,
4509,
1174,
1621,
450,
83,
2,
673,
298,
460,
2909,
63,
2614,
63,
344,
1621,
450,
83,
2,
673,
298,
460,
3336,
63,
344,
1621,
450,
83,
2,
673,
298,
923,
701,
1434,
12,
2558,
63,
344,
401,
4725,
16391,
1673,
12941,
1673,
14093,
659,
2960,
8,
2102,
63,
1580,
9,
2360,
2960,
8,
2558,
63,
1580,
18399,
398,
367,
334,
5643,
12,
4487,
12,
12441,
63,
344,
9,
315,
2467,
14,
10174,
837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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
restless/django-guardian
|
guardian/utils.py
|
1
|
4832
|
"""
django-guardian helper functions.
Functions defined within this module should be considered as django-guardian's
internal functionality. They are **not** guaranteed to be stable - which means
they actual input parameters/output type may change in future releases.
"""
import os
import logging
from itertools import chain
from django.conf import settings
from django.contrib.auth import REDIRECT_FIELD_NAME
from django.core.exceptions import PermissionDenied
from django.http import HttpResponseForbidden, HttpResponseRedirect
from django.shortcuts import render_to_response
from django.template import RequestContext, TemplateDoesNotExist
from django.utils.http import urlquote
from guardian.compat import AnonymousUser
from guardian.compat import Group
from guardian.compat import User
from guardian.conf import settings as guardian_settings
from guardian.exceptions import NotUserNorGroup
logger = logging.getLogger(__name__)
abspath = lambda *p: os.path.abspath(os.path.join(*p))
def get_anonymous_user():
"""
Returns ``User`` instance (not ``AnonymousUser``) depending on
``ANONYMOUS_USER_ID`` configuration.
"""
return User.objects.get(id=guardian_settings.ANONYMOUS_USER_ID)
def get_groups_backref_name():
"""
Returns backreference name from Group to user model.
"""
return User._meta.get_field_by_name('groups')[0].related_query_name()
def get_identity(identity):
"""
Returns (user_obj, None) or (None, group_obj) tuple depending on what is
given. Also accepts AnonymousUser instance but would return ``User``
instead - it is convenient and needed for authorization backend to support
anonymous users.
:param identity: either ``User`` or ``Group`` instance
:raises ``NotUserNorGroup``: if cannot return proper identity instance
**Examples**::
>>> user = User.objects.create(username='joe')
>>> get_identity(user)
(<User: joe>, None)
>>> group = Group.objects.create(name='users')
>>> get_identity(group)
(None, <Group: users>)
>>> anon = AnonymousUser()
>>> get_identity(anon)
(<User: AnonymousUser>, None)
>>> get_identity("not instance")
...
NotUserNorGroup: User/AnonymousUser or Group instance is required (got )
"""
if isinstance(identity, AnonymousUser):
identity = get_anonymous_user()
if isinstance(identity, User):
return identity, None
elif isinstance(identity, Group):
return None, identity
raise NotUserNorGroup("User/AnonymousUser or Group instance is required "
"(got %s)" % identity)
def get_403_or_None(request, perms, obj=None, login_url=None,
redirect_field_name=None, return_403=False, accept_global_perms=False):
login_url = login_url or settings.LOGIN_URL
redirect_field_name = redirect_field_name or REDIRECT_FIELD_NAME
# Handles both original and with object provided permission check
# as ``obj`` defaults to None
has_permissions = False
# global perms check first (if accept_global_perms)
if accept_global_perms:
has_permissions = all(request.user.has_perm(perm) for perm in perms)
# if still no permission granted, try obj perms
if not has_permissions:
has_permissions = all(request.user.has_perm(perm, obj) for perm in perms)
if not has_permissions:
if return_403:
if guardian_settings.RENDER_403:
try:
response = render_to_response(
guardian_settings.TEMPLATE_403, {},
RequestContext(request))
response.status_code = 403
return response
except TemplateDoesNotExist, e:
if settings.DEBUG:
raise e
elif guardian_settings.RAISE_403:
raise PermissionDenied
return HttpResponseForbidden()
else:
path = urlquote(request.get_full_path())
tup = login_url, redirect_field_name, path
return HttpResponseRedirect("%s?%s=%s" % tup)
def clean_orphan_obj_perms():
"""
Seeks and removes all object permissions entries pointing at non-existing
targets.
Returns number of removed objects.
"""
from guardian.models import UserObjectPermission
from guardian.models import GroupObjectPermission
deleted = 0
# TODO: optimise
for perm in chain(UserObjectPermission.objects.all(),
GroupObjectPermission.objects.all()):
if perm.content_object is None:
logger.debug("Removing %s (pk=%d)" % (perm, perm.pk))
perm.delete()
deleted += 1
logger.info("Total removed orphan object permissions instances: %d" %
deleted)
return deleted
|
bsd-2-clause
|
[
624,
199,
1176,
13,
6051,
31186,
5922,
3423,
14,
199,
199,
13967,
3247,
4453,
642,
859,
1077,
506,
8652,
465,
1639,
13,
6051,
31186,
1159,
199,
4672,
9330,
14,
9322,
787,
1011,
1397,
538,
17334,
370,
506,
17830,
446,
1314,
4910,
199,
29002,
3503,
1324,
2633,
15,
1199,
730,
1443,
1570,
315,
6466,
19015,
14,
199,
624,
199,
646,
747,
199,
646,
2050,
199,
504,
7975,
492,
6036,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
2828,
14,
1178,
492,
820,
7458,
4168,
63,
8609,
63,
2339,
199,
504,
1639,
14,
1018,
14,
3924,
492,
23724,
199,
504,
1639,
14,
1014,
492,
6183,
17454,
12,
14935,
199,
504,
1639,
14,
17469,
492,
3795,
63,
475,
63,
1310,
199,
504,
1639,
14,
1160,
492,
22538,
12,
27193,
199,
504,
1639,
14,
1208,
14,
1014,
492,
1166,
3513,
199,
199,
504,
8129,
31186,
14,
5819,
492,
29952,
199,
504,
8129,
31186,
14,
5819,
492,
5611,
199,
504,
8129,
31186,
14,
5819,
492,
2876,
199,
504,
8129,
31186,
14,
2190,
492,
2202,
465,
8129,
31186,
63,
1751,
199,
504,
8129,
31186,
14,
3924,
492,
2832,
1899,
23008,
2448,
199,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
4832,
275,
2400,
627,
80,
26,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
904,
2031,
80,
430,
421,
199,
318,
664,
63,
12628,
63,
751,
837,
272,
408,
272,
1803,
1124,
1899,
1040,
1256,
334,
1397,
1124,
23902,
1899,
16580,
10298,
641,
272,
1124,
879,
32537,
2679,
1668,
63,
3791,
63,
998,
1040,
2897,
14,
272,
408,
272,
372,
2876,
14,
1462,
14,
362,
8,
344,
29,
6051,
31186,
63,
1751,
14,
879,
32537,
2679,
1668,
63,
3791,
63,
998,
9,
421,
199,
318,
664,
63,
2634,
63,
894,
1121,
63,
354,
837,
272,
408,
272,
1803,
1771,
4443,
536,
687,
5611,
370,
922,
1402,
14,
272,
408,
272,
372,
2876,
423,
2024,
14,
362,
63,
698,
63,
991,
63,
354,
360,
2634,
5832,
16,
1055,
2407,
63,
1131,
63,
354,
342,
421,
199,
318,
664,
63,
5582,
8,
5582,
304,
272,
408,
272,
1803,
334,
751,
63,
1113,
12,
488,
9,
503,
334,
403,
12,
1572,
63,
1113,
9,
2008,
10298,
641,
4052,
365,
272,
1627,
14,
6121,
11479,
29952,
1256,
1325,
3955,
372,
1124,
1899,
1040,
272,
3140,
446,
652,
365,
22700,
436,
4346,
367,
13448,
4865,
370,
2291,
272,
16535,
4390,
14,
339,
520,
635,
8503,
26,
1902,
1124,
1899,
1040,
503,
1124,
2448,
1040,
1256,
339,
520,
3536,
1124,
1763,
1899,
23008,
2448,
18983,
340,
3913,
372,
5576,
8503,
1256,
339,
1011,
22787,
538,
447,
10817,
1306,
922,
275,
2876,
14,
1462,
14,
981,
8,
2473,
534,
20241,
358,
2126,
1306,
664,
63,
5582,
8,
751,
9,
2126,
8642,
1899,
26,
5225,
69,
6244,
488,
9,
10817,
1306,
1572,
275,
5611,
14,
1462,
14,
981,
8,
354,
534,
3707,
358,
2126,
1306,
664,
63,
5582,
8,
923,
9,
2126,
334,
403,
12,
665,
2448,
26,
4390,
18956,
10817,
1306,
24757,
275,
29952,
342,
2126,
1306,
664,
63,
5582,
8,
21009,
9,
2126,
8642,
1899,
26,
29952,
6244,
488,
9,
10817,
1306,
664,
63,
5582,
480,
1397,
1256,
531,
2126,
2263,
2126,
2832,
1899,
23008,
2448,
26,
2876,
15,
23902,
1899,
503,
5611,
1256,
365,
1415,
334,
7808,
776,
339,
408,
272,
340,
1228,
8,
5582,
12,
29952,
304,
267,
8503,
275,
664,
63,
12628,
63,
751,
342,
339,
340,
1228,
8,
5582,
12,
2876,
304,
267,
372,
8503,
12,
488,
272,
916,
1228,
8,
5582,
12,
5611,
304,
267,
372,
488,
12,
8503,
339,
746,
2832,
1899,
23008,
2448,
480,
1899,
15,
23902,
1899,
503,
5611,
1256,
365,
1415,
298,
267,
7340,
7808,
450,
83,
2924,
450,
8503,
9,
421,
199,
318,
664,
63,
13353,
63,
269,
63,
403,
8,
1069,
12,
17340,
12,
1559,
29,
403,
12,
4676,
63,
633,
29,
403,
12,
272,
4660,
63,
698,
63,
354,
29,
403,
12,
372,
63,
13353,
29,
797,
12,
4729,
63,
2966,
63,
12068,
29,
797,
304,
272,
4676,
63,
633,
275,
4676,
63,
633,
503,
2202,
14,
17208,
63,
2632,
272,
4660,
63,
698,
63,
354,
275,
4660,
63,
698,
63,
354,
503,
820,
7458,
4168,
63,
8609,
63,
2339,
339,
327,
23873,
3865,
3379,
436,
543,
909,
2741,
4983,
1104,
272,
327,
465,
1124,
1113,
1040,
4243,
370,
488,
339,
965,
63,
6060,
275,
756,
272,
327,
2288,
17340,
1104,
1642,
334,
692,
4729,
63,
2966,
63,
12068,
9,
272,
340,
4729,
63,
2966,
63,
12068,
26,
267,
965,
63,
6060,
275,
1006,
8,
1069,
14,
751,
14,
1989,
63,
8220,
8,
8220,
9,
367,
10869,
315,
17340,
9,
272,
327,
340,
5139,
949,
4983,
10009,
12,
862,
1559,
17340,
272,
340,
440,
965,
63,
6060,
26,
267,
965,
63,
6060,
275,
1006,
8,
1069,
14,
751,
14,
1989,
63,
8220,
8,
8220,
12,
1559,
9,
367,
10869,
315,
17340,
9,
339,
340,
440,
965,
63,
6060,
26,
267,
340,
372,
63,
13353,
26,
288,
340,
8129,
31186,
63,
1751,
14,
31587,
63,
13353,
26,
355,
862,
26,
490,
1177,
275,
3795,
63,
475,
63,
1310,
8,
717,
8129,
31186,
63,
1751,
14,
7433,
63,
13353,
12,
5479,
717,
22538,
8,
1069,
430,
490,
1177,
14,
1205,
63,
600,
275,
13269,
490,
372,
1177,
355,
871,
27193,
12,
325,
26,
490,
340,
2202,
14,
5287,
26,
717,
746,
325,
288,
916,
8129,
31186,
63,
1751,
14,
2847,
4971,
63,
13353,
26,
355,
746,
23724,
288,
372,
6183,
17454,
342,
267,
587,
26,
288,
931,
275,
1166,
3513,
8,
1069,
14,
362,
63,
2861,
63,
515,
1012,
288,
16477,
275,
4676,
63,
633,
12,
4660,
63,
698,
63,
354,
12,
931,
288,
372,
14935,
3647,
83,
25790,
83,
2458,
83,
2,
450,
16477,
9,
421,
199,
318,
3633,
63,
22161,
63,
1113,
63,
12068,
837,
272,
408,
272,
1666,
6080,
436,
14185,
1006,
909,
3443,
4811,
20686,
737,
2222,
13,
5952,
272,
4545,
14,
339,
1803,
1329,
402,
4829,
2251,
14,
272,
408,
272,
687,
8129,
31186,
14,
992,
492,
2876,
1692,
7980,
272,
687,
8129,
31186,
14,
992,
492,
5611,
1692,
7980,
2378,
5463,
275,
378,
272,
327,
3254,
26,
5323,
572,
272,
367,
10869,
315
] |
[
199,
1176,
13,
6051,
31186,
5922,
3423,
14,
199,
199,
13967,
3247,
4453,
642,
859,
1077,
506,
8652,
465,
1639,
13,
6051,
31186,
1159,
199,
4672,
9330,
14,
9322,
787,
1011,
1397,
538,
17334,
370,
506,
17830,
446,
1314,
4910,
199,
29002,
3503,
1324,
2633,
15,
1199,
730,
1443,
1570,
315,
6466,
19015,
14,
199,
624,
199,
646,
747,
199,
646,
2050,
199,
504,
7975,
492,
6036,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
2828,
14,
1178,
492,
820,
7458,
4168,
63,
8609,
63,
2339,
199,
504,
1639,
14,
1018,
14,
3924,
492,
23724,
199,
504,
1639,
14,
1014,
492,
6183,
17454,
12,
14935,
199,
504,
1639,
14,
17469,
492,
3795,
63,
475,
63,
1310,
199,
504,
1639,
14,
1160,
492,
22538,
12,
27193,
199,
504,
1639,
14,
1208,
14,
1014,
492,
1166,
3513,
199,
199,
504,
8129,
31186,
14,
5819,
492,
29952,
199,
504,
8129,
31186,
14,
5819,
492,
5611,
199,
504,
8129,
31186,
14,
5819,
492,
2876,
199,
504,
8129,
31186,
14,
2190,
492,
2202,
465,
8129,
31186,
63,
1751,
199,
504,
8129,
31186,
14,
3924,
492,
2832,
1899,
23008,
2448,
199,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
4832,
275,
2400,
627,
80,
26,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
904,
2031,
80,
430,
421,
199,
318,
664,
63,
12628,
63,
751,
837,
272,
408,
272,
1803,
1124,
1899,
1040,
1256,
334,
1397,
1124,
23902,
1899,
16580,
10298,
641,
272,
1124,
879,
32537,
2679,
1668,
63,
3791,
63,
998,
1040,
2897,
14,
272,
408,
272,
372,
2876,
14,
1462,
14,
362,
8,
344,
29,
6051,
31186,
63,
1751,
14,
879,
32537,
2679,
1668,
63,
3791,
63,
998,
9,
421,
199,
318,
664,
63,
2634,
63,
894,
1121,
63,
354,
837,
272,
408,
272,
1803,
1771,
4443,
536,
687,
5611,
370,
922,
1402,
14,
272,
408,
272,
372,
2876,
423,
2024,
14,
362,
63,
698,
63,
991,
63,
354,
360,
2634,
5832,
16,
1055,
2407,
63,
1131,
63,
354,
342,
421,
199,
318,
664,
63,
5582,
8,
5582,
304,
272,
408,
272,
1803,
334,
751,
63,
1113,
12,
488,
9,
503,
334,
403,
12,
1572,
63,
1113,
9,
2008,
10298,
641,
4052,
365,
272,
1627,
14,
6121,
11479,
29952,
1256,
1325,
3955,
372,
1124,
1899,
1040,
272,
3140,
446,
652,
365,
22700,
436,
4346,
367,
13448,
4865,
370,
2291,
272,
16535,
4390,
14,
339,
520,
635,
8503,
26,
1902,
1124,
1899,
1040,
503,
1124,
2448,
1040,
1256,
339,
520,
3536,
1124,
1763,
1899,
23008,
2448,
18983,
340,
3913,
372,
5576,
8503,
1256,
339,
1011,
22787,
538,
447,
10817,
1306,
922,
275,
2876,
14,
1462,
14,
981,
8,
2473,
534,
20241,
358,
2126,
1306,
664,
63,
5582,
8,
751,
9,
2126,
8642,
1899,
26,
5225,
69,
6244,
488,
9,
10817,
1306,
1572,
275,
5611,
14,
1462,
14,
981,
8,
354,
534,
3707,
358,
2126,
1306,
664,
63,
5582,
8,
923,
9,
2126,
334,
403,
12,
665,
2448,
26,
4390,
18956,
10817,
1306,
24757,
275,
29952,
342,
2126,
1306,
664,
63,
5582,
8,
21009,
9,
2126,
8642,
1899,
26,
29952,
6244,
488,
9,
10817,
1306,
664,
63,
5582,
480,
1397,
1256,
531,
2126,
2263,
2126,
2832,
1899,
23008,
2448,
26,
2876,
15,
23902,
1899,
503,
5611,
1256,
365,
1415,
334,
7808,
776,
339,
408,
272,
340,
1228,
8,
5582,
12,
29952,
304,
267,
8503,
275,
664,
63,
12628,
63,
751,
342,
339,
340,
1228,
8,
5582,
12,
2876,
304,
267,
372,
8503,
12,
488,
272,
916,
1228,
8,
5582,
12,
5611,
304,
267,
372,
488,
12,
8503,
339,
746,
2832,
1899,
23008,
2448,
480,
1899,
15,
23902,
1899,
503,
5611,
1256,
365,
1415,
298,
267,
7340,
7808,
450,
83,
2924,
450,
8503,
9,
421,
199,
318,
664,
63,
13353,
63,
269,
63,
403,
8,
1069,
12,
17340,
12,
1559,
29,
403,
12,
4676,
63,
633,
29,
403,
12,
272,
4660,
63,
698,
63,
354,
29,
403,
12,
372,
63,
13353,
29,
797,
12,
4729,
63,
2966,
63,
12068,
29,
797,
304,
272,
4676,
63,
633,
275,
4676,
63,
633,
503,
2202,
14,
17208,
63,
2632,
272,
4660,
63,
698,
63,
354,
275,
4660,
63,
698,
63,
354,
503,
820,
7458,
4168,
63,
8609,
63,
2339,
339,
327,
23873,
3865,
3379,
436,
543,
909,
2741,
4983,
1104,
272,
327,
465,
1124,
1113,
1040,
4243,
370,
488,
339,
965,
63,
6060,
275,
756,
272,
327,
2288,
17340,
1104,
1642,
334,
692,
4729,
63,
2966,
63,
12068,
9,
272,
340,
4729,
63,
2966,
63,
12068,
26,
267,
965,
63,
6060,
275,
1006,
8,
1069,
14,
751,
14,
1989,
63,
8220,
8,
8220,
9,
367,
10869,
315,
17340,
9,
272,
327,
340,
5139,
949,
4983,
10009,
12,
862,
1559,
17340,
272,
340,
440,
965,
63,
6060,
26,
267,
965,
63,
6060,
275,
1006,
8,
1069,
14,
751,
14,
1989,
63,
8220,
8,
8220,
12,
1559,
9,
367,
10869,
315,
17340,
9,
339,
340,
440,
965,
63,
6060,
26,
267,
340,
372,
63,
13353,
26,
288,
340,
8129,
31186,
63,
1751,
14,
31587,
63,
13353,
26,
355,
862,
26,
490,
1177,
275,
3795,
63,
475,
63,
1310,
8,
717,
8129,
31186,
63,
1751,
14,
7433,
63,
13353,
12,
5479,
717,
22538,
8,
1069,
430,
490,
1177,
14,
1205,
63,
600,
275,
13269,
490,
372,
1177,
355,
871,
27193,
12,
325,
26,
490,
340,
2202,
14,
5287,
26,
717,
746,
325,
288,
916,
8129,
31186,
63,
1751,
14,
2847,
4971,
63,
13353,
26,
355,
746,
23724,
288,
372,
6183,
17454,
342,
267,
587,
26,
288,
931,
275,
1166,
3513,
8,
1069,
14,
362,
63,
2861,
63,
515,
1012,
288,
16477,
275,
4676,
63,
633,
12,
4660,
63,
698,
63,
354,
12,
931,
288,
372,
14935,
3647,
83,
25790,
83,
2458,
83,
2,
450,
16477,
9,
421,
199,
318,
3633,
63,
22161,
63,
1113,
63,
12068,
837,
272,
408,
272,
1666,
6080,
436,
14185,
1006,
909,
3443,
4811,
20686,
737,
2222,
13,
5952,
272,
4545,
14,
339,
1803,
1329,
402,
4829,
2251,
14,
272,
408,
272,
687,
8129,
31186,
14,
992,
492,
2876,
1692,
7980,
272,
687,
8129,
31186,
14,
992,
492,
5611,
1692,
7980,
2378,
5463,
275,
378,
272,
327,
3254,
26,
5323,
572,
272,
367,
10869,
315,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
omnirom/android_kernel_oppo_apq8064
|
arch/ia64/scripts/unwcheck.py
|
13143
|
1714
|
#!/usr/bin/python
#
# Usage: unwcheck.py FILE
#
# This script checks the unwind info of each function in file FILE
# and verifies that the sum of the region-lengths matches the total
# length of the function.
#
# Based on a shell/awk script originally written by Harish Patil,
# which was converted to Perl by Matthew Chapman, which was converted
# to Python by David Mosberger.
#
import os
import re
import sys
if len(sys.argv) != 2:
print "Usage: %s FILE" % sys.argv[0]
sys.exit(2)
readelf = os.getenv("READELF", "readelf")
start_pattern = re.compile("<([^>]*)>: \[0x([0-9a-f]+)-0x([0-9a-f]+)\]")
rlen_pattern = re.compile(".*rlen=([0-9]+)")
def check_func (func, slots, rlen_sum):
if slots != rlen_sum:
global num_errors
num_errors += 1
if not func: func = "[%#x-%#x]" % (start, end)
print "ERROR: %s: %lu slots, total region length = %lu" % (func, slots, rlen_sum)
return
num_funcs = 0
num_errors = 0
func = False
slots = 0
rlen_sum = 0
for line in os.popen("%s -u %s" % (readelf, sys.argv[1])):
m = start_pattern.match(line)
if m:
check_func(func, slots, rlen_sum)
func = m.group(1)
start = long(m.group(2), 16)
end = long(m.group(3), 16)
slots = 3 * (end - start) / 16
rlen_sum = 0L
num_funcs += 1
else:
m = rlen_pattern.match(line)
if m:
rlen_sum += long(m.group(1))
check_func(func, slots, rlen_sum)
if num_errors == 0:
print "No errors detected in %u functions." % num_funcs
else:
if num_errors > 1:
err="errors"
else:
err="error"
print "%u %s detected in %u functions." % (num_errors, err, num_funcs)
sys.exit(1)
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
11028,
26,
625,
87,
1074,
14,
647,
13024,
199,
3,
199,
3,
961,
2884,
5920,
314,
625,
11530,
2256,
402,
1924,
805,
315,
570,
13024,
199,
3,
436,
22694,
626,
314,
3089,
402,
314,
4897,
13,
14563,
4450,
314,
3141,
199,
3,
2582,
402,
314,
805,
14,
199,
3,
199,
3,
21311,
641,
282,
5218,
15,
10084,
75,
2884,
20657,
5313,
701,
25378,
2453,
510,
2159,
76,
12,
199,
3,
1314,
1990,
6702,
370,
3492,
76,
701,
18619,
29640,
2799,
439,
1237,
12,
1314,
1990,
6702,
199,
3,
370,
2018,
701,
20232,
603,
736,
605,
836,
14,
199,
3,
199,
646,
747,
199,
646,
295,
199,
646,
984,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
1137,
499,
26,
272,
870,
298,
7692,
26,
450,
83,
13024,
2,
450,
984,
14,
3020,
59,
16,
61,
272,
984,
14,
2224,
8,
18,
9,
199,
199,
8273,
271,
276,
275,
747,
14,
12959,
480,
24345,
4424,
38,
401,
298,
8273,
271,
276,
531,
199,
199,
928,
63,
3401,
275,
295,
14,
2014,
6757,
7059,
30,
3672,
13032,
26,
30257,
16,
88,
779,
16,
13,
25,
65,
13,
70,
2807,
7216,
16,
88,
779,
16,
13,
25,
65,
13,
70,
18096,
12523,
199,
82,
552,
63,
3401,
221,
275,
295,
14,
2014,
480,
2795,
82,
552,
30982,
16,
13,
25,
2807,
6320,
199,
199,
318,
1104,
63,
1532,
334,
1532,
12,
14319,
12,
24746,
63,
1838,
304,
272,
340,
14319,
1137,
24746,
63,
1838,
26,
267,
2288,
1967,
63,
2550,
267,
1967,
63,
2550,
847,
413,
267,
340,
440,
2562,
26,
2562,
275,
26503,
3,
88,
3295,
3,
88,
8480,
450,
334,
928,
12,
1284,
9,
267,
870,
298,
3170,
26,
450,
83,
26,
450,
10836,
14319,
12,
3141,
4897,
2582,
275,
450,
10836,
2,
450,
334,
1532,
12,
14319,
12,
24746,
63,
1838,
9,
272,
372,
199,
199,
1507,
63,
9204,
275,
378,
199,
1507,
63,
2550,
275,
378,
199,
1532,
275,
756,
199,
7257,
275,
378,
199,
82,
552,
63,
1838,
275,
378,
199,
509,
1004,
315,
747,
14,
12207,
3647,
83,
446,
85,
450,
83,
2,
450,
334,
8273,
271,
276,
12,
984,
14,
3020,
59,
17,
18710,
272,
333,
275,
1343,
63,
3401,
14,
1431,
8,
604,
9,
272,
340,
333,
26,
267,
1104,
63,
1532,
8,
1532,
12,
14319,
12,
24746,
63,
1838,
9,
398,
2562,
221,
275,
333,
14,
923,
8,
17,
9,
267,
1343,
275,
1846,
8,
77,
14,
923,
8,
18,
395,
3193,
9,
267,
1284,
257,
275,
1846,
8,
77,
14,
923,
8,
19,
395,
3193,
9,
267,
14319,
275,
650,
627,
334,
500,
446,
1343,
9,
1182,
3193,
267,
24746,
63,
1838,
275,
378,
44,
267,
1967,
63,
9204,
847,
413,
272,
587,
26,
267,
333,
275,
24746,
63,
3401,
14,
1431,
8,
604,
9,
267,
340,
333,
26,
288,
24746,
63,
1838,
847,
1846,
8,
77,
14,
923,
8,
17,
430,
199,
1074,
63,
1532,
8,
1532,
12,
14319,
12,
24746,
63,
1838,
9,
199,
199,
692,
1967,
63,
2550,
508,
378,
26,
272,
870,
298,
1944,
2552,
10501,
315,
450,
85,
3423,
2122,
450,
1967,
63,
9204,
199,
2836,
26,
272,
340,
1967,
63,
2550,
690,
413,
26,
267,
2329,
628,
2550,
2,
272,
587,
26,
267,
2329,
628,
705,
2,
272,
870,
2071,
85,
450,
83,
10501,
315,
450,
85,
3423,
2122,
450,
334,
1507,
63,
2550,
12,
2329,
12,
1967,
63,
9204,
9,
272,
984,
14,
2224,
8,
17,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
11028,
26,
625,
87,
1074,
14,
647,
13024,
199,
3,
199,
3,
961,
2884,
5920,
314,
625,
11530,
2256,
402,
1924,
805,
315,
570,
13024,
199,
3,
436,
22694,
626,
314,
3089,
402,
314,
4897,
13,
14563,
4450,
314,
3141,
199,
3,
2582,
402,
314,
805,
14,
199,
3,
199,
3,
21311,
641,
282,
5218,
15,
10084,
75,
2884,
20657,
5313,
701,
25378,
2453,
510,
2159,
76,
12,
199,
3,
1314,
1990,
6702,
370,
3492,
76,
701,
18619,
29640,
2799,
439,
1237,
12,
1314,
1990,
6702,
199,
3,
370,
2018,
701,
20232,
603,
736,
605,
836,
14,
199,
3,
199,
646,
747,
199,
646,
295,
199,
646,
984,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
1137,
499,
26,
272,
870,
298,
7692,
26,
450,
83,
13024,
2,
450,
984,
14,
3020,
59,
16,
61,
272,
984,
14,
2224,
8,
18,
9,
199,
199,
8273,
271,
276,
275,
747,
14,
12959,
480,
24345,
4424,
38,
401,
298,
8273,
271,
276,
531,
199,
199,
928,
63,
3401,
275,
295,
14,
2014,
6757,
7059,
30,
3672,
13032,
26,
30257,
16,
88,
779,
16,
13,
25,
65,
13,
70,
2807,
7216,
16,
88,
779,
16,
13,
25,
65,
13,
70,
18096,
12523,
199,
82,
552,
63,
3401,
221,
275,
295,
14,
2014,
480,
2795,
82,
552,
30982,
16,
13,
25,
2807,
6320,
199,
199,
318,
1104,
63,
1532,
334,
1532,
12,
14319,
12,
24746,
63,
1838,
304,
272,
340,
14319,
1137,
24746,
63,
1838,
26,
267,
2288,
1967,
63,
2550,
267,
1967,
63,
2550,
847,
413,
267,
340,
440,
2562,
26,
2562,
275,
26503,
3,
88,
3295,
3,
88,
8480,
450,
334,
928,
12,
1284,
9,
267,
870,
298,
3170,
26,
450,
83,
26,
450,
10836,
14319,
12,
3141,
4897,
2582,
275,
450,
10836,
2,
450,
334,
1532,
12,
14319,
12,
24746,
63,
1838,
9,
272,
372,
199,
199,
1507,
63,
9204,
275,
378,
199,
1507,
63,
2550,
275,
378,
199,
1532,
275,
756,
199,
7257,
275,
378,
199,
82,
552,
63,
1838,
275,
378,
199,
509,
1004,
315,
747,
14,
12207,
3647,
83,
446,
85,
450,
83,
2,
450,
334,
8273,
271,
276,
12,
984,
14,
3020,
59,
17,
18710,
272,
333,
275,
1343,
63,
3401,
14,
1431,
8,
604,
9,
272,
340,
333,
26,
267,
1104,
63,
1532,
8,
1532,
12,
14319,
12,
24746,
63,
1838,
9,
398,
2562,
221,
275,
333,
14,
923,
8,
17,
9,
267,
1343,
275,
1846,
8,
77,
14,
923,
8,
18,
395,
3193,
9,
267,
1284,
257,
275,
1846,
8,
77,
14,
923,
8,
19,
395,
3193,
9,
267,
14319,
275,
650,
627,
334,
500,
446,
1343,
9,
1182,
3193,
267,
24746,
63,
1838,
275,
378,
44,
267,
1967,
63,
9204,
847,
413,
272,
587,
26,
267,
333,
275,
24746,
63,
3401,
14,
1431,
8,
604,
9,
267,
340,
333,
26,
288,
24746,
63,
1838,
847,
1846,
8,
77,
14,
923,
8,
17,
430,
199,
1074,
63,
1532,
8,
1532,
12,
14319,
12,
24746,
63,
1838,
9,
199,
199,
692,
1967,
63,
2550,
508,
378,
26,
272,
870,
298,
1944,
2552,
10501,
315,
450,
85,
3423,
2122,
450,
1967,
63,
9204,
199,
2836,
26,
272,
340,
1967,
63,
2550,
690,
413,
26,
267,
2329,
628,
2550,
2,
272,
587,
26,
267,
2329,
628,
705,
2,
272,
870,
2071,
85,
450,
83,
10501,
315,
450,
85,
3423,
2122,
450,
334,
1507,
63,
2550,
12,
2329,
12,
1967,
63,
9204,
9,
272,
984,
14,
2224,
8,
17,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
hamole/pbl8
|
pbl8_project/pbl/migrations/0003_auto.py
|
1
|
3700
|
# -*- coding: utf-8 -*-
import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
class Migration(SchemaMigration):
def forwards(self, orm):
# Adding M2M table for field studies_for on 'Treatment'
m2m_table_name = db.shorten_name(u'pbl_treatment_studies_for')
db.create_table(m2m_table_name, (
('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
('treatment', models.ForeignKey(orm[u'pbl.treatment'], null=False)),
('study', models.ForeignKey(orm[u'pbl.study'], null=False))
))
db.create_unique(m2m_table_name, ['treatment_id', 'study_id'])
# Adding M2M table for field studies_against on 'Treatment'
m2m_table_name = db.shorten_name(u'pbl_treatment_studies_against')
db.create_table(m2m_table_name, (
('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
('treatment', models.ForeignKey(orm[u'pbl.treatment'], null=False)),
('study', models.ForeignKey(orm[u'pbl.study'], null=False))
))
db.create_unique(m2m_table_name, ['treatment_id', 'study_id'])
# Removing M2M table for field treatment on 'Study'
db.delete_table(db.shorten_name(u'pbl_study_treatment'))
def backwards(self, orm):
# Removing M2M table for field studies_for on 'Treatment'
db.delete_table(db.shorten_name(u'pbl_treatment_studies_for'))
# Removing M2M table for field studies_against on 'Treatment'
db.delete_table(db.shorten_name(u'pbl_treatment_studies_against'))
# Adding M2M table for field treatment on 'Study'
m2m_table_name = db.shorten_name(u'pbl_study_treatment')
db.create_table(m2m_table_name, (
('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
('study', models.ForeignKey(orm[u'pbl.study'], null=False)),
('treatment', models.ForeignKey(orm[u'pbl.treatment'], null=False))
))
db.create_unique(m2m_table_name, ['study_id', 'treatment_id'])
models = {
u'pbl.study': {
'Meta': {'ordering': "('title',)", 'object_name': 'Study'},
'author': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'funder': ('django.db.models.fields.CharField', [], {'max_length': '200', 'blank': 'True'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'journal': ('django.db.models.fields.CharField', [], {'max_length': '200'}),
'title': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'year': ('django.db.models.fields.IntegerField', [], {'default': '2014', 'max_length': '4'})
},
u'pbl.treatment': {
'Meta': {'ordering': "('name',)", 'object_name': 'Treatment'},
'description': ('django.db.models.fields.TextField', [], {}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'slug': ('django.db.models.fields.SlugField', [], {'max_length': '50'}),
'studies_against': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "'studies_against+'", 'blank': 'True', 'to': u"orm['pbl.Study']"}),
'studies_for': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "'studies_for+'", 'blank': 'True', 'to': u"orm['pbl.Study']"})
}
}
complete_apps = ['pbl']
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
646,
2197,
199,
504,
12919,
14,
697,
492,
1592,
199,
504,
12919,
14,
86,
18,
492,
24765,
199,
504,
1639,
14,
697,
492,
1709,
421,
199,
533,
12090,
8,
24822,
304,
339,
347,
17465,
8,
277,
12,
9813,
304,
267,
327,
12934,
603,
18,
45,
1817,
367,
901,
410,
14525,
397,
63,
509,
641,
283,
29442,
434,
7,
267,
333,
18,
77,
63,
1224,
63,
354,
275,
1592,
14,
30686,
63,
354,
8,
85,
7,
3317,
76,
63,
84,
8319,
434,
63,
270,
14525,
397,
63,
509,
358,
267,
1592,
14,
981,
63,
1224,
8,
77,
18,
77,
63,
1224,
63,
354,
12,
334,
288,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
5062,
63,
498,
29,
549,
12,
2599,
63,
3966,
29,
549,
1826,
288,
661,
84,
8319,
434,
297,
1709,
14,
3190,
8,
1025,
59,
85,
7,
3317,
76,
14,
84,
8319,
434,
995,
2973,
29,
797,
1826,
288,
661,
22851,
297,
1709,
14,
3190,
8,
1025,
59,
85,
7,
3317,
76,
14,
22851,
995,
2973,
29,
797,
430,
267,
5082,
267,
1592,
14,
981,
63,
3235,
8,
77,
18,
77,
63,
1224,
63,
354,
12,
788,
84,
8319,
434,
63,
344,
297,
283,
22851,
63,
344,
1105,
398,
327,
12934,
603,
18,
45,
1817,
367,
901,
410,
14525,
397,
63,
17777,
641,
283,
29442,
434,
7,
267,
333,
18,
77,
63,
1224,
63,
354,
275,
1592,
14,
30686,
63,
354,
8,
85,
7,
3317,
76,
63,
84,
8319,
434,
63,
270,
14525,
397,
63,
17777,
358,
267,
1592,
14,
981,
63,
1224,
8,
77,
18,
77,
63,
1224,
63,
354,
12,
334,
288,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
5062,
63,
498,
29,
549,
12,
2599,
63,
3966,
29,
549,
1826,
288,
661,
84,
8319,
434,
297,
1709,
14,
3190,
8,
1025,
59,
85,
7,
3317,
76,
14,
84,
8319,
434,
995,
2973,
29,
797,
1826,
288,
661,
22851,
297,
1709,
14,
3190,
8,
1025,
59,
85,
7,
3317,
76,
14,
22851,
995,
2973,
29,
797,
430,
267,
5082,
267,
1592,
14,
981,
63,
3235,
8,
77,
18,
77,
63,
1224,
63,
354,
12,
788,
84,
8319,
434,
63,
344,
297,
283,
22851,
63,
344,
1105,
398,
327,
29343,
603,
18,
45,
1817,
367,
901,
14312,
434,
641,
283,
933,
14181,
7,
267,
1592,
14,
1807,
63,
1224,
8,
697,
14,
30686,
63,
354,
8,
85,
7,
3317,
76,
63,
22851,
63,
84,
8319,
434,
1333,
2378,
347,
8552,
8,
277,
12,
9813,
304,
267,
327,
29343,
603,
18,
45,
1817,
367,
901,
410,
14525,
397,
63,
509,
641,
283,
29442,
434,
7,
267,
1592,
14,
1807,
63,
1224,
8,
697,
14,
30686,
63,
354,
8,
85,
7,
3317,
76,
63,
84,
8319,
434,
63,
270,
14525,
397,
63,
509,
1333,
398,
327,
29343,
603,
18,
45,
1817,
367,
901,
410,
14525,
397,
63,
17777,
641,
283,
29442,
434,
7,
267,
1592,
14,
1807,
63,
1224,
8,
697,
14,
30686,
63,
354,
8,
85,
7,
3317,
76,
63,
84,
8319,
434,
63,
270,
14525,
397,
63,
17777,
1333,
398,
327,
12934,
603,
18,
45,
1817,
367,
901,
14312,
434,
641,
283,
933,
14181,
7,
267,
333,
18,
77,
63,
1224,
63,
354,
275,
1592,
14,
30686,
63,
354,
8,
85,
7,
3317,
76,
63,
22851,
63,
84,
8319,
434,
358,
267,
1592,
14,
981,
63,
1224,
8,
77,
18,
77,
63,
1224,
63,
354,
12,
334,
288,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
5062,
63,
498,
29,
549,
12,
2599,
63,
3966,
29,
549,
1826,
288,
661,
22851,
297,
1709,
14,
3190,
8,
1025,
59,
85,
7,
3317,
76,
14,
22851,
995,
2973,
29,
797,
1826,
288,
661,
84,
8319,
434,
297,
1709,
14,
3190,
8,
1025,
59,
85,
7,
3317,
76,
14,
84,
8319,
434,
995,
2973,
29,
797,
430,
267,
5082,
267,
1592,
14,
981,
63,
3235,
8,
77,
18,
77,
63,
1224,
63,
354,
12,
788,
22851,
63,
344,
297,
283,
84,
8319,
434,
63,
344,
1105,
2378,
1709,
275,
469,
267,
399,
7,
3317,
76,
14,
22851,
356,
469,
288,
283,
3396,
356,
791,
7128,
356,
16111,
1213,
21099,
283,
785,
63,
354,
356,
283,
933,
14181,
2267,
288,
283,
2502,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1960,
1604,
288,
283,
7036,
424,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1840,
297,
283,
2500,
356,
283,
549,
1604,
288,
399,
7,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
7067,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1840,
1604,
288,
283,
1213,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1960,
1604,
288,
283,
3403,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
3901,
297,
990,
791,
885,
356,
283,
7280,
297,
283,
988,
63,
1267,
356,
283,
20,
3071,
267,
1660,
267,
399,
7,
3317,
76,
14,
84,
8319,
434,
356,
469,
288,
283,
3396,
356,
791,
7128,
356,
16111,
354,
21099,
283,
785,
63,
354,
356,
283,
29442,
434,
2267,
288,
283,
1802,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
6254,
297,
990,
8613,
288,
399,
7,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1960,
1604,
288,
283,
5464,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
17315,
297,
990,
791,
988,
63,
1267,
356,
283,
1400,
1604,
288,
283,
270,
14525,
397,
63,
17777,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
10247,
356,
283,
797,
297,
283,
2407,
63
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
646,
2197,
199,
504,
12919,
14,
697,
492,
1592,
199,
504,
12919,
14,
86,
18,
492,
24765,
199,
504,
1639,
14,
697,
492,
1709,
421,
199,
533,
12090,
8,
24822,
304,
339,
347,
17465,
8,
277,
12,
9813,
304,
267,
327,
12934,
603,
18,
45,
1817,
367,
901,
410,
14525,
397,
63,
509,
641,
283,
29442,
434,
7,
267,
333,
18,
77,
63,
1224,
63,
354,
275,
1592,
14,
30686,
63,
354,
8,
85,
7,
3317,
76,
63,
84,
8319,
434,
63,
270,
14525,
397,
63,
509,
358,
267,
1592,
14,
981,
63,
1224,
8,
77,
18,
77,
63,
1224,
63,
354,
12,
334,
288,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
5062,
63,
498,
29,
549,
12,
2599,
63,
3966,
29,
549,
1826,
288,
661,
84,
8319,
434,
297,
1709,
14,
3190,
8,
1025,
59,
85,
7,
3317,
76,
14,
84,
8319,
434,
995,
2973,
29,
797,
1826,
288,
661,
22851,
297,
1709,
14,
3190,
8,
1025,
59,
85,
7,
3317,
76,
14,
22851,
995,
2973,
29,
797,
430,
267,
5082,
267,
1592,
14,
981,
63,
3235,
8,
77,
18,
77,
63,
1224,
63,
354,
12,
788,
84,
8319,
434,
63,
344,
297,
283,
22851,
63,
344,
1105,
398,
327,
12934,
603,
18,
45,
1817,
367,
901,
410,
14525,
397,
63,
17777,
641,
283,
29442,
434,
7,
267,
333,
18,
77,
63,
1224,
63,
354,
275,
1592,
14,
30686,
63,
354,
8,
85,
7,
3317,
76,
63,
84,
8319,
434,
63,
270,
14525,
397,
63,
17777,
358,
267,
1592,
14,
981,
63,
1224,
8,
77,
18,
77,
63,
1224,
63,
354,
12,
334,
288,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
5062,
63,
498,
29,
549,
12,
2599,
63,
3966,
29,
549,
1826,
288,
661,
84,
8319,
434,
297,
1709,
14,
3190,
8,
1025,
59,
85,
7,
3317,
76,
14,
84,
8319,
434,
995,
2973,
29,
797,
1826,
288,
661,
22851,
297,
1709,
14,
3190,
8,
1025,
59,
85,
7,
3317,
76,
14,
22851,
995,
2973,
29,
797,
430,
267,
5082,
267,
1592,
14,
981,
63,
3235,
8,
77,
18,
77,
63,
1224,
63,
354,
12,
788,
84,
8319,
434,
63,
344,
297,
283,
22851,
63,
344,
1105,
398,
327,
29343,
603,
18,
45,
1817,
367,
901,
14312,
434,
641,
283,
933,
14181,
7,
267,
1592,
14,
1807,
63,
1224,
8,
697,
14,
30686,
63,
354,
8,
85,
7,
3317,
76,
63,
22851,
63,
84,
8319,
434,
1333,
2378,
347,
8552,
8,
277,
12,
9813,
304,
267,
327,
29343,
603,
18,
45,
1817,
367,
901,
410,
14525,
397,
63,
509,
641,
283,
29442,
434,
7,
267,
1592,
14,
1807,
63,
1224,
8,
697,
14,
30686,
63,
354,
8,
85,
7,
3317,
76,
63,
84,
8319,
434,
63,
270,
14525,
397,
63,
509,
1333,
398,
327,
29343,
603,
18,
45,
1817,
367,
901,
410,
14525,
397,
63,
17777,
641,
283,
29442,
434,
7,
267,
1592,
14,
1807,
63,
1224,
8,
697,
14,
30686,
63,
354,
8,
85,
7,
3317,
76,
63,
84,
8319,
434,
63,
270,
14525,
397,
63,
17777,
1333,
398,
327,
12934,
603,
18,
45,
1817,
367,
901,
14312,
434,
641,
283,
933,
14181,
7,
267,
333,
18,
77,
63,
1224,
63,
354,
275,
1592,
14,
30686,
63,
354,
8,
85,
7,
3317,
76,
63,
22851,
63,
84,
8319,
434,
358,
267,
1592,
14,
981,
63,
1224,
8,
77,
18,
77,
63,
1224,
63,
354,
12,
334,
288,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
5062,
63,
498,
29,
549,
12,
2599,
63,
3966,
29,
549,
1826,
288,
661,
22851,
297,
1709,
14,
3190,
8,
1025,
59,
85,
7,
3317,
76,
14,
22851,
995,
2973,
29,
797,
1826,
288,
661,
84,
8319,
434,
297,
1709,
14,
3190,
8,
1025,
59,
85,
7,
3317,
76,
14,
84,
8319,
434,
995,
2973,
29,
797,
430,
267,
5082,
267,
1592,
14,
981,
63,
3235,
8,
77,
18,
77,
63,
1224,
63,
354,
12,
788,
22851,
63,
344,
297,
283,
84,
8319,
434,
63,
344,
1105,
2378,
1709,
275,
469,
267,
399,
7,
3317,
76,
14,
22851,
356,
469,
288,
283,
3396,
356,
791,
7128,
356,
16111,
1213,
21099,
283,
785,
63,
354,
356,
283,
933,
14181,
2267,
288,
283,
2502,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1960,
1604,
288,
283,
7036,
424,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1840,
297,
283,
2500,
356,
283,
549,
1604,
288,
399,
7,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
7067,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1840,
1604,
288,
283,
1213,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1960,
1604,
288,
283,
3403,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
3901,
297,
990,
791,
885,
356,
283,
7280,
297,
283,
988,
63,
1267,
356,
283,
20,
3071,
267,
1660,
267,
399,
7,
3317,
76,
14,
84,
8319,
434,
356,
469,
288,
283,
3396,
356,
791,
7128,
356,
16111,
354,
21099,
283,
785,
63,
354,
356,
283,
29442,
434,
2267,
288,
283,
1802,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
6254,
297,
990,
8613,
288,
399,
7,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1960,
1604,
288,
283,
5464,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
17315,
297,
990,
791,
988,
63,
1267,
356,
283,
1400,
1604,
288,
283,
270,
14525,
397,
63,
17777,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
10247,
356,
283,
797,
297,
283,
2407,
63,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
blurstudio/cross3d
|
cross3d/softimage/external.py
|
1
|
4267
|
##
# \namespace cross3d.softimage.external
#
# \remarks This class can be used even outside of softimage. It gives you info on where
# softimage is installed, and allows you to run scripts in softimage.
# To Access this class use: cross3d.external('softimage')
#
# \author dougl
# \author Blur Studio
# \date 01/21/14
#
#------------------------------------------------------------------------------------------------------------------------
import os
import subprocess
import xml.etree.cElementTree as ET
from cross3d import Exceptions
from cross3d.constants import ScriptLanguage
from cross3d.abstract.external import External as AbstractExternal
#------------------------------------------------------------------------------------------------------------------------
class External(AbstractExternal):
# In case the software is installed but not used don't find it when not passing in a version
_ignoredVersions = set(os.environ.get('CROSS3D_STUDIO_IGNORED_SOFTIMAGE', '').split(','))
# map years to version numbers
_yearForVersion = {'8': '2010', '9': '2011', '10': '2012', '11': '2013', '12': '2014', '13': '2015'}
@classmethod
def name(cls):
return 'Softimage'
@classmethod
def getFileVersion(cls, filepath):
"""
Reads the xsi version of an xsi file from the associated scntoc.
"""
scntoc_path = filepath + 'toc'
if os.path.isfile(scntoc_path):
tree = ET.parse(scntoc_path)
root = tree.getroot()
return root.get('xsi_version')
return None
@classmethod
def runScript(cls, script, version=None, architecture=64, language=ScriptLanguage.Python, debug=False, headless=True):
if os.path.exists(script):
scriptPath = script
else:
scriptPath = cls.scriptPath()
with open(scriptPath, "w") as fle:
fle.write(script)
binary = os.path.join(cls.binariesPath(version, architecture), 'xsibatch.exe' if headless else 'xsi.exe')
scriptArgumentName = '-script' if headless else '-uiscript'
# Contrinue makes sure there is no prompts.
command = [binary, '-continue', scriptArgumentName, scriptPath]
# Processing means that it will not shot the GUI and not grab a license.
if headless:
command.insert(1, '-processing')
process = subprocess.Popen(command, stdout=subprocess.PIPE)
# TODO: This is the way to check for success. But it is blocking.
# Writing the log file.
with open(cls.scriptLog(), 'w') as fle:
fle.write(process.stdout.read())
# Checking the error in the log file.
with open(cls.scriptLog()) as fle:
content = fle.read()
return False if 'FATAL' in content else True
@classmethod
def binariesPath(cls, version=None, architecture=64, language='English'):
""" Finds the install path for various software installations. If version is None, the default
it will return the latest installed version of the software. Raises cross3d.Exceptions.SoftwareNotInstalled
if the software is not installed.
:param version: The version of the software. Default is None
:param architecture: The bit type to query the registry for(32, 64). Default is 64
:param language: Optional language that may be required for specific softwares.
"""
from cross3d.migrate import winregistry
hive = 'HKEY_LOCAL_MACHINE'
hkey = r'Software\Autodesk\Softimage\InstallPaths'
ret = None
if version == None:
# Find the latest version
versions = winregistry.listRegKeyValues(hive, hkey, architecture=architecture)
for version in sorted(versions, key= lambda i: i[0], reverse=True):
if version[0] not in cls._ignoredVersions:
ret = version[1]
break
else:
version = cls._yearForVersion.get(unicode(version), version)
try:
ret = winregistry.registryValue(hive, hkey, unicode(version), architecture)[0]
except WindowsError:
raise Exceptions.SoftwareNotInstalled('Softimage', version=version, architecture=architecture, language=language)
# If the version is not installed this will return '.', we want to return False.
if ret:
return os.path.join(os.path.normpath(ret), 'Application', 'bin')
raise Exceptions.SoftwareNotInstalled('Softimage', version=version, architecture=architecture, language=language)
|
mit
|
[
309,
202,
199,
3,
221,
198,
60,
3251,
198,
7925,
19,
68,
14,
1152,
15141,
960,
14,
5159,
202,
199,
3,
202,
199,
3,
198,
60,
264,
10375,
198,
2765,
1021,
883,
506,
1202,
2755,
9682,
402,
880,
15141,
960,
14,
2779,
10557,
1265,
2256,
641,
2382,
202,
199,
3,
9622,
198,
1152,
15141,
960,
365,
4903,
12,
436,
6127,
1265,
370,
1255,
10554,
315,
880,
15141,
960,
14,
202,
199,
3,
9622,
198,
1378,
11003,
642,
1021,
675,
26,
8059,
19,
68,
14,
5159,
360,
1152,
15141,
960,
358,
202,
199,
3,
202,
199,
3,
221,
198,
60,
2502,
198,
198,
68,
810,
3528,
202,
199,
3,
221,
198,
60,
2502,
198,
198,
24613,
300,
13225,
202,
199,
3,
221,
198,
60,
602,
198,
198,
614,
15,
2025,
15,
1079,
202,
199,
3,
2999,
199,
7656,
6489,
518,
2999,
199,
646,
747,
202,
199,
646,
3873,
202,
199,
646,
2748,
14,
9464,
14,
67,
15325,
465,
12265,
2999,
199,
504,
8059,
19,
68,
492,
24873,
202,
199,
504,
8059,
19,
68,
14,
5559,
492,
14914,
8493,
202,
199,
504,
8059,
19,
68,
14,
6198,
14,
5159,
492,
18802,
465,
11836,
11389,
2999,
199,
7656,
6489,
518,
2999,
199,
533,
18802,
8,
8458,
11389,
304,
1223,
198,
3,
1010,
1930,
314,
2032,
365,
4903,
1325,
440,
1202,
2793,
1133,
2342,
652,
1380,
440,
9476,
315,
282,
1015,
1223,
198,
63,
11996,
21167,
275,
663,
8,
736,
14,
2314,
14,
362,
360,
28368,
19,
36,
63,
840,
53,
19283,
63,
3203,
25517,
63,
26999,
9438,
297,
12548,
1294,
5102,
1333,
1223,
198,
3,
2341,
17399,
370,
1015,
5579,
1223,
198,
63,
3403,
1858,
3353,
275,
791,
24,
356,
283,
6542,
297,
283,
25,
356,
283,
8128,
297,
283,
709,
356,
283,
7409,
297,
283,
845,
356,
283,
6965,
297,
283,
713,
356,
283,
7280,
297,
283,
969,
356,
283,
7806,
936,
10060,
198,
32,
3744,
1223,
198,
318,
536,
8,
1886,
304,
4122,
198,
1107,
283,
51,
1618,
280,
960,
7,
10060,
198,
32,
3744,
1223,
198,
318,
664,
1173,
3353,
8,
1886,
12,
9911,
304,
4122,
198,
624,
4122,
198,
23614,
314,
671,
338,
1015,
402,
376,
671,
338,
570,
687,
314,
4568,
4061,
343,
679,
14,
221,
4122,
198,
624,
4122,
198,
551,
343,
679,
63,
515,
275,
9911,
435,
283,
13255,
7,
4122,
198,
692,
747,
14,
515,
14,
6292,
8,
551,
343,
679,
63,
515,
304,
7903,
198,
2350,
275,
12265,
14,
1122,
8,
551,
343,
679,
63,
515,
9,
7903,
198,
1231,
275,
3123,
14,
24544,
342,
7903,
198,
1107,
1738,
14,
362,
360,
88,
338,
63,
1023,
358,
4122,
198,
1107,
488,
10060,
198,
32,
3744,
1223,
198,
318,
1255,
5229,
8,
1886,
12,
2884,
12,
1015,
29,
403,
12,
15931,
29,
772,
12,
2637,
29,
5229,
8493,
14,
4718,
12,
3105,
29,
797,
12,
4854,
2003,
29,
549,
304,
26045,
198,
692,
747,
14,
515,
14,
2444,
8,
1579,
304,
7903,
198,
1579,
2042,
275,
2884,
26045,
198,
2836,
26,
7903,
198,
1579,
2042,
275,
843,
14,
1579,
2042,
342,
7903,
198,
1045,
1551,
8,
1579,
2042,
12,
298,
87,
531,
465,
289,
274,
26,
13610,
198,
21599,
14,
952,
8,
1579,
9,
26045,
198,
3008,
275,
747,
14,
515,
14,
904,
8,
1886,
14,
27542,
2042,
8,
1023,
12,
15931,
395,
283,
88,
338,
2912,
14,
5803,
7,
340,
4854,
2003,
587,
283,
88,
338,
14,
5803,
358,
4122,
198,
1579,
5201,
985,
275,
2475,
1579,
7,
340,
4854,
2003,
587,
2475,
85,
374,
1669,
7,
26045,
198,
3,
1448,
454,
262,
310,
7704,
3238,
2337,
365,
949,
29951,
14,
4122,
198,
1531,
275,
359,
3008,
12,
2475,
6958,
297,
2884,
5201,
985,
12,
2884,
2042,
61,
26045,
198,
3,
20157,
4910,
626,
652,
911,
440,
1033,
357,
314,
17160,
436,
440,
18200,
282,
4190,
14,
4122,
198,
692,
4854,
2003,
26,
7903,
198,
1531,
14,
3176,
8,
17,
12,
2475,
6338,
358,
26045,
198,
1412,
275,
3873,
14,
7942,
8,
1531,
12,
3839,
29,
5781,
14,
6089,
9,
26045,
198,
3,
3254,
26,
961,
365,
314,
4340,
370,
1104,
367,
3182,
14,
11017,
652,
365,
14592,
14,
4122,
198,
3,
12859,
1337,
314,
943,
570,
14,
4122,
198,
1045,
1551,
8,
1886,
14,
1579,
2445,
1062,
283,
87,
358,
465,
289,
274,
26,
7903,
198,
21599,
14,
952,
8,
1412,
14,
2703,
14,
739,
1012,
26045,
198,
3,
25109,
314,
1125,
315,
314,
943,
570,
14,
4122,
198,
1045,
1551,
8,
1886,
14,
1579,
2445,
1012,
465,
289,
274,
26,
7903,
198,
1317,
275,
289,
274,
14,
739,
342,
26045,
198,
1107,
756,
340,
283,
29086,
7,
315,
1564,
587,
715,
10060,
198,
32,
3744,
1223,
198,
318,
21984,
2042,
8,
1886,
12,
1015,
29,
403,
12,
15931,
29,
772,
12,
2637,
534,
19410,
735,
4122,
198,
624,
31434,
314,
3907,
931,
367,
7750,
2032,
2727,
279,
6011,
14,
982,
1015,
365,
488,
12,
314,
849,
4122,
198,
390,
911,
372,
314,
8839,
4903,
1015,
402,
314,
2032,
14,
6218,
8059,
19,
68,
14,
16836,
14,
10337,
1763,
21268,
4122,
198,
692,
314,
2032,
365,
440,
4903,
14,
4122,
198,
26,
635,
1015,
26,
710,
1015,
402,
314,
2032,
14,
3758,
365,
488,
4122,
198,
26,
635,
15931,
26,
710,
4546,
730,
370,
1827,
314,
7086,
367,
8,
708,
12,
5049,
680,
3758,
365,
5049,
4122,
198,
26,
635,
2637,
26,
4879,
2637,
626,
1443,
506,
1415,
367,
2488,
11620,
758,
470,
14,
4122,
198,
624,
4122,
198,
504,
8059,
19,
68,
14,
8462,
492,
4747,
5189,
4122,
198,
17230,
275,
283,
23802,
63,
7486,
63,
20890,
7,
4122,
198,
72,
498,
275,
519,
7,
10337,
60,
23570,
380,
1339,
60,
51,
1618,
280,
960,
60,
8154,
11804,
7,
4122,
198,
3292,
275,
488,
4122,
198,
692,
1015,
508,
488,
26,
7903,
198,
3,
6668,
314,
8839,
1015,
7903,
198,
6234,
275,
4747,
5189,
14,
513,
2872,
1197,
6550,
8,
17230,
12,
394,
498,
12,
15931,
29,
19134,
9,
7903,
198,
509,
1015,
315,
3355,
8,
6234,
12,
790,
29,
2400,
284,
26,
284,
59,
16,
467,
3837,
29,
549,
304,
13610,
198,
692,
1015,
59,
16,
61,
440,
315,
843,
423,
11996,
21167,
26,
19744
] |
[
202,
199,
3,
221,
198,
60,
3251,
198,
7925,
19,
68,
14,
1152,
15141,
960,
14,
5159,
202,
199,
3,
202,
199,
3,
198,
60,
264,
10375,
198,
2765,
1021,
883,
506,
1202,
2755,
9682,
402,
880,
15141,
960,
14,
2779,
10557,
1265,
2256,
641,
2382,
202,
199,
3,
9622,
198,
1152,
15141,
960,
365,
4903,
12,
436,
6127,
1265,
370,
1255,
10554,
315,
880,
15141,
960,
14,
202,
199,
3,
9622,
198,
1378,
11003,
642,
1021,
675,
26,
8059,
19,
68,
14,
5159,
360,
1152,
15141,
960,
358,
202,
199,
3,
202,
199,
3,
221,
198,
60,
2502,
198,
198,
68,
810,
3528,
202,
199,
3,
221,
198,
60,
2502,
198,
198,
24613,
300,
13225,
202,
199,
3,
221,
198,
60,
602,
198,
198,
614,
15,
2025,
15,
1079,
202,
199,
3,
2999,
199,
7656,
6489,
518,
2999,
199,
646,
747,
202,
199,
646,
3873,
202,
199,
646,
2748,
14,
9464,
14,
67,
15325,
465,
12265,
2999,
199,
504,
8059,
19,
68,
492,
24873,
202,
199,
504,
8059,
19,
68,
14,
5559,
492,
14914,
8493,
202,
199,
504,
8059,
19,
68,
14,
6198,
14,
5159,
492,
18802,
465,
11836,
11389,
2999,
199,
7656,
6489,
518,
2999,
199,
533,
18802,
8,
8458,
11389,
304,
1223,
198,
3,
1010,
1930,
314,
2032,
365,
4903,
1325,
440,
1202,
2793,
1133,
2342,
652,
1380,
440,
9476,
315,
282,
1015,
1223,
198,
63,
11996,
21167,
275,
663,
8,
736,
14,
2314,
14,
362,
360,
28368,
19,
36,
63,
840,
53,
19283,
63,
3203,
25517,
63,
26999,
9438,
297,
12548,
1294,
5102,
1333,
1223,
198,
3,
2341,
17399,
370,
1015,
5579,
1223,
198,
63,
3403,
1858,
3353,
275,
791,
24,
356,
283,
6542,
297,
283,
25,
356,
283,
8128,
297,
283,
709,
356,
283,
7409,
297,
283,
845,
356,
283,
6965,
297,
283,
713,
356,
283,
7280,
297,
283,
969,
356,
283,
7806,
936,
10060,
198,
32,
3744,
1223,
198,
318,
536,
8,
1886,
304,
4122,
198,
1107,
283,
51,
1618,
280,
960,
7,
10060,
198,
32,
3744,
1223,
198,
318,
664,
1173,
3353,
8,
1886,
12,
9911,
304,
4122,
198,
624,
4122,
198,
23614,
314,
671,
338,
1015,
402,
376,
671,
338,
570,
687,
314,
4568,
4061,
343,
679,
14,
221,
4122,
198,
624,
4122,
198,
551,
343,
679,
63,
515,
275,
9911,
435,
283,
13255,
7,
4122,
198,
692,
747,
14,
515,
14,
6292,
8,
551,
343,
679,
63,
515,
304,
7903,
198,
2350,
275,
12265,
14,
1122,
8,
551,
343,
679,
63,
515,
9,
7903,
198,
1231,
275,
3123,
14,
24544,
342,
7903,
198,
1107,
1738,
14,
362,
360,
88,
338,
63,
1023,
358,
4122,
198,
1107,
488,
10060,
198,
32,
3744,
1223,
198,
318,
1255,
5229,
8,
1886,
12,
2884,
12,
1015,
29,
403,
12,
15931,
29,
772,
12,
2637,
29,
5229,
8493,
14,
4718,
12,
3105,
29,
797,
12,
4854,
2003,
29,
549,
304,
26045,
198,
692,
747,
14,
515,
14,
2444,
8,
1579,
304,
7903,
198,
1579,
2042,
275,
2884,
26045,
198,
2836,
26,
7903,
198,
1579,
2042,
275,
843,
14,
1579,
2042,
342,
7903,
198,
1045,
1551,
8,
1579,
2042,
12,
298,
87,
531,
465,
289,
274,
26,
13610,
198,
21599,
14,
952,
8,
1579,
9,
26045,
198,
3008,
275,
747,
14,
515,
14,
904,
8,
1886,
14,
27542,
2042,
8,
1023,
12,
15931,
395,
283,
88,
338,
2912,
14,
5803,
7,
340,
4854,
2003,
587,
283,
88,
338,
14,
5803,
358,
4122,
198,
1579,
5201,
985,
275,
2475,
1579,
7,
340,
4854,
2003,
587,
2475,
85,
374,
1669,
7,
26045,
198,
3,
1448,
454,
262,
310,
7704,
3238,
2337,
365,
949,
29951,
14,
4122,
198,
1531,
275,
359,
3008,
12,
2475,
6958,
297,
2884,
5201,
985,
12,
2884,
2042,
61,
26045,
198,
3,
20157,
4910,
626,
652,
911,
440,
1033,
357,
314,
17160,
436,
440,
18200,
282,
4190,
14,
4122,
198,
692,
4854,
2003,
26,
7903,
198,
1531,
14,
3176,
8,
17,
12,
2475,
6338,
358,
26045,
198,
1412,
275,
3873,
14,
7942,
8,
1531,
12,
3839,
29,
5781,
14,
6089,
9,
26045,
198,
3,
3254,
26,
961,
365,
314,
4340,
370,
1104,
367,
3182,
14,
11017,
652,
365,
14592,
14,
4122,
198,
3,
12859,
1337,
314,
943,
570,
14,
4122,
198,
1045,
1551,
8,
1886,
14,
1579,
2445,
1062,
283,
87,
358,
465,
289,
274,
26,
7903,
198,
21599,
14,
952,
8,
1412,
14,
2703,
14,
739,
1012,
26045,
198,
3,
25109,
314,
1125,
315,
314,
943,
570,
14,
4122,
198,
1045,
1551,
8,
1886,
14,
1579,
2445,
1012,
465,
289,
274,
26,
7903,
198,
1317,
275,
289,
274,
14,
739,
342,
26045,
198,
1107,
756,
340,
283,
29086,
7,
315,
1564,
587,
715,
10060,
198,
32,
3744,
1223,
198,
318,
21984,
2042,
8,
1886,
12,
1015,
29,
403,
12,
15931,
29,
772,
12,
2637,
534,
19410,
735,
4122,
198,
624,
31434,
314,
3907,
931,
367,
7750,
2032,
2727,
279,
6011,
14,
982,
1015,
365,
488,
12,
314,
849,
4122,
198,
390,
911,
372,
314,
8839,
4903,
1015,
402,
314,
2032,
14,
6218,
8059,
19,
68,
14,
16836,
14,
10337,
1763,
21268,
4122,
198,
692,
314,
2032,
365,
440,
4903,
14,
4122,
198,
26,
635,
1015,
26,
710,
1015,
402,
314,
2032,
14,
3758,
365,
488,
4122,
198,
26,
635,
15931,
26,
710,
4546,
730,
370,
1827,
314,
7086,
367,
8,
708,
12,
5049,
680,
3758,
365,
5049,
4122,
198,
26,
635,
2637,
26,
4879,
2637,
626,
1443,
506,
1415,
367,
2488,
11620,
758,
470,
14,
4122,
198,
624,
4122,
198,
504,
8059,
19,
68,
14,
8462,
492,
4747,
5189,
4122,
198,
17230,
275,
283,
23802,
63,
7486,
63,
20890,
7,
4122,
198,
72,
498,
275,
519,
7,
10337,
60,
23570,
380,
1339,
60,
51,
1618,
280,
960,
60,
8154,
11804,
7,
4122,
198,
3292,
275,
488,
4122,
198,
692,
1015,
508,
488,
26,
7903,
198,
3,
6668,
314,
8839,
1015,
7903,
198,
6234,
275,
4747,
5189,
14,
513,
2872,
1197,
6550,
8,
17230,
12,
394,
498,
12,
15931,
29,
19134,
9,
7903,
198,
509,
1015,
315,
3355,
8,
6234,
12,
790,
29,
2400,
284,
26,
284,
59,
16,
467,
3837,
29,
549,
304,
13610,
198,
692,
1015,
59,
16,
61,
440,
315,
843,
423,
11996,
21167,
26,
19744,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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ered_report.py
|
375
|
2089
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import time
from openerp.osv import fields, osv
class account_budget_crossvered_report(osv.osv_memory):
_name = "account.budget.crossvered.report"
_description = "Account Budget crossvered report"
_columns = {
'date_from': fields.date('Start of period', required=True),
'date_to': fields.date('End of period', required=True),
}
_defaults = {
'date_from': lambda *a: time.strftime('%Y-01-01'),
'date_to': lambda *a: time.strftime('%Y-%m-%d'),
}
def check_report(self, cr, uid, ids, context=None):
if context is None:
context = {}
data = self.read(cr, uid, ids, context=context)[0]
datas = {
'ids': context.get('active_ids', []),
'model': 'crossovered.budget',
'form': data
}
datas['form']['ids'] = datas['ids']
datas['form']['report'] = 'analytic-full'
return self.pool['report'].get_action(cr, uid, [], 'account_budget.report_crossoveredbudget', data=datas, context=context)
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
646,
900,
199,
504,
5166,
14,
4795,
492,
1504,
12,
9506,
421,
199,
533,
2933,
63,
16501,
63,
7925,
10050,
63,
3070,
8,
4795,
14,
4795,
63,
4844,
304,
339,
485,
354,
275,
298,
2048,
14,
16501,
14,
7925,
10050,
14,
3070,
2,
272,
485,
1802,
275,
298,
6009,
699,
1181,
362,
8059,
10050,
3622,
2,
272,
485,
3406,
275,
469,
267,
283,
602,
63,
504,
356,
1504,
14,
602,
360,
3162,
402,
6247,
297,
1415,
29,
549,
395,
267,
283,
602,
63,
475,
356,
1504,
14,
602,
360,
3005,
402,
6247,
297,
1415,
29,
549,
395,
272,
789,
272,
485,
4322,
275,
469,
267,
283,
602,
63,
504,
356,
2400,
627,
65,
26,
900,
14,
6205,
3508,
57,
13,
614,
13,
614,
659,
267,
283,
602,
63,
475,
356,
2400,
627,
65,
26,
900,
14,
6205,
3508,
57,
3295,
77,
3295,
68,
659,
272,
789,
339,
347,
1104,
63,
3070,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
29,
403,
304,
267,
340,
1067,
365,
488,
26,
288,
1067,
275,
1052,
267,
666,
275,
291,
14,
739,
8,
1556,
12,
1747,
12,
2762,
12,
1067,
29,
1100,
2788,
16,
61,
267,
15012,
275,
469,
288,
283,
1580,
356,
1067,
14,
362,
360,
2682,
63,
1580,
297,
14431,
288,
283,
1238,
356,
283,
7925,
79,
10050,
14,
16501,
297,
288,
283,
964,
356,
666,
267,
789,
267,
15012,
459,
964,
2545,
1580,
418,
275,
15012,
459,
1580,
418,
267,
15012,
459,
964,
2545,
3070,
418,
275,
283,
9782,
13,
2861,
7,
267,
372,
291,
14,
2293,
459,
3070,
2278,
362,
63,
1287,
8,
1556,
12,
1747,
12,
990,
283,
2048,
63,
16501,
14,
3070,
63,
7925,
79,
10050,
16501,
297,
666,
29,
11563,
12,
1067,
29,
1100,
9,
199,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
646,
900,
199,
504,
5166,
14,
4795,
492,
1504,
12,
9506,
421,
199,
533,
2933,
63,
16501,
63,
7925,
10050,
63,
3070,
8,
4795,
14,
4795,
63,
4844,
304,
339,
485,
354,
275,
298,
2048,
14,
16501,
14,
7925,
10050,
14,
3070,
2,
272,
485,
1802,
275,
298,
6009,
699,
1181,
362,
8059,
10050,
3622,
2,
272,
485,
3406,
275,
469,
267,
283,
602,
63,
504,
356,
1504,
14,
602,
360,
3162,
402,
6247,
297,
1415,
29,
549,
395,
267,
283,
602,
63,
475,
356,
1504,
14,
602,
360,
3005,
402,
6247,
297,
1415,
29,
549,
395,
272,
789,
272,
485,
4322,
275,
469,
267,
283,
602,
63,
504,
356,
2400,
627,
65,
26,
900,
14,
6205,
3508,
57,
13,
614,
13,
614,
659,
267,
283,
602,
63,
475,
356,
2400,
627,
65,
26,
900,
14,
6205,
3508,
57,
3295,
77,
3295,
68,
659,
272,
789,
339,
347,
1104,
63,
3070,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
29,
403,
304,
267,
340,
1067,
365,
488,
26,
288,
1067,
275,
1052,
267,
666,
275,
291,
14,
739,
8,
1556,
12,
1747,
12,
2762,
12,
1067,
29,
1100,
2788,
16,
61,
267,
15012,
275,
469,
288,
283,
1580,
356,
1067,
14,
362,
360,
2682,
63,
1580,
297,
14431,
288,
283,
1238,
356,
283,
7925,
79,
10050,
14,
16501,
297,
288,
283,
964,
356,
666,
267,
789,
267,
15012,
459,
964,
2545,
1580,
418,
275,
15012,
459,
1580,
418,
267,
15012,
459,
964,
2545,
3070,
418,
275,
283,
9782,
13,
2861,
7,
267,
372,
291,
14,
2293,
459,
3070,
2278,
362,
63,
1287,
8,
1556,
12,
1747,
12,
990,
283,
2048,
63,
16501,
14,
3070,
63,
7925,
79,
10050,
16501,
297,
666,
29,
11563,
12,
1067,
29,
1100,
9,
199,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
Geof23/SESABench_II
|
parboil/driver/benchmark.py
|
1
|
19162
|
# (c) 2007 The Board of Trustees of the University of Illinois.
import sys
import os
from os import path
import re
from itertools import imap, repeat, chain
import globals
import process
import parboilfile as pbf
from futures import Future
from error import ErrorType
class Benchmark(object):
"""A benchmark.
If the benchmark is malformed or otherwise invalid, only the 'name' and
'invalid' fields will be set. Otherwise all fields will be set.
Fields:
name The name of the benchmark. This is also the benchmark
directory name.
invalid None if the benchmark is valid; otherwise, an exception
describing why the benchmark is invalid.
path Full path of the benchmark directory.
descr A description of the benchmark.
impls A dictionary of benchmark source implementations.
datas A dictionary of data sets used to run the benchmark."""
def __init__(self, name, path = None, impls = [], datasets = [],
description=None, invalid=None):
self.name = name
self.invalid = invalid
if invalid is None:
self.path = path
self.impls = dict(imap(lambda i: (i.name, i), impls))
self.datas = dict(imap(lambda i: (i.name, i), datasets))
self.descr = description
def createFromName(name):
"""Scan the benchmark directory for the benchmark named 'name'
and create a benchmark object for it."""
bmkdir = globals.benchdir.getChildByName(name)
datadir = globals.datadir.getChildByName(name)
descr = process.read_description_file(bmkdir)
try:
# Scan implementations of the benchmark
impls = [BenchImpl.createFromDir(impl)
for impl in process.scan_for_benchmark_versions(bmkdir)]
# Scan data sets of the benchmark
datas = [BenchDataset.createFromDir(data)
for data in process.scan_for_benchmark_datasets(datadir)]
# If no exception occurred, the benchmark is valid
return Benchmark(name, bmkdir.getPath(), impls, datas, descr)
finally:
pass
#except Exception, e:
# return Benchmark(name, invalid=e)
createFromName = staticmethod(createFromName)
def describe(self):
"""Return a string describing this benchmark."""
if self.invalid:
return "Error in benchmark:\n" + str(self.invalid)
if self.descr is None:
header = "Benchmark '" + self.name + "'"
else:
header = self.descr
impls = " ".join([impl.name for impl in self.impls.itervalues()])
datas = " ".join([data.name for data in self.datas.itervalues()])
return header + "\nVersions: " + impls + "\nData sets: " + datas
def instance_check(x):
if not isinstance(x, Benchmark):
raise TypeError, "argument must be an instance of Benchmark"
instance_check = staticmethod(instance_check)
class BenchImpl(object):
"""An implementation of a benchmark."""
def __init__(self, dir, description=None):
if not isinstance(dir, pbf.Directory):
raise TypeEror, "dir must be a directory"
self.name = dir.getName()
self.dir = dir
self.descr = description
def createFromDir(dir):
"""Scan the directory containing a benchmark implementation
and create a BenchImpl object from it."""
# Get the description from a file, if provided
descr = process.read_description_file(dir)
return BenchImpl(dir, descr)
createFromDir = staticmethod(createFromDir)
def makefile(self, benchmark, target=None, action=None, platform=None, opt={}):
"""Run this implementation's makefile."""
self.platform = platform
Benchmark.instance_check(benchmark)
def perform():
srcdir = path.join('src', self.name)
builddir = path.join('build', self.name)
if self.platform == None: platform = 'default'
else: platform = self.platform
env={'SRCDIR':srcdir,
'BUILDDIR':builddir + '_' + platform,
'BIN':path.join(builddir+'_'+platform,benchmark.name),
'PARBOIL_ROOT':globals.root,
'PLATFORM':platform,
'BUILD':self.name}
env.update(opt)
mkfile = globals.root + os.sep + 'common' + os.sep + 'mk'
# Run the makefile to build the benchmark
ret = process.makefile(target=target,
action=action,
filepath=path.join(mkfile, "Makefile"),
env=env)
if ret == True:
return ErrorType.Success
else:
return ErrorType.CompileError
# Go to the benchmark directory before building
return process.with_path(benchmark.path, perform)
def build(self, benchmark, platform):
"""Build an executable of this benchmark implementation."""
return self.makefile(benchmark, action='build', platform=platform)
def isBuilt(self, benchmark, platform):
"""Determine whether the executable is up to date."""
return self.makefile(benchmark, action='q', platform=platform) == ErrorType.Success
def clean(self, benchmark, platform):
"""Remove build files for this benchmark implementation."""
return self.makefile(benchmark, action='clean', platform=platform)
def run(self, benchmark, dataset, do_output=True, extra_opts=[], platform=None):
"""Run this benchmark implementation.
Return True if the benchmark terminated normally or False
if there was an error."""
if platform == None:
self.platform = 'default'
else:
self.platform = platform
# Ensure that the benchmark has been built
if not self.isBuilt(benchmark, platform):
rc = self.build(benchmark, platform)
# Stop if 'make' failed
if rc != ErrorType.Success: return rc
def perform():
if self.platform == None:
platform = 'default'
else:
platform = self.platform
# Run the program
#exename = path.join('build', self.name+'_'+platform, benchmark.name)
#args = [exename] + extra_opts + dataset.getCommandLineArguments(benchmark, do_output)
#rc = process.spawnwaitv(exename, args)
args = extra_opts + dataset.getCommandLineArguments(benchmark, do_output)
args = reduce(lambda x, y: x + ' ' + y, args)
###
try:
rc = self.makefile(benchmark, action='run', platform=platform, opt={"ARGS":args})
except KeyboardInterrupt:
rc = ErrorType.Killed
# Program exited with error?
# if rc != 0: return ErrorType.RunFailed
# return ErrorType.Success
return rc
return process.with_path(benchmark.path, perform)
def debug(self, benchmark, dataset, do_output=True, extra_opts=[], platform=None):
"""Debug this benchmark implementation."""
if platform == None:
self.platform = 'default'
else:
self.platform = platform
# Ensure that the benchmark has been built
if not self.isBuilt(benchmark, platform):
rc = self.build(benchmark, platform)
# Stop if 'make' failed
if rc != ErrorType.Success: return rc
def perform():
if self.platform == None:
platform = 'default'
else:
platform = self.platform
# Run the program
args = extra_opts + dataset.getCommandLineArguments(benchmark, do_output)
args = reduce(lambda x, y: x + ' ' + y, args)
###
rc = self.makefile(benchmark, action='debug', platform=platform, opt={"ARGS":args})
# Program exited with error?
if rc != 0: return ErrorType.RunFailed
return ErrorType.Success
return process.with_path(benchmark.path, perform)
def check(self, benchmark, dataset):
"""Check the output from the last run of this benchmark
implementation.
Return True if the output checks successfully or False
otherwise."""
def perform():
output_file = dataset.getTemporaryOutputFile(benchmark).getPath()
reference_file = dataset.getReferenceOutputPath()
compare = os.path.join('tools', 'compare-output')
rc = process.spawnwaitl(compare,
compare, reference_file, output_file)
# Program exited with error, or mismatch in output?
if rc != 0: return False
return True
return process.with_path(benchmark.path, perform)
def __str__(self):
return "<BenchImpl '" + self.name + "'>"
class BenchDataset(object):
"""Data sets for running a benchmark."""
def __init__(self, dir, in_files=[], out_files=[], parameters=[],
description=None):
if not isinstance(dir, pbf.Directory):
raise TypeError, "dir must be a pbf.Directory"
self.name = dir.getName()
self.dir = dir
self.inFiles = in_files
self.outFiles = out_files
self.parameters = parameters
self.descr = description
def createFromDir(dir):
"""Scan the directory containing a dataset
and create a BenchDataset object from it."""
# Identify the paths where files may be found
input_dir = dir.getChildByName('input')
output_dir = dir.getChildByName('output')
#benchmark_path = path.join(globals.root, 'benchmarks', name)
def check_default_input_files():
# This function is called to see if the input file set
# guessed by scanning the input directory can be used
if invalid_default_input_files:
raise ValueError, "Cannot infer command line when there are multiple input files in a data set\n(Fix by adding an input DESCRIPTION file)"
if input_dir.exists():
input_descr = process.read_description_file(input_dir)
input_files = input_dir.scanAndReturnNames()
# If more than one input file was found, cannot use the default
# input file list produced by scanning the directory
invalid_default_input_files = len(input_files) > 1
else:
# If there's no input directory, assume the benchmark
# takes no input
input_descr = None
input_files = []
invalid_default_input_files = False
# Read the text of the input description file
if input_descr is not None:
(parameters, input_files1, input_descr) = \
unpack_dataset_description(input_descr, input_files=None)
if input_files1 is None:
# No override value given; use the default
check_default_input_files()
else:
input_files = input_files1
else:
check_default_input_files()
parameters = []
# Look for output files
output_descr = process.read_description_file(output_dir)
output_files = output_dir.scanAndReturnNames()
if len(output_files) > 1:
raise ValueError, "Multiple output files not supported"
# Concatenate input and output descriptions
if input_descr and output_descr:
descr = input_descr + "\n\n" + output_descr
else:
descr = input_descr or output_descr
return BenchDataset(dir, input_files, output_files, parameters, descr)
createFromDir = staticmethod(createFromDir)
def getName(self):
"""Get the name of this dataset."""
return self.name
def getTemporaryOutputDir(self, benchmark):
"""Get the pbf.Directory for the output of a benchmark run.
This function should always return the same pbf.Directory if its parameters
are the same. The output path is not the path where the reference
output is stored."""
rundir = globals.benchdir.getChildByName(benchmark.name).getChildByName('run')
if rundir.getChildByName(self.name) is None:
datasetpath = path.join(rundir.getPath(), self.name)
filepath = path.join(datasetpath, self.outFiles[0])
rundir.addChild(pbf.Directory(datasetpath, [pbf.File(filepath, False)]))
return rundir.getChildByName(self.name)
def getTemporaryOutputFile(self, benchmark):
"""Get the pbf.File for the output of a benchmark run.
This function should always return the same pbf.File if its parameters
are the same. The output path is not where the referrence output
is stored."""
return self.getTemporaryOutputDir(benchmark).getChildByName(self.outFiles[0])
def getReferenceOutputPath(self):
"""Get the name of the reference file, to which the output of a
benchmark run should be compared."""
return path.join(self.dir.getPath(), 'output', self.outFiles[0])
def getCommandLineArguments(self, benchmark, do_output=True):
"""Get the command line arguments that should be passed to the
executable to run this data set. If 'output' is True, then
the executable will be passed flags to save its output to a file.
Directories to hold ouptut files are created if they do not exist."""
args = []
# Add arguments to pass input files to the benchmark
if self.inFiles:
in_files = ",".join([path.join(self.dir.getPath(),'input', x)
for x in self.inFiles])
args.append("-i")
args.append(in_files)
# Add arguments to store the output somewhere, if output is
# desired
if do_output and self.outFiles:
if len(self.outFiles) != 1:
raise ValueError, "only one output file is supported"
out_file = self.getTemporaryOutputFile(benchmark)
args.append("-o")
args.append(out_file.getPath())
# Ensure that a directory exists for the output
self.getTemporaryOutputDir(benchmark).touch()
args += self.parameters
return args
def __str__(self):
return "<BenchData '" + self.name + "'>"
def unpack_dataset_description(descr, parameters=[], input_files=[]):
"""Read information from the raw contents of a data set description
file. Optional 'parameters' and 'input_files' arguments may be
given, which will be retained unless overridden by the description
file."""
leftover = []
split_at_colon = re.compile(r"^\s*([a-zA-Z]+)\s*:(.*)$")
# Initialize these to default empty strings
parameter_text = None
input_file_text = None
# Scan the description line by line
for line in descr.split('\n'):
m = split_at_colon.match(line)
if m is None: continue
# This line appears to declare something that should be
# interpreted
keyword = m.group(1)
if keyword == "Parameters":
parameter_text = m.group(2)
elif keyword == "Inputs":
input_file_text = m.group(2)
# else, ignore the line
# Split the strings into (possibly) multiple arguments, discarding
# whitespace
if parameter_text is not None: parameters = parameter_text.split()
if input_file_text is not None: input_files = input_file_text.split()
return (parameters, input_files, descr)
def version_scanner():
"""version_scanner() -> (path -> pbf.Directory)
Return a function to find benchmark versions in the src
directory for the benchmark."""
return lambda x: pbf.scan_file(x, True, lambda y: pbf.Directory(y), ['.svn'])
def find_benchmarks():
"""Find benchmarks in the repository. The benchmarks are
identified, but their contents are not scanned immediately. A
dictionary is returned mapping benchmark names to futures
containing the benchmarks."""
if not globals.root:
raise ValueError, "root directory has not been set"
# Scan all benchmarks in the 'benchmarks' directory and
# lazily create benchmark objects.
db = {}
try:
globals.benchdir.scan()
globals.datadir.scan()
for bmkdir in globals.benchdir.getScannedChildren():
bmk = Future(lambda bmkdir=bmkdir: Benchmark.createFromName(bmkdir.getName()))
db[bmkdir.getName()] = bmk
except OSError, e:
sys.stdout.write("Benchmark directory not found!\n\n")
return {}
return db
def _desc_file(dpath):
"""_desc_file(dpath)
Returns a pbf.File for an optional description file in the directory dpath."""
return pbf.File(path.join(dpath,'DESCRIPTION'), False)
def benchmark_scanner():
"""benchmark_scanner -> (path -> pbf.Directory)
Returns a function which will scan a filename and create a pbf.Directory
for a benchmark represented by that name."""
def create_benchmark_dir(dpath):
expected = [pbf.Directory(path.join(dpath,'src'), [], version_scanner()),
pbf.Directory(path.join(dpath,'tools'),
[pbf.File(path.join(dpath,'compare-output'))]),
pbf.Directory(path.join(dpath,'build'), must_exist=False),
pbf.Directory(path.join(dpath,'run'), must_exist=False),
_desc_file(dpath)]
return pbf.Directory(dpath, expected)
return lambda x: pbf.scan_file(x, True, create_benchmark_dir,['_darcs','.svn'])
def dataset_scanner():
"""dataset_scanner -> (path -> pbf.Directory)
Returns a function which will scan a filename and create a pbf.Directory
for a folder containing datasets for the benchmark of the same name."""
def create_dataset_dir(dpath):
simple_scan = lambda x: pbf.scan_file(x)
expected = [pbf.Directory(path.join(dpath,'input'),
[_desc_file(path.join(dpath,'input'))], simple_scan),
pbf.Directory(path.join(dpath,'output'), [], simple_scan),
_desc_file(dpath)]
return pbf.Directory(dpath, expected)
return lambda x: pbf.scan_file(x, True, create_dataset_dir, ['.svn', '_darcs'])
def dataset_repo_scanner():
"""dataset_repo_scanner -> (path -> pbf.Directory)
Returns a function which will scan a filename and create a pbf.Directory
for a folder containing a dataset repository for parboil benchmarks."""
benchmark_dsets_scanner = lambda x: pbf.Directory(x, [], dataset_scanner())
return lambda x: pbf.scan_file(x, True, benchmark_dsets_scanner)
|
mit
|
[
3,
334,
67,
9,
10219,
710,
5088,
1005,
402,
377,
20791,
266,
397,
402,
314,
15904,
402,
473,
76,
472,
79,
374,
14,
199,
199,
646,
984,
199,
646,
747,
199,
504,
747,
492,
931,
199,
646,
295,
199,
504,
7975,
492,
23646,
12,
11982,
12,
6036,
199,
199,
646,
7992,
199,
646,
2112,
199,
646,
623,
656,
73,
12059,
465,
299,
4361,
199,
504,
27471,
492,
20799,
199,
199,
504,
1125,
492,
4520,
804,
199,
199,
533,
27067,
8,
785,
304,
272,
408,
33,
12338,
14,
339,
982,
314,
12338,
365,
24159,
503,
4257,
3866,
12,
1454,
314,
283,
354,
7,
436,
272,
283,
3197,
7,
1504,
911,
506,
663,
14,
221,
6630,
1006,
1504,
911,
506,
663,
14,
339,
16424,
26,
489,
536,
263,
710,
536,
402,
314,
12338,
14,
221,
961,
365,
2597,
314,
12338,
2116,
2082,
536,
14,
489,
3866,
258,
488,
340,
314,
12338,
365,
1686,
27,
4257,
12,
376,
1919,
2116,
13660,
10842,
314,
12338,
365,
3866,
14,
489,
931,
263,
16579,
931,
402,
314,
12338,
2082,
14,
489,
16193,
755,
437,
1369,
402,
314,
12338,
14,
489,
1742,
478,
755,
437,
2600,
402,
12338,
1350,
12591,
14,
489,
15012,
755,
437,
2600,
402,
666,
5951,
1202,
370,
1255,
314,
12338,
1041,
339,
347,
636,
826,
721,
277,
12,
536,
12,
931,
275,
488,
12,
1742,
478,
275,
990,
13148,
275,
990,
326,
1369,
29,
403,
12,
3866,
29,
403,
304,
267,
291,
14,
354,
275,
536,
267,
291,
14,
3197,
275,
3866,
398,
340,
3866,
365,
488,
26,
288,
291,
14,
515,
275,
931,
288,
291,
14,
3236,
478,
275,
1211,
8,
15311,
8,
2734,
284,
26,
334,
73,
14,
354,
12,
284,
395,
1742,
478,
430,
288,
291,
14,
11563,
275,
1211,
8,
15311,
8,
2734,
284,
26,
334,
73,
14,
354,
12,
284,
395,
13148,
430,
288,
291,
14,
12113,
275,
1369,
339,
347,
1218,
2532,
985,
8,
354,
304,
267,
408,
15936,
314,
12338,
2082,
367,
314,
12338,
4310,
283,
354,
7,
267,
436,
1218,
282,
12338,
909,
367,
652,
1041,
267,
330,
8215,
275,
7992,
14,
16571,
694,
14,
26023,
11190,
8,
354,
9,
267,
666,
694,
275,
7992,
14,
18259,
14,
26023,
11190,
8,
354,
9,
267,
16193,
275,
2112,
14,
739,
63,
1802,
63,
493,
8,
66,
8215,
9,
7318,
862,
26,
288,
327,
24833,
12591,
402,
314,
12338,
288,
1742,
478,
275,
359,
34,
5368,
4748,
14,
981,
2532,
3567,
8,
5472,
9,
2151,
367,
11512,
315,
2112,
14,
6282,
63,
509,
63,
11861,
63,
6234,
8,
66,
8215,
1874,
7846,
327,
24833,
666,
5951,
402,
314,
12338,
288,
15012,
275,
359,
34,
5368,
9271,
14,
981,
2532,
3567,
8,
576,
9,
2151,
367,
666,
315,
2112,
14,
6282,
63,
509,
63,
11861,
63,
12281,
8,
18259,
1874,
953,
327,
982,
949,
1919,
8920,
12,
314,
12338,
365,
1686,
288,
372,
27067,
8,
354,
12,
330,
8215,
14,
362,
2042,
1062,
1742,
478,
12,
15012,
12,
16193,
9,
267,
3753,
26,
288,
986,
267,
327,
2590,
2186,
12,
325,
26,
267,
327,
259,
372,
27067,
8,
354,
12,
3866,
29,
69,
9,
5493,
1218,
2532,
985,
275,
12822,
8,
981,
2532,
985,
9,
339,
347,
13743,
8,
277,
304,
267,
408,
1767,
282,
1059,
13660,
642,
12338,
1041,
398,
340,
291,
14,
3197,
26,
288,
372,
298,
547,
315,
12338,
3427,
78,
2,
435,
620,
8,
277,
14,
3197,
9,
398,
340,
291,
14,
12113,
221,
365,
488,
26,
288,
1406,
275,
298,
18644,
5522,
435,
291,
14,
354,
435,
21673,
267,
587,
26,
288,
1406,
275,
291,
14,
12113,
398,
1742,
478,
275,
298,
3680,
904,
779,
5472,
14,
354,
367,
11512,
315,
291,
14,
3236,
478,
14,
13012,
9383,
267,
15012,
275,
298,
3680,
904,
779,
576,
14,
354,
367,
666,
315,
291,
14,
11563,
14,
13012,
9383,
398,
372,
1406,
435,
1867,
78,
21167,
26,
298,
435,
1742,
478,
435,
1867,
78,
1451,
5951,
26,
298,
435,
15012,
339,
347,
1256,
63,
1074,
8,
88,
304,
267,
340,
440,
1228,
8,
88,
12,
27067,
304,
288,
746,
3146,
12,
298,
2094,
1471,
506,
376,
1256,
402,
27067,
2,
339,
1256,
63,
1074,
275,
12822,
8,
842,
63,
1074,
9,
199,
199,
533,
699,
5368,
4748,
8,
785,
304,
272,
408,
2493,
4514,
402,
282,
12338,
1041,
339,
347,
636,
826,
721,
277,
12,
2935,
12,
1369,
29,
403,
304,
267,
340,
440,
1228,
8,
694,
12,
299,
4361,
14,
6231,
304,
288,
746,
2434,
37,
451,
12,
298,
694,
1471,
506,
282,
2082,
2,
398,
291,
14,
354,
275,
2935,
14,
16405,
342,
4960,
291,
14,
694,
275,
2935,
267,
291,
14,
12113,
275,
1369,
339,
347,
1218,
2532,
3567,
8,
694,
304,
267,
408,
15936,
314,
2082,
3035,
282,
12338,
4514,
267,
436,
1218,
282,
699,
5368,
4748,
909,
687,
652,
1041,
398,
327,
2372,
314,
1369,
687,
282,
570,
12,
340,
2741,
267,
16193,
275,
2112,
14,
739,
63,
1802,
63,
493,
8,
694,
9,
398,
372,
699,
5368,
4748,
8,
694,
12,
16193,
9,
339,
1218,
2532,
3567,
275,
12822,
8,
981,
2532,
3567,
9,
339,
347,
16818,
8,
277,
12,
12338,
12,
1347,
29,
403,
12,
1595,
29,
403,
12,
4298,
29,
403,
12,
2450,
16420,
267,
408,
2540,
642,
4514,
1159,
16818,
1041,
2728,
291,
14,
3246,
275,
4298,
267,
27067,
14,
842,
63,
1074,
8,
11861,
9,
398,
347,
5147,
837,
288,
31967,
275,
931,
14,
904,
360,
2164,
297,
291,
14,
354,
9,
288,
1900,
694,
275,
931,
14,
904,
360,
1506,
297,
291,
14,
354,
9,
953,
340,
291,
14,
3246,
508,
488,
26,
4298,
275,
283,
885,
7,
288,
587,
26,
4298,
275,
291,
14,
3246,
953,
2589,
3713,
12447,
3022,
356,
17878,
12,
326,
283,
8248,
3022,
356,
21728,
435,
14135,
435,
4298,
12,
326,
283,
9431,
356,
515,
14,
904,
8,
21728,
4786,
20013,
3246,
12,
11861,
14,
354,
395,
326,
283,
4014,
3973,
1193,
63,
5441,
356,
8473,
14,
1231,
12,
326,
283,
17805,
356,
3246,
12,
326,
283,
8248,
356,
277,
14,
354,
93,
288,
2589,
14,
873,
8,
2992,
9,
953,
9199,
493,
275,
7992,
14,
1231,
435,
747,
14,
4127,
435,
283
] |
[
334,
67,
9,
10219,
710,
5088,
1005,
402,
377,
20791,
266,
397,
402,
314,
15904,
402,
473,
76,
472,
79,
374,
14,
199,
199,
646,
984,
199,
646,
747,
199,
504,
747,
492,
931,
199,
646,
295,
199,
504,
7975,
492,
23646,
12,
11982,
12,
6036,
199,
199,
646,
7992,
199,
646,
2112,
199,
646,
623,
656,
73,
12059,
465,
299,
4361,
199,
504,
27471,
492,
20799,
199,
199,
504,
1125,
492,
4520,
804,
199,
199,
533,
27067,
8,
785,
304,
272,
408,
33,
12338,
14,
339,
982,
314,
12338,
365,
24159,
503,
4257,
3866,
12,
1454,
314,
283,
354,
7,
436,
272,
283,
3197,
7,
1504,
911,
506,
663,
14,
221,
6630,
1006,
1504,
911,
506,
663,
14,
339,
16424,
26,
489,
536,
263,
710,
536,
402,
314,
12338,
14,
221,
961,
365,
2597,
314,
12338,
2116,
2082,
536,
14,
489,
3866,
258,
488,
340,
314,
12338,
365,
1686,
27,
4257,
12,
376,
1919,
2116,
13660,
10842,
314,
12338,
365,
3866,
14,
489,
931,
263,
16579,
931,
402,
314,
12338,
2082,
14,
489,
16193,
755,
437,
1369,
402,
314,
12338,
14,
489,
1742,
478,
755,
437,
2600,
402,
12338,
1350,
12591,
14,
489,
15012,
755,
437,
2600,
402,
666,
5951,
1202,
370,
1255,
314,
12338,
1041,
339,
347,
636,
826,
721,
277,
12,
536,
12,
931,
275,
488,
12,
1742,
478,
275,
990,
13148,
275,
990,
326,
1369,
29,
403,
12,
3866,
29,
403,
304,
267,
291,
14,
354,
275,
536,
267,
291,
14,
3197,
275,
3866,
398,
340,
3866,
365,
488,
26,
288,
291,
14,
515,
275,
931,
288,
291,
14,
3236,
478,
275,
1211,
8,
15311,
8,
2734,
284,
26,
334,
73,
14,
354,
12,
284,
395,
1742,
478,
430,
288,
291,
14,
11563,
275,
1211,
8,
15311,
8,
2734,
284,
26,
334,
73,
14,
354,
12,
284,
395,
13148,
430,
288,
291,
14,
12113,
275,
1369,
339,
347,
1218,
2532,
985,
8,
354,
304,
267,
408,
15936,
314,
12338,
2082,
367,
314,
12338,
4310,
283,
354,
7,
267,
436,
1218,
282,
12338,
909,
367,
652,
1041,
267,
330,
8215,
275,
7992,
14,
16571,
694,
14,
26023,
11190,
8,
354,
9,
267,
666,
694,
275,
7992,
14,
18259,
14,
26023,
11190,
8,
354,
9,
267,
16193,
275,
2112,
14,
739,
63,
1802,
63,
493,
8,
66,
8215,
9,
7318,
862,
26,
288,
327,
24833,
12591,
402,
314,
12338,
288,
1742,
478,
275,
359,
34,
5368,
4748,
14,
981,
2532,
3567,
8,
5472,
9,
2151,
367,
11512,
315,
2112,
14,
6282,
63,
509,
63,
11861,
63,
6234,
8,
66,
8215,
1874,
7846,
327,
24833,
666,
5951,
402,
314,
12338,
288,
15012,
275,
359,
34,
5368,
9271,
14,
981,
2532,
3567,
8,
576,
9,
2151,
367,
666,
315,
2112,
14,
6282,
63,
509,
63,
11861,
63,
12281,
8,
18259,
1874,
953,
327,
982,
949,
1919,
8920,
12,
314,
12338,
365,
1686,
288,
372,
27067,
8,
354,
12,
330,
8215,
14,
362,
2042,
1062,
1742,
478,
12,
15012,
12,
16193,
9,
267,
3753,
26,
288,
986,
267,
327,
2590,
2186,
12,
325,
26,
267,
327,
259,
372,
27067,
8,
354,
12,
3866,
29,
69,
9,
5493,
1218,
2532,
985,
275,
12822,
8,
981,
2532,
985,
9,
339,
347,
13743,
8,
277,
304,
267,
408,
1767,
282,
1059,
13660,
642,
12338,
1041,
398,
340,
291,
14,
3197,
26,
288,
372,
298,
547,
315,
12338,
3427,
78,
2,
435,
620,
8,
277,
14,
3197,
9,
398,
340,
291,
14,
12113,
221,
365,
488,
26,
288,
1406,
275,
298,
18644,
5522,
435,
291,
14,
354,
435,
21673,
267,
587,
26,
288,
1406,
275,
291,
14,
12113,
398,
1742,
478,
275,
298,
3680,
904,
779,
5472,
14,
354,
367,
11512,
315,
291,
14,
3236,
478,
14,
13012,
9383,
267,
15012,
275,
298,
3680,
904,
779,
576,
14,
354,
367,
666,
315,
291,
14,
11563,
14,
13012,
9383,
398,
372,
1406,
435,
1867,
78,
21167,
26,
298,
435,
1742,
478,
435,
1867,
78,
1451,
5951,
26,
298,
435,
15012,
339,
347,
1256,
63,
1074,
8,
88,
304,
267,
340,
440,
1228,
8,
88,
12,
27067,
304,
288,
746,
3146,
12,
298,
2094,
1471,
506,
376,
1256,
402,
27067,
2,
339,
1256,
63,
1074,
275,
12822,
8,
842,
63,
1074,
9,
199,
199,
533,
699,
5368,
4748,
8,
785,
304,
272,
408,
2493,
4514,
402,
282,
12338,
1041,
339,
347,
636,
826,
721,
277,
12,
2935,
12,
1369,
29,
403,
304,
267,
340,
440,
1228,
8,
694,
12,
299,
4361,
14,
6231,
304,
288,
746,
2434,
37,
451,
12,
298,
694,
1471,
506,
282,
2082,
2,
398,
291,
14,
354,
275,
2935,
14,
16405,
342,
4960,
291,
14,
694,
275,
2935,
267,
291,
14,
12113,
275,
1369,
339,
347,
1218,
2532,
3567,
8,
694,
304,
267,
408,
15936,
314,
2082,
3035,
282,
12338,
4514,
267,
436,
1218,
282,
699,
5368,
4748,
909,
687,
652,
1041,
398,
327,
2372,
314,
1369,
687,
282,
570,
12,
340,
2741,
267,
16193,
275,
2112,
14,
739,
63,
1802,
63,
493,
8,
694,
9,
398,
372,
699,
5368,
4748,
8,
694,
12,
16193,
9,
339,
1218,
2532,
3567,
275,
12822,
8,
981,
2532,
3567,
9,
339,
347,
16818,
8,
277,
12,
12338,
12,
1347,
29,
403,
12,
1595,
29,
403,
12,
4298,
29,
403,
12,
2450,
16420,
267,
408,
2540,
642,
4514,
1159,
16818,
1041,
2728,
291,
14,
3246,
275,
4298,
267,
27067,
14,
842,
63,
1074,
8,
11861,
9,
398,
347,
5147,
837,
288,
31967,
275,
931,
14,
904,
360,
2164,
297,
291,
14,
354,
9,
288,
1900,
694,
275,
931,
14,
904,
360,
1506,
297,
291,
14,
354,
9,
953,
340,
291,
14,
3246,
508,
488,
26,
4298,
275,
283,
885,
7,
288,
587,
26,
4298,
275,
291,
14,
3246,
953,
2589,
3713,
12447,
3022,
356,
17878,
12,
326,
283,
8248,
3022,
356,
21728,
435,
14135,
435,
4298,
12,
326,
283,
9431,
356,
515,
14,
904,
8,
21728,
4786,
20013,
3246,
12,
11861,
14,
354,
395,
326,
283,
4014,
3973,
1193,
63,
5441,
356,
8473,
14,
1231,
12,
326,
283,
17805,
356,
3246,
12,
326,
283,
8248,
356,
277,
14,
354,
93,
288,
2589,
14,
873,
8,
2992,
9,
953,
9199,
493,
275,
7992,
14,
1231,
435,
747,
14,
4127,
435,
283,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
molotof/infernal-twin
|
build/pip/pip/_vendor/packaging/version.py
|
439
|
11949
|
# Copyright 2014 Donald Stufft
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import absolute_import, division, print_function
import collections
import itertools
import re
from ._structures import Infinity
__all__ = [
"parse", "Version", "LegacyVersion", "InvalidVersion", "VERSION_PATTERN"
]
_Version = collections.namedtuple(
"_Version",
["epoch", "release", "dev", "pre", "post", "local"],
)
def parse(version):
"""
Parse the given version string and return either a :class:`Version` object
or a :class:`LegacyVersion` object depending on if the given version is
a valid PEP 440 version or a legacy version.
"""
try:
return Version(version)
except InvalidVersion:
return LegacyVersion(version)
class InvalidVersion(ValueError):
"""
An invalid version was found, users should refer to PEP 440.
"""
class _BaseVersion(object):
def __hash__(self):
return hash(self._key)
def __lt__(self, other):
return self._compare(other, lambda s, o: s < o)
def __le__(self, other):
return self._compare(other, lambda s, o: s <= o)
def __eq__(self, other):
return self._compare(other, lambda s, o: s == o)
def __ge__(self, other):
return self._compare(other, lambda s, o: s >= o)
def __gt__(self, other):
return self._compare(other, lambda s, o: s > o)
def __ne__(self, other):
return self._compare(other, lambda s, o: s != o)
def _compare(self, other, method):
if not isinstance(other, _BaseVersion):
return NotImplemented
return method(self._key, other._key)
class LegacyVersion(_BaseVersion):
def __init__(self, version):
self._version = str(version)
self._key = _legacy_cmpkey(self._version)
def __str__(self):
return self._version
def __repr__(self):
return "<LegacyVersion({0})>".format(repr(str(self)))
@property
def public(self):
return self._version
@property
def base_version(self):
return self._version
@property
def local(self):
return None
@property
def is_prerelease(self):
return False
@property
def is_postrelease(self):
return False
_legacy_version_component_re = re.compile(
r"(\d+ | [a-z]+ | \.| -)", re.VERBOSE,
)
_legacy_version_replacement_map = {
"pre": "c", "preview": "c", "-": "final-", "rc": "c", "dev": "@",
}
def _parse_version_parts(s):
for part in _legacy_version_component_re.split(s):
part = _legacy_version_replacement_map.get(part, part)
if not part or part == ".":
continue
if part[:1] in "0123456789":
# pad for numeric comparison
yield part.zfill(8)
else:
yield "*" + part
# ensure that alpha/beta/candidate are before final
yield "*final"
def _legacy_cmpkey(version):
# We hardcode an epoch of -1 here. A PEP 440 version can only have a epoch
# greater than or equal to 0. This will effectively put the LegacyVersion,
# which uses the defacto standard originally implemented by setuptools,
# as before all PEP 440 versions.
epoch = -1
# This scheme is taken from pkg_resources.parse_version setuptools prior to
# it's adoption of the packaging library.
parts = []
for part in _parse_version_parts(version.lower()):
if part.startswith("*"):
# remove "-" before a prerelease tag
if part < "*final":
while parts and parts[-1] == "*final-":
parts.pop()
# remove trailing zeros from each series of numeric parts
while parts and parts[-1] == "00000000":
parts.pop()
parts.append(part)
parts = tuple(parts)
return epoch, parts
# Deliberately not anchored to the start and end of the string, to make it
# easier for 3rd party code to reuse
VERSION_PATTERN = r"""
v?
(?:
(?:(?P<epoch>[0-9]+)!)? # epoch
(?P<release>[0-9]+(?:\.[0-9]+)*) # release segment
(?P<pre> # pre-release
[-_\.]?
(?P<pre_l>(a|b|c|rc|alpha|beta|pre|preview))
[-_\.]?
(?P<pre_n>[0-9]+)?
)?
(?P<post> # post release
(?:-(?P<post_n1>[0-9]+))
|
(?:
[-_\.]?
(?P<post_l>post|rev|r)
[-_\.]?
(?P<post_n2>[0-9]+)?
)
)?
(?P<dev> # dev release
[-_\.]?
(?P<dev_l>dev)
[-_\.]?
(?P<dev_n>[0-9]+)?
)?
)
(?:\+(?P<local>[a-z0-9]+(?:[-_\.][a-z0-9]+)*))? # local version
"""
class Version(_BaseVersion):
_regex = re.compile(
r"^\s*" + VERSION_PATTERN + r"\s*$",
re.VERBOSE | re.IGNORECASE,
)
def __init__(self, version):
# Validate the version and parse it into pieces
match = self._regex.search(version)
if not match:
raise InvalidVersion("Invalid version: '{0}'".format(version))
# Store the parsed out pieces of the version
self._version = _Version(
epoch=int(match.group("epoch")) if match.group("epoch") else 0,
release=tuple(int(i) for i in match.group("release").split(".")),
pre=_parse_letter_version(
match.group("pre_l"),
match.group("pre_n"),
),
post=_parse_letter_version(
match.group("post_l"),
match.group("post_n1") or match.group("post_n2"),
),
dev=_parse_letter_version(
match.group("dev_l"),
match.group("dev_n"),
),
local=_parse_local_version(match.group("local")),
)
# Generate a key which will be used for sorting
self._key = _cmpkey(
self._version.epoch,
self._version.release,
self._version.pre,
self._version.post,
self._version.dev,
self._version.local,
)
def __repr__(self):
return "<Version({0})>".format(repr(str(self)))
def __str__(self):
parts = []
# Epoch
if self._version.epoch != 0:
parts.append("{0}!".format(self._version.epoch))
# Release segment
parts.append(".".join(str(x) for x in self._version.release))
# Pre-release
if self._version.pre is not None:
parts.append("".join(str(x) for x in self._version.pre))
# Post-release
if self._version.post is not None:
parts.append(".post{0}".format(self._version.post[1]))
# Development release
if self._version.dev is not None:
parts.append(".dev{0}".format(self._version.dev[1]))
# Local version segment
if self._version.local is not None:
parts.append(
"+{0}".format(".".join(str(x) for x in self._version.local))
)
return "".join(parts)
@property
def public(self):
return str(self).split("+", 1)[0]
@property
def base_version(self):
parts = []
# Epoch
if self._version.epoch != 0:
parts.append("{0}!".format(self._version.epoch))
# Release segment
parts.append(".".join(str(x) for x in self._version.release))
return "".join(parts)
@property
def local(self):
version_string = str(self)
if "+" in version_string:
return version_string.split("+", 1)[1]
@property
def is_prerelease(self):
return bool(self._version.dev or self._version.pre)
@property
def is_postrelease(self):
return bool(self._version.post)
def _parse_letter_version(letter, number):
if letter:
# We consider there to be an implicit 0 in a pre-release if there is
# not a numeral associated with it.
if number is None:
number = 0
# We normalize any letters to their lower case form
letter = letter.lower()
# We consider some words to be alternate spellings of other words and
# in those cases we want to normalize the spellings to our preferred
# spelling.
if letter == "alpha":
letter = "a"
elif letter == "beta":
letter = "b"
elif letter in ["c", "pre", "preview"]:
letter = "rc"
elif letter in ["rev", "r"]:
letter = "post"
return letter, int(number)
if not letter and number:
# We assume if we are given a number, but we are not given a letter
# then this is using the implicit post release syntax (e.g. 1.0-1)
letter = "post"
return letter, int(number)
_local_version_seperators = re.compile(r"[\._-]")
def _parse_local_version(local):
"""
Takes a string like abc.1.twelve and turns it into ("abc", 1, "twelve").
"""
if local is not None:
return tuple(
part.lower() if not part.isdigit() else int(part)
for part in _local_version_seperators.split(local)
)
def _cmpkey(epoch, release, pre, post, dev, local):
# When we compare a release version, we want to compare it with all of the
# trailing zeros removed. So we'll use a reverse the list, drop all the now
# leading zeros until we come to something non zero, then take the rest
# re-reverse it back into the correct order and make it a tuple and use
# that for our sorting key.
release = tuple(
reversed(list(
itertools.dropwhile(
lambda x: x == 0,
reversed(release),
)
))
)
# We need to "trick" the sorting algorithm to put 1.0.dev0 before 1.0a0.
# We'll do this by abusing the pre segment, but we _only_ want to do this
# if there is not a pre or a post segment. If we have one of those then
# the normal sorting rules will handle this case correctly.
if pre is None and post is None and dev is not None:
pre = -Infinity
# Versions without a pre-release (except as noted above) should sort after
# those with one.
elif pre is None:
pre = Infinity
# Versions without a post segment should sort before those with one.
if post is None:
post = -Infinity
# Versions without a development segment should sort after those with one.
if dev is None:
dev = Infinity
if local is None:
# Versions without a local segment should sort before those with one.
local = -Infinity
else:
# Versions with a local segment need that segment parsed to implement
# the sorting rules in PEP440.
# - Alpha numeric segments sort before numeric segments
# - Alpha numeric segments sort lexicographically
# - Numeric segments sort numerically
# - Shorter versions sort before longer versions when the prefixes
# match exactly
local = tuple(
(i, "") if isinstance(i, int) else (-Infinity, i)
for i in local
)
return epoch, release, pre, post, dev, local
|
gpl-3.0
|
[
3,
1898,
6927,
7529,
27075,
1933,
3043,
84,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
199,
646,
5055,
199,
646,
7975,
199,
646,
295,
199,
199,
504,
13653,
13547,
492,
1010,
9693,
421,
199,
363,
452,
363,
275,
359,
272,
298,
1122,
401,
298,
3353,
401,
298,
22628,
3353,
401,
298,
3364,
3353,
401,
298,
4612,
63,
10764,
2,
199,
61,
421,
199,
63,
3353,
275,
5055,
14,
18921,
8,
272,
2668,
3353,
401,
272,
2097,
7367,
401,
298,
3221,
401,
298,
2374,
401,
298,
657,
401,
298,
1932,
401,
298,
1832,
2255,
199,
9,
421,
199,
318,
2198,
8,
1023,
304,
272,
408,
272,
6077,
314,
1627,
1015,
1059,
436,
372,
1902,
282,
520,
533,
1705,
3353,
64,
909,
272,
503,
282,
520,
533,
1705,
22628,
3353,
64,
909,
10298,
641,
340,
314,
1627,
1015,
365,
272,
282,
1686,
13663,
841,
2167,
1015,
503,
282,
12139,
1015,
14,
272,
408,
272,
862,
26,
267,
372,
3394,
8,
1023,
9,
272,
871,
6378,
3353,
26,
267,
372,
26251,
3353,
8,
1023,
9,
421,
199,
533,
6378,
3353,
8,
3393,
304,
272,
408,
272,
1626,
3866,
1015,
1990,
1911,
12,
4390,
1077,
10618,
370,
13663,
841,
2167,
14,
272,
408,
421,
199,
533,
485,
1563,
3353,
8,
785,
304,
339,
347,
636,
2227,
721,
277,
304,
267,
372,
2631,
8,
277,
423,
498,
9,
339,
347,
636,
4116,
721,
277,
12,
1163,
304,
267,
372,
291,
423,
5785,
8,
1848,
12,
2400,
308,
12,
312,
26,
308,
665,
312,
9,
339,
347,
636,
274,
721,
277,
12,
1163,
304,
267,
372,
291,
423,
5785,
8,
1848,
12,
2400,
308,
12,
312,
26,
308,
2695,
312,
9,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
372,
291,
423,
5785,
8,
1848,
12,
2400,
308,
12,
312,
26,
308,
508,
312,
9,
339,
347,
636,
303,
721,
277,
12,
1163,
304,
267,
372,
291,
423,
5785,
8,
1848,
12,
2400,
308,
12,
312,
26,
308,
2356,
312,
9,
339,
347,
636,
3308,
721,
277,
12,
1163,
304,
267,
372,
291,
423,
5785,
8,
1848,
12,
2400,
308,
12,
312,
26,
308,
690,
312,
9,
339,
347,
636,
685,
721,
277,
12,
1163,
304,
267,
372,
291,
423,
5785,
8,
1848,
12,
2400,
308,
12,
312,
26,
308,
1137,
312,
9,
339,
347,
485,
5785,
8,
277,
12,
1163,
12,
1083,
304,
267,
340,
440,
1228,
8,
1848,
12,
485,
1563,
3353,
304,
288,
372,
3784,
398,
372,
1083,
8,
277,
423,
498,
12,
1163,
423,
498,
9,
421,
199,
533,
26251,
3353,
1547,
1563,
3353,
304,
339,
347,
636,
826,
721,
277,
12,
1015,
304,
267,
291,
423,
1023,
275,
620,
8,
1023,
9,
267,
291,
423,
498,
275,
485,
10000,
63,
5730,
498,
8,
277,
423,
1023,
9,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
423,
1023,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
3886,
22628,
3353,
2561,
16,
1552,
23167,
908,
8,
2722,
8,
495,
8,
277,
1724,
339,
768,
1829,
272,
347,
4575,
8,
277,
304,
267,
372,
291,
423,
1023,
339,
768,
1829,
272,
347,
1300,
63,
1023,
8,
277,
304,
267,
372,
291,
423,
1023,
339,
768,
1829,
272,
347,
2257,
8,
277,
304,
267,
372,
488,
339,
768,
1829,
272,
347,
365,
63,
657,
3221,
8,
277,
304,
267,
372,
756,
339,
768,
1829,
272,
347,
365,
63,
1932,
3221,
8,
277,
304,
267,
372,
756,
421,
199,
63,
10000,
63,
1023,
63,
3173,
63,
264,
275,
295,
14,
2014,
8,
272,
519,
2,
2961,
68,
11,
1204,
359,
65,
13,
90,
2807,
1204,
971,
14,
92,
446,
4186,
295,
14,
16075,
12,
199,
9,
199,
199,
63,
10000,
63,
1023,
63,
15895,
63,
1130,
275,
469,
272,
298,
657,
582,
298,
67,
401,
298,
7780,
582,
298,
67,
401,
30312,
298,
5094,
13,
401,
298,
1195,
582,
298,
67,
401,
298,
2374,
582,
9244,
401,
199,
93,
421,
199,
318,
485,
1122,
63,
1023,
63,
4181,
8,
83,
304,
272,
367,
1777,
315,
485,
10000,
63,
1023,
63,
3173,
63,
264,
14,
1294,
8,
83,
304,
267,
1777,
275,
485,
10000,
63,
1023,
63,
15895,
63,
1130,
14,
362,
8,
2064,
12,
1777,
9,
398,
340,
440,
1777,
503,
1777,
508,
3680,
582,
288,
1980,
398,
340,
1777,
1491,
17,
61,
315,
298,
11371,
582,
288,
327,
6567,
367,
8950,
9132,
288,
1995,
1777,
14,
26626,
8,
24,
9,
267,
587,
26,
288,
1995,
22423,
435,
1777,
339,
327,
4868,
626,
5131,
15,
5683,
15,
9007,
787,
2544,
4242,
272,
1995,
8969,
5094,
2,
421,
199,
318,
485,
10000,
63,
5730,
498,
8,
1023,
304,
272,
327,
2136,
7508,
600,
376,
9463,
402,
446,
17,
2348,
14,
437,
13663,
841,
2167,
1015,
883,
1454,
1172,
282,
9463,
272,
327,
8932,
2419,
503,
4472,
370,
378,
14,
961,
911,
27881,
5324,
314,
26251,
3353,
12,
272,
327,
1314,
4440,
314,
347,
2442,
79,
4465,
20657,
6366,
701,
9116,
12,
272,
327,
465,
2544,
1006,
13663,
841,
2167,
5459,
14,
272,
9463,
275,
446,
17,
339,
327,
961,
5687,
365,
9394,
687,
5496,
63,
4435,
14,
1122,
63,
1023,
9116,
6791,
370,
272,
327,
652,
1159,
1503,
1422,
402,
314,
27369,
3555,
14,
272,
4184,
275,
942,
272,
367,
1777,
315,
485,
1122,
63,
1023,
63,
4181,
8,
1023,
14,
2325,
5109,
267,
340,
1777,
14
] |
[
1898,
6927,
7529,
27075,
1933,
3043,
84,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
199,
646,
5055,
199,
646,
7975,
199,
646,
295,
199,
199,
504,
13653,
13547,
492,
1010,
9693,
421,
199,
363,
452,
363,
275,
359,
272,
298,
1122,
401,
298,
3353,
401,
298,
22628,
3353,
401,
298,
3364,
3353,
401,
298,
4612,
63,
10764,
2,
199,
61,
421,
199,
63,
3353,
275,
5055,
14,
18921,
8,
272,
2668,
3353,
401,
272,
2097,
7367,
401,
298,
3221,
401,
298,
2374,
401,
298,
657,
401,
298,
1932,
401,
298,
1832,
2255,
199,
9,
421,
199,
318,
2198,
8,
1023,
304,
272,
408,
272,
6077,
314,
1627,
1015,
1059,
436,
372,
1902,
282,
520,
533,
1705,
3353,
64,
909,
272,
503,
282,
520,
533,
1705,
22628,
3353,
64,
909,
10298,
641,
340,
314,
1627,
1015,
365,
272,
282,
1686,
13663,
841,
2167,
1015,
503,
282,
12139,
1015,
14,
272,
408,
272,
862,
26,
267,
372,
3394,
8,
1023,
9,
272,
871,
6378,
3353,
26,
267,
372,
26251,
3353,
8,
1023,
9,
421,
199,
533,
6378,
3353,
8,
3393,
304,
272,
408,
272,
1626,
3866,
1015,
1990,
1911,
12,
4390,
1077,
10618,
370,
13663,
841,
2167,
14,
272,
408,
421,
199,
533,
485,
1563,
3353,
8,
785,
304,
339,
347,
636,
2227,
721,
277,
304,
267,
372,
2631,
8,
277,
423,
498,
9,
339,
347,
636,
4116,
721,
277,
12,
1163,
304,
267,
372,
291,
423,
5785,
8,
1848,
12,
2400,
308,
12,
312,
26,
308,
665,
312,
9,
339,
347,
636,
274,
721,
277,
12,
1163,
304,
267,
372,
291,
423,
5785,
8,
1848,
12,
2400,
308,
12,
312,
26,
308,
2695,
312,
9,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
372,
291,
423,
5785,
8,
1848,
12,
2400,
308,
12,
312,
26,
308,
508,
312,
9,
339,
347,
636,
303,
721,
277,
12,
1163,
304,
267,
372,
291,
423,
5785,
8,
1848,
12,
2400,
308,
12,
312,
26,
308,
2356,
312,
9,
339,
347,
636,
3308,
721,
277,
12,
1163,
304,
267,
372,
291,
423,
5785,
8,
1848,
12,
2400,
308,
12,
312,
26,
308,
690,
312,
9,
339,
347,
636,
685,
721,
277,
12,
1163,
304,
267,
372,
291,
423,
5785,
8,
1848,
12,
2400,
308,
12,
312,
26,
308,
1137,
312,
9,
339,
347,
485,
5785,
8,
277,
12,
1163,
12,
1083,
304,
267,
340,
440,
1228,
8,
1848,
12,
485,
1563,
3353,
304,
288,
372,
3784,
398,
372,
1083,
8,
277,
423,
498,
12,
1163,
423,
498,
9,
421,
199,
533,
26251,
3353,
1547,
1563,
3353,
304,
339,
347,
636,
826,
721,
277,
12,
1015,
304,
267,
291,
423,
1023,
275,
620,
8,
1023,
9,
267,
291,
423,
498,
275,
485,
10000,
63,
5730,
498,
8,
277,
423,
1023,
9,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
423,
1023,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
3886,
22628,
3353,
2561,
16,
1552,
23167,
908,
8,
2722,
8,
495,
8,
277,
1724,
339,
768,
1829,
272,
347,
4575,
8,
277,
304,
267,
372,
291,
423,
1023,
339,
768,
1829,
272,
347,
1300,
63,
1023,
8,
277,
304,
267,
372,
291,
423,
1023,
339,
768,
1829,
272,
347,
2257,
8,
277,
304,
267,
372,
488,
339,
768,
1829,
272,
347,
365,
63,
657,
3221,
8,
277,
304,
267,
372,
756,
339,
768,
1829,
272,
347,
365,
63,
1932,
3221,
8,
277,
304,
267,
372,
756,
421,
199,
63,
10000,
63,
1023,
63,
3173,
63,
264,
275,
295,
14,
2014,
8,
272,
519,
2,
2961,
68,
11,
1204,
359,
65,
13,
90,
2807,
1204,
971,
14,
92,
446,
4186,
295,
14,
16075,
12,
199,
9,
199,
199,
63,
10000,
63,
1023,
63,
15895,
63,
1130,
275,
469,
272,
298,
657,
582,
298,
67,
401,
298,
7780,
582,
298,
67,
401,
30312,
298,
5094,
13,
401,
298,
1195,
582,
298,
67,
401,
298,
2374,
582,
9244,
401,
199,
93,
421,
199,
318,
485,
1122,
63,
1023,
63,
4181,
8,
83,
304,
272,
367,
1777,
315,
485,
10000,
63,
1023,
63,
3173,
63,
264,
14,
1294,
8,
83,
304,
267,
1777,
275,
485,
10000,
63,
1023,
63,
15895,
63,
1130,
14,
362,
8,
2064,
12,
1777,
9,
398,
340,
440,
1777,
503,
1777,
508,
3680,
582,
288,
1980,
398,
340,
1777,
1491,
17,
61,
315,
298,
11371,
582,
288,
327,
6567,
367,
8950,
9132,
288,
1995,
1777,
14,
26626,
8,
24,
9,
267,
587,
26,
288,
1995,
22423,
435,
1777,
339,
327,
4868,
626,
5131,
15,
5683,
15,
9007,
787,
2544,
4242,
272,
1995,
8969,
5094,
2,
421,
199,
318,
485,
10000,
63,
5730,
498,
8,
1023,
304,
272,
327,
2136,
7508,
600,
376,
9463,
402,
446,
17,
2348,
14,
437,
13663,
841,
2167,
1015,
883,
1454,
1172,
282,
9463,
272,
327,
8932,
2419,
503,
4472,
370,
378,
14,
961,
911,
27881,
5324,
314,
26251,
3353,
12,
272,
327,
1314,
4440,
314,
347,
2442,
79,
4465,
20657,
6366,
701,
9116,
12,
272,
327,
465,
2544,
1006,
13663,
841,
2167,
5459,
14,
272,
9463,
275,
446,
17,
339,
327,
961,
5687,
365,
9394,
687,
5496,
63,
4435,
14,
1122,
63,
1023,
9116,
6791,
370,
272,
327,
652,
1159,
1503,
1422,
402,
314,
27369,
3555,
14,
272,
4184,
275,
942,
272,
367,
1777,
315,
485,
1122,
63,
1023,
63,
4181,
8,
1023,
14,
2325,
5109,
267,
340,
1777,
14,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
agry/NGECore2
|
scripts/mobiles/instances/tuskenking/tusken/tusken_raider.py
|
2
|
1552
|
import sys
from services.spawn import MobileTemplate
from services.spawn import WeaponTemplate
from resources.datatables import WeaponType
from resources.datatables import Difficulty
from resources.datatables import Options
from java.util import Vector
def addTemplate(core):
mobileTemplate = MobileTemplate()
mobileTemplate.setCreatureName('heroic_tusken_raider')
mobileTemplate.setLevel(90)
mobileTemplate.setDifficulty(Difficulty.NORMAL)
mobileTemplate.setMinSpawnDistance(4)
mobileTemplate.setMaxSpawnDistance(8)
mobileTemplate.setDeathblow(True)
mobileTemplate.setScale(1)
mobileTemplate.setSocialGroup("heroic tusken")
mobileTemplate.setAssistRange(12)
mobileTemplate.setStalker(True)
mobileTemplate.setOptionsBitmask(Options.AGGRESSIVE | Options.ATTACKABLE)
templates = Vector()
templates.add('object/mobile/shared_tusken_raider.iff')
mobileTemplate.setTemplates(templates)
weaponTemplates = Vector()
weapontemplate = WeaponTemplate('object/weapon/ranged/rifle/shared_rifle_tusken.iff', WeaponType.RIFLE, 1.0, 24, 'kinetic')
weapontemplate1 = WeaponTemplate('object/weapon/melee/baton/shared_baton_gaderiffi_elite.iff', WeaponType.ONEHANDEDMELEE, 1.0, 5, 'kinetic')
weaponTemplates.add(weapontemplate)
weaponTemplates.add(weapontemplate1)
mobileTemplate.setWeaponTemplateVector(weaponTemplates)
attacks = Vector()
mobileTemplate.setDefaultAttack('rangedShotrifle')
attacks.add('meleeHit')
mobileTemplate.setAttacks(attacks)
core.spawnService.addMobileTemplate('heroic_tusken_raider', mobileTemplate)
return
|
lgpl-3.0
|
[
646,
984,
199,
504,
8500,
14,
10212,
492,
29724,
4231,
199,
504,
8500,
14,
10212,
492,
2136,
21921,
4231,
199,
504,
5944,
14,
4616,
292,
5921,
492,
2136,
21921,
804,
199,
504,
5944,
14,
4616,
292,
5921,
492,
577,
692,
24161,
199,
504,
5944,
14,
4616,
292,
5921,
492,
8394,
199,
504,
12120,
14,
1974,
492,
11388,
421,
199,
318,
1050,
4231,
8,
1018,
304,
199,
198,
27339,
275,
29724,
4231,
342,
8299,
198,
27339,
14,
409,
5482,
1463,
985,
360,
31863,
530,
63,
84,
527,
917,
63,
345,
73,
424,
358,
199,
198,
27339,
14,
13548,
8,
2710,
9,
199,
198,
27339,
14,
409,
36,
692,
24161,
8,
36,
692,
24161,
14,
10765,
9,
421,
198,
27339,
14,
409,
4649,
12739,
3501,
10076,
8,
20,
9,
199,
198,
27339,
14,
409,
4261,
12739,
3501,
10076,
8,
24,
9,
199,
198,
27339,
14,
409,
31577,
66,
674,
8,
549,
9,
199,
198,
27339,
14,
409,
9944,
8,
17,
9,
199,
198,
27339,
14,
409,
31356,
2448,
480,
31863,
530,
307,
527,
917,
531,
199,
198,
27339,
14,
409,
2822,
11734,
4709,
8,
713,
9,
199,
198,
27339,
14,
409,
933,
14976,
8,
549,
9,
199,
198,
27339,
14,
409,
4558,
4734,
2629,
8,
4558,
14,
1254,
19568,
5399,
1204,
8394,
14,
11712,
3099,
2617,
9,
8299,
198,
5876,
275,
11388,
342,
199,
198,
5876,
14,
525,
360,
785,
15,
11375,
15,
5555,
63,
84,
527,
917,
63,
345,
73,
424,
14,
15126,
358,
199,
198,
27339,
14,
409,
17969,
8,
5876,
9,
8299,
198,
30804,
17969,
275,
11388,
342,
199,
198,
30804,
1160,
275,
2136,
21921,
4231,
360,
785,
15,
30804,
15,
1842,
68,
15,
20546,
274,
15,
5555,
63,
20546,
274,
63,
84,
527,
917,
14,
15126,
297,
2136,
21921,
804,
14,
50,
4656,
906,
12,
413,
14,
16,
12,
5504,
12,
283,
75,
1132,
764,
358,
199,
198,
30804,
1160,
17,
275,
2136,
21921,
4231,
360,
785,
15,
30804,
15,
278,
18387,
15,
13475,
265,
15,
5555,
63,
13475,
265,
63,
5294,
9910,
11286,
63,
69,
5333,
14,
15126,
297,
2136,
21921,
804,
14,
4817,
40,
879,
8280,
3635,
906,
37,
12,
413,
14,
16,
12,
959,
12,
283,
75,
1132,
764,
358,
199,
198,
30804,
17969,
14,
525,
8,
30804,
1160,
9,
199,
198,
30804,
17969,
14,
525,
8,
30804,
1160,
17,
9,
199,
198,
27339,
14,
409,
6004,
21921,
4231,
3646,
8,
30804,
17969,
9,
421,
198,
292,
21807,
275,
11388,
342,
199,
198,
27339,
14,
409,
2698,
1271,
13058,
360,
1842,
68,
2662,
357,
20546,
274,
358,
199,
198,
292,
21807,
14,
525,
360,
278,
18387,
26852,
358,
199,
198,
27339,
14,
409,
1271,
21807,
8,
292,
21807,
9,
8299,
198,
1018,
14,
10212,
3167,
14,
525,
27245,
4231,
360,
31863,
530,
63,
84,
527,
917,
63,
345,
73,
424,
297,
21305,
4231,
9,
199,
198,
1107,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
984,
199,
504,
8500,
14,
10212,
492,
29724,
4231,
199,
504,
8500,
14,
10212,
492,
2136,
21921,
4231,
199,
504,
5944,
14,
4616,
292,
5921,
492,
2136,
21921,
804,
199,
504,
5944,
14,
4616,
292,
5921,
492,
577,
692,
24161,
199,
504,
5944,
14,
4616,
292,
5921,
492,
8394,
199,
504,
12120,
14,
1974,
492,
11388,
421,
199,
318,
1050,
4231,
8,
1018,
304,
199,
198,
27339,
275,
29724,
4231,
342,
8299,
198,
27339,
14,
409,
5482,
1463,
985,
360,
31863,
530,
63,
84,
527,
917,
63,
345,
73,
424,
358,
199,
198,
27339,
14,
13548,
8,
2710,
9,
199,
198,
27339,
14,
409,
36,
692,
24161,
8,
36,
692,
24161,
14,
10765,
9,
421,
198,
27339,
14,
409,
4649,
12739,
3501,
10076,
8,
20,
9,
199,
198,
27339,
14,
409,
4261,
12739,
3501,
10076,
8,
24,
9,
199,
198,
27339,
14,
409,
31577,
66,
674,
8,
549,
9,
199,
198,
27339,
14,
409,
9944,
8,
17,
9,
199,
198,
27339,
14,
409,
31356,
2448,
480,
31863,
530,
307,
527,
917,
531,
199,
198,
27339,
14,
409,
2822,
11734,
4709,
8,
713,
9,
199,
198,
27339,
14,
409,
933,
14976,
8,
549,
9,
199,
198,
27339,
14,
409,
4558,
4734,
2629,
8,
4558,
14,
1254,
19568,
5399,
1204,
8394,
14,
11712,
3099,
2617,
9,
8299,
198,
5876,
275,
11388,
342,
199,
198,
5876,
14,
525,
360,
785,
15,
11375,
15,
5555,
63,
84,
527,
917,
63,
345,
73,
424,
14,
15126,
358,
199,
198,
27339,
14,
409,
17969,
8,
5876,
9,
8299,
198,
30804,
17969,
275,
11388,
342,
199,
198,
30804,
1160,
275,
2136,
21921,
4231,
360,
785,
15,
30804,
15,
1842,
68,
15,
20546,
274,
15,
5555,
63,
20546,
274,
63,
84,
527,
917,
14,
15126,
297,
2136,
21921,
804,
14,
50,
4656,
906,
12,
413,
14,
16,
12,
5504,
12,
283,
75,
1132,
764,
358,
199,
198,
30804,
1160,
17,
275,
2136,
21921,
4231,
360,
785,
15,
30804,
15,
278,
18387,
15,
13475,
265,
15,
5555,
63,
13475,
265,
63,
5294,
9910,
11286,
63,
69,
5333,
14,
15126,
297,
2136,
21921,
804,
14,
4817,
40,
879,
8280,
3635,
906,
37,
12,
413,
14,
16,
12,
959,
12,
283,
75,
1132,
764,
358,
199,
198,
30804,
17969,
14,
525,
8,
30804,
1160,
9,
199,
198,
30804,
17969,
14,
525,
8,
30804,
1160,
17,
9,
199,
198,
27339,
14,
409,
6004,
21921,
4231,
3646,
8,
30804,
17969,
9,
421,
198,
292,
21807,
275,
11388,
342,
199,
198,
27339,
14,
409,
2698,
1271,
13058,
360,
1842,
68,
2662,
357,
20546,
274,
358,
199,
198,
292,
21807,
14,
525,
360,
278,
18387,
26852,
358,
199,
198,
27339,
14,
409,
1271,
21807,
8,
292,
21807,
9,
8299,
198,
1018,
14,
10212,
3167,
14,
525,
27245,
4231,
360,
31863,
530,
63,
84,
527,
917,
63,
345,
73,
424,
297,
21305,
4231,
9,
199,
198,
1107,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
jakirkham/bokeh
|
bokeh/command/subcommands/html.py
|
3
|
4243
|
#-----------------------------------------------------------------------------
# Copyright (c) 2012 - 2018, Anaconda, Inc. All rights reserved.
#
# Powered by the Bokeh Development Team.
#
# The full license is in the file LICENSE.txt, distributed with this software.
#-----------------------------------------------------------------------------
'''
To generate a standalone HTML page for a Bokeh application from a single
Python script, pass the script name to ``bokeh html`` on the command
line:
.. code-block:: sh
bokeh html app_script.py
The generated HTML will be saved in the current working directory with
the name ``app_script.html``.
It is also possible to run the same commmand with jupyter notebooks:
.. code-block:: sh
bokeh html app_notebook.ipynb
This will generate an HTML file named ``app_notebook.html`` just like
with a python script.
Applications can also be created from directories. The directory should
contain a ``main.py`` (and any other helper modules that are required) as
well as any additional assets (e.g., theme files). Pass the directory name
to ``bokeh html`` to generate the HTML:
.. code-block:: sh
bokeh html app_dir
It is possible to generate HTML pages for multiple applications at once:
.. code-block:: sh
bokeh html app_script.py app_dir
If you would like to automatically open a browser to display the HTML
page(s), you can pass the ``--show`` option on the command line:
.. code-block:: sh
bokeh html app_script.py app_dir --show
This will open two pages, for ``app_script.html`` and ``app_dir.html``,
respectively.
.. warning::
Applications that use ``on_change`` callbacks require using the Bokeh
server to execute the callback code.
'''
#-----------------------------------------------------------------------------
# Boilerplate
#-----------------------------------------------------------------------------
from __future__ import absolute_import, division, print_function, unicode_literals
import logging
log = logging.getLogger(__name__)
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
# Standard library imports
# External imports
# Bokeh imports
from bokeh.resources import Resources
from bokeh.embed import file_html
from .file_output import FileOutputSubcommand
#-----------------------------------------------------------------------------
# Globals and constants
#-----------------------------------------------------------------------------
__all__ = (
'HTML',
)
#-----------------------------------------------------------------------------
# General API
#-----------------------------------------------------------------------------
class HTML(FileOutputSubcommand):
''' Subcommand to output applications as standalone HTML files.
'''
#: name for this subcommand
name = "html"
#: file extension for output generated by this :class:`~bokeh.command.subcommands.file_output.FileOutputSubcommand`
extension = "html"
help = "Create standalone HTML files for one or more applications"
args = (
FileOutputSubcommand.files_arg("HTML"),
(
'--show', dict(
action='store_true',
help="Open generated file(s) in a browser"
)),
) + FileOutputSubcommand.other_args()
def after_write_file(self, args, filename, doc):
'''
'''
if args.show:
from bokeh.util.browser import view
view(filename)
def file_contents(self, args, doc):
'''
'''
resources = Resources(mode="cdn", root_dir=None)
return file_html(doc, resources)
#-----------------------------------------------------------------------------
# Dev API
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Private API
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Code
#-----------------------------------------------------------------------------
|
bsd-3-clause
|
[
18045,
199,
3,
1898,
334,
67,
9,
6029,
446,
14894,
12,
1626,
16928,
983,
12,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
510,
583,
16179,
701,
314,
5088,
16610,
15290,
11682,
14,
199,
3,
199,
3,
710,
2615,
4190,
365,
315,
314,
570,
5113,
14,
2424,
12,
1854,
543,
642,
2032,
14,
199,
18045,
199,
2344,
199,
1378,
3550,
282,
18042,
4163,
2034,
367,
282,
5088,
16610,
4223,
687,
282,
2849,
199,
4718,
2884,
12,
986,
314,
2884,
536,
370,
1124,
656,
16610,
3517,
1040,
641,
314,
1414,
199,
604,
26,
199,
199,
703,
1233,
13,
1457,
447,
1033,
339,
25214,
3517,
1145,
63,
1579,
14,
647,
199,
199,
1918,
4046,
4163,
911,
506,
6290,
315,
314,
1453,
6449,
2082,
543,
199,
1589,
536,
1124,
571,
63,
1579,
14,
1360,
4345,
199,
199,
7940,
365,
2597,
3962,
370,
1255,
314,
2011,
1923,
10333,
543,
1335,
28022,
351,
5317,
8858,
26,
199,
199,
703,
1233,
13,
1457,
447,
1033,
339,
25214,
3517,
1145,
63,
19174,
14,
73,
647,
4994,
199,
199,
2765,
911,
3550,
376,
4163,
570,
4310,
1124,
571,
63,
19174,
14,
1360,
1040,
2951,
2839,
199,
1045,
282,
2366,
2884,
14,
199,
199,
31907,
883,
2597,
506,
2737,
687,
6602,
14,
710,
2082,
1077,
199,
7747,
282,
1124,
973,
14,
647,
1040,
334,
460,
1263,
1163,
5922,
4621,
626,
787,
1415,
9,
465,
199,
20501,
465,
1263,
4722,
17202,
334,
69,
14,
71,
2020,
8879,
1584,
680,
8325,
314,
2082,
536,
199,
475,
1124,
656,
16610,
3517,
1040,
370,
3550,
314,
4163,
26,
199,
199,
703,
1233,
13,
1457,
447,
1033,
339,
25214,
3517,
1145,
63,
694,
199,
199,
7940,
365,
3962,
370,
3550,
4163,
6497,
367,
3663,
13103,
737,
5403,
26,
199,
199,
703,
1233,
13,
1457,
447,
1033,
339,
25214,
3517,
1145,
63,
1579,
14,
647,
1145,
63,
694,
199,
199,
3917,
1265,
3955,
2839,
370,
5847,
1551,
282,
7042,
370,
2929,
314,
4163,
199,
1606,
8,
83,
395,
1265,
883,
986,
314,
1124,
306,
2384,
1040,
945,
641,
314,
1414,
1004,
26,
199,
199,
703,
1233,
13,
1457,
447,
1033,
339,
25214,
3517,
1145,
63,
1579,
14,
647,
1145,
63,
694,
1553,
2384,
199,
199,
2765,
911,
1551,
2877,
6497,
12,
367,
1124,
571,
63,
1579,
14,
1360,
1040,
436,
1124,
571,
63,
694,
14,
1360,
4542,
199,
470,
733,
9462,
14,
199,
199,
703,
5721,
447,
272,
24636,
626,
675,
1124,
265,
63,
1461,
1040,
13484,
4409,
1808,
314,
5088,
16610,
272,
1654,
370,
5341,
314,
3233,
1233,
14,
199,
199,
2344,
199,
199,
18045,
199,
3,
5088,
27025,
199,
18045,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
12,
2649,
63,
5955,
199,
199,
646,
2050,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
18045,
199,
3,
24339,
199,
18045,
199,
199,
3,
9739,
3555,
8925,
199,
199,
3,
18802,
8925,
199,
199,
3,
5088,
16610,
8925,
199,
504,
25214,
14,
4435,
492,
26250,
199,
504,
25214,
14,
6427,
492,
570,
63,
1360,
199,
199,
504,
1275,
493,
63,
1199,
492,
3814,
2959,
2610,
1531,
199,
199,
18045,
199,
3,
13641,
83,
436,
5262,
199,
18045,
199,
199,
363,
452,
363,
275,
334,
272,
283,
4943,
297,
199,
9,
199,
199,
18045,
199,
3,
1696,
3261,
199,
18045,
199,
199,
533,
4163,
8,
1173,
2959,
2610,
1531,
304,
272,
1449,
4804,
1531,
370,
1072,
13103,
465,
18042,
4163,
1584,
14,
339,
1449,
339,
6079,
536,
367,
642,
21474,
272,
536,
275,
298,
1360,
2,
339,
6079,
570,
3329,
367,
1072,
4046,
701,
642,
520,
533,
6054,
656,
16610,
14,
1531,
14,
954,
4405,
14,
493,
63,
1199,
14,
1173,
2959,
2610,
1531,
64,
272,
3329,
275,
298,
1360,
2,
339,
1720,
275,
298,
2499,
18042,
4163,
1584,
367,
1373,
503,
1655,
13103,
2,
339,
1249,
275,
334,
398,
3814,
2959,
2610,
1531,
14,
1725,
63,
1273,
480,
4943,
1288,
398,
334,
288,
2850,
2384,
297,
1211,
8,
288,
1595,
534,
1617,
63,
2052,
297,
288,
1720,
628,
4299,
4046,
570,
8,
83,
9,
315,
282,
7042,
2,
267,
22583,
339,
776,
435,
3814,
2959,
2610,
1531,
14,
1848,
63,
589,
342,
339,
347,
2410,
63,
952,
63,
493,
8,
277,
12,
1249,
12,
1788,
12,
1382,
304,
267,
1449,
398,
1449,
267,
340,
1249,
14,
2384,
26,
288,
687,
25214,
14,
1974,
14,
5750,
492,
2455,
288,
2455,
8,
1501,
9,
339,
347,
570,
63,
4407,
8,
277,
12,
1249,
12,
1382,
304,
267,
1449,
398,
1449,
267,
5944,
275,
26250,
8,
632,
628,
23982,
401,
1738,
63,
694,
29,
403,
9,
267,
372,
570,
63,
1360,
8,
1301,
12,
5944,
9,
199,
199,
18045,
199,
3,
29314,
3261,
199,
18045,
199,
199,
18045,
199,
3,
18551,
3261,
199,
18045,
199,
199,
18045,
199,
3,
5495,
199,
18045,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
3,
1898,
334,
67,
9,
6029,
446,
14894,
12,
1626,
16928,
983,
12,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
510,
583,
16179,
701,
314,
5088,
16610,
15290,
11682,
14,
199,
3,
199,
3,
710,
2615,
4190,
365,
315,
314,
570,
5113,
14,
2424,
12,
1854,
543,
642,
2032,
14,
199,
18045,
199,
2344,
199,
1378,
3550,
282,
18042,
4163,
2034,
367,
282,
5088,
16610,
4223,
687,
282,
2849,
199,
4718,
2884,
12,
986,
314,
2884,
536,
370,
1124,
656,
16610,
3517,
1040,
641,
314,
1414,
199,
604,
26,
199,
199,
703,
1233,
13,
1457,
447,
1033,
339,
25214,
3517,
1145,
63,
1579,
14,
647,
199,
199,
1918,
4046,
4163,
911,
506,
6290,
315,
314,
1453,
6449,
2082,
543,
199,
1589,
536,
1124,
571,
63,
1579,
14,
1360,
4345,
199,
199,
7940,
365,
2597,
3962,
370,
1255,
314,
2011,
1923,
10333,
543,
1335,
28022,
351,
5317,
8858,
26,
199,
199,
703,
1233,
13,
1457,
447,
1033,
339,
25214,
3517,
1145,
63,
19174,
14,
73,
647,
4994,
199,
199,
2765,
911,
3550,
376,
4163,
570,
4310,
1124,
571,
63,
19174,
14,
1360,
1040,
2951,
2839,
199,
1045,
282,
2366,
2884,
14,
199,
199,
31907,
883,
2597,
506,
2737,
687,
6602,
14,
710,
2082,
1077,
199,
7747,
282,
1124,
973,
14,
647,
1040,
334,
460,
1263,
1163,
5922,
4621,
626,
787,
1415,
9,
465,
199,
20501,
465,
1263,
4722,
17202,
334,
69,
14,
71,
2020,
8879,
1584,
680,
8325,
314,
2082,
536,
199,
475,
1124,
656,
16610,
3517,
1040,
370,
3550,
314,
4163,
26,
199,
199,
703,
1233,
13,
1457,
447,
1033,
339,
25214,
3517,
1145,
63,
694,
199,
199,
7940,
365,
3962,
370,
3550,
4163,
6497,
367,
3663,
13103,
737,
5403,
26,
199,
199,
703,
1233,
13,
1457,
447,
1033,
339,
25214,
3517,
1145,
63,
1579,
14,
647,
1145,
63,
694,
199,
199,
3917,
1265,
3955,
2839,
370,
5847,
1551,
282,
7042,
370,
2929,
314,
4163,
199,
1606,
8,
83,
395,
1265,
883,
986,
314,
1124,
306,
2384,
1040,
945,
641,
314,
1414,
1004,
26,
199,
199,
703,
1233,
13,
1457,
447,
1033,
339,
25214,
3517,
1145,
63,
1579,
14,
647,
1145,
63,
694,
1553,
2384,
199,
199,
2765,
911,
1551,
2877,
6497,
12,
367,
1124,
571,
63,
1579,
14,
1360,
1040,
436,
1124,
571,
63,
694,
14,
1360,
4542,
199,
470,
733,
9462,
14,
199,
199,
703,
5721,
447,
272,
24636,
626,
675,
1124,
265,
63,
1461,
1040,
13484,
4409,
1808,
314,
5088,
16610,
272,
1654,
370,
5341,
314,
3233,
1233,
14,
199,
199,
2344,
199,
199,
18045,
199,
3,
5088,
27025,
199,
18045,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
12,
2649,
63,
5955,
199,
199,
646,
2050,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
18045,
199,
3,
24339,
199,
18045,
199,
199,
3,
9739,
3555,
8925,
199,
199,
3,
18802,
8925,
199,
199,
3,
5088,
16610,
8925,
199,
504,
25214,
14,
4435,
492,
26250,
199,
504,
25214,
14,
6427,
492,
570,
63,
1360,
199,
199,
504,
1275,
493,
63,
1199,
492,
3814,
2959,
2610,
1531,
199,
199,
18045,
199,
3,
13641,
83,
436,
5262,
199,
18045,
199,
199,
363,
452,
363,
275,
334,
272,
283,
4943,
297,
199,
9,
199,
199,
18045,
199,
3,
1696,
3261,
199,
18045,
199,
199,
533,
4163,
8,
1173,
2959,
2610,
1531,
304,
272,
1449,
4804,
1531,
370,
1072,
13103,
465,
18042,
4163,
1584,
14,
339,
1449,
339,
6079,
536,
367,
642,
21474,
272,
536,
275,
298,
1360,
2,
339,
6079,
570,
3329,
367,
1072,
4046,
701,
642,
520,
533,
6054,
656,
16610,
14,
1531,
14,
954,
4405,
14,
493,
63,
1199,
14,
1173,
2959,
2610,
1531,
64,
272,
3329,
275,
298,
1360,
2,
339,
1720,
275,
298,
2499,
18042,
4163,
1584,
367,
1373,
503,
1655,
13103,
2,
339,
1249,
275,
334,
398,
3814,
2959,
2610,
1531,
14,
1725,
63,
1273,
480,
4943,
1288,
398,
334,
288,
2850,
2384,
297,
1211,
8,
288,
1595,
534,
1617,
63,
2052,
297,
288,
1720,
628,
4299,
4046,
570,
8,
83,
9,
315,
282,
7042,
2,
267,
22583,
339,
776,
435,
3814,
2959,
2610,
1531,
14,
1848,
63,
589,
342,
339,
347,
2410,
63,
952,
63,
493,
8,
277,
12,
1249,
12,
1788,
12,
1382,
304,
267,
1449,
398,
1449,
267,
340,
1249,
14,
2384,
26,
288,
687,
25214,
14,
1974,
14,
5750,
492,
2455,
288,
2455,
8,
1501,
9,
339,
347,
570,
63,
4407,
8,
277,
12,
1249,
12,
1382,
304,
267,
1449,
398,
1449,
267,
5944,
275,
26250,
8,
632,
628,
23982,
401,
1738,
63,
694,
29,
403,
9,
267,
372,
570,
63,
1360,
8,
1301,
12,
5944,
9,
199,
199,
18045,
199,
3,
29314,
3261,
199,
18045,
199,
199,
18045,
199,
3,
18551,
3261,
199,
18045,
199,
199,
18045,
199,
3,
5495,
199,
18045,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
theo-l/django
|
tests/admin_inlines/models.py
|
10
|
7855
|
"""
Testing of admin inline formsets.
"""
import random
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.db import models
class Parent(models.Model):
name = models.CharField(max_length=50)
def __str__(self):
return self.name
class Teacher(models.Model):
name = models.CharField(max_length=50)
def __str__(self):
return self.name
class Child(models.Model):
name = models.CharField(max_length=50)
teacher = models.ForeignKey(Teacher, models.CASCADE)
content_type = models.ForeignKey(ContentType, models.CASCADE)
object_id = models.PositiveIntegerField()
parent = GenericForeignKey()
def __str__(self):
return 'I am %s, a child of %s' % (self.name, self.parent)
class Book(models.Model):
name = models.CharField(max_length=50)
def __str__(self):
return self.name
class Author(models.Model):
name = models.CharField(max_length=50)
books = models.ManyToManyField(Book)
class NonAutoPKBook(models.Model):
rand_pk = models.IntegerField(primary_key=True, editable=False)
author = models.ForeignKey(Author, models.CASCADE)
title = models.CharField(max_length=50)
def save(self, *args, **kwargs):
while not self.rand_pk:
test_pk = random.randint(1, 99999)
if not NonAutoPKBook.objects.filter(rand_pk=test_pk).exists():
self.rand_pk = test_pk
super().save(*args, **kwargs)
class NonAutoPKBookChild(NonAutoPKBook):
pass
class EditablePKBook(models.Model):
manual_pk = models.IntegerField(primary_key=True)
author = models.ForeignKey(Author, models.CASCADE)
title = models.CharField(max_length=50)
class Holder(models.Model):
dummy = models.IntegerField()
class Inner(models.Model):
dummy = models.IntegerField()
holder = models.ForeignKey(Holder, models.CASCADE)
readonly = models.CharField("Inner readonly label", max_length=1)
def get_absolute_url(self):
return '/inner/'
class Holder2(models.Model):
dummy = models.IntegerField()
class Inner2(models.Model):
dummy = models.IntegerField()
holder = models.ForeignKey(Holder2, models.CASCADE)
class Holder3(models.Model):
dummy = models.IntegerField()
class Inner3(models.Model):
dummy = models.IntegerField()
holder = models.ForeignKey(Holder3, models.CASCADE)
# Models for ticket #8190
class Holder4(models.Model):
dummy = models.IntegerField()
class Inner4Stacked(models.Model):
dummy = models.IntegerField(help_text="Awesome stacked help text is awesome.")
holder = models.ForeignKey(Holder4, models.CASCADE)
class Meta:
constraints = [
models.UniqueConstraint(fields=['dummy', 'holder'], name='unique_stacked_dummy_per_holder')
]
class Inner4Tabular(models.Model):
dummy = models.IntegerField(help_text="Awesome tabular help text is awesome.")
holder = models.ForeignKey(Holder4, models.CASCADE)
class Meta:
constraints = [
models.UniqueConstraint(fields=['dummy', 'holder'], name='unique_tabular_dummy_per_holder')
]
# Models for ticket #31441
class Holder5(models.Model):
dummy = models.IntegerField()
class Inner5Stacked(models.Model):
name = models.CharField(max_length=10)
select = models.CharField(choices=(('1', 'One'), ('2', 'Two')), max_length=10)
text = models.TextField()
dummy = models.IntegerField()
holder = models.ForeignKey(Holder5, models.CASCADE)
class Inner5Tabular(models.Model):
name = models.CharField(max_length=10)
select = models.CharField(choices=(('1', 'One'), ('2', 'Two')), max_length=10)
text = models.TextField()
dummy = models.IntegerField()
holder = models.ForeignKey(Holder5, models.CASCADE)
# Models for #12749
class Person(models.Model):
firstname = models.CharField(max_length=15)
class OutfitItem(models.Model):
name = models.CharField(max_length=15)
class Fashionista(models.Model):
person = models.OneToOneField(Person, models.CASCADE, primary_key=True)
weaknesses = models.ManyToManyField(OutfitItem, through='ShoppingWeakness', blank=True)
class ShoppingWeakness(models.Model):
fashionista = models.ForeignKey(Fashionista, models.CASCADE)
item = models.ForeignKey(OutfitItem, models.CASCADE)
# Models for #13510
class TitleCollection(models.Model):
pass
class Title(models.Model):
collection = models.ForeignKey(TitleCollection, models.SET_NULL, blank=True, null=True)
title1 = models.CharField(max_length=100)
title2 = models.CharField(max_length=100)
# Models for #15424
class Poll(models.Model):
name = models.CharField(max_length=40)
class Question(models.Model):
text = models.CharField(max_length=40)
poll = models.ForeignKey(Poll, models.CASCADE)
class Novel(models.Model):
name = models.CharField(max_length=40)
class NovelReadonlyChapter(Novel):
class Meta:
proxy = True
class Chapter(models.Model):
name = models.CharField(max_length=40)
novel = models.ForeignKey(Novel, models.CASCADE)
class FootNote(models.Model):
"""
Model added for ticket 19838
"""
chapter = models.ForeignKey(Chapter, models.PROTECT)
note = models.CharField(max_length=40)
# Models for #16838
class CapoFamiglia(models.Model):
name = models.CharField(max_length=100)
class Consigliere(models.Model):
name = models.CharField(max_length=100, help_text='Help text for Consigliere')
capo_famiglia = models.ForeignKey(CapoFamiglia, models.CASCADE, related_name='+')
class SottoCapo(models.Model):
name = models.CharField(max_length=100)
capo_famiglia = models.ForeignKey(CapoFamiglia, models.CASCADE, related_name='+')
class ReadOnlyInline(models.Model):
name = models.CharField(max_length=100, help_text='Help text for ReadOnlyInline')
capo_famiglia = models.ForeignKey(CapoFamiglia, models.CASCADE)
# Models for #18433
class ParentModelWithCustomPk(models.Model):
my_own_pk = models.CharField(max_length=100, primary_key=True)
name = models.CharField(max_length=100)
class ChildModel1(models.Model):
my_own_pk = models.CharField(max_length=100, primary_key=True)
name = models.CharField(max_length=100)
parent = models.ForeignKey(ParentModelWithCustomPk, models.CASCADE)
def get_absolute_url(self):
return '/child_model1/'
class ChildModel2(models.Model):
my_own_pk = models.CharField(max_length=100, primary_key=True)
name = models.CharField(max_length=100)
parent = models.ForeignKey(ParentModelWithCustomPk, models.CASCADE)
def get_absolute_url(self):
return '/child_model2/'
# Models for #19425
class BinaryTree(models.Model):
name = models.CharField(max_length=100)
parent = models.ForeignKey('self', models.SET_NULL, null=True, blank=True)
# Models for #19524
class LifeForm(models.Model):
pass
class ExtraTerrestrial(LifeForm):
name = models.CharField(max_length=100)
class Sighting(models.Model):
et = models.ForeignKey(ExtraTerrestrial, models.CASCADE)
place = models.CharField(max_length=100)
# Models for #18263
class SomeParentModel(models.Model):
name = models.CharField(max_length=1)
class SomeChildModel(models.Model):
name = models.CharField(max_length=1)
position = models.PositiveIntegerField()
parent = models.ForeignKey(SomeParentModel, models.CASCADE)
readonly_field = models.CharField(max_length=1)
# Other models
class ProfileCollection(models.Model):
pass
class Profile(models.Model):
collection = models.ForeignKey(ProfileCollection, models.SET_NULL, blank=True, null=True)
first_name = models.CharField(max_length=100)
last_name = models.CharField(max_length=100)
|
bsd-3-clause
|
[
624,
199,
9029,
402,
4628,
8308,
1824,
2193,
14,
199,
624,
199,
646,
2196,
199,
199,
504,
1639,
14,
2828,
14,
10778,
14,
955,
492,
8307,
3190,
199,
504,
1639,
14,
2828,
14,
10778,
14,
992,
492,
14501,
199,
504,
1639,
14,
697,
492,
1709,
421,
199,
533,
16396,
8,
992,
14,
1685,
304,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
9,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
354,
421,
199,
533,
5773,
19728,
8,
992,
14,
1685,
304,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
9,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
354,
421,
199,
533,
12988,
8,
992,
14,
1685,
304,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
9,
272,
1565,
19728,
275,
1709,
14,
3190,
8,
6301,
19728,
12,
1709,
14,
10855,
9,
339,
1564,
63,
466,
275,
1709,
14,
3190,
8,
11282,
12,
1709,
14,
10855,
9,
272,
909,
63,
344,
275,
1709,
14,
8591,
342,
272,
1676,
275,
8307,
3190,
342,
339,
347,
636,
495,
721,
277,
304,
267,
372,
283,
41,
8140,
450,
83,
12,
282,
1982,
402,
450,
83,
7,
450,
334,
277,
14,
354,
12,
291,
14,
1708,
9,
421,
199,
533,
8944,
8,
992,
14,
1685,
304,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
9,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
354,
421,
199,
533,
6529,
8,
992,
14,
1685,
304,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
9,
272,
19040,
275,
1709,
14,
7624,
8,
8696,
9,
421,
199,
533,
10172,
3358,
8884,
8696,
8,
992,
14,
1685,
304,
272,
10261,
63,
2051,
275,
1709,
14,
3901,
8,
3327,
63,
498,
29,
549,
12,
14783,
29,
797,
9,
272,
4132,
275,
1709,
14,
3190,
8,
5949,
12,
1709,
14,
10855,
9,
272,
2538,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
9,
339,
347,
3354,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
1830,
440,
291,
14,
3759,
63,
2051,
26,
288,
511,
63,
2051,
275,
2196,
14,
8393,
8,
17,
12,
221,
27055,
9,
288,
340,
440,
10172,
3358,
8884,
8696,
14,
1462,
14,
1541,
8,
3759,
63,
2051,
29,
396,
63,
2051,
680,
2444,
837,
355,
291,
14,
3759,
63,
2051,
275,
511,
63,
2051,
267,
1613,
1252,
2117,
2031,
589,
12,
1011,
958,
9,
421,
199,
533,
10172,
3358,
8884,
8696,
3493,
8,
6932,
3358,
8884,
8696,
304,
272,
986,
421,
199,
533,
662,
328,
1224,
8884,
8696,
8,
992,
14,
1685,
304,
272,
8722,
63,
2051,
275,
1709,
14,
3901,
8,
3327,
63,
498,
29,
549,
9,
272,
4132,
275,
1709,
14,
3190,
8,
5949,
12,
1709,
14,
10855,
9,
272,
2538,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
9,
421,
199,
533,
869,
2149,
8,
992,
14,
1685,
304,
272,
7283,
275,
1709,
14,
3901,
342,
421,
199,
533,
19646,
8,
992,
14,
1685,
304,
272,
7283,
275,
1709,
14,
3901,
342,
272,
16712,
275,
1709,
14,
3190,
8,
22570,
12,
1709,
14,
10855,
9,
272,
6863,
275,
1709,
14,
2183,
480,
22964,
6863,
1768,
401,
1390,
63,
1267,
29,
17,
9,
339,
347,
664,
63,
6116,
63,
633,
8,
277,
304,
267,
372,
1994,
5216,
4805,
421,
199,
533,
869,
2149,
18,
8,
992,
14,
1685,
304,
272,
7283,
275,
1709,
14,
3901,
342,
421,
199,
533,
19646,
18,
8,
992,
14,
1685,
304,
272,
7283,
275,
1709,
14,
3901,
342,
272,
16712,
275,
1709,
14,
3190,
8,
22570,
18,
12,
1709,
14,
10855,
9,
421,
199,
533,
869,
2149,
19,
8,
992,
14,
1685,
304,
272,
7283,
275,
1709,
14,
3901,
342,
421,
199,
533,
19646,
19,
8,
992,
14,
1685,
304,
272,
7283,
275,
1709,
14,
3901,
342,
272,
16712,
275,
1709,
14,
3190,
8,
22570,
19,
12,
1709,
14,
10855,
9,
199,
199,
3,
29941,
367,
12052,
327,
24,
12205,
421,
199,
533,
869,
2149,
20,
8,
992,
14,
1685,
304,
272,
7283,
275,
1709,
14,
3901,
342,
421,
199,
533,
19646,
20,
4851,
379,
8,
992,
14,
1685,
304,
272,
7283,
275,
1709,
14,
3901,
8,
3437,
63,
505,
628,
26917,
22666,
28378,
1720,
1318,
365,
26936,
22666,
2685,
272,
16712,
275,
1709,
14,
3190,
8,
22570,
20,
12,
1709,
14,
10855,
9,
339,
1021,
6288,
26,
267,
9565,
275,
359,
288,
1709,
14,
11427,
8463,
8,
955,
2968,
5869,
297,
283,
4302,
995,
536,
534,
3235,
63,
27266,
63,
5869,
63,
529,
63,
4302,
358,
267,
1622,
421,
199,
533,
19646,
20,
30187,
8,
992,
14,
1685,
304,
272,
7283,
275,
1709,
14,
3901,
8,
3437,
63,
505,
628,
26917,
22666,
5174,
2238,
1720,
1318,
365,
26936,
22666,
2685,
272,
16712,
275,
1709,
14,
3190,
8,
22570,
20,
12,
1709,
14,
10855,
9,
339,
1021,
6288,
26,
267,
9565,
275,
359,
288,
1709,
14,
11427,
8463,
8,
955,
2968,
5869,
297,
283,
4302,
995,
536,
534,
3235,
63,
2902,
2238,
63,
5869,
63,
529,
63,
4302,
358,
267,
1622,
199,
199,
3,
29941,
367,
12052,
327,
8988,
2953,
421,
199,
533,
869,
2149,
21,
8,
992,
14,
1685,
304,
272,
7283,
275,
1709,
14,
3901,
342,
421,
199,
533,
19646,
21,
4851,
379,
8,
992,
14,
1685,
304,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
709,
9,
272,
3504,
275,
1709,
14,
2183,
8,
4577,
2687,
360,
17,
297,
283,
4395,
659,
661,
18,
297,
283,
11467,
3855,
1390,
63,
1267,
29,
709,
9,
272,
1318,
275,
1709,
14,
6254,
342,
272,
7283,
275,
1709,
14,
3901,
342,
272,
16712,
275,
1709,
14,
3190,
8,
22570,
21,
12,
1709,
14,
10855,
9,
421,
199,
533,
19646,
21,
30187,
8,
992,
14,
1685,
304,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
709,
9,
272,
3504,
275,
1709,
14,
2183,
8,
4577,
2687,
360,
17,
297,
283,
4395,
659,
661,
18,
297,
283,
11467,
3855,
1390,
63,
1267,
29,
709,
9,
272,
1318,
275,
1709,
14,
6254,
342,
272,
7283,
275,
1709,
14,
3901,
342,
272,
16712,
275,
1709,
14
] |
[
199,
9029,
402,
4628,
8308,
1824,
2193,
14,
199,
624,
199,
646,
2196,
199,
199,
504,
1639,
14,
2828,
14,
10778,
14,
955,
492,
8307,
3190,
199,
504,
1639,
14,
2828,
14,
10778,
14,
992,
492,
14501,
199,
504,
1639,
14,
697,
492,
1709,
421,
199,
533,
16396,
8,
992,
14,
1685,
304,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
9,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
354,
421,
199,
533,
5773,
19728,
8,
992,
14,
1685,
304,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
9,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
354,
421,
199,
533,
12988,
8,
992,
14,
1685,
304,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
9,
272,
1565,
19728,
275,
1709,
14,
3190,
8,
6301,
19728,
12,
1709,
14,
10855,
9,
339,
1564,
63,
466,
275,
1709,
14,
3190,
8,
11282,
12,
1709,
14,
10855,
9,
272,
909,
63,
344,
275,
1709,
14,
8591,
342,
272,
1676,
275,
8307,
3190,
342,
339,
347,
636,
495,
721,
277,
304,
267,
372,
283,
41,
8140,
450,
83,
12,
282,
1982,
402,
450,
83,
7,
450,
334,
277,
14,
354,
12,
291,
14,
1708,
9,
421,
199,
533,
8944,
8,
992,
14,
1685,
304,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
9,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
354,
421,
199,
533,
6529,
8,
992,
14,
1685,
304,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
9,
272,
19040,
275,
1709,
14,
7624,
8,
8696,
9,
421,
199,
533,
10172,
3358,
8884,
8696,
8,
992,
14,
1685,
304,
272,
10261,
63,
2051,
275,
1709,
14,
3901,
8,
3327,
63,
498,
29,
549,
12,
14783,
29,
797,
9,
272,
4132,
275,
1709,
14,
3190,
8,
5949,
12,
1709,
14,
10855,
9,
272,
2538,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
9,
339,
347,
3354,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
1830,
440,
291,
14,
3759,
63,
2051,
26,
288,
511,
63,
2051,
275,
2196,
14,
8393,
8,
17,
12,
221,
27055,
9,
288,
340,
440,
10172,
3358,
8884,
8696,
14,
1462,
14,
1541,
8,
3759,
63,
2051,
29,
396,
63,
2051,
680,
2444,
837,
355,
291,
14,
3759,
63,
2051,
275,
511,
63,
2051,
267,
1613,
1252,
2117,
2031,
589,
12,
1011,
958,
9,
421,
199,
533,
10172,
3358,
8884,
8696,
3493,
8,
6932,
3358,
8884,
8696,
304,
272,
986,
421,
199,
533,
662,
328,
1224,
8884,
8696,
8,
992,
14,
1685,
304,
272,
8722,
63,
2051,
275,
1709,
14,
3901,
8,
3327,
63,
498,
29,
549,
9,
272,
4132,
275,
1709,
14,
3190,
8,
5949,
12,
1709,
14,
10855,
9,
272,
2538,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
9,
421,
199,
533,
869,
2149,
8,
992,
14,
1685,
304,
272,
7283,
275,
1709,
14,
3901,
342,
421,
199,
533,
19646,
8,
992,
14,
1685,
304,
272,
7283,
275,
1709,
14,
3901,
342,
272,
16712,
275,
1709,
14,
3190,
8,
22570,
12,
1709,
14,
10855,
9,
272,
6863,
275,
1709,
14,
2183,
480,
22964,
6863,
1768,
401,
1390,
63,
1267,
29,
17,
9,
339,
347,
664,
63,
6116,
63,
633,
8,
277,
304,
267,
372,
1994,
5216,
4805,
421,
199,
533,
869,
2149,
18,
8,
992,
14,
1685,
304,
272,
7283,
275,
1709,
14,
3901,
342,
421,
199,
533,
19646,
18,
8,
992,
14,
1685,
304,
272,
7283,
275,
1709,
14,
3901,
342,
272,
16712,
275,
1709,
14,
3190,
8,
22570,
18,
12,
1709,
14,
10855,
9,
421,
199,
533,
869,
2149,
19,
8,
992,
14,
1685,
304,
272,
7283,
275,
1709,
14,
3901,
342,
421,
199,
533,
19646,
19,
8,
992,
14,
1685,
304,
272,
7283,
275,
1709,
14,
3901,
342,
272,
16712,
275,
1709,
14,
3190,
8,
22570,
19,
12,
1709,
14,
10855,
9,
199,
199,
3,
29941,
367,
12052,
327,
24,
12205,
421,
199,
533,
869,
2149,
20,
8,
992,
14,
1685,
304,
272,
7283,
275,
1709,
14,
3901,
342,
421,
199,
533,
19646,
20,
4851,
379,
8,
992,
14,
1685,
304,
272,
7283,
275,
1709,
14,
3901,
8,
3437,
63,
505,
628,
26917,
22666,
28378,
1720,
1318,
365,
26936,
22666,
2685,
272,
16712,
275,
1709,
14,
3190,
8,
22570,
20,
12,
1709,
14,
10855,
9,
339,
1021,
6288,
26,
267,
9565,
275,
359,
288,
1709,
14,
11427,
8463,
8,
955,
2968,
5869,
297,
283,
4302,
995,
536,
534,
3235,
63,
27266,
63,
5869,
63,
529,
63,
4302,
358,
267,
1622,
421,
199,
533,
19646,
20,
30187,
8,
992,
14,
1685,
304,
272,
7283,
275,
1709,
14,
3901,
8,
3437,
63,
505,
628,
26917,
22666,
5174,
2238,
1720,
1318,
365,
26936,
22666,
2685,
272,
16712,
275,
1709,
14,
3190,
8,
22570,
20,
12,
1709,
14,
10855,
9,
339,
1021,
6288,
26,
267,
9565,
275,
359,
288,
1709,
14,
11427,
8463,
8,
955,
2968,
5869,
297,
283,
4302,
995,
536,
534,
3235,
63,
2902,
2238,
63,
5869,
63,
529,
63,
4302,
358,
267,
1622,
199,
199,
3,
29941,
367,
12052,
327,
8988,
2953,
421,
199,
533,
869,
2149,
21,
8,
992,
14,
1685,
304,
272,
7283,
275,
1709,
14,
3901,
342,
421,
199,
533,
19646,
21,
4851,
379,
8,
992,
14,
1685,
304,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
709,
9,
272,
3504,
275,
1709,
14,
2183,
8,
4577,
2687,
360,
17,
297,
283,
4395,
659,
661,
18,
297,
283,
11467,
3855,
1390,
63,
1267,
29,
709,
9,
272,
1318,
275,
1709,
14,
6254,
342,
272,
7283,
275,
1709,
14,
3901,
342,
272,
16712,
275,
1709,
14,
3190,
8,
22570,
21,
12,
1709,
14,
10855,
9,
421,
199,
533,
19646,
21,
30187,
8,
992,
14,
1685,
304,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
709,
9,
272,
3504,
275,
1709,
14,
2183,
8,
4577,
2687,
360,
17,
297,
283,
4395,
659,
661,
18,
297,
283,
11467,
3855,
1390,
63,
1267,
29,
709,
9,
272,
1318,
275,
1709,
14,
6254,
342,
272,
7283,
275,
1709,
14,
3901,
342,
272,
16712,
275,
1709,
14,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
realsobek/freeipa
|
ipalib/cli.py
|
2
|
47051
|
# Authors:
# Jason Gerard DeRose <jderose@redhat.com>
#
# Copyright (C) 2008 Red Hat
# see file 'COPYING' for use and warranty information
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
Functionality for Command Line Interface.
"""
from __future__ import print_function
import importlib
import textwrap
import sys
import getpass
import code
import optparse # pylint: disable=deprecated-module
import fcntl
import termios
import struct
import base64
import traceback
import six
from six.moves import input
if six.PY3:
unicode = str
if six.PY2:
reload(sys) # pylint: disable=reload-builtin, undefined-variable
sys.setdefaultencoding('utf-8') # pylint: disable=no-member
from ipalib import frontend
from ipalib import backend
from ipalib import plugable
from ipalib.errors import (PublicError, CommandError, HelpError, InternalError,
NoSuchNamespaceError, ValidationError, NotFound,
NotConfiguredError, PromptFailed)
from ipalib.constants import CLI_TAB, LDAP_GENERALIZED_TIME_FORMAT
from ipalib.parameters import File, Str, Enum, Any, Flag
from ipalib.text import _
from ipalib import api # pylint: disable=unused-import
from ipapython.dnsutil import DNSName
import datetime
def to_cli(name):
"""
Takes a Python identifier and transforms it into form suitable for the
Command Line Interface.
"""
assert isinstance(name, str)
return name.replace('_', '-')
def from_cli(cli_name):
"""
Takes a string from the Command Line Interface and transforms it into a
Python identifier.
"""
return str(cli_name).replace('-', '_')
class textui(backend.Backend):
"""
Backend plugin to nicely format output to stdout.
"""
def get_tty_width(self):
"""
Return the width (in characters) of output tty.
If stdout is not a tty, this method will return ``None``.
"""
# /usr/include/asm/termios.h says that struct winsize has four
# unsigned shorts, hence the HHHH
if sys.stdout.isatty():
try:
winsize = fcntl.ioctl(sys.stdout, termios.TIOCGWINSZ,
struct.pack('HHHH', 0, 0, 0, 0))
return struct.unpack('HHHH', winsize)[1]
except IOError:
return None
def max_col_width(self, rows, col=None):
"""
Return the max width (in characters) of a specified column.
For example:
>>> ui = textui(api)
>>> rows = [
... ('a', 'package'),
... ('an', 'egg'),
... ]
>>> ui.max_col_width(rows, col=0) # len('an')
2
>>> ui.max_col_width(rows, col=1) # len('package')
7
>>> ui.max_col_width(['a', 'cherry', 'py']) # len('cherry')
6
"""
if type(rows) not in (list, tuple):
raise TypeError(
'rows: need %r or %r; got %r' % (list, tuple, rows)
)
if len(rows) == 0:
return 0
if col is None:
return max(len(row) for row in rows)
return max(len(row[col]) for row in rows)
def __get_encoding(self, stream):
assert stream in (sys.stdin, sys.stdout)
if getattr(stream, 'encoding', None) is None:
return 'UTF-8'
return stream.encoding
if six.PY2:
def decode(self, value):
"""
Decode text from stdin.
"""
if type(value) is bytes:
encoding = self.__get_encoding(sys.stdin)
return value.decode(encoding)
elif type(value) in (list, tuple):
return tuple(self.decode(v) for v in value)
return value
def encode(self, unicode_text):
"""
Encode text for output to stdout.
"""
assert type(unicode_text) is unicode
encoding = self.__get_encoding(sys.stdout)
return unicode_text.encode(encoding)
else:
def decode(self, value):
return value
def encode(self, value):
return value
def choose_number(self, n, singular, plural=None):
if n == 1 or plural is None:
return singular % n
return plural % n
def encode_binary(self, value):
"""
Convert a binary value to base64. We know a value is binary
if it is a python bytes type, otherwise it is a plain string.
This function also converts datetime and DNSName values to string.
"""
if type(value) is bytes:
return base64.b64encode(value).decode('ascii')
elif type(value) is datetime.datetime:
return value.strftime(LDAP_GENERALIZED_TIME_FORMAT)
elif isinstance(value, DNSName):
return unicode(value)
else:
return value
def print_plain(self, string):
"""
Print exactly like ``print`` statement would.
"""
print(unicode(string))
def print_line(self, text, width=None):
"""
Force printing on a single line, using ellipsis if needed.
For example:
>>> ui = textui(api)
>>> ui.print_line('This line can fit!', width=18)
This line can fit!
>>> ui.print_line('This line wont quite fit!', width=18)
This line wont ...
The above example aside, you normally should not specify the
``width``. When you don't, it is automatically determined by calling
`textui.get_tty_width()`.
"""
if width is None:
width = self.get_tty_width()
if width is not None and width < len(text):
text = text[:width - 3] + '...'
print(unicode(text))
def print_paragraph(self, text, width=None):
"""
Print a paragraph, automatically word-wrapping to tty width.
For example:
>>> text = '''
... Python is a dynamic object-oriented programming language that can
... be used for many kinds of software development.
... '''
>>> ui = textui(api)
>>> ui.print_paragraph(text, width=45)
Python is a dynamic object-oriented
programming language that can be used for
many kinds of software development.
The above example aside, you normally should not specify the
``width``. When you don't, it is automatically determined by calling
`textui.get_tty_width()`.
The word-wrapping is done using the Python ``textwrap`` module. See:
http://docs.python.org/library/textwrap.html
"""
if width is None:
width = self.get_tty_width()
for line in textwrap.wrap(text.strip(), width):
print(line)
def print_indented(self, text, indent=1):
"""
Print at specified indentation level.
For example:
>>> ui = textui(api)
>>> ui.print_indented('One indentation level.')
One indentation level.
>>> ui.print_indented('Two indentation levels.', indent=2)
Two indentation levels.
>>> ui.print_indented('No indentation.', indent=0)
No indentation.
"""
print((CLI_TAB * indent + text))
def print_keyval(self, rows, indent=1):
"""
Print (key = value) pairs, one pair per line.
For example:
>>> items = [
... ('in_server', True),
... ('mode', u'production'),
... ]
>>> ui = textui(api)
>>> ui.print_keyval(items)
in_server = True
mode = u'production'
>>> ui.print_keyval(items, indent=0)
in_server = True
mode = u'production'
Also see `textui.print_indented`.
"""
for (key, value) in rows:
self.print_indented('%s = %r' % (key, self.encode_binary(value)), indent)
def print_attribute(self, attr, value, format='%s: %s', indent=1, one_value_per_line=True):
"""
Print an ldap attribute.
For example:
>>> attr = 'dn'
>>> ui = textui(api)
>>> ui.print_attribute(attr, u'dc=example,dc=com')
dn: dc=example,dc=com
>>> attr = 'objectClass'
>>> ui.print_attribute(attr, [u'top', u'someClass'], one_value_per_line=False)
objectClass: top, someClass
>>> ui.print_attribute(attr, [u'top', u'someClass'])
objectClass: top
objectClass: someClass
"""
assert isinstance(attr, six.string_types)
if not isinstance(value, (list, tuple)):
# single-value attribute
self.print_indented(format % (attr, self.encode_binary(value)), indent)
else:
# multi-value attribute
if one_value_per_line:
for v in value:
self.print_indented(format % (attr, self.encode_binary(v)), indent)
else:
value = [self.encode_binary(v) for v in value]
if len(value) > 0 and type(value[0]) in (list, tuple):
# This is where we print failed add/remove members
for l in value:
text = ': '.join(l)
self.print_indented(format % (attr, self.encode_binary(text)), indent)
return
else:
if len(value) > 0:
text = ', '.join(str(v) for v in value)
else:
return
line_len = self.get_tty_width()
if line_len and text:
s_indent = '%s%s' % (
CLI_TAB * indent, ' ' * (len(attr) + 2)
)
line_len -= len(s_indent)
text = textwrap.wrap(
text, line_len, break_long_words=False
)
if len(text) == 0:
text = [u'']
else:
s_indent = u''
text = [text]
self.print_indented(format % (attr, text[0]), indent)
for line in text[1:]:
self.print_plain('%s%s' % (s_indent, line))
def print_entry1(self, entry, indent=1, attr_map={}, attr_order=['dn'],
one_value_per_line=True):
"""
Print an ldap entry dict.
"""
assert isinstance(entry, dict)
assert isinstance(attr_map, dict)
assert isinstance(attr_order, (list, tuple))
def print_attr(a):
if attr in attr_map:
self.print_attribute(
attr_map[attr], entry[attr], indent=indent, one_value_per_line=one_value_per_line
)
else:
self.print_attribute(
attr, entry[attr], indent=indent, one_value_per_line=one_value_per_line
)
for attr in attr_order:
if attr in entry:
print_attr(attr)
del entry[attr]
for attr in sorted(entry):
print_attr(attr)
def print_entries(self, entries, order=None, labels=None, flags=None, print_all=True, format='%s: %s', indent=1):
assert isinstance(entries, (list, tuple))
first = True
for entry in entries:
if not first:
print('')
first = False
self.print_entry(entry, order, labels, flags, print_all, format, indent)
def print_entry(self, entry, order=None, labels=None, flags=None, print_all=True, format='%s: %s', indent=1):
if isinstance(entry, (list, tuple)):
entry = dict(entry)
assert isinstance(entry, dict)
if labels is None:
labels = dict()
one_value_per_line = True
else:
one_value_per_line = False
if order is not None:
for key in order:
if key not in entry:
continue
label = labels.get(key, key)
flag = flags.get(key, [])
value = entry[key]
if ('suppress_empty' in flag and
value in [u'', '', (), [], None]):
continue
if isinstance(value, dict):
if frontend.entry_count(value) == 0:
continue
self.print_indented(format % (label, ''), indent)
self.print_entry(
value, order, labels, flags, print_all, format,
indent=indent+1
)
else:
if isinstance(value, (list, tuple)) and \
all(isinstance(val, dict) for val in value):
# this is a list of entries (dicts), not values
self.print_attribute(label, u'', format, indent)
self.print_entries(value, order, labels, flags, print_all,
format, indent+1)
else:
self.print_attribute(
label, value, format, indent, one_value_per_line
)
del entry[key]
if print_all:
for key in sorted(entry):
label = labels.get(key, key)
self.print_attribute(
key, entry[key], format, indent, one_value_per_line
)
def print_dashed(self, string, above=True, below=True, indent=0, dash='-'):
"""
Print a string with a dashed line above and/or below.
For example:
>>> ui = textui(api)
>>> ui.print_dashed('Dashed above and below.')
-----------------------
Dashed above and below.
-----------------------
>>> ui.print_dashed('Only dashed below.', above=False)
Only dashed below.
------------------
>>> ui.print_dashed('Only dashed above.', below=False)
------------------
Only dashed above.
"""
assert isinstance(dash, six.string_types)
assert len(dash) == 1
dashes = dash * len(string)
if above:
self.print_indented(dashes, indent)
self.print_indented(string, indent)
if below:
self.print_indented(dashes, indent)
def print_h1(self, text):
"""
Print a primary header at indentation level 0.
For example:
>>> ui = textui(api)
>>> ui.print_h1('A primary header')
================
A primary header
================
"""
self.print_dashed(text, indent=0, dash='=')
def print_h2(self, text):
"""
Print a secondary header at indentation level 1.
For example:
>>> ui = textui(api)
>>> ui.print_h2('A secondary header')
------------------
A secondary header
------------------
"""
self.print_dashed(text, indent=1, dash='-')
def print_name(self, name):
"""
Print a command name.
The typical use for this is to mark the start of output from a
command. For example, a hypothetical ``show_status`` command would
output something like this:
>>> ui = textui(api)
>>> ui.print_name('show_status')
------------
show-status:
------------
"""
self.print_dashed('%s:' % to_cli(name))
def print_header(self, msg, output):
self.print_dashed(msg % output)
def print_summary(self, msg):
"""
Print a summary at the end of a comand's output.
For example:
>>> ui = textui(api)
>>> ui.print_summary('Added user "jdoe"')
-----------------
Added user "jdoe"
-----------------
"""
self.print_dashed(msg)
def print_count(self, count, singular, plural=None):
"""
Print a summary count.
The typical use for this is to print the number of items returned
by a command, especially when this return count can vary. This
preferably should be used as a summary and should be the final text
a command outputs.
For example:
>>> ui = textui(api)
>>> ui.print_count(1, '%d goose', '%d geese')
-------
1 goose
-------
>>> ui.print_count(['Don', 'Sue'], 'Found %d user', 'Found %d users')
-------------
Found 2 users
-------------
If ``count`` is not an integer, it must be a list or tuple, and then
``len(count)`` is used as the count.
"""
if type(count) is not int:
assert type(count) in (list, tuple, dict)
count = len(count)
self.print_dashed(
self.choose_number(count, singular, plural)
)
def print_error(self, text):
print(' ** %s **' % unicode(text))
def prompt_helper(self, prompt, label, prompt_func=input):
"""Prompt user for input
Handles encoding the prompt and decoding the input.
On end of stream or ctrl+c, raise PromptFailed.
"""
try:
return self.decode(prompt_func(self.encode(prompt)))
except (KeyboardInterrupt, EOFError):
print()
raise PromptFailed(name=label)
def print_prompt_attribute_error(self, attribute, error):
self.print_plain('>>> %s: %s' % (attribute, error))
def prompt(self, label, default=None, get_values=None, optional=False):
"""
Prompt user for input.
"""
# TODO: Add tab completion using readline
if optional:
prompt = u'[%s]' % label
else:
prompt = u'%s' % label
if default is None:
prompt = u'%s: ' % prompt
else:
prompt = u'%s [%s]: ' % (prompt, default)
return self.prompt_helper(prompt, label)
def prompt_yesno(self, label, default=None):
"""
Prompt user for yes/no input. This method returns True/False according
to user response.
Parameter "default" should be True, False or None
If Default parameter is not None, user can enter an empty input instead
of Yes/No answer. Value passed to Default is returned in that case.
If Default parameter is None, user is asked for Yes/No answer until
a correct answer is provided. Answer is then returned.
"""
default_prompt = None
if default is not None:
if default:
default_prompt = "Yes"
else:
default_prompt = "No"
if default_prompt:
prompt = u'%s Yes/No (default %s): ' % (label, default_prompt)
else:
prompt = u'%s Yes/No: ' % label
while True:
data = self.prompt_helper(prompt, label).lower() #pylint: disable=E1103
if data in (u'yes', u'y'):
return True
elif data in ( u'n', u'no'):
return False
elif default is not None and data == u'':
return default
def prompt_password(self, label, confirm=True):
"""
Prompt user for a password or read it in via stdin depending
on whether there is a tty or not.
"""
if sys.stdin.isatty():
prompt = u'%s: ' % unicode(label)
repeat_prompt = unicode(_('Enter %(label)s again to verify: ') % dict(label=label))
while True:
pw1 = self.prompt_helper(prompt, label, prompt_func=getpass.getpass)
if not confirm:
return pw1
pw2 = self.prompt_helper(repeat_prompt, label, prompt_func=getpass.getpass)
if pw1 == pw2:
return pw1
self.print_error( _('Passwords do not match!'))
else:
return self.decode(sys.stdin.readline().strip())
def select_entry(self, entries, format, attrs, display_count=True):
"""
Display a list of lines in with formatting defined in ``format``.
``attrs`` is a list of attributes in the format.
Prompt user for a selection and return the value (index of
``entries`` -1).
If only one entry is provided then always return 0.
Return: 0..n for the index of the selected entry
-1 if all entries should be displayed
-2 to quit, no entries to be displayed
"""
if not self.env.interactive or not sys.stdout.isatty():
return -1
counter = len(entries)
if counter == 0:
raise NotFound(reason=_("No matching entries found"))
i = 1
for e in entries:
# There is no guarantee that all attrs are in any given
# entry
d = {}
for a in attrs:
d[a] = e.get(a, '')
self.print_line("%d: %s" % (i, format % d))
i = i + 1
if display_count:
self.print_count(entries, 'Found %d match', 'Found %d matches')
while True:
try:
resp = self.prompt("Choose one: (1 - %s), a for all, q to quit" % counter)
except EOFError:
return -2
if resp.lower() == "q": #pylint: disable=E1103
return -2
if resp.lower() == "a": #pylint: disable=E1103
return -1
try:
selection = int(resp) - 1
if (selection >= 0 and selection < counter):
break
except Exception:
# fall through to the error msg
pass
self.print_line("Please enter a number between 1 and %s" % counter)
self.print_line('')
return selection
class help(frontend.Local):
"""
Display help for a command or topic.
"""
takes_args = (
Str('command?', cli_name='topic', label=_('Topic or Command'),
doc=_('The topic or command name.')),
)
takes_options = (
Any('outfile?', flags=['no_option']),
)
has_output = tuple()
topic = None
def _get_topic(self, topic):
doc = u''
parent_topic = None
for package in self.api.packages:
module_name = '%s.%s' % (package.__name__, topic)
try:
module = sys.modules[module_name]
except KeyError:
try:
module = importlib.import_module(module_name)
except ImportError:
continue
if module.__doc__ is not None:
doc = unicode(module.__doc__ or '').strip()
try:
parent_topic = module.topic
except AttributeError:
pass
return doc, parent_topic
def _count_topic_mcl(self, topic_name, mod_name):
mcl = max((self._topics[topic_name][1], len(mod_name)))
self._topics[topic_name][1] = mcl
def _on_finalize(self):
# {topic: ["description", mcl, {"subtopic": ["description", mcl, [commands]]}]}
# {topic: ["description", mcl, [commands]]}
self._topics = {}
# [builtin_commands]
self._builtins = []
# build help topics
for c in self.api.Command:
if c is not self.api.Command.get_plugin(c.name):
continue
if c.NO_CLI:
continue
if c.topic is not None:
doc, topic_name = self._get_topic(c.topic)
doc = doc.split('\n', 1)[0]
if topic_name is None: # a module without grouping
topic_name = c.topic
if topic_name in self._topics:
self._topics[topic_name][2].append(c)
else:
self._topics[topic_name] = [doc, 0, [c]]
mcl = max((self._topics[topic_name][1], len(c.name)))
self._topics[topic_name][1] = mcl
else: # a module grouped in a topic
topic = self._get_topic(topic_name)
mod_name = c.topic
if topic_name in self._topics:
if mod_name in self._topics[topic_name][2]:
self._topics[topic_name][2][mod_name][2].append(c)
else:
self._topics[topic_name][2][mod_name] = [doc, 0, [c]]
self._count_topic_mcl(topic_name, mod_name)
# count mcl for for the subtopic
mcl = max((self._topics[topic_name][2][mod_name][1], len(c.name)))
self._topics[topic_name][2][mod_name][1] = mcl
else:
self._topics[topic_name] = [topic[0].split('\n', 1)[0],
0,
{mod_name: [doc, 0, [c]]}]
self._count_topic_mcl(topic_name, mod_name)
else:
self._builtins.append(c)
# compute maximum topic length
topics = list(self._topics) + [c.name for c in self._builtins]
self._mtl = max(len(s) for s in topics)
super(help, self)._on_finalize()
def run(self, key=None, outfile=None, **options):
if outfile is None:
outfile = sys.stdout
writer = self._writer(outfile)
name = from_cli(key)
if key is None:
self.api.parser.print_help(outfile)
return
if name == "topics":
self.print_topics(outfile)
return
if name in self._topics:
self.print_commands(name, outfile)
elif name in self.Command:
cmd = self.Command[name]
if cmd.NO_CLI:
raise HelpError(topic=name)
self.Backend.cli.build_parser(cmd).print_help(outfile)
elif any(name in t[2] for t in self._topics.values()
if type(t[2]) is dict):
self.print_commands(name, outfile)
elif name == "commands":
mcl = 0
for cmd_plugin in self.Command:
if cmd_plugin is not self.Command.get_plugin(cmd_plugin.name):
continue
if cmd_plugin.NO_CLI:
continue
mcl = max(mcl, len(cmd_plugin.name))
writer('%s %s' % (to_cli(cmd_plugin.name).ljust(mcl),
cmd_plugin.summary))
else:
raise HelpError(topic=name)
def _writer(self, outfile):
def writer(string=''):
try:
print(unicode(string), file=outfile)
except IOError:
pass
return writer
def print_topics(self, outfile):
writer = self._writer(outfile)
for t, topic in sorted(self._topics.items()):
writer('%s %s' % (to_cli(t).ljust(self._mtl), topic[0]))
def print_commands(self, topic, outfile):
writer = self._writer(outfile)
if topic in self._topics and type(self._topics[topic][2]) is dict:
# we want to display topic which has subtopics
for subtopic in self._topics[topic][2]:
doc = self._topics[topic][2][subtopic][0]
mcl = self._topics[topic][1]
writer(' %s %s' % (to_cli(subtopic).ljust(mcl), doc))
else:
# we want to display subtopic or a topic which has no subtopics
if topic in self._topics:
mcl = self._topics[topic][1]
commands = self._topics[topic][2]
else:
commands = []
for t in self._topics:
if type(self._topics[t][2]) is not dict:
continue
if topic not in self._topics[t][2]:
continue
mcl = self._topics[t][2][topic][1]
commands = self._topics[t][2][topic][2]
break
doc, _topic = self._get_topic(topic)
if topic not in self.Command and len(commands) == 0:
raise HelpError(topic=topic)
writer(doc)
if commands:
writer()
writer(_('Topic commands:'))
for c in commands:
writer(
' %s %s' % (to_cli(c.name).ljust(mcl), c.summary))
writer()
writer(_('To get command help, use:'))
writer(_(' ipa <command> --help'))
writer()
class show_mappings(frontend.Command):
"""
Show mapping of LDAP attributes to command-line option.
"""
takes_args = (
Str('command_name',
label=_('Command name'),
),
)
has_output = tuple()
topic = None
def run(self, command_name, **options):
command_name = from_cli(command_name)
if command_name not in self.Command:
raise CommandError(name=command_name)
params = self.Command[command_name].options
out = [('Parameter','LDAP attribute'),
('=========','==============')]
mcl = len(out[0][0])
for param in params():
if param.exclude and 'webui' in param.exclude:
continue
out.append((param.cli_name, param.param_spec))
mcl = max(mcl,len(param.cli_name))
for item in out:
print(to_cli(item[0]).ljust(mcl)+' : '+item[1])
class console(frontend.Command):
"""Start the IPA interactive Python console, or run a script.
An IPA API object is initialized and made available
in the `api` global variable.
"""
takes_args = ('filename?',)
has_output = tuple()
topic = None
def run(self, filename=None, **options):
local = dict(api=self.api)
if filename:
try:
script = open(filename)
except IOError as e:
exit("%s: %s" % (e.filename, e.strerror))
try:
with script:
exec(script, globals(), local)
except Exception:
traceback.print_exc()
exit(1)
else:
code.interact(
'(Custom IPA interactive Python console)',
local=local
)
class show_api(frontend.Command):
'Show attributes on dynamic API object'
takes_args = ('namespaces*',)
topic = None
def run(self, namespaces=None):
if namespaces is None:
names = tuple(self.api)
else:
for name in namespaces:
if name not in self.api:
raise NoSuchNamespaceError(name=name)
names = namespaces
lines = self.__traverse(names)
ml = max(len(l[1]) for l in lines)
self.Backend.textui.print_name('run')
first = True
for line in lines:
if line[0] == 0 and not first:
print('')
if first:
first = False
print('%s%s %r' % (
' ' * line[0],
line[1].ljust(ml),
line[2],
))
if len(lines) == 1:
s = '1 attribute shown.'
else:
s = '%d attributes show.' % len(lines)
self.Backend.textui.print_dashed(s)
def __traverse(self, names):
lines = []
for name in names:
namespace = self.api[name]
self.__traverse_namespace('%s' % name, namespace, lines)
return lines
def __traverse_namespace(self, name, namespace, lines, tab=0):
lines.append((tab, name, namespace))
for member_name in namespace:
member = namespace[member_name]
lines.append((tab + 1, member_name, member))
if not hasattr(member, '__iter__'):
continue
for n in member:
attr = member[n]
if isinstance(attr, plugable.APINameSpace) and len(attr) > 0:
self.__traverse_namespace(n, attr, lines, tab + 2)
cli_application_commands = (
help,
console,
show_api,
)
class Collector(object):
def __init__(self):
object.__setattr__(self, '_Collector__options', {})
def __setattr__(self, name, value):
if name in self.__options:
v = self.__options[name]
if type(v) is tuple:
value = v + (value,)
else:
value = (v, value)
self.__options[name] = value
object.__setattr__(self, name, value)
def __todict__(self):
return dict(self.__options)
class CLIOptionParserFormatter(optparse.IndentedHelpFormatter):
def format_argument(self, name, help_string):
result = []
opt_width = self.help_position - self.current_indent - 2
if len(name) > opt_width:
name = "%*s%s\n" % (self.current_indent, "", name)
indent_first = self.help_position
else: # start help on same line as name
name = "%*s%-*s " % (self.current_indent, "", opt_width, name)
indent_first = 0
result.append(name)
if help_string:
help_lines = textwrap.wrap(help_string, self.help_width)
result.append("%*s%s\n" % (indent_first, "", help_lines[0]))
result.extend(["%*s%s\n" % (self.help_position, "", line)
for line in help_lines[1:]])
elif name[-1] != "\n":
result.append("\n")
return "".join(result)
class CLIOptionParser(optparse.OptionParser):
"""
This OptionParser subclass adds an ability to print positional
arguments in CLI help. Custom formatter is used to format the argument
list in the same way as OptionParser formats options.
"""
def __init__(self, *args, **kwargs):
self._arguments = []
if 'formatter' not in kwargs:
kwargs['formatter'] = CLIOptionParserFormatter()
optparse.OptionParser.__init__(self, *args, **kwargs)
def format_option_help(self, formatter=None):
"""
Prepend argument help to standard OptionParser's option help
"""
option_help = optparse.OptionParser.format_option_help(self, formatter)
if isinstance(formatter, CLIOptionParserFormatter):
heading = unicode(_("Positional arguments"))
arguments = [formatter.format_heading(heading)]
formatter.indent()
for (name, help_string) in self._arguments:
arguments.append(formatter.format_argument(name, help_string))
formatter.dedent()
if len(arguments) > 1:
# there is more than just the heading
arguments.append(u"\n")
else:
arguments = []
option_help = "".join(arguments) + option_help
return option_help
def add_argument(self, name, help_string):
self._arguments.append((name, help_string))
class cli(backend.Executioner):
"""
Backend plugin for executing from command line interface.
"""
def get_command(self, argv):
"""Given CLI arguments, return the Command to use
On incorrect invocation, prints out a help message and returns None
"""
if len(argv) == 0:
self.Command.help(outfile=sys.stderr)
print(file=sys.stderr)
print('Error: Command not specified', file=sys.stderr)
exit(2)
(key, argv) = (argv[0], argv[1:])
name = from_cli(key)
if name not in self.Command and len(argv) == 0:
try:
self.Command.help(unicode(key), outfile=sys.stderr)
except HelpError:
pass
if name not in self.Command or self.Command[name].NO_CLI:
raise CommandError(name=key)
cmd = self.Command[name]
return cmd
def process_keyword_arguments(self, cmd, kw):
"""Get the keyword arguments for a Command"""
if self.env.interactive:
self.prompt_interactively(cmd, kw)
try:
callbacks = cmd.get_callbacks('interactive_prompt')
except AttributeError:
pass
else:
for callback in callbacks:
callback(cmd, kw)
self.load_files(cmd, kw)
return kw
def run(self, argv):
cmd = self.get_command(argv)
if cmd is None:
return
name = cmd.full_name
kw = self.parse(cmd, argv[1:])
if not isinstance(cmd, frontend.Local):
self.create_context()
try:
kw = self.process_keyword_arguments(cmd, kw)
result = self.execute(name, **kw)
if callable(cmd.output_for_cli):
for param in cmd.params():
if param.password and param.name in kw:
del kw[param.name]
(args, options) = cmd.params_2_args_options(**kw)
rv = cmd.output_for_cli(self.api.Backend.textui, result, *args, **options)
if rv:
return rv
else:
return 0
finally:
self.destroy_context()
def parse(self, cmd, argv):
parser = self.build_parser(cmd)
(collector, args) = parser.parse_args(argv, Collector())
options = collector.__todict__()
kw = cmd.args_options_2_params(*args, **options)
return dict(self.parse_iter(cmd, kw))
# FIXME: Probably move decoding to Command, use same method regardless of
# request source:
def parse_iter(self, cmd, kw):
"""
Decode param values if appropriate.
"""
for (key, value) in kw.items():
yield (key, self.Backend.textui.decode(value))
def build_parser(self, cmd):
parser = CLIOptionParser(
usage=' '.join(self.usage_iter(cmd)),
description=unicode(cmd.doc),
formatter=IPAHelpFormatter(),
)
option_groups = {}
def _get_option_group(group_name):
"""Get or create an option group for the given name"""
option_group = option_groups.get(group_name)
if option_group is None:
option_group = optparse.OptionGroup(parser, group_name)
parser.add_option_group(option_group)
option_groups[group_name] = option_group
return option_group
for option in cmd.options():
kw = dict(
dest=option.name,
help=unicode(option.doc),
)
if 'no_option' in option.flags:
continue
if option.password and self.env.interactive:
kw['action'] = 'store_true'
elif isinstance(option, Flag):
if option.default is True:
kw['action'] = 'store_false'
else:
kw['action'] = 'store_true'
else:
kw['metavar'] = option.cli_metavar
cli_name = to_cli(option.cli_name)
option_names = ['--%s' % cli_name]
if option.cli_short_name:
option_names.append('-%s' % option.cli_short_name)
opt = optparse.make_option(*option_names, **kw)
if option.option_group is None:
parser.add_option(opt)
else:
_get_option_group(option.option_group).add_option(opt)
if option.deprecated_cli_aliases:
new_kw = dict(kw)
new_kw['help'] = _('Same as --%s') % cli_name
if isinstance(option, Enum):
new_kw['metavar'] = 'VAL'
group = _get_option_group(unicode(_('Deprecated options')))
for alias in option.deprecated_cli_aliases:
name = '--%s' % alias
group.add_option(optparse.make_option(name, **new_kw))
for arg in cmd.args():
name = self.__get_arg_name(arg, format_name=False)
if 'no_option' in arg.flags or name is None:
continue
doc = unicode(arg.doc)
parser.add_argument(name, doc)
return parser
def __get_arg_name(self, arg, format_name=True):
if arg.password:
return
name = to_cli(arg.cli_name).upper()
if not format_name:
return name
if arg.multivalue:
name = '%s...' % name
if arg.required:
return name
else:
return '[%s]' % name
def usage_iter(self, cmd):
yield 'Usage: %%prog [global-options] %s' % to_cli(cmd.name)
for arg in cmd.args():
name = self.__get_arg_name(arg)
if name is None:
continue
yield name
yield '[options]'
def prompt_interactively(self, cmd, kw):
"""
Interactively prompt for missing or invalid values.
By default this method will only prompt for *required* Param that
have a missing or invalid value. However, if
``self.env.prompt_all`` is ``True``, this method will prompt for any
params that have a missing values, even if the param is optional.
"""
honor_alwaysask = True
for param in cmd.params():
if param.alwaysask and param.name in kw:
honor_alwaysask = False
break
for param in cmd.params():
if (param.required and param.name not in kw) or \
(param.alwaysask and honor_alwaysask) or self.env.prompt_all:
if param.autofill:
kw[param.name] = cmd.get_default_of(param.name, **kw)
if param.name in kw and kw[param.name] is not None:
if param.autofill:
del kw[param.name]
continue
if param.password:
kw[param.name] = self.Backend.textui.prompt_password(
param.label, param.confirm
)
else:
default = cmd.get_default_of(param.name, **kw)
optional = param.alwaysask or not param.required
value = cmd.prompt_param(param,
default=default,
optional=optional,
kw=kw)
if value is not None:
kw[param.name] = value
elif param.password and kw.get(param.name, False) is True:
kw[param.name] = self.Backend.textui.prompt_password(
param.label, param.confirm
)
def load_files(self, cmd, kw):
"""
Load files from File parameters.
This has to be done after all required parameters have been read
(i.e. after prompt_interactively has or would have been called)
AND before they are passed to the command. This is because:
1) we need to be sure no more files are going to be added
2) we load files from the machine where the command was executed
3) the webUI will use a different way of loading files
"""
for p in cmd.params():
if isinstance(p, File):
# FIXME: this only reads the first file
raw = None
if p.name in kw:
if type(kw[p.name]) in (tuple, list):
fname = kw[p.name][0]
else:
fname = kw[p.name]
try:
f = open(fname, 'r')
raw = f.read()
f.close()
except IOError as e:
raise ValidationError(
name=to_cli(p.cli_name),
error='%s: %s:' % (fname, e.args[1])
)
elif p.stdin_if_missing:
try:
raw = sys.stdin.read()
except IOError as e:
raise ValidationError(
name=to_cli(p.cli_name), error=e.args[1]
)
if raw:
kw[p.name] = self.Backend.textui.decode(raw)
elif p.required:
raise ValidationError(
name=to_cli(p.cli_name), error=_('No file to read')
)
class IPAHelpFormatter(optparse.IndentedHelpFormatter):
"""Formatter suitable for printing IPA command help
The default help formatter reflows text to fit the terminal, but it
ignores line/paragraph breaks.
IPA's descriptions already have correct line breaks. This formatter
doesn't touch them (save for removing initial/trailing whitespace).
"""
def format_description(self, description):
if description:
return description.strip()
else:
return ""
cli_plugins = (
cli,
textui,
console,
help,
show_mappings,
)
def run(api):
error = None
try:
(_options, argv) = api.bootstrap_with_global_options(context='cli')
for klass in cli_plugins:
api.add_plugin(klass)
api.finalize()
if not 'config_loaded' in api.env and not 'help' in argv:
raise NotConfiguredError()
sys.exit(api.Backend.cli.run(argv))
except KeyboardInterrupt:
print('')
api.log.info('operation aborted')
except PublicError as e:
error = e
except Exception as e:
api.log.exception('%s: %s', e.__class__.__name__, str(e))
error = InternalError()
if error is not None:
assert isinstance(error, PublicError)
api.log.error(error.strerror)
sys.exit(error.rval)
|
gpl-3.0
|
[
3,
6642,
26,
199,
3,
257,
1603,
2660,
22261,
1005,
1487,
50,
3362,
665,
74,
271,
293,
261,
32,
17164,
14,
957,
30,
199,
3,
199,
3,
1898,
334,
35,
9,
9079,
221,
9572,
13002,
199,
3,
1937,
570,
283,
16188,
1206,
7,
367,
675,
436,
3750,
2556,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
624,
199,
3481,
6712,
367,
5817,
7030,
14816,
14,
199,
624,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
14802,
199,
646,
13390,
199,
646,
984,
199,
646,
18354,
199,
646,
1233,
199,
646,
8691,
221,
327,
4287,
26,
3507,
29,
6667,
13,
578,
199,
646,
12871,
199,
646,
28725,
199,
646,
2702,
199,
646,
1300,
772,
199,
646,
5190,
199,
199,
646,
3816,
199,
504,
3816,
14,
4912,
492,
1324,
199,
199,
692,
3816,
14,
4521,
19,
26,
272,
2649,
275,
620,
199,
199,
692,
3816,
14,
4521,
18,
26,
272,
13101,
8,
1274,
9,
221,
327,
4287,
26,
3507,
29,
9233,
13,
5351,
12,
10942,
13,
1975,
272,
984,
14,
409,
27205,
28139,
360,
1624,
13,
24,
358,
221,
327,
4287,
26,
3507,
29,
889,
13,
1114,
199,
199,
504,
3384,
25530,
492,
22523,
199,
504,
3384,
25530,
492,
4865,
199,
504,
3384,
25530,
492,
14202,
461,
199,
504,
3384,
25530,
14,
2550,
492,
334,
9885,
547,
12,
14393,
12,
15456,
547,
12,
12624,
547,
12,
2574,
23798,
8814,
547,
12,
8505,
12,
21909,
12,
2574,
2832,
9902,
547,
12,
2165,
4787,
4276,
9,
199,
504,
3384,
25530,
14,
5559,
492,
14214,
63,
10129,
12,
20717,
63,
31548,
18732,
63,
4961,
63,
4807,
199,
504,
3384,
25530,
14,
3214,
492,
3814,
12,
8303,
12,
11305,
12,
6184,
12,
18241,
199,
504,
3384,
25530,
14,
505,
492,
485,
199,
504,
3384,
25530,
492,
2986,
221,
327,
4287,
26,
3507,
29,
8618,
13,
646,
199,
504,
18210,
1548,
14,
5797,
1974,
492,
10237,
985,
199,
199,
646,
2197,
421,
199,
318,
370,
63,
2764,
8,
354,
304,
272,
408,
272,
17415,
282,
2018,
5148,
436,
18501,
652,
1901,
1824,
11233,
367,
314,
272,
5817,
7030,
14816,
14,
272,
408,
272,
702,
1228,
8,
354,
12,
620,
9,
272,
372,
536,
14,
1814,
20928,
26942,
421,
199,
318,
687,
63,
2764,
8,
2764,
63,
354,
304,
272,
408,
272,
17415,
282,
1059,
687,
314,
5817,
7030,
14816,
436,
18501,
652,
1901,
282,
272,
2018,
5148,
14,
272,
408,
272,
372,
620,
8,
2764,
63,
354,
680,
1814,
13858,
18962,
421,
199,
533,
1318,
1907,
8,
4620,
14,
8447,
304,
272,
408,
272,
25674,
3589,
370,
14213,
590,
1475,
1072,
370,
3839,
14,
272,
408,
339,
347,
664,
63,
4707,
63,
2063,
8,
277,
304,
267,
408,
267,
1432,
314,
3462,
334,
262,
4110,
9,
402,
1072,
21862,
14,
398,
982,
3839,
365,
440,
282,
21862,
12,
642,
1083,
911,
372,
1124,
403,
4345,
267,
408,
267,
327,
1182,
2647,
15,
2613,
15,
11374,
15,
351,
24597,
14,
72,
20065,
626,
2702,
4747,
890,
965,
11648,
267,
327,
7381,
3974,
83,
12,
19407,
314,
869,
10213,
40,
267,
340,
984,
14,
2703,
14,
21122,
837,
288,
862,
26,
355,
4747,
890,
275,
12871,
14,
2308,
8077,
8,
1274,
14,
2703,
12,
28725,
14,
52,
2090,
4064,
7941,
18101,
12,
4228,
2702,
14,
1389,
360,
10213,
10213,
297,
378,
12,
378,
12,
378,
12,
378,
430,
355,
372,
2702,
14,
5301,
360,
10213,
10213,
297,
4747,
890,
2788,
17,
61,
288,
871,
5925,
26,
355,
372,
488,
339,
347,
1390,
63,
761,
63,
2063,
8,
277,
12,
4730,
12,
1048,
29,
403,
304,
267,
408,
267,
1432,
314,
1390,
3462,
334,
262,
4110,
9,
402,
282,
2013,
2763,
14,
398,
2104,
2893,
26,
398,
1306,
8574,
275,
1318,
1907,
8,
1246,
9,
267,
1306,
4730,
275,
359,
267,
2263,
258,
661,
65,
297,
283,
2491,
659,
267,
2263,
258,
661,
290,
297,
283,
5799,
659,
267,
2263,
1622,
267,
1306,
8574,
14,
988,
63,
761,
63,
2063,
8,
3838,
12,
1048,
29,
16,
9,
221,
327,
822,
360,
290,
358,
267,
499,
267,
1306,
8574,
14,
988,
63,
761,
63,
2063,
8,
3838,
12,
1048,
29,
17,
9,
221,
327,
822,
360,
2491,
358,
267,
1520,
267,
1306,
8574,
14,
988,
63,
761,
63,
2063,
2941,
65,
297,
283,
7641,
651,
297,
283,
647,
1105,
221,
327,
822,
360,
7641,
651,
358,
267,
1227,
267,
408,
267,
340,
730,
8,
3838,
9,
440,
315,
334,
513,
12,
2008,
304,
288,
746,
3146,
8,
355,
283,
3838,
26,
1929,
450,
82,
503,
450,
82,
27,
4788,
450,
82,
7,
450,
334,
513,
12,
2008,
12,
4730,
9,
288,
776,
267,
340,
822,
8,
3838,
9,
508,
378,
26,
288,
372,
378,
267,
340,
1048,
365,
488,
26,
288,
372,
1390,
8,
552,
8,
1143,
9,
367,
1962,
315,
4730,
9,
267,
372,
1390,
8,
552,
8,
1143,
59,
761,
566,
367,
1962,
315,
4730,
9,
339,
347,
636,
362,
63,
2991,
8,
277,
12,
2547,
304,
267,
702,
2547,
315,
334,
1274,
14,
6626,
12,
984,
14,
2703,
9,
267,
340,
2519,
8,
1745,
12,
283,
2991,
297,
488,
9,
365,
488,
26,
288,
372,
283,
6610,
13,
24,
7,
267,
372,
2547,
14,
2991,
339,
340,
3816,
14,
4521,
18,
26,
267,
347,
4849,
8,
277,
12,
574,
304,
288,
408,
288
] |
[
6642,
26,
199,
3,
257,
1603,
2660,
22261,
1005,
1487,
50,
3362,
665,
74,
271,
293,
261,
32,
17164,
14,
957,
30,
199,
3,
199,
3,
1898,
334,
35,
9,
9079,
221,
9572,
13002,
199,
3,
1937,
570,
283,
16188,
1206,
7,
367,
675,
436,
3750,
2556,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
624,
199,
3481,
6712,
367,
5817,
7030,
14816,
14,
199,
624,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
14802,
199,
646,
13390,
199,
646,
984,
199,
646,
18354,
199,
646,
1233,
199,
646,
8691,
221,
327,
4287,
26,
3507,
29,
6667,
13,
578,
199,
646,
12871,
199,
646,
28725,
199,
646,
2702,
199,
646,
1300,
772,
199,
646,
5190,
199,
199,
646,
3816,
199,
504,
3816,
14,
4912,
492,
1324,
199,
199,
692,
3816,
14,
4521,
19,
26,
272,
2649,
275,
620,
199,
199,
692,
3816,
14,
4521,
18,
26,
272,
13101,
8,
1274,
9,
221,
327,
4287,
26,
3507,
29,
9233,
13,
5351,
12,
10942,
13,
1975,
272,
984,
14,
409,
27205,
28139,
360,
1624,
13,
24,
358,
221,
327,
4287,
26,
3507,
29,
889,
13,
1114,
199,
199,
504,
3384,
25530,
492,
22523,
199,
504,
3384,
25530,
492,
4865,
199,
504,
3384,
25530,
492,
14202,
461,
199,
504,
3384,
25530,
14,
2550,
492,
334,
9885,
547,
12,
14393,
12,
15456,
547,
12,
12624,
547,
12,
2574,
23798,
8814,
547,
12,
8505,
12,
21909,
12,
2574,
2832,
9902,
547,
12,
2165,
4787,
4276,
9,
199,
504,
3384,
25530,
14,
5559,
492,
14214,
63,
10129,
12,
20717,
63,
31548,
18732,
63,
4961,
63,
4807,
199,
504,
3384,
25530,
14,
3214,
492,
3814,
12,
8303,
12,
11305,
12,
6184,
12,
18241,
199,
504,
3384,
25530,
14,
505,
492,
485,
199,
504,
3384,
25530,
492,
2986,
221,
327,
4287,
26,
3507,
29,
8618,
13,
646,
199,
504,
18210,
1548,
14,
5797,
1974,
492,
10237,
985,
199,
199,
646,
2197,
421,
199,
318,
370,
63,
2764,
8,
354,
304,
272,
408,
272,
17415,
282,
2018,
5148,
436,
18501,
652,
1901,
1824,
11233,
367,
314,
272,
5817,
7030,
14816,
14,
272,
408,
272,
702,
1228,
8,
354,
12,
620,
9,
272,
372,
536,
14,
1814,
20928,
26942,
421,
199,
318,
687,
63,
2764,
8,
2764,
63,
354,
304,
272,
408,
272,
17415,
282,
1059,
687,
314,
5817,
7030,
14816,
436,
18501,
652,
1901,
282,
272,
2018,
5148,
14,
272,
408,
272,
372,
620,
8,
2764,
63,
354,
680,
1814,
13858,
18962,
421,
199,
533,
1318,
1907,
8,
4620,
14,
8447,
304,
272,
408,
272,
25674,
3589,
370,
14213,
590,
1475,
1072,
370,
3839,
14,
272,
408,
339,
347,
664,
63,
4707,
63,
2063,
8,
277,
304,
267,
408,
267,
1432,
314,
3462,
334,
262,
4110,
9,
402,
1072,
21862,
14,
398,
982,
3839,
365,
440,
282,
21862,
12,
642,
1083,
911,
372,
1124,
403,
4345,
267,
408,
267,
327,
1182,
2647,
15,
2613,
15,
11374,
15,
351,
24597,
14,
72,
20065,
626,
2702,
4747,
890,
965,
11648,
267,
327,
7381,
3974,
83,
12,
19407,
314,
869,
10213,
40,
267,
340,
984,
14,
2703,
14,
21122,
837,
288,
862,
26,
355,
4747,
890,
275,
12871,
14,
2308,
8077,
8,
1274,
14,
2703,
12,
28725,
14,
52,
2090,
4064,
7941,
18101,
12,
4228,
2702,
14,
1389,
360,
10213,
10213,
297,
378,
12,
378,
12,
378,
12,
378,
430,
355,
372,
2702,
14,
5301,
360,
10213,
10213,
297,
4747,
890,
2788,
17,
61,
288,
871,
5925,
26,
355,
372,
488,
339,
347,
1390,
63,
761,
63,
2063,
8,
277,
12,
4730,
12,
1048,
29,
403,
304,
267,
408,
267,
1432,
314,
1390,
3462,
334,
262,
4110,
9,
402,
282,
2013,
2763,
14,
398,
2104,
2893,
26,
398,
1306,
8574,
275,
1318,
1907,
8,
1246,
9,
267,
1306,
4730,
275,
359,
267,
2263,
258,
661,
65,
297,
283,
2491,
659,
267,
2263,
258,
661,
290,
297,
283,
5799,
659,
267,
2263,
1622,
267,
1306,
8574,
14,
988,
63,
761,
63,
2063,
8,
3838,
12,
1048,
29,
16,
9,
221,
327,
822,
360,
290,
358,
267,
499,
267,
1306,
8574,
14,
988,
63,
761,
63,
2063,
8,
3838,
12,
1048,
29,
17,
9,
221,
327,
822,
360,
2491,
358,
267,
1520,
267,
1306,
8574,
14,
988,
63,
761,
63,
2063,
2941,
65,
297,
283,
7641,
651,
297,
283,
647,
1105,
221,
327,
822,
360,
7641,
651,
358,
267,
1227,
267,
408,
267,
340,
730,
8,
3838,
9,
440,
315,
334,
513,
12,
2008,
304,
288,
746,
3146,
8,
355,
283,
3838,
26,
1929,
450,
82,
503,
450,
82,
27,
4788,
450,
82,
7,
450,
334,
513,
12,
2008,
12,
4730,
9,
288,
776,
267,
340,
822,
8,
3838,
9,
508,
378,
26,
288,
372,
378,
267,
340,
1048,
365,
488,
26,
288,
372,
1390,
8,
552,
8,
1143,
9,
367,
1962,
315,
4730,
9,
267,
372,
1390,
8,
552,
8,
1143,
59,
761,
566,
367,
1962,
315,
4730,
9,
339,
347,
636,
362,
63,
2991,
8,
277,
12,
2547,
304,
267,
702,
2547,
315,
334,
1274,
14,
6626,
12,
984,
14,
2703,
9,
267,
340,
2519,
8,
1745,
12,
283,
2991,
297,
488,
9,
365,
488,
26,
288,
372,
283,
6610,
13,
24,
7,
267,
372,
2547,
14,
2991,
339,
340,
3816,
14,
4521,
18,
26,
267,
347,
4849,
8,
277,
12,
574,
304,
288,
408,
288,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
oxc/Flexget
|
flexget/plugins/sites/bakabt.py
|
3
|
1621
|
from __future__ import unicode_literals, division, absolute_import
from builtins import * # pylint: disable=unused-import, redefined-builtin
import logging
from flexget import plugin
from flexget.event import event
from flexget.plugins.internal.urlrewriting import UrlRewritingError
from flexget.utils.soup import get_soup
log = logging.getLogger('bakabt')
class UrlRewriteBakaBT(object):
"""BakaBT urlrewriter."""
# urlrewriter API
def url_rewritable(self, task, entry):
url = entry['url']
if url.startswith('http://www.bakabt.com/download/'):
return False
if url.startswith('http://www.bakabt.com/') or url.startswith('http://bakabt.com/'):
return True
return False
# urlrewriter API
def url_rewrite(self, task, entry):
entry['url'] = self.parse_download_page(entry['url'], task.requests)
@plugin.internet(log)
def parse_download_page(self, url, requests):
txheaders = {'User-agent': 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'}
page = requests.get(url, headers=txheaders)
try:
soup = get_soup(page.text)
except Exception as e:
raise UrlRewritingError(e)
tag_a = soup.find('a', attrs={'class': 'download_link'})
if not tag_a:
raise UrlRewritingError('Unable to locate download link from url %s' % url)
torrent_url = 'http://www.bakabt.com' + tag_a.get('href')
return torrent_url
@event('plugin.register')
def register_plugin():
plugin.register(UrlRewriteBakaBT, 'bakabt', groups=['urlrewriter'], api_ver=2)
|
mit
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
12,
4629,
12,
3679,
63,
646,
199,
504,
12963,
492,
627,
221,
327,
4287,
26,
3507,
29,
8618,
13,
646,
12,
295,
4037,
13,
5351,
199,
199,
646,
2050,
199,
199,
504,
20758,
362,
492,
3589,
199,
504,
20758,
362,
14,
1430,
492,
1566,
199,
504,
20758,
362,
14,
5265,
14,
4672,
14,
633,
264,
14827,
492,
20503,
497,
14827,
547,
199,
504,
20758,
362,
14,
1208,
14,
9317,
492,
664,
63,
9317,
199,
199,
793,
275,
2050,
14,
5572,
360,
27162,
371,
84,
358,
421,
199,
533,
20503,
497,
952,
34,
24685,
19162,
8,
785,
304,
272,
408,
34,
24685,
19162,
1166,
264,
5491,
1041,
339,
327,
1166,
264,
5491,
3261,
272,
347,
1166,
63,
264,
15053,
8,
277,
12,
2120,
12,
2397,
304,
267,
1166,
275,
2397,
459,
633,
418,
267,
340,
1166,
14,
2460,
360,
1014,
921,
1544,
14,
27162,
371,
84,
14,
957,
15,
4249,
26985,
288,
372,
756,
267,
340,
1166,
14,
2460,
360,
1014,
921,
1544,
14,
27162,
371,
84,
14,
957,
6217,
503,
1166,
14,
2460,
360,
1014,
921,
27162,
371,
84,
14,
957,
26985,
288,
372,
715,
267,
372,
756,
339,
327,
1166,
264,
5491,
3261,
272,
347,
1166,
63,
14366,
8,
277,
12,
2120,
12,
2397,
304,
267,
2397,
459,
633,
418,
275,
291,
14,
1122,
63,
4249,
63,
1606,
8,
2373,
459,
633,
995,
2120,
14,
6615,
9,
339,
768,
2718,
14,
4901,
8,
793,
9,
272,
347,
2198,
63,
4249,
63,
1606,
8,
277,
12,
1166,
12,
4145,
304,
267,
4773,
2139,
275,
791,
1899,
13,
4054,
356,
283,
22285,
15,
20,
14,
16,
334,
6490,
27,
603,
2684,
37,
959,
14,
21,
27,
5417,
23350,
9,
936,
267,
2034,
275,
4145,
14,
362,
8,
633,
12,
2323,
29,
2347,
2139,
9,
267,
862,
26,
288,
9108,
275,
664,
63,
9317,
8,
1606,
14,
505,
9,
267,
871,
2186,
465,
325,
26,
288,
746,
20503,
497,
14827,
547,
8,
69,
9,
267,
1947,
63,
65,
275,
9108,
14,
1623,
360,
65,
297,
3290,
3713,
533,
356,
283,
4249,
63,
1073,
3071,
267,
340,
440,
1947,
63,
65,
26,
288,
746,
20503,
497,
14827,
547,
360,
6005,
370,
16592,
5235,
2142,
687,
1166,
450,
83,
7,
450,
1166,
9,
267,
17671,
63,
633,
275,
283,
1014,
921,
1544,
14,
27162,
371,
84,
14,
957,
7,
435,
1947,
63,
65,
14,
362,
360,
6399,
358,
267,
372,
17671,
63,
633,
421,
199,
32,
1430,
360,
2718,
14,
2683,
358,
199,
318,
2274,
63,
2718,
837,
272,
3589,
14,
2683,
8,
6417,
497,
952,
34,
24685,
19162,
12,
283,
27162,
371,
84,
297,
4652,
2968,
633,
264,
5491,
995,
2986,
63,
422,
29,
18,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
636,
2443,
363,
492,
2649,
63,
5955,
12,
4629,
12,
3679,
63,
646,
199,
504,
12963,
492,
627,
221,
327,
4287,
26,
3507,
29,
8618,
13,
646,
12,
295,
4037,
13,
5351,
199,
199,
646,
2050,
199,
199,
504,
20758,
362,
492,
3589,
199,
504,
20758,
362,
14,
1430,
492,
1566,
199,
504,
20758,
362,
14,
5265,
14,
4672,
14,
633,
264,
14827,
492,
20503,
497,
14827,
547,
199,
504,
20758,
362,
14,
1208,
14,
9317,
492,
664,
63,
9317,
199,
199,
793,
275,
2050,
14,
5572,
360,
27162,
371,
84,
358,
421,
199,
533,
20503,
497,
952,
34,
24685,
19162,
8,
785,
304,
272,
408,
34,
24685,
19162,
1166,
264,
5491,
1041,
339,
327,
1166,
264,
5491,
3261,
272,
347,
1166,
63,
264,
15053,
8,
277,
12,
2120,
12,
2397,
304,
267,
1166,
275,
2397,
459,
633,
418,
267,
340,
1166,
14,
2460,
360,
1014,
921,
1544,
14,
27162,
371,
84,
14,
957,
15,
4249,
26985,
288,
372,
756,
267,
340,
1166,
14,
2460,
360,
1014,
921,
1544,
14,
27162,
371,
84,
14,
957,
6217,
503,
1166,
14,
2460,
360,
1014,
921,
27162,
371,
84,
14,
957,
26985,
288,
372,
715,
267,
372,
756,
339,
327,
1166,
264,
5491,
3261,
272,
347,
1166,
63,
14366,
8,
277,
12,
2120,
12,
2397,
304,
267,
2397,
459,
633,
418,
275,
291,
14,
1122,
63,
4249,
63,
1606,
8,
2373,
459,
633,
995,
2120,
14,
6615,
9,
339,
768,
2718,
14,
4901,
8,
793,
9,
272,
347,
2198,
63,
4249,
63,
1606,
8,
277,
12,
1166,
12,
4145,
304,
267,
4773,
2139,
275,
791,
1899,
13,
4054,
356,
283,
22285,
15,
20,
14,
16,
334,
6490,
27,
603,
2684,
37,
959,
14,
21,
27,
5417,
23350,
9,
936,
267,
2034,
275,
4145,
14,
362,
8,
633,
12,
2323,
29,
2347,
2139,
9,
267,
862,
26,
288,
9108,
275,
664,
63,
9317,
8,
1606,
14,
505,
9,
267,
871,
2186,
465,
325,
26,
288,
746,
20503,
497,
14827,
547,
8,
69,
9,
267,
1947,
63,
65,
275,
9108,
14,
1623,
360,
65,
297,
3290,
3713,
533,
356,
283,
4249,
63,
1073,
3071,
267,
340,
440,
1947,
63,
65,
26,
288,
746,
20503,
497,
14827,
547,
360,
6005,
370,
16592,
5235,
2142,
687,
1166,
450,
83,
7,
450,
1166,
9,
267,
17671,
63,
633,
275,
283,
1014,
921,
1544,
14,
27162,
371,
84,
14,
957,
7,
435,
1947,
63,
65,
14,
362,
360,
6399,
358,
267,
372,
17671,
63,
633,
421,
199,
32,
1430,
360,
2718,
14,
2683,
358,
199,
318,
2274,
63,
2718,
837,
272,
3589,
14,
2683,
8,
6417,
497,
952,
34,
24685,
19162,
12,
283,
27162,
371,
84,
297,
4652,
2968,
633,
264,
5491,
995,
2986,
63,
422,
29,
18,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
yongtang/tensorflow
|
tensorflow/python/keras/utils/generic_utils_test.py
|
6
|
15931
|
# Copyright 2016 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the 'License');
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an 'AS IS' BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Tests for Keras generic Python utils."""
from functools import partial
import numpy as np
from tensorflow.python import keras
from tensorflow.python.keras.utils import generic_utils
from tensorflow.python.platform import test
class HasArgTest(test.TestCase):
def test_has_arg(self):
def f_x(x):
return x
def f_x_args(x, *args):
_ = args
return x
def f_x_kwargs(x, **kwargs):
_ = kwargs
return x
def f(a, b, c):
return a + b + c
partial_f = partial(f, b=1)
self.assertTrue(keras.utils.generic_utils.has_arg(
f_x, 'x', accept_all=False))
self.assertFalse(keras.utils.generic_utils.has_arg(
f_x, 'y', accept_all=False))
self.assertTrue(keras.utils.generic_utils.has_arg(
f_x_args, 'x', accept_all=False))
self.assertFalse(keras.utils.generic_utils.has_arg(
f_x_args, 'y', accept_all=False))
self.assertTrue(keras.utils.generic_utils.has_arg(
f_x_kwargs, 'x', accept_all=False))
self.assertFalse(keras.utils.generic_utils.has_arg(
f_x_kwargs, 'y', accept_all=False))
self.assertTrue(keras.utils.generic_utils.has_arg(
f_x_kwargs, 'y', accept_all=True))
self.assertTrue(
keras.utils.generic_utils.has_arg(partial_f, 'c', accept_all=True))
class TestCustomObjectScope(test.TestCase):
def test_custom_object_scope(self):
def custom_fn():
pass
class CustomClass(object):
pass
with keras.utils.generic_utils.custom_object_scope(
{'CustomClass': CustomClass, 'custom_fn': custom_fn}):
act = keras.activations.get('custom_fn')
self.assertEqual(act, custom_fn)
cl = keras.regularizers.get('CustomClass')
self.assertEqual(cl.__class__, CustomClass)
class SerializeKerasObjectTest(test.TestCase):
def test_serialize_none(self):
serialized = keras.utils.generic_utils.serialize_keras_object(None)
self.assertEqual(serialized, None)
deserialized = keras.utils.generic_utils.deserialize_keras_object(
serialized)
self.assertEqual(deserialized, None)
def test_serialize_custom_class_with_default_name(self):
@keras.utils.generic_utils.register_keras_serializable()
class TestClass(object):
def __init__(self, value):
self._value = value
def get_config(self):
return {'value': self._value}
serialized_name = 'Custom>TestClass'
inst = TestClass(value=10)
class_name = keras.utils.generic_utils._GLOBAL_CUSTOM_NAMES[TestClass]
self.assertEqual(serialized_name, class_name)
config = keras.utils.generic_utils.serialize_keras_object(inst)
self.assertEqual(class_name, config['class_name'])
new_inst = keras.utils.generic_utils.deserialize_keras_object(config)
self.assertIsNot(inst, new_inst)
self.assertIsInstance(new_inst, TestClass)
self.assertEqual(10, new_inst._value)
# Make sure registering a new class with same name will fail.
with self.assertRaisesRegex(ValueError, '.*has already been registered.*'):
@keras.utils.generic_utils.register_keras_serializable() # pylint: disable=function-redefined
class TestClass(object): # pylint: disable=function-redefined
def __init__(self, value):
self._value = value
def get_config(self):
return {'value': self._value}
def test_serialize_custom_class_with_custom_name(self):
@keras.utils.generic_utils.register_keras_serializable(
'TestPackage', 'CustomName')
class OtherTestClass(object):
def __init__(self, val):
self._val = val
def get_config(self):
return {'val': self._val}
serialized_name = 'TestPackage>CustomName'
inst = OtherTestClass(val=5)
class_name = keras.utils.generic_utils._GLOBAL_CUSTOM_NAMES[OtherTestClass]
self.assertEqual(serialized_name, class_name)
fn_class_name = keras.utils.generic_utils.get_registered_name(
OtherTestClass)
self.assertEqual(fn_class_name, class_name)
cls = keras.utils.generic_utils.get_registered_object(fn_class_name)
self.assertEqual(OtherTestClass, cls)
config = keras.utils.generic_utils.serialize_keras_object(inst)
self.assertEqual(class_name, config['class_name'])
new_inst = keras.utils.generic_utils.deserialize_keras_object(config)
self.assertIsNot(inst, new_inst)
self.assertIsInstance(new_inst, OtherTestClass)
self.assertEqual(5, new_inst._val)
def test_serialize_custom_function(self):
@keras.utils.generic_utils.register_keras_serializable()
def my_fn():
return 42
serialized_name = 'Custom>my_fn'
class_name = keras.utils.generic_utils._GLOBAL_CUSTOM_NAMES[my_fn]
self.assertEqual(serialized_name, class_name)
fn_class_name = keras.utils.generic_utils.get_registered_name(my_fn)
self.assertEqual(fn_class_name, class_name)
config = keras.utils.generic_utils.serialize_keras_object(my_fn)
self.assertEqual(class_name, config)
fn = keras.utils.generic_utils.deserialize_keras_object(config)
self.assertEqual(42, fn())
fn_2 = keras.utils.generic_utils.get_registered_object(fn_class_name)
self.assertEqual(42, fn_2())
def test_serialize_custom_class_without_get_config_fails(self):
with self.assertRaisesRegex(
ValueError, 'Cannot register a class that does '
'not have a get_config.*'):
@keras.utils.generic_utils.register_keras_serializable( # pylint: disable=unused-variable
'TestPackage', 'TestClass')
class TestClass(object):
def __init__(self, value):
self._value = value
def test_serializable_object(self):
class SerializableInt(int):
"""A serializable object to pass out of a test layer's config."""
def __new__(cls, value):
return int.__new__(cls, value)
def get_config(self):
return {'value': int(self)}
@classmethod
def from_config(cls, config):
return cls(**config)
layer = keras.layers.Dense(
SerializableInt(3),
activation='relu',
kernel_initializer='ones',
bias_regularizer='l2')
config = keras.layers.serialize(layer)
new_layer = keras.layers.deserialize(
config, custom_objects={'SerializableInt': SerializableInt})
self.assertEqual(new_layer.activation, keras.activations.relu)
self.assertEqual(new_layer.bias_regularizer.__class__,
keras.regularizers.L2)
self.assertEqual(new_layer.units.__class__, SerializableInt)
self.assertEqual(new_layer.units, 3)
def test_nested_serializable_object(self):
class SerializableInt(int):
"""A serializable object to pass out of a test layer's config."""
def __new__(cls, value):
return int.__new__(cls, value)
def get_config(self):
return {'value': int(self)}
@classmethod
def from_config(cls, config):
return cls(**config)
class SerializableNestedInt(int):
"""A serializable object containing another serializable object."""
def __new__(cls, value, int_obj):
obj = int.__new__(cls, value)
obj.int_obj = int_obj
return obj
def get_config(self):
return {'value': int(self), 'int_obj': self.int_obj}
@classmethod
def from_config(cls, config):
return cls(**config)
nested_int = SerializableInt(4)
layer = keras.layers.Dense(
SerializableNestedInt(3, nested_int),
name='SerializableNestedInt',
activation='relu',
kernel_initializer='ones',
bias_regularizer='l2')
config = keras.layers.serialize(layer)
new_layer = keras.layers.deserialize(
config,
custom_objects={
'SerializableInt': SerializableInt,
'SerializableNestedInt': SerializableNestedInt
})
# Make sure the string field doesn't get convert to custom object, even
# they have same value.
self.assertEqual(new_layer.name, 'SerializableNestedInt')
self.assertEqual(new_layer.activation, keras.activations.relu)
self.assertEqual(new_layer.bias_regularizer.__class__,
keras.regularizers.L2)
self.assertEqual(new_layer.units.__class__, SerializableNestedInt)
self.assertEqual(new_layer.units, 3)
self.assertEqual(new_layer.units.int_obj.__class__, SerializableInt)
self.assertEqual(new_layer.units.int_obj, 4)
def test_nested_serializable_fn(self):
def serializable_fn(x):
"""A serializable function to pass out of a test layer's config."""
return x
class SerializableNestedInt(int):
"""A serializable object containing a serializable function."""
def __new__(cls, value, fn):
obj = int.__new__(cls, value)
obj.fn = fn
return obj
def get_config(self):
return {'value': int(self), 'fn': self.fn}
@classmethod
def from_config(cls, config):
return cls(**config)
layer = keras.layers.Dense(
SerializableNestedInt(3, serializable_fn),
activation='relu',
kernel_initializer='ones',
bias_regularizer='l2')
config = keras.layers.serialize(layer)
new_layer = keras.layers.deserialize(
config,
custom_objects={
'serializable_fn': serializable_fn,
'SerializableNestedInt': SerializableNestedInt
})
self.assertEqual(new_layer.activation, keras.activations.relu)
self.assertIsInstance(new_layer.bias_regularizer, keras.regularizers.L2)
self.assertIsInstance(new_layer.units, SerializableNestedInt)
self.assertEqual(new_layer.units, 3)
self.assertIs(new_layer.units.fn, serializable_fn)
def test_serialize_type_object_initializer(self):
layer = keras.layers.Dense(
1,
kernel_initializer=keras.initializers.ones,
bias_initializer=keras.initializers.zeros)
config = keras.layers.serialize(layer)
self.assertEqual(config['config']['bias_initializer']['class_name'],
'Zeros')
self.assertEqual(config['config']['kernel_initializer']['class_name'],
'Ones')
def test_serializable_with_old_config(self):
# model config generated by tf-1.2.1
old_model_config = {
'class_name':
'Sequential',
'config': [{
'class_name': 'Dense',
'config': {
'name': 'dense_1',
'trainable': True,
'batch_input_shape': [None, 784],
'dtype': 'float32',
'units': 32,
'activation': 'linear',
'use_bias': True,
'kernel_initializer': {
'class_name': 'Ones',
'config': {
'dtype': 'float32'
}
},
'bias_initializer': {
'class_name': 'Zeros',
'config': {
'dtype': 'float32'
}
},
'kernel_regularizer': None,
'bias_regularizer': None,
'activity_regularizer': None,
'kernel_constraint': None,
'bias_constraint': None
}
}]
}
old_model = keras.utils.generic_utils.deserialize_keras_object(
old_model_config, module_objects={'Sequential': keras.Sequential})
new_model = keras.Sequential([
keras.layers.Dense(32, input_dim=784, kernel_initializer='Ones'),
])
input_data = np.random.normal(2, 1, (5, 784))
output = old_model.predict(input_data)
expected_output = new_model.predict(input_data)
self.assertAllEqual(output, expected_output)
def test_deserialize_unknown_object(self):
class CustomLayer(keras.layers.Layer):
pass
layer = CustomLayer()
config = keras.utils.generic_utils.serialize_keras_object(layer)
with self.assertRaisesRegexp(ValueError,
'passed to the `custom_objects` arg'):
keras.utils.generic_utils.deserialize_keras_object(config)
restored = keras.utils.generic_utils.deserialize_keras_object(
config, custom_objects={'CustomLayer': CustomLayer})
self.assertIsInstance(restored, CustomLayer)
class SliceArraysTest(test.TestCase):
def test_slice_arrays(self):
input_a = list([1, 2, 3])
self.assertEqual(
keras.utils.generic_utils.slice_arrays(input_a, start=0),
[None, None, None])
self.assertEqual(
keras.utils.generic_utils.slice_arrays(input_a, stop=3),
[None, None, None])
self.assertEqual(
keras.utils.generic_utils.slice_arrays(input_a, start=0, stop=1),
[None, None, None])
# object() alone isn't compatible with WeakKeyDictionary, which we use to
# track shared configs.
class MaybeSharedObject(object):
pass
class SharedObjectScopeTest(test.TestCase):
def test_shared_object_saving_scope_single_object_doesnt_export_id(self):
with generic_utils.SharedObjectSavingScope() as scope:
single_object = MaybeSharedObject()
self.assertIsNone(scope.get_config(single_object))
single_object_config = scope.create_config({}, single_object)
self.assertIsNotNone(single_object_config)
self.assertNotIn(generic_utils.SHARED_OBJECT_KEY,
single_object_config)
def test_shared_object_saving_scope_shared_object_exports_id(self):
with generic_utils.SharedObjectSavingScope() as scope:
shared_object = MaybeSharedObject()
self.assertIsNone(scope.get_config(shared_object))
scope.create_config({}, shared_object)
first_object_config = scope.get_config(shared_object)
second_object_config = scope.get_config(shared_object)
self.assertIn(generic_utils.SHARED_OBJECT_KEY,
first_object_config)
self.assertIn(generic_utils.SHARED_OBJECT_KEY,
second_object_config)
self.assertIs(first_object_config, second_object_config)
def test_shared_object_loading_scope_noop(self):
# Test that, without a context manager scope, adding configs will do
# nothing.
obj_id = 1
obj = MaybeSharedObject()
generic_utils._shared_object_loading_scope().set(obj_id, obj)
self.assertIsNone(generic_utils._shared_object_loading_scope().get(obj_id))
def test_shared_object_loading_scope_returns_shared_obj(self):
obj_id = 1
obj = MaybeSharedObject()
with generic_utils.SharedObjectLoadingScope() as scope:
scope.set(obj_id, obj)
self.assertIs(scope.get(obj_id), obj)
def test_nested_shared_object_saving_scopes(self):
my_obj = MaybeSharedObject()
with generic_utils.SharedObjectSavingScope() as scope_1:
scope_1.create_config({}, my_obj)
with generic_utils.SharedObjectSavingScope() as scope_2:
# Nesting saving scopes should return the original scope and should
# not clear any objects we're tracking.
self.assertIs(scope_1, scope_2)
self.assertIsNotNone(scope_2.get_config(my_obj))
self.assertIsNotNone(scope_1.get_config(my_obj))
self.assertIsNone(generic_utils._shared_object_saving_scope())
if __name__ == '__main__':
test.main()
|
apache-2.0
|
[
3,
1898,
7800,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
283,
3761,
11339,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
283,
1179,
2281,
7,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
2925,
367,
1804,
30037,
7809,
2018,
3778,
1041,
199,
199,
504,
9143,
492,
7417,
199,
199,
646,
2680,
465,
980,
199,
199,
504,
3228,
14,
1548,
492,
11708,
199,
504,
3228,
14,
1548,
14,
8811,
14,
1208,
492,
7809,
63,
1208,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
421,
199,
533,
13481,
6373,
774,
8,
396,
14,
1746,
304,
819,
347,
511,
63,
1989,
63,
1273,
8,
277,
304,
339,
347,
289,
63,
88,
8,
88,
304,
489,
372,
671,
339,
347,
289,
63,
88,
63,
589,
8,
88,
12,
627,
589,
304,
489,
485,
275,
1249,
489,
372,
671,
339,
347,
289,
63,
88,
63,
958,
8,
88,
12,
1011,
958,
304,
489,
485,
275,
2074,
489,
372,
671,
339,
347,
289,
8,
65,
12,
330,
12,
286,
304,
489,
372,
282,
435,
330,
435,
286,
339,
7417,
63,
70,
275,
7417,
8,
70,
12,
330,
29,
17,
9,
339,
291,
14,
1815,
8,
8811,
14,
1208,
14,
6767,
63,
1208,
14,
1989,
63,
1273,
8,
267,
289,
63,
88,
12,
283,
88,
297,
4729,
63,
452,
29,
797,
430,
272,
291,
14,
3334,
8,
8811,
14,
1208,
14,
6767,
63,
1208,
14,
1989,
63,
1273,
8,
267,
289,
63,
88,
12,
283,
89,
297,
4729,
63,
452,
29,
797,
430,
272,
291,
14,
1815,
8,
8811,
14,
1208,
14,
6767,
63,
1208,
14,
1989,
63,
1273,
8,
267,
289,
63,
88,
63,
589,
12,
283,
88,
297,
4729,
63,
452,
29,
797,
430,
272,
291,
14,
3334,
8,
8811,
14,
1208,
14,
6767,
63,
1208,
14,
1989,
63,
1273,
8,
267,
289,
63,
88,
63,
589,
12,
283,
89,
297,
4729,
63,
452,
29,
797,
430,
272,
291,
14,
1815,
8,
8811,
14,
1208,
14,
6767,
63,
1208,
14,
1989,
63,
1273,
8,
267,
289,
63,
88,
63,
958,
12,
283,
88,
297,
4729,
63,
452,
29,
797,
430,
272,
291,
14,
3334,
8,
8811,
14,
1208,
14,
6767,
63,
1208,
14,
1989,
63,
1273,
8,
267,
289,
63,
88,
63,
958,
12,
283,
89,
297,
4729,
63,
452,
29,
797,
430,
272,
291,
14,
1815,
8,
8811,
14,
1208,
14,
6767,
63,
1208,
14,
1989,
63,
1273,
8,
267,
289,
63,
88,
63,
958,
12,
283,
89,
297,
4729,
63,
452,
29,
549,
430,
272,
291,
14,
1815,
8,
267,
11708,
14,
1208,
14,
6767,
63,
1208,
14,
1989,
63,
1273,
8,
6672,
63,
70,
12,
283,
67,
297,
4729,
63,
452,
29,
549,
430,
421,
199,
533,
1379,
7223,
1692,
7812,
8,
396,
14,
1746,
304,
819,
347,
511,
63,
4229,
63,
785,
63,
2645,
8,
277,
304,
339,
347,
3537,
63,
2324,
837,
489,
986,
339,
1021,
8388,
2543,
8,
785,
304,
489,
986,
339,
543,
11708,
14,
1208,
14,
6767,
63,
1208,
14,
4229,
63,
785,
63,
2645,
8,
267,
791,
7223,
2543,
356,
8388,
2543,
12,
283,
4229,
63,
2324,
356,
3537,
63,
2324,
22558,
489,
2454,
275,
11708,
14,
31117,
14,
362,
360,
4229,
63,
2324,
358,
489,
291,
14,
629,
8,
2442,
12,
3537,
63,
2324,
9,
489,
824,
275,
11708,
14,
7898,
6315,
14,
362,
360,
7223,
2543,
358,
489,
291,
14,
629,
8,
429,
855,
533,
3108,
8388,
2543,
9,
421,
199,
533,
11973,
794,
43,
30037,
1692,
774,
8,
396,
14,
1746,
304,
819,
347,
511,
63,
3549,
63,
3592,
8,
277,
304,
272,
6380,
275,
11708,
14,
1208,
14,
6767,
63,
1208,
14,
3549,
63,
8811,
63,
785,
8,
403,
9,
272,
291,
14,
629,
8,
8397,
12,
488,
9,
272,
13256,
275,
11708,
14,
1208,
14,
6767,
63,
1208,
14,
11143,
63,
8811,
63,
785,
8,
267,
6380,
9,
272,
291,
14,
629,
8,
271,
8397,
12,
488,
9,
819,
347,
511,
63,
3549,
63,
4229,
63,
533,
63,
1045,
63,
885,
63,
354,
8,
277,
304,
339,
768,
8811,
14,
1208,
14,
6767,
63,
1208,
14,
2683,
63,
8811,
63,
2171,
14065,
342,
272,
1021,
1379,
2543,
8,
785,
304,
2541,
347,
636,
826,
721,
277,
12,
574,
304,
267,
291,
423,
585,
275,
574,
2541,
347,
664,
63,
888,
8,
277,
304,
267,
372,
791,
585,
356,
291,
423,
585,
93,
339,
6380,
63,
354,
275,
283,
7223,
30,
22009,
7,
272,
2727,
275,
1379,
2543,
8,
585,
29,
709,
9,
272,
1021,
63,
354,
275,
11708,
14,
1208,
14,
6767,
63,
1208,
423,
13808,
63,
20519,
63,
14546,
59,
22009,
61,
272,
291,
14,
629,
8,
8397,
63,
354,
12,
1021,
63,
354,
9,
272,
1101,
275,
11708,
14,
1208,
14,
6767,
63,
1208,
14,
3549,
63,
8811,
63,
785,
8,
3615,
9,
272,
291,
14,
629,
8,
533,
63,
354,
12,
1101,
459,
533,
63,
354,
1105,
272,
892,
63,
3615,
275,
11708,
14,
1208,
14,
6767,
63,
1208,
14,
11143,
63,
8811,
63,
785,
8,
888,
9,
272,
291,
14,
9422,
8,
3615,
12,
892,
63,
3615,
9,
272,
291,
14,
6926,
8,
1222,
63,
3615,
12,
1379,
2543,
9,
272,
291,
14,
629,
8,
709,
12,
892,
63,
3615,
423,
585,
9,
339,
327,
4155,
3238,
2274,
316,
282,
892,
1021,
543,
2011,
536,
911,
2449,
14,
272,
543,
291,
14,
16499,
8,
3393,
12,
1987,
10,
1989,
2575,
2757,
7264,
2795,
735,
489,
768,
8811,
14,
1208,
14,
6767,
63,
1208,
14,
2683,
63
] |
[
1898,
7800,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
283,
3761,
11339,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
283,
1179,
2281,
7,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
2925,
367,
1804,
30037,
7809,
2018,
3778,
1041,
199,
199,
504,
9143,
492,
7417,
199,
199,
646,
2680,
465,
980,
199,
199,
504,
3228,
14,
1548,
492,
11708,
199,
504,
3228,
14,
1548,
14,
8811,
14,
1208,
492,
7809,
63,
1208,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
421,
199,
533,
13481,
6373,
774,
8,
396,
14,
1746,
304,
819,
347,
511,
63,
1989,
63,
1273,
8,
277,
304,
339,
347,
289,
63,
88,
8,
88,
304,
489,
372,
671,
339,
347,
289,
63,
88,
63,
589,
8,
88,
12,
627,
589,
304,
489,
485,
275,
1249,
489,
372,
671,
339,
347,
289,
63,
88,
63,
958,
8,
88,
12,
1011,
958,
304,
489,
485,
275,
2074,
489,
372,
671,
339,
347,
289,
8,
65,
12,
330,
12,
286,
304,
489,
372,
282,
435,
330,
435,
286,
339,
7417,
63,
70,
275,
7417,
8,
70,
12,
330,
29,
17,
9,
339,
291,
14,
1815,
8,
8811,
14,
1208,
14,
6767,
63,
1208,
14,
1989,
63,
1273,
8,
267,
289,
63,
88,
12,
283,
88,
297,
4729,
63,
452,
29,
797,
430,
272,
291,
14,
3334,
8,
8811,
14,
1208,
14,
6767,
63,
1208,
14,
1989,
63,
1273,
8,
267,
289,
63,
88,
12,
283,
89,
297,
4729,
63,
452,
29,
797,
430,
272,
291,
14,
1815,
8,
8811,
14,
1208,
14,
6767,
63,
1208,
14,
1989,
63,
1273,
8,
267,
289,
63,
88,
63,
589,
12,
283,
88,
297,
4729,
63,
452,
29,
797,
430,
272,
291,
14,
3334,
8,
8811,
14,
1208,
14,
6767,
63,
1208,
14,
1989,
63,
1273,
8,
267,
289,
63,
88,
63,
589,
12,
283,
89,
297,
4729,
63,
452,
29,
797,
430,
272,
291,
14,
1815,
8,
8811,
14,
1208,
14,
6767,
63,
1208,
14,
1989,
63,
1273,
8,
267,
289,
63,
88,
63,
958,
12,
283,
88,
297,
4729,
63,
452,
29,
797,
430,
272,
291,
14,
3334,
8,
8811,
14,
1208,
14,
6767,
63,
1208,
14,
1989,
63,
1273,
8,
267,
289,
63,
88,
63,
958,
12,
283,
89,
297,
4729,
63,
452,
29,
797,
430,
272,
291,
14,
1815,
8,
8811,
14,
1208,
14,
6767,
63,
1208,
14,
1989,
63,
1273,
8,
267,
289,
63,
88,
63,
958,
12,
283,
89,
297,
4729,
63,
452,
29,
549,
430,
272,
291,
14,
1815,
8,
267,
11708,
14,
1208,
14,
6767,
63,
1208,
14,
1989,
63,
1273,
8,
6672,
63,
70,
12,
283,
67,
297,
4729,
63,
452,
29,
549,
430,
421,
199,
533,
1379,
7223,
1692,
7812,
8,
396,
14,
1746,
304,
819,
347,
511,
63,
4229,
63,
785,
63,
2645,
8,
277,
304,
339,
347,
3537,
63,
2324,
837,
489,
986,
339,
1021,
8388,
2543,
8,
785,
304,
489,
986,
339,
543,
11708,
14,
1208,
14,
6767,
63,
1208,
14,
4229,
63,
785,
63,
2645,
8,
267,
791,
7223,
2543,
356,
8388,
2543,
12,
283,
4229,
63,
2324,
356,
3537,
63,
2324,
22558,
489,
2454,
275,
11708,
14,
31117,
14,
362,
360,
4229,
63,
2324,
358,
489,
291,
14,
629,
8,
2442,
12,
3537,
63,
2324,
9,
489,
824,
275,
11708,
14,
7898,
6315,
14,
362,
360,
7223,
2543,
358,
489,
291,
14,
629,
8,
429,
855,
533,
3108,
8388,
2543,
9,
421,
199,
533,
11973,
794,
43,
30037,
1692,
774,
8,
396,
14,
1746,
304,
819,
347,
511,
63,
3549,
63,
3592,
8,
277,
304,
272,
6380,
275,
11708,
14,
1208,
14,
6767,
63,
1208,
14,
3549,
63,
8811,
63,
785,
8,
403,
9,
272,
291,
14,
629,
8,
8397,
12,
488,
9,
272,
13256,
275,
11708,
14,
1208,
14,
6767,
63,
1208,
14,
11143,
63,
8811,
63,
785,
8,
267,
6380,
9,
272,
291,
14,
629,
8,
271,
8397,
12,
488,
9,
819,
347,
511,
63,
3549,
63,
4229,
63,
533,
63,
1045,
63,
885,
63,
354,
8,
277,
304,
339,
768,
8811,
14,
1208,
14,
6767,
63,
1208,
14,
2683,
63,
8811,
63,
2171,
14065,
342,
272,
1021,
1379,
2543,
8,
785,
304,
2541,
347,
636,
826,
721,
277,
12,
574,
304,
267,
291,
423,
585,
275,
574,
2541,
347,
664,
63,
888,
8,
277,
304,
267,
372,
791,
585,
356,
291,
423,
585,
93,
339,
6380,
63,
354,
275,
283,
7223,
30,
22009,
7,
272,
2727,
275,
1379,
2543,
8,
585,
29,
709,
9,
272,
1021,
63,
354,
275,
11708,
14,
1208,
14,
6767,
63,
1208,
423,
13808,
63,
20519,
63,
14546,
59,
22009,
61,
272,
291,
14,
629,
8,
8397,
63,
354,
12,
1021,
63,
354,
9,
272,
1101,
275,
11708,
14,
1208,
14,
6767,
63,
1208,
14,
3549,
63,
8811,
63,
785,
8,
3615,
9,
272,
291,
14,
629,
8,
533,
63,
354,
12,
1101,
459,
533,
63,
354,
1105,
272,
892,
63,
3615,
275,
11708,
14,
1208,
14,
6767,
63,
1208,
14,
11143,
63,
8811,
63,
785,
8,
888,
9,
272,
291,
14,
9422,
8,
3615,
12,
892,
63,
3615,
9,
272,
291,
14,
6926,
8,
1222,
63,
3615,
12,
1379,
2543,
9,
272,
291,
14,
629,
8,
709,
12,
892,
63,
3615,
423,
585,
9,
339,
327,
4155,
3238,
2274,
316,
282,
892,
1021,
543,
2011,
536,
911,
2449,
14,
272,
543,
291,
14,
16499,
8,
3393,
12,
1987,
10,
1989,
2575,
2757,
7264,
2795,
735,
489,
768,
8811,
14,
1208,
14,
6767,
63,
1208,
14,
2683,
63,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
cristian69/KernotekV3
|
venv/lib/python2.7/site-packages/pip/_vendor/requests/packages/chardet/jpcntx.py
|
949
|
19104
|
######################## BEGIN LICENSE BLOCK ########################
# The Original Code is Mozilla Communicator client code.
#
# The Initial Developer of the Original Code is
# Netscape Communications Corporation.
# Portions created by the Initial Developer are Copyright (C) 1998
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Mark Pilgrim - port to Python
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA
######################### END LICENSE BLOCK #########################
from .compat import wrap_ord
NUM_OF_CATEGORY = 6
DONT_KNOW = -1
ENOUGH_REL_THRESHOLD = 100
MAX_REL_THRESHOLD = 1000
MINIMUM_DATA_THRESHOLD = 4
# This is hiragana 2-char sequence table, the number in each cell represents its frequency category
jp2CharContext = (
(0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1),
(2,4,0,4,0,3,0,4,0,3,4,4,4,2,4,3,3,4,3,2,3,3,4,2,3,3,3,2,4,1,4,3,3,1,5,4,3,4,3,4,3,5,3,0,3,5,4,2,0,3,1,0,3,3,0,3,3,0,1,1,0,4,3,0,3,3,0,4,0,2,0,3,5,5,5,5,4,0,4,1,0,3,4),
(0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2),
(0,4,0,5,0,5,0,4,0,4,5,4,4,3,5,3,5,1,5,3,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5,5,4,3,4,5,5,3,2,2,3,3,3,3,2,3,3,1,2,3,2,4,3,3,3,4,0,4,0,2,0,4,3,2,2,1,2,0,3,0,0,4,1),
)
class JapaneseContextAnalysis:
def __init__(self):
self.reset()
def reset(self):
self._mTotalRel = 0 # total sequence received
# category counters, each interger counts sequence in its category
self._mRelSample = [0] * NUM_OF_CATEGORY
# if last byte in current buffer is not the last byte of a character,
# we need to know how many bytes to skip in next buffer
self._mNeedToSkipCharNum = 0
self._mLastCharOrder = -1 # The order of previous char
# If this flag is set to True, detection is done and conclusion has
# been made
self._mDone = False
def feed(self, aBuf, aLen):
if self._mDone:
return
# The buffer we got is byte oriented, and a character may span in more than one
# buffers. In case the last one or two byte in last buffer is not
# complete, we record how many byte needed to complete that character
# and skip these bytes here. We can choose to record those bytes as
# well and analyse the character once it is complete, but since a
# character will not make much difference, by simply skipping
# this character will simply our logic and improve performance.
i = self._mNeedToSkipCharNum
while i < aLen:
order, charLen = self.get_order(aBuf[i:i + 2])
i += charLen
if i > aLen:
self._mNeedToSkipCharNum = i - aLen
self._mLastCharOrder = -1
else:
if (order != -1) and (self._mLastCharOrder != -1):
self._mTotalRel += 1
if self._mTotalRel > MAX_REL_THRESHOLD:
self._mDone = True
break
self._mRelSample[jp2CharContext[self._mLastCharOrder][order]] += 1
self._mLastCharOrder = order
def got_enough_data(self):
return self._mTotalRel > ENOUGH_REL_THRESHOLD
def get_confidence(self):
# This is just one way to calculate confidence. It works well for me.
if self._mTotalRel > MINIMUM_DATA_THRESHOLD:
return (self._mTotalRel - self._mRelSample[0]) / self._mTotalRel
else:
return DONT_KNOW
def get_order(self, aBuf):
return -1, 1
class SJISContextAnalysis(JapaneseContextAnalysis):
def get_order(self, aBuf):
if not aBuf:
return -1, 1
# find out current char's byte length
first_char = wrap_ord(aBuf[0])
if ((0x81 <= first_char <= 0x9F) or (0xE0 <= first_char <= 0xFC)):
charLen = 2
else:
charLen = 1
# return its order if it is hiragana
if len(aBuf) > 1:
second_char = wrap_ord(aBuf[1])
if (first_char == 202) and (0x9F <= second_char <= 0xF1):
return second_char - 0x9F, charLen
return -1, charLen
class EUCJPContextAnalysis(JapaneseContextAnalysis):
def get_order(self, aBuf):
if not aBuf:
return -1, 1
# find out current char's byte length
first_char = wrap_ord(aBuf[0])
if (first_char == 0x8E) or (0xA1 <= first_char <= 0xFE):
charLen = 2
elif first_char == 0x8F:
charLen = 3
else:
charLen = 1
# return its order if it is hiragana
if len(aBuf) > 1:
second_char = wrap_ord(aBuf[1])
if (first_char == 0xA4) and (0xA1 <= second_char <= 0xF3):
return second_char - 0xA1, charLen
return -1, charLen
# flake8: noqa
|
gpl-3.0
|
[
6565,
16427,
5113,
8068,
11945,
199,
3,
710,
12769,
5495,
365,
17728,
13338,
707,
1890,
1233,
14,
199,
3,
199,
3,
710,
6026,
9607,
402,
314,
12769,
5495,
365,
199,
3,
20433,
18686,
11098,
14,
199,
3,
20825,
2737,
701,
314,
6026,
9607,
787,
1898,
334,
35,
9,
19960,
199,
3,
314,
6026,
9607,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
17636,
8,
83,
304,
199,
3,
257,
7173,
19641,
446,
1844,
370,
2018,
199,
3,
199,
3,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
1933,
12,
12066,
11844,
12,
8226,
12,
4828,
199,
3,
11315,
13,
10067,
221,
8217,
199,
19054,
7729,
5113,
8068,
21186,
199,
199,
504,
1275,
5819,
492,
4816,
63,
2181,
199,
199,
7125,
63,
3359,
63,
22690,
275,
1227,
199,
31874,
63,
43,
14283,
275,
446,
17,
199,
15577,
10134,
40,
63,
13604,
63,
19307,
275,
2948,
199,
4283,
63,
13604,
63,
19307,
275,
5198,
199,
4896,
27078,
63,
3998,
63,
19307,
275,
841,
199,
199,
3,
961,
365,
13759,
23161,
499,
13,
1560,
3414,
1817,
12,
314,
1329,
315,
1924,
4917,
8469,
2399,
9857,
4637,
199,
11538,
18,
1610,
2998,
275,
334,
199,
8,
16,
12,
16,
12,
16,
12,
18,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
17,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
17,
12,
16,
12,
16,
12,
16,
12,
17,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
17,
395,
199,
8,
18,
12,
20,
12,
16,
12,
20,
12,
16,
12,
19,
12,
16,
12,
20,
12,
16,
12,
19,
12,
20,
12,
20,
12,
20,
12,
18,
12,
20,
12,
19,
12,
19,
12,
20,
12,
19,
12,
18,
12,
19,
12,
19,
12,
20,
12,
18,
12,
19,
12,
19,
12,
19,
12,
18,
12,
20,
12,
17,
12,
20,
12,
19,
12,
19,
12,
17,
12,
21,
12,
20,
12,
19,
12,
20,
12,
19,
12,
20,
12,
19,
12,
21,
12,
19,
12,
16,
12,
19,
12,
21,
12,
20,
12,
18,
12,
16,
12,
19,
12,
17,
12,
16,
12,
19,
12,
19,
12,
16,
12,
19,
12,
19,
12,
16,
12,
17,
12,
17,
12,
16,
12,
20,
12,
19,
12,
16,
12,
19,
12,
19,
12,
16,
12,
20,
12,
16,
12,
18,
12,
16,
12,
19,
12,
21,
12,
21,
12,
21,
12,
21,
12,
20,
12,
16,
12,
20,
12,
17,
12,
16,
12,
19,
12,
20,
395,
199,
8,
16,
12,
16,
12,
17,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
17,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
18,
395,
199,
8,
16,
12,
20,
12,
16,
12,
21,
12,
16,
12,
21,
12,
16,
12,
20,
12,
16,
12,
20,
12,
21,
12,
20,
12,
20,
12,
19,
12,
21,
12,
19,
12,
21,
12,
17,
12,
21,
12,
19,
12,
20,
12,
19,
12,
20,
12,
20,
12,
19,
12,
20,
12,
19,
12,
19,
12,
20,
12,
19,
12,
21,
12,
20,
12,
20,
12,
19,
12,
21,
12,
21,
12,
19,
12,
21,
12,
21,
12,
21,
12,
19,
12,
21,
12,
21,
12,
19,
12,
20,
12,
21,
12,
21,
12,
19,
12,
17,
12,
19,
12,
18,
12,
16,
12,
19,
12,
20,
12,
16,
12,
20,
12,
18,
12,
16,
12,
20,
12,
18,
12,
17,
12,
21,
12,
19,
12,
18,
12,
19,
12,
21,
12,
16,
12,
20,
12,
16,
12,
18,
12,
16,
12,
21,
12,
20,
12,
20,
12,
21,
12,
20,
12,
21,
12,
16,
12,
20,
12,
16,
12,
16,
12,
20,
12,
20,
395,
199,
8,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16
] |
[
16427,
5113,
8068,
11945,
199,
3,
710,
12769,
5495,
365,
17728,
13338,
707,
1890,
1233,
14,
199,
3,
199,
3,
710,
6026,
9607,
402,
314,
12769,
5495,
365,
199,
3,
20433,
18686,
11098,
14,
199,
3,
20825,
2737,
701,
314,
6026,
9607,
787,
1898,
334,
35,
9,
19960,
199,
3,
314,
6026,
9607,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
17636,
8,
83,
304,
199,
3,
257,
7173,
19641,
446,
1844,
370,
2018,
199,
3,
199,
3,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
1933,
12,
12066,
11844,
12,
8226,
12,
4828,
199,
3,
11315,
13,
10067,
221,
8217,
199,
19054,
7729,
5113,
8068,
21186,
199,
199,
504,
1275,
5819,
492,
4816,
63,
2181,
199,
199,
7125,
63,
3359,
63,
22690,
275,
1227,
199,
31874,
63,
43,
14283,
275,
446,
17,
199,
15577,
10134,
40,
63,
13604,
63,
19307,
275,
2948,
199,
4283,
63,
13604,
63,
19307,
275,
5198,
199,
4896,
27078,
63,
3998,
63,
19307,
275,
841,
199,
199,
3,
961,
365,
13759,
23161,
499,
13,
1560,
3414,
1817,
12,
314,
1329,
315,
1924,
4917,
8469,
2399,
9857,
4637,
199,
11538,
18,
1610,
2998,
275,
334,
199,
8,
16,
12,
16,
12,
16,
12,
18,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
17,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
17,
12,
16,
12,
16,
12,
16,
12,
17,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
17,
395,
199,
8,
18,
12,
20,
12,
16,
12,
20,
12,
16,
12,
19,
12,
16,
12,
20,
12,
16,
12,
19,
12,
20,
12,
20,
12,
20,
12,
18,
12,
20,
12,
19,
12,
19,
12,
20,
12,
19,
12,
18,
12,
19,
12,
19,
12,
20,
12,
18,
12,
19,
12,
19,
12,
19,
12,
18,
12,
20,
12,
17,
12,
20,
12,
19,
12,
19,
12,
17,
12,
21,
12,
20,
12,
19,
12,
20,
12,
19,
12,
20,
12,
19,
12,
21,
12,
19,
12,
16,
12,
19,
12,
21,
12,
20,
12,
18,
12,
16,
12,
19,
12,
17,
12,
16,
12,
19,
12,
19,
12,
16,
12,
19,
12,
19,
12,
16,
12,
17,
12,
17,
12,
16,
12,
20,
12,
19,
12,
16,
12,
19,
12,
19,
12,
16,
12,
20,
12,
16,
12,
18,
12,
16,
12,
19,
12,
21,
12,
21,
12,
21,
12,
21,
12,
20,
12,
16,
12,
20,
12,
17,
12,
16,
12,
19,
12,
20,
395,
199,
8,
16,
12,
16,
12,
17,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
17,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
18,
395,
199,
8,
16,
12,
20,
12,
16,
12,
21,
12,
16,
12,
21,
12,
16,
12,
20,
12,
16,
12,
20,
12,
21,
12,
20,
12,
20,
12,
19,
12,
21,
12,
19,
12,
21,
12,
17,
12,
21,
12,
19,
12,
20,
12,
19,
12,
20,
12,
20,
12,
19,
12,
20,
12,
19,
12,
19,
12,
20,
12,
19,
12,
21,
12,
20,
12,
20,
12,
19,
12,
21,
12,
21,
12,
19,
12,
21,
12,
21,
12,
21,
12,
19,
12,
21,
12,
21,
12,
19,
12,
20,
12,
21,
12,
21,
12,
19,
12,
17,
12,
19,
12,
18,
12,
16,
12,
19,
12,
20,
12,
16,
12,
20,
12,
18,
12,
16,
12,
20,
12,
18,
12,
17,
12,
21,
12,
19,
12,
18,
12,
19,
12,
21,
12,
16,
12,
20,
12,
16,
12,
18,
12,
16,
12,
21,
12,
20,
12,
20,
12,
21,
12,
20,
12,
21,
12,
16,
12,
20,
12,
16,
12,
16,
12,
20,
12,
20,
395,
199,
8,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
12,
16,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
systers/mailman-old-archive
|
src/mailman/utilities/modules.py
|
7
|
3895
|
# Copyright (C) 2009-2015 by the Free Software Foundation, Inc.
#
# This file is part of GNU Mailman.
#
# GNU Mailman is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along with
# GNU Mailman. If not, see <http://www.gnu.org/licenses/>.
"""Package and module utilities."""
__all__ = [
'call_name',
'expand_path',
'find_components',
'find_name',
'scan_module',
]
import os
import sys
from pkg_resources import resource_filename, resource_listdir
def find_name(dotted_name):
"""Import and return the named object in package space.
:param dotted_name: The dotted module path name to the object.
:type dotted_name: string
:return: The object.
:rtype: object
"""
package_path, dot, object_name = dotted_name.rpartition('.')
__import__(package_path)
return getattr(sys.modules[package_path], object_name)
def call_name(dotted_name, *args, **kws):
"""Imports and calls the named object in package space.
:param dotted_name: The dotted module path name to the object.
:type dotted_name: string
:param args: The positional arguments.
:type args: tuple
:param kws: The keyword arguments.
:type kws: dict
:return: The object.
:rtype: object
"""
named_callable = find_name(dotted_name)
return named_callable(*args, **kws)
def scan_module(module, interface):
"""Return all the items in a module that conform to an interface.
:param module: A module object. The module's `__all__` will be scanned.
:type module: module
:param interface: The interface that returned objects must conform to.
:type interface: `Interface`
:return: The sequence of matching components.
:rtype: objects implementing `interface`
"""
missing = object()
for name in module.__all__:
component = getattr(module, name, missing)
assert component is not missing, (
'%s has bad __all__: %s' % (module, name))
if interface.implementedBy(component):
yield component
def find_components(package, interface):
"""Find components which conform to a given interface.
Search all the modules in a given package, returning an iterator over all
objects found that conform to the given interface.
:param package: The package path to search.
:type package: string
:param interface: The interface that returned objects must conform to.
:type interface: `Interface`
:return: The sequence of matching components.
:rtype: objects implementing `interface`
"""
for filename in resource_listdir(package, ''):
basename, extension = os.path.splitext(filename)
if extension != '.py':
continue
module_name = '{0}.{1}'.format(package, basename)
__import__(module_name, fromlist='*')
module = sys.modules[module_name]
if not hasattr(module, '__all__'):
continue
for component in scan_module(module, interface):
yield component
def expand_path(url):
"""Expand a python: path, returning the absolute file system path."""
# Is the context coming from a file system or Python path?
if url.startswith('python:'):
resource_path = url[7:]
package, dot, resource = resource_path.rpartition('.')
return resource_filename(package, resource + '.cfg')
else:
return url
|
gpl-3.0
|
[
3,
1898,
334,
35,
9,
8937,
13,
7806,
701,
314,
2868,
2290,
2752,
12,
3277,
14,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
1664,
18027,
1237,
14,
199,
3,
199,
3,
1664,
18027,
1237,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
1334,
199,
3,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
314,
2868,
199,
3,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
199,
3,
1263,
2945,
1015,
14,
199,
3,
199,
3,
1664,
18027,
1237,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
2428,
199,
3,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
3169,
503,
199,
3,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
1696,
1684,
844,
367,
199,
3,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
3180,
543,
199,
3,
1664,
18027,
1237,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
624,
8599,
436,
859,
15841,
1041,
199,
199,
363,
452,
363,
275,
359,
272,
283,
1250,
63,
354,
297,
272,
283,
4441,
63,
515,
297,
272,
283,
1623,
63,
4608,
297,
272,
283,
1623,
63,
354,
297,
272,
283,
6282,
63,
578,
297,
272,
1622,
421,
199,
646,
747,
199,
646,
984,
199,
199,
504,
5496,
63,
4435,
492,
2073,
63,
1501,
12,
2073,
63,
7374,
4388,
201,
199,
318,
2342,
63,
354,
8,
19404,
63,
354,
304,
272,
408,
6295,
436,
372,
314,
4310,
909,
315,
2559,
4601,
14,
339,
520,
635,
18947,
63,
354,
26,
710,
18947,
859,
931,
536,
370,
314,
909,
14,
272,
520,
466,
18947,
63,
354,
26,
1059,
272,
520,
1107,
26,
710,
909,
14,
272,
520,
4500,
26,
909,
272,
408,
272,
2559,
63,
515,
12,
6308,
12,
909,
63,
354,
275,
18947,
63,
354,
14,
25817,
7563,
272,
636,
646,
721,
2491,
63,
515,
9,
272,
372,
2519,
8,
1274,
14,
3112,
59,
2491,
63,
515,
467,
909,
63,
354,
9,
4388,
201,
199,
318,
1240,
63,
354,
8,
19404,
63,
354,
12,
627,
589,
12,
1011,
28769,
304,
272,
408,
32447,
436,
4882,
314,
4310,
909,
315,
2559,
4601,
14,
339,
520,
635,
18947,
63,
354,
26,
710,
18947,
859,
931,
536,
370,
314,
909,
14,
272,
520,
466,
18947,
63,
354,
26,
1059,
272,
520,
635,
1249,
26,
710,
11333,
2368,
14,
272,
520,
466,
1249,
26,
2008,
272,
520,
635,
4775,
83,
26,
710,
4252,
2368,
14,
272,
520,
466,
4775,
83,
26,
1211,
272,
520,
1107,
26,
710,
909,
14,
272,
520,
4500,
26,
909,
272,
408,
272,
4310,
63,
8296,
275,
2342,
63,
354,
8,
19404,
63,
354,
9,
272,
372,
4310,
63,
8296,
2031,
589,
12,
1011,
28769,
9,
4388,
201,
199,
318,
8000,
63,
578,
8,
578,
12,
3217,
304,
272,
408,
1767,
1006,
314,
2974,
315,
282,
859,
626,
26449,
370,
376,
3217,
14,
339,
520,
635,
859,
26,
437,
859,
909,
14,
221,
710,
859,
1159,
26856,
452,
29341,
911,
506,
28261,
14,
272,
520,
466,
859,
26,
859,
272,
520,
635,
3217,
26,
710,
3217,
626,
2138,
2251,
1471,
26449,
370,
14,
272,
520,
466,
3217,
26,
658,
4267,
64,
272,
520,
1107,
26,
710,
3414,
402,
4877,
7323,
14,
272,
520,
4500,
26,
2251,
18234,
658,
3266,
64,
272,
408,
272,
4124,
275,
909,
342,
272,
367,
536,
315,
859,
855,
452,
10651,
267,
3931,
275,
2519,
8,
578,
12,
536,
12,
4124,
9,
267,
702,
3931,
365,
440,
4124,
12,
334,
288,
1543,
83,
965,
4875,
636,
452,
10651,
450,
83,
7,
450,
334,
578,
12,
536,
430,
267,
340,
3217,
14,
13825,
2175,
8,
3173,
304,
288,
1995,
3931,
4388,
201,
199,
318,
2342,
63,
4608,
8,
2491,
12,
3217,
304,
272,
408,
6591,
7323,
1314,
26449,
370,
282,
1627,
3217,
14,
339,
8730,
1006,
314,
4621,
315,
282,
1627,
2559,
12,
8152,
376,
6122,
1806,
1006,
272,
2251,
1911,
626,
26449,
370,
314,
1627,
3217,
14,
339,
520,
635,
2559,
26,
710,
2559,
931,
370,
2754,
14,
272,
520,
466,
2559,
26,
1059,
272,
520,
635,
3217,
26,
710,
3217,
626,
2138,
2251,
1471,
26449,
370,
14,
272,
520,
466,
3217,
26,
658,
4267,
64,
272,
520,
1107,
26,
710,
3414,
402,
4877,
7323,
14,
272,
520,
4500,
26,
2251,
18234,
658,
3266,
64,
272,
408,
272,
367,
1788,
315,
2073,
63,
7374,
8,
2491,
12,
21019,
267,
9593,
12,
3329,
275,
747,
14,
515,
14,
7973,
8,
1501,
9,
267,
340,
3329,
1137,
1987,
647,
356,
288,
1980,
267,
859,
63,
354,
275,
5041,
16,
26944,
17,
5285,
908,
8,
2491,
12,
9593,
9,
267,
636,
646,
721,
578,
63,
354,
12,
25321,
534,
13418,
267,
859,
275,
984,
14,
3112,
59,
578,
63,
354,
61,
267,
340,
440,
2688,
8,
578,
12,
2560,
452,
12168,
288,
1980,
267,
367,
3931,
315,
8000,
63,
578,
8,
578,
12,
3217,
304,
288,
1995,
3931,
4388,
201,
199,
318,
6544,
63,
515,
8,
633,
304,
272,
408,
12839,
282,
2366,
26,
931,
12,
8152,
314,
3679,
570,
2656,
931,
1041,
272,
327,
6596,
314,
1067,
17262,
687,
282,
570,
2656,
503,
2018,
931,
31,
272,
340,
1166,
14,
2460,
360,
1548,
23117,
267,
2073,
63,
515,
275,
1166,
59,
23,
2938,
267,
2559,
12,
6308,
12,
2073,
275,
2073,
63,
515,
14,
25817,
7563,
267,
372,
2073,
63,
1501,
8,
2491,
12,
2073,
435,
1987,
4128,
358,
272,
587,
26,
267,
372,
1166,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
334,
35,
9,
8937,
13,
7806,
701,
314,
2868,
2290,
2752,
12,
3277,
14,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
1664,
18027,
1237,
14,
199,
3,
199,
3,
1664,
18027,
1237,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
1334,
199,
3,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
314,
2868,
199,
3,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
199,
3,
1263,
2945,
1015,
14,
199,
3,
199,
3,
1664,
18027,
1237,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
2428,
199,
3,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
3169,
503,
199,
3,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
1696,
1684,
844,
367,
199,
3,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
3180,
543,
199,
3,
1664,
18027,
1237,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
624,
8599,
436,
859,
15841,
1041,
199,
199,
363,
452,
363,
275,
359,
272,
283,
1250,
63,
354,
297,
272,
283,
4441,
63,
515,
297,
272,
283,
1623,
63,
4608,
297,
272,
283,
1623,
63,
354,
297,
272,
283,
6282,
63,
578,
297,
272,
1622,
421,
199,
646,
747,
199,
646,
984,
199,
199,
504,
5496,
63,
4435,
492,
2073,
63,
1501,
12,
2073,
63,
7374,
4388,
201,
199,
318,
2342,
63,
354,
8,
19404,
63,
354,
304,
272,
408,
6295,
436,
372,
314,
4310,
909,
315,
2559,
4601,
14,
339,
520,
635,
18947,
63,
354,
26,
710,
18947,
859,
931,
536,
370,
314,
909,
14,
272,
520,
466,
18947,
63,
354,
26,
1059,
272,
520,
1107,
26,
710,
909,
14,
272,
520,
4500,
26,
909,
272,
408,
272,
2559,
63,
515,
12,
6308,
12,
909,
63,
354,
275,
18947,
63,
354,
14,
25817,
7563,
272,
636,
646,
721,
2491,
63,
515,
9,
272,
372,
2519,
8,
1274,
14,
3112,
59,
2491,
63,
515,
467,
909,
63,
354,
9,
4388,
201,
199,
318,
1240,
63,
354,
8,
19404,
63,
354,
12,
627,
589,
12,
1011,
28769,
304,
272,
408,
32447,
436,
4882,
314,
4310,
909,
315,
2559,
4601,
14,
339,
520,
635,
18947,
63,
354,
26,
710,
18947,
859,
931,
536,
370,
314,
909,
14,
272,
520,
466,
18947,
63,
354,
26,
1059,
272,
520,
635,
1249,
26,
710,
11333,
2368,
14,
272,
520,
466,
1249,
26,
2008,
272,
520,
635,
4775,
83,
26,
710,
4252,
2368,
14,
272,
520,
466,
4775,
83,
26,
1211,
272,
520,
1107,
26,
710,
909,
14,
272,
520,
4500,
26,
909,
272,
408,
272,
4310,
63,
8296,
275,
2342,
63,
354,
8,
19404,
63,
354,
9,
272,
372,
4310,
63,
8296,
2031,
589,
12,
1011,
28769,
9,
4388,
201,
199,
318,
8000,
63,
578,
8,
578,
12,
3217,
304,
272,
408,
1767,
1006,
314,
2974,
315,
282,
859,
626,
26449,
370,
376,
3217,
14,
339,
520,
635,
859,
26,
437,
859,
909,
14,
221,
710,
859,
1159,
26856,
452,
29341,
911,
506,
28261,
14,
272,
520,
466,
859,
26,
859,
272,
520,
635,
3217,
26,
710,
3217,
626,
2138,
2251,
1471,
26449,
370,
14,
272,
520,
466,
3217,
26,
658,
4267,
64,
272,
520,
1107,
26,
710,
3414,
402,
4877,
7323,
14,
272,
520,
4500,
26,
2251,
18234,
658,
3266,
64,
272,
408,
272,
4124,
275,
909,
342,
272,
367,
536,
315,
859,
855,
452,
10651,
267,
3931,
275,
2519,
8,
578,
12,
536,
12,
4124,
9,
267,
702,
3931,
365,
440,
4124,
12,
334,
288,
1543,
83,
965,
4875,
636,
452,
10651,
450,
83,
7,
450,
334,
578,
12,
536,
430,
267,
340,
3217,
14,
13825,
2175,
8,
3173,
304,
288,
1995,
3931,
4388,
201,
199,
318,
2342,
63,
4608,
8,
2491,
12,
3217,
304,
272,
408,
6591,
7323,
1314,
26449,
370,
282,
1627,
3217,
14,
339,
8730,
1006,
314,
4621,
315,
282,
1627,
2559,
12,
8152,
376,
6122,
1806,
1006,
272,
2251,
1911,
626,
26449,
370,
314,
1627,
3217,
14,
339,
520,
635,
2559,
26,
710,
2559,
931,
370,
2754,
14,
272,
520,
466,
2559,
26,
1059,
272,
520,
635,
3217,
26,
710,
3217,
626,
2138,
2251,
1471,
26449,
370,
14,
272,
520,
466,
3217,
26,
658,
4267,
64,
272,
520,
1107,
26,
710,
3414,
402,
4877,
7323,
14,
272,
520,
4500,
26,
2251,
18234,
658,
3266,
64,
272,
408,
272,
367,
1788,
315,
2073,
63,
7374,
8,
2491,
12,
21019,
267,
9593,
12,
3329,
275,
747,
14,
515,
14,
7973,
8,
1501,
9,
267,
340,
3329,
1137,
1987,
647,
356,
288,
1980,
267,
859,
63,
354,
275,
5041,
16,
26944,
17,
5285,
908,
8,
2491,
12,
9593,
9,
267,
636,
646,
721,
578,
63,
354,
12,
25321,
534,
13418,
267,
859,
275,
984,
14,
3112,
59,
578,
63,
354,
61,
267,
340,
440,
2688,
8,
578,
12,
2560,
452,
12168,
288,
1980,
267,
367,
3931,
315,
8000,
63,
578,
8,
578,
12,
3217,
304,
288,
1995,
3931,
4388,
201,
199,
318,
6544,
63,
515,
8,
633,
304,
272,
408,
12839,
282,
2366,
26,
931,
12,
8152,
314,
3679,
570,
2656,
931,
1041,
272,
327,
6596,
314,
1067,
17262,
687,
282,
570,
2656,
503,
2018,
931,
31,
272,
340,
1166,
14,
2460,
360,
1548,
23117,
267,
2073,
63,
515,
275,
1166,
59,
23,
2938,
267,
2559,
12,
6308,
12,
2073,
275,
2073,
63,
515,
14,
25817,
7563,
267,
372,
2073,
63,
1501,
8,
2491,
12,
2073,
435,
1987,
4128,
358,
272,
587,
26,
267,
372,
1166,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
mapennell/ansible
|
lib/ansible/vars/hostvars.py
|
36
|
1758
|
# (c) 2012-2014, Michael DeHaan <michael.dehaan@gmail.com>
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible.template import Templar
__all__ = ['HostVars']
class HostVars(dict):
''' A special view of vars_cache that adds values from the inventory when needed. '''
def __init__(self, vars_manager, inventory, loader):
self._vars_manager = vars_manager
self._inventory = inventory
self._loader = loader
self._lookup = {}
#self.update(vars_cache)
def __getitem__(self, host_name):
if host_name not in self._lookup:
host = self._inventory.get_host(host_name)
result = self._vars_manager.get_vars(loader=self._loader, host=host)
#result.update(self._vars_cache.get(host, {}))
#templar = Templar(variables=self._vars_cache, loader=self._loader)
#self._lookup[host] = templar.template(result)
self._lookup[host_name] = result
return self._lookup[host_name]
|
gpl-3.0
|
[
3,
334,
67,
9,
6029,
13,
7280,
12,
16922,
22453,
665,
22333,
14,
24247,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
3,
4155,
2803,
1655,
2366,
19,
13,
2453,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
504,
3242,
14,
1160,
492,
12540,
9828,
199,
199,
363,
452,
363,
275,
788,
4965,
16270,
418,
199,
199,
533,
10891,
16270,
8,
807,
304,
272,
1449,
437,
4539,
2455,
402,
6802,
63,
1637,
626,
9584,
1338,
687,
314,
8200,
1380,
4346,
14,
1449,
339,
347,
636,
826,
721,
277,
12,
6802,
63,
2609,
12,
8200,
12,
5077,
304,
267,
291,
423,
2936,
63,
2609,
275,
6802,
63,
2609,
267,
291,
423,
7212,
259,
275,
8200,
267,
291,
423,
3422,
755,
275,
5077,
267,
291,
423,
3892,
755,
275,
1052,
398,
327,
277,
14,
873,
8,
2936,
63,
1637,
9,
339,
347,
636,
6095,
721,
277,
12,
1591,
63,
354,
304,
2728,
340,
1591,
63,
354,
440,
315,
291,
423,
3892,
26,
288,
1591,
275,
291,
423,
7212,
14,
362,
63,
1102,
8,
1102,
63,
354,
9,
288,
754,
275,
291,
423,
2936,
63,
2609,
14,
362,
63,
2936,
8,
3422,
29,
277,
423,
3422,
12,
1591,
29,
1102,
9,
288,
327,
1099,
14,
873,
8,
277,
423,
2936,
63,
1637,
14,
362,
8,
1102,
12,
17003,
288,
327,
26718,
275,
12540,
9828,
8,
3669,
29,
277,
423,
2936,
63,
1637,
12,
5077,
29,
277,
423,
3422,
9,
288,
327,
277,
423,
3892,
59,
1102,
61,
275,
28038,
14,
1160,
8,
1099,
9,
288,
291,
423,
3892,
59,
1102,
63,
354,
61,
275,
754,
267,
372,
291,
423,
3892,
59,
1102,
63,
354,
61,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
334,
67,
9,
6029,
13,
7280,
12,
16922,
22453,
665,
22333,
14,
24247,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
3,
4155,
2803,
1655,
2366,
19,
13,
2453,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
504,
3242,
14,
1160,
492,
12540,
9828,
199,
199,
363,
452,
363,
275,
788,
4965,
16270,
418,
199,
199,
533,
10891,
16270,
8,
807,
304,
272,
1449,
437,
4539,
2455,
402,
6802,
63,
1637,
626,
9584,
1338,
687,
314,
8200,
1380,
4346,
14,
1449,
339,
347,
636,
826,
721,
277,
12,
6802,
63,
2609,
12,
8200,
12,
5077,
304,
267,
291,
423,
2936,
63,
2609,
275,
6802,
63,
2609,
267,
291,
423,
7212,
259,
275,
8200,
267,
291,
423,
3422,
755,
275,
5077,
267,
291,
423,
3892,
755,
275,
1052,
398,
327,
277,
14,
873,
8,
2936,
63,
1637,
9,
339,
347,
636,
6095,
721,
277,
12,
1591,
63,
354,
304,
2728,
340,
1591,
63,
354,
440,
315,
291,
423,
3892,
26,
288,
1591,
275,
291,
423,
7212,
14,
362,
63,
1102,
8,
1102,
63,
354,
9,
288,
754,
275,
291,
423,
2936,
63,
2609,
14,
362,
63,
2936,
8,
3422,
29,
277,
423,
3422,
12,
1591,
29,
1102,
9,
288,
327,
1099,
14,
873,
8,
277,
423,
2936,
63,
1637,
14,
362,
8,
1102,
12,
17003,
288,
327,
26718,
275,
12540,
9828,
8,
3669,
29,
277,
423,
2936,
63,
1637,
12,
5077,
29,
277,
423,
3422,
9,
288,
327,
277,
423,
3892,
59,
1102,
61,
275,
28038,
14,
1160,
8,
1099,
9,
288,
291,
423,
3892,
59,
1102,
63,
354,
61,
275,
754,
267,
372,
291,
423,
3892,
59,
1102,
63,
354,
61,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
alistairlow/tensorflow
|
tensorflow/contrib/graph_editor/tests/util_test.py
|
154
|
6110
|
# Copyright 2015 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Tests for tensorflow.contrib.graph_editor."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from tensorflow.contrib import graph_editor as ge
from tensorflow.python.framework import constant_op
from tensorflow.python.framework import dtypes
from tensorflow.python.framework import ops
from tensorflow.python.ops import math_ops
from tensorflow.python.platform import test
class UtilTest(test.TestCase):
def test_list_view(self):
"""Test for ge.util.ListView."""
l = [0, 1, 2]
lv = ge.util.ListView(l)
# Should not be the same id.
self.assertIsNot(l, lv)
# Should behave the same way than the original list.
self.assertTrue(len(lv) == 3 and lv[0] == 0 and lv[1] == 1 and lv[2] == 2)
# Should be read only.
with self.assertRaises(TypeError):
lv[0] = 0
def test_is_iterable(self):
"""Test for ge.util.is_iterable."""
self.assertTrue(ge.util.is_iterable([0, 1, 2]))
self.assertFalse(ge.util.is_iterable(3))
def test_unique_graph(self):
"""Test for ge.util.check_graphs and ge.util.get_unique_graph."""
g0 = ops.Graph()
with g0.as_default():
a0 = constant_op.constant(1)
b0 = constant_op.constant(2)
g1 = ops.Graph()
with g1.as_default():
a1 = constant_op.constant(1)
b1 = constant_op.constant(2)
# Same graph, should be fine.
self.assertIsNone(ge.util.check_graphs(a0, b0))
# Two different graphs, should assert.
with self.assertRaises(ValueError):
ge.util.check_graphs(a0, b0, a1, b1)
# a0 and b0 belongs to the same graph, should be fine.
self.assertEqual(ge.util.get_unique_graph([a0, b0]), g0)
# Different graph, should raise an error.
with self.assertRaises(ValueError):
ge.util.get_unique_graph([a0, b0, a1, b1])
def test_make_list_of_op(self):
"""Test for ge.util.make_list_of_op."""
g0 = ops.Graph()
with g0.as_default():
a0 = constant_op.constant(1)
b0 = constant_op.constant(2)
# Should extract the ops from the graph.
self.assertEqual(len(ge.util.make_list_of_op(g0)), 2)
# Should extract the ops from the tuple.
self.assertEqual(len(ge.util.make_list_of_op((a0.op, b0.op))), 2)
def test_make_list_of_t(self):
"""Test for ge.util.make_list_of_t."""
g0 = ops.Graph()
with g0.as_default():
a0 = constant_op.constant(1)
b0 = constant_op.constant(2)
c0 = math_ops.add(a0, b0) # pylint: disable=unused-variable
# Should extract the tensors from tre graph.
self.assertEqual(len(ge.util.make_list_of_t(g0)), 3)
# Should extract the tensors from the tuple
self.assertEqual(len(ge.util.make_list_of_t((a0, b0))), 2)
# Should extract the tensors and ignore the ops.
self.assertEqual(
len(ge.util.make_list_of_t(
(a0, a0.op, b0), ignore_ops=True)), 2)
def test_get_generating_consuming(self):
"""Test for ge.util.get_generating_ops and ge.util.get_generating_ops."""
g0 = ops.Graph()
with g0.as_default():
a0 = constant_op.constant(1)
b0 = constant_op.constant(2)
c0 = math_ops.add(a0, b0)
self.assertEqual(len(ge.util.get_generating_ops([a0, b0])), 2)
self.assertEqual(len(ge.util.get_consuming_ops([a0, b0])), 1)
self.assertEqual(len(ge.util.get_generating_ops([c0])), 1)
self.assertEqual(ge.util.get_consuming_ops([c0]), [])
def test_control_outputs(self):
"""Test for the ge.util.ControlOutputs class."""
g0 = ops.Graph()
with g0.as_default():
a0 = constant_op.constant(1)
b0 = constant_op.constant(2)
x0 = constant_op.constant(3)
with ops.control_dependencies([x0.op]):
c0 = math_ops.add(a0, b0) # pylint: disable=unused-variable
control_outputs = ge.util.ControlOutputs(g0).get_all()
self.assertEqual(len(control_outputs), 1)
self.assertEqual(len(control_outputs[x0.op]), 1)
self.assertIs(list(control_outputs[x0.op])[0], c0.op)
def test_scope(self):
"""Test simple path scope functionalities."""
self.assertEqual(ge.util.scope_finalize("foo/bar"), "foo/bar/")
self.assertEqual(ge.util.scope_dirname("foo/bar/op"), "foo/bar/")
self.assertEqual(ge.util.scope_basename("foo/bar/op"), "op")
def test_placeholder(self):
"""Test placeholder functionalities."""
g0 = ops.Graph()
with g0.as_default():
a0 = constant_op.constant(1, name="foo")
# Test placeholder name.
self.assertEqual(ge.util.placeholder_name(a0), "geph__foo_0")
self.assertEqual(ge.util.placeholder_name(None), "geph")
self.assertEqual(
ge.util.placeholder_name(
a0, scope="foo/"), "foo/geph__foo_0")
self.assertEqual(
ge.util.placeholder_name(
a0, scope="foo"), "foo/geph__foo_0")
self.assertEqual(ge.util.placeholder_name(None, scope="foo/"), "foo/geph")
self.assertEqual(ge.util.placeholder_name(None, scope="foo"), "foo/geph")
# Test placeholder creation.
g0 = ops.Graph()
with g0.as_default():
a0 = constant_op.constant(1, dtype=dtypes.float32, name="a0")
c0 = math_ops.add(
ge.util.make_placeholder_from_tensor(a0),
ge.util.make_placeholder_from_dtype_and_shape(dtype=dtypes.float32))
self.assertEqual(c0.op.inputs[0].op.name, "geph__a0_0")
self.assertEqual(c0.op.inputs[1].op.name, "geph")
if __name__ == "__main__":
test.main()
|
apache-2.0
|
[
3,
1898,
6900,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
2925,
367,
3228,
14,
2828,
14,
2180,
63,
7515,
1041,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
3228,
14,
2828,
492,
3343,
63,
7515,
465,
2312,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4413,
63,
411,
199,
504,
3228,
14,
1548,
14,
4857,
492,
6674,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3473,
63,
1483,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
421,
199,
533,
21248,
774,
8,
396,
14,
1746,
304,
819,
347,
511,
63,
513,
63,
1345,
8,
277,
304,
272,
408,
774,
367,
2312,
14,
1974,
14,
23239,
1041,
272,
634,
275,
359,
16,
12,
413,
12,
499,
61,
272,
20604,
275,
2312,
14,
1974,
14,
23239,
8,
76,
9,
272,
327,
7719,
440,
506,
314,
2011,
1305,
14,
272,
291,
14,
9422,
8,
76,
12,
20604,
9,
272,
327,
7719,
24062,
314,
2011,
4340,
2419,
314,
3379,
769,
14,
272,
291,
14,
1815,
8,
552,
8,
6371,
9,
508,
650,
436,
20604,
59,
16,
61,
508,
378,
436,
20604,
59,
17,
61,
508,
413,
436,
20604,
59,
18,
61,
508,
499,
9,
272,
327,
7719,
506,
1586,
1454,
14,
272,
543,
291,
14,
1855,
8,
4333,
304,
489,
20604,
59,
16,
61,
275,
378,
819,
347,
511,
63,
374,
63,
8147,
8,
277,
304,
272,
408,
774,
367,
2312,
14,
1974,
14,
374,
63,
8147,
1041,
272,
291,
14,
1815,
8,
303,
14,
1974,
14,
374,
63,
8147,
779,
16,
12,
413,
12,
499,
2459,
272,
291,
14,
3334,
8,
303,
14,
1974,
14,
374,
63,
8147,
8,
19,
430,
819,
347,
511,
63,
3235,
63,
2180,
8,
277,
304,
272,
408,
774,
367,
2312,
14,
1974,
14,
1074,
63,
16670,
436,
2312,
14,
1974,
14,
362,
63,
3235,
63,
2180,
1041,
272,
486,
16,
275,
4156,
14,
4578,
342,
272,
543,
486,
16,
14,
305,
63,
885,
837,
489,
282,
16,
275,
4413,
63,
411,
14,
4083,
8,
17,
9,
489,
330,
16,
275,
4413,
63,
411,
14,
4083,
8,
18,
9,
272,
486,
17,
275,
4156,
14,
4578,
342,
272,
543,
486,
17,
14,
305,
63,
885,
837,
489,
282,
17,
275,
4413,
63,
411,
14,
4083,
8,
17,
9,
489,
330,
17,
275,
4413,
63,
411,
14,
4083,
8,
18,
9,
272,
327,
14766,
3343,
12,
1077,
506,
15701,
14,
272,
291,
14,
7702,
8,
303,
14,
1974,
14,
1074,
63,
16670,
8,
65,
16,
12,
330,
16,
430,
272,
327,
16853,
3365,
18312,
12,
1077,
702,
14,
272,
543,
291,
14,
1855,
8,
3393,
304,
489,
2312,
14,
1974,
14,
1074,
63,
16670,
8,
65,
16,
12,
330,
16,
12,
282,
17,
12,
330,
17,
9,
272,
327,
282,
16,
436,
330,
16,
15006,
370,
314,
2011,
3343,
12,
1077,
506,
15701,
14,
272,
291,
14,
629,
8,
303,
14,
1974,
14,
362,
63,
3235,
63,
2180,
779,
65,
16,
12,
330,
16,
2522,
486,
16,
9,
272,
327,
18029,
640,
3343,
12,
1077,
746,
376,
1125,
14,
272,
543,
291,
14,
1855,
8,
3393,
304,
489,
2312,
14,
1974,
14,
362,
63,
3235,
63,
2180,
779,
65,
16,
12,
330,
16,
12,
282,
17,
12,
330,
17,
566,
819,
347,
511,
63,
1875,
63,
513,
63,
1618,
63,
411,
8,
277,
304,
272,
408,
774,
367,
2312,
14,
1974,
14,
1875,
63,
513,
63,
1618,
63,
411,
1041,
272,
486,
16,
275,
4156,
14,
4578,
342,
272,
543,
486,
16,
14,
305,
63,
885,
837,
489,
282,
16,
275,
4413,
63,
411,
14,
4083,
8,
17,
9,
489,
330,
16,
275,
4413,
63,
411,
14,
4083,
8,
18,
9,
272,
327,
7719,
5536,
314,
4156,
687,
314,
3343,
14,
272,
291,
14,
629,
8,
552,
8,
303,
14,
1974,
14,
1875,
63,
513,
63,
1618,
63,
411,
8,
71,
16,
1826,
499,
9,
272,
327,
7719,
5536,
314,
4156,
687,
314,
2008,
14,
272,
291,
14,
629,
8,
552,
8,
303,
14,
1974,
14,
1875,
63,
513,
63,
1618,
63,
411,
1332,
65,
16,
14,
411,
12,
330,
16,
14,
411,
11508,
499,
9,
819,
347,
511,
63,
1875,
63,
513,
63,
1618,
63,
84,
8,
277,
304,
272,
408,
774,
367,
2312,
14,
1974,
14,
1875,
63,
513,
63,
1618,
63,
84,
1041,
272,
486,
16,
275,
4156,
14,
4578,
342,
272,
543,
486,
16,
14,
305,
63,
885,
837,
489,
282,
16,
275,
4413,
63,
411,
14,
4083,
8,
17,
9,
489,
330,
16,
275,
4413,
63,
411,
14,
4083,
8,
18,
9,
489,
286,
16,
275,
3473,
63,
1483,
14,
525,
8,
65,
16,
12,
330,
16,
9,
221,
327,
4287,
26,
3507,
29,
8618,
13,
1975,
272,
327,
7719,
5536,
314,
10519,
687,
20991,
3343,
14,
272,
291,
14,
629,
8,
552,
8,
303,
14,
1974,
14,
1875,
63,
513,
63,
1618,
63,
84,
8,
71,
16,
1826,
650,
9,
272,
327,
7719,
5536,
314,
10519,
687,
314,
2008,
272,
291,
14,
629,
8,
552,
8,
303,
14,
1974,
14,
1875,
63,
513,
63,
1618,
63,
84,
1332,
65,
16,
12,
330,
16,
11508,
499,
9,
272,
327,
7719,
5536,
314,
10519,
436,
3686,
314,
4156,
14,
272,
291,
14
] |
[
1898,
6900,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
2925,
367,
3228,
14,
2828,
14,
2180,
63,
7515,
1041,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
3228,
14,
2828,
492,
3343,
63,
7515,
465,
2312,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4413,
63,
411,
199,
504,
3228,
14,
1548,
14,
4857,
492,
6674,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3473,
63,
1483,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
421,
199,
533,
21248,
774,
8,
396,
14,
1746,
304,
819,
347,
511,
63,
513,
63,
1345,
8,
277,
304,
272,
408,
774,
367,
2312,
14,
1974,
14,
23239,
1041,
272,
634,
275,
359,
16,
12,
413,
12,
499,
61,
272,
20604,
275,
2312,
14,
1974,
14,
23239,
8,
76,
9,
272,
327,
7719,
440,
506,
314,
2011,
1305,
14,
272,
291,
14,
9422,
8,
76,
12,
20604,
9,
272,
327,
7719,
24062,
314,
2011,
4340,
2419,
314,
3379,
769,
14,
272,
291,
14,
1815,
8,
552,
8,
6371,
9,
508,
650,
436,
20604,
59,
16,
61,
508,
378,
436,
20604,
59,
17,
61,
508,
413,
436,
20604,
59,
18,
61,
508,
499,
9,
272,
327,
7719,
506,
1586,
1454,
14,
272,
543,
291,
14,
1855,
8,
4333,
304,
489,
20604,
59,
16,
61,
275,
378,
819,
347,
511,
63,
374,
63,
8147,
8,
277,
304,
272,
408,
774,
367,
2312,
14,
1974,
14,
374,
63,
8147,
1041,
272,
291,
14,
1815,
8,
303,
14,
1974,
14,
374,
63,
8147,
779,
16,
12,
413,
12,
499,
2459,
272,
291,
14,
3334,
8,
303,
14,
1974,
14,
374,
63,
8147,
8,
19,
430,
819,
347,
511,
63,
3235,
63,
2180,
8,
277,
304,
272,
408,
774,
367,
2312,
14,
1974,
14,
1074,
63,
16670,
436,
2312,
14,
1974,
14,
362,
63,
3235,
63,
2180,
1041,
272,
486,
16,
275,
4156,
14,
4578,
342,
272,
543,
486,
16,
14,
305,
63,
885,
837,
489,
282,
16,
275,
4413,
63,
411,
14,
4083,
8,
17,
9,
489,
330,
16,
275,
4413,
63,
411,
14,
4083,
8,
18,
9,
272,
486,
17,
275,
4156,
14,
4578,
342,
272,
543,
486,
17,
14,
305,
63,
885,
837,
489,
282,
17,
275,
4413,
63,
411,
14,
4083,
8,
17,
9,
489,
330,
17,
275,
4413,
63,
411,
14,
4083,
8,
18,
9,
272,
327,
14766,
3343,
12,
1077,
506,
15701,
14,
272,
291,
14,
7702,
8,
303,
14,
1974,
14,
1074,
63,
16670,
8,
65,
16,
12,
330,
16,
430,
272,
327,
16853,
3365,
18312,
12,
1077,
702,
14,
272,
543,
291,
14,
1855,
8,
3393,
304,
489,
2312,
14,
1974,
14,
1074,
63,
16670,
8,
65,
16,
12,
330,
16,
12,
282,
17,
12,
330,
17,
9,
272,
327,
282,
16,
436,
330,
16,
15006,
370,
314,
2011,
3343,
12,
1077,
506,
15701,
14,
272,
291,
14,
629,
8,
303,
14,
1974,
14,
362,
63,
3235,
63,
2180,
779,
65,
16,
12,
330,
16,
2522,
486,
16,
9,
272,
327,
18029,
640,
3343,
12,
1077,
746,
376,
1125,
14,
272,
543,
291,
14,
1855,
8,
3393,
304,
489,
2312,
14,
1974,
14,
362,
63,
3235,
63,
2180,
779,
65,
16,
12,
330,
16,
12,
282,
17,
12,
330,
17,
566,
819,
347,
511,
63,
1875,
63,
513,
63,
1618,
63,
411,
8,
277,
304,
272,
408,
774,
367,
2312,
14,
1974,
14,
1875,
63,
513,
63,
1618,
63,
411,
1041,
272,
486,
16,
275,
4156,
14,
4578,
342,
272,
543,
486,
16,
14,
305,
63,
885,
837,
489,
282,
16,
275,
4413,
63,
411,
14,
4083,
8,
17,
9,
489,
330,
16,
275,
4413,
63,
411,
14,
4083,
8,
18,
9,
272,
327,
7719,
5536,
314,
4156,
687,
314,
3343,
14,
272,
291,
14,
629,
8,
552,
8,
303,
14,
1974,
14,
1875,
63,
513,
63,
1618,
63,
411,
8,
71,
16,
1826,
499,
9,
272,
327,
7719,
5536,
314,
4156,
687,
314,
2008,
14,
272,
291,
14,
629,
8,
552,
8,
303,
14,
1974,
14,
1875,
63,
513,
63,
1618,
63,
411,
1332,
65,
16,
14,
411,
12,
330,
16,
14,
411,
11508,
499,
9,
819,
347,
511,
63,
1875,
63,
513,
63,
1618,
63,
84,
8,
277,
304,
272,
408,
774,
367,
2312,
14,
1974,
14,
1875,
63,
513,
63,
1618,
63,
84,
1041,
272,
486,
16,
275,
4156,
14,
4578,
342,
272,
543,
486,
16,
14,
305,
63,
885,
837,
489,
282,
16,
275,
4413,
63,
411,
14,
4083,
8,
17,
9,
489,
330,
16,
275,
4413,
63,
411,
14,
4083,
8,
18,
9,
489,
286,
16,
275,
3473,
63,
1483,
14,
525,
8,
65,
16,
12,
330,
16,
9,
221,
327,
4287,
26,
3507,
29,
8618,
13,
1975,
272,
327,
7719,
5536,
314,
10519,
687,
20991,
3343,
14,
272,
291,
14,
629,
8,
552,
8,
303,
14,
1974,
14,
1875,
63,
513,
63,
1618,
63,
84,
8,
71,
16,
1826,
650,
9,
272,
327,
7719,
5536,
314,
10519,
687,
314,
2008,
272,
291,
14,
629,
8,
552,
8,
303,
14,
1974,
14,
1875,
63,
513,
63,
1618,
63,
84,
1332,
65,
16,
12,
330,
16,
11508,
499,
9,
272,
327,
7719,
5536,
314,
10519,
436,
3686,
314,
4156,
14,
272,
291,
14,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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f = '''
C FILE: FIB3.F
SUBROUTINE FIB(A,N)
C
C CALCULATE FIRST N FIBONACCI NUMBERS
C
INTEGER N
REAL*8 A(N)
Cf2py intent(in) n
Cf2py intent(out) a
Cf2py depend(n) a
DO I=1,N
IF (I.EQ.1) THEN
A(I) = 0.0D0
ELSEIF (I.EQ.2) THEN
A(I) = 1.0D0
ELSE
A(I) = A(I-1) + A(I-2)
ENDIF
ENDDO
END
C END FILE FIB3.F
'''
def source_func(ext, build_dir):
import os
from distutils.dep_util import newer
target = os.path.join(build_dir,'fib3.f')
if newer(__file__, target):
f = open(target,'w')
f.write(fib3_f)
f.close()
return [target]
def configuration(parent_package='',top_path=None):
from numpy.distutils.misc_util import Configuration
config = Configuration('gen_ext',parent_package,top_path)
config.add_extension('fib3',
[source_func]
)
return config
if __name__ == "__main__":
from numpy.distutils.core import setup
setup(configuration=configuration)
|
agpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
329,
66,
19,
63,
70,
275,
1449,
199,
35,
13024,
26,
481,
2100,
19,
14,
38,
489,
7605,
14999,
3565,
481,
2100,
8,
33,
12,
46,
9,
199,
35,
199,
35,
258,
445,
748,
35,
1293,
1951,
28137,
840,
653,
481,
2100,
615,
1348,
3553,
11576,
34,
3960,
199,
35,
489,
17086,
653,
489,
5363,
748,
10,
24,
437,
8,
46,
9,
199,
24304,
18,
647,
21020,
8,
262,
9,
302,
199,
24304,
18,
647,
21020,
8,
548,
9,
282,
199,
24304,
18,
647,
11687,
8,
78,
9,
282,
489,
3506,
473,
29,
17,
12,
46,
268,
8036,
334,
41,
14,
17420,
14,
17,
9,
27299,
288,
437,
8,
41,
9,
275,
378,
14,
16,
36,
16,
268,
22325,
899,
4656,
334,
41,
14,
17420,
14,
18,
9,
27299,
288,
437,
8,
41,
9,
275,
413,
14,
16,
36,
16,
268,
22325,
899,
288,
437,
8,
41,
9,
275,
437,
8,
41,
13,
17,
9,
435,
437,
8,
41,
13,
18,
9,
268,
5070,
1914,
38,
489,
7729,
1649,
489,
7729,
199,
35,
7729,
13024,
481,
2100,
19,
14,
38,
199,
2344,
199,
199,
318,
1350,
63,
1532,
8,
832,
12,
1900,
63,
694,
304,
272,
492,
747,
272,
687,
7065,
14,
2601,
63,
1974,
492,
15666,
272,
1347,
275,
747,
14,
515,
14,
904,
8,
1506,
63,
694,
2584,
329,
66,
19,
14,
70,
358,
272,
340,
15666,
3460,
493,
3108,
1347,
304,
267,
289,
275,
1551,
8,
1375,
2584,
87,
358,
267,
289,
14,
952,
8,
329,
66,
19,
63,
70,
9,
267,
289,
14,
1600,
342,
272,
372,
359,
1375,
61,
199,
199,
318,
2897,
8,
1708,
63,
2491,
4581,
2119,
63,
515,
29,
403,
304,
272,
687,
2680,
14,
13350,
14,
9923,
63,
1974,
492,
11595,
272,
1101,
275,
11595,
360,
2268,
63,
832,
297,
1708,
63,
2491,
12,
2119,
63,
515,
9,
272,
1101,
14,
525,
63,
3435,
360,
329,
66,
19,
297,
586,
359,
1365,
63,
1532,
61,
586,
776,
272,
372,
1101,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
687,
2680,
14,
13350,
14,
1018,
492,
3272,
272,
3272,
8,
4758,
29,
4758,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
329,
66,
19,
63,
70,
275,
1449,
199,
35,
13024,
26,
481,
2100,
19,
14,
38,
489,
7605,
14999,
3565,
481,
2100,
8,
33,
12,
46,
9,
199,
35,
199,
35,
258,
445,
748,
35,
1293,
1951,
28137,
840,
653,
481,
2100,
615,
1348,
3553,
11576,
34,
3960,
199,
35,
489,
17086,
653,
489,
5363,
748,
10,
24,
437,
8,
46,
9,
199,
24304,
18,
647,
21020,
8,
262,
9,
302,
199,
24304,
18,
647,
21020,
8,
548,
9,
282,
199,
24304,
18,
647,
11687,
8,
78,
9,
282,
489,
3506,
473,
29,
17,
12,
46,
268,
8036,
334,
41,
14,
17420,
14,
17,
9,
27299,
288,
437,
8,
41,
9,
275,
378,
14,
16,
36,
16,
268,
22325,
899,
4656,
334,
41,
14,
17420,
14,
18,
9,
27299,
288,
437,
8,
41,
9,
275,
413,
14,
16,
36,
16,
268,
22325,
899,
288,
437,
8,
41,
9,
275,
437,
8,
41,
13,
17,
9,
435,
437,
8,
41,
13,
18,
9,
268,
5070,
1914,
38,
489,
7729,
1649,
489,
7729,
199,
35,
7729,
13024,
481,
2100,
19,
14,
38,
199,
2344,
199,
199,
318,
1350,
63,
1532,
8,
832,
12,
1900,
63,
694,
304,
272,
492,
747,
272,
687,
7065,
14,
2601,
63,
1974,
492,
15666,
272,
1347,
275,
747,
14,
515,
14,
904,
8,
1506,
63,
694,
2584,
329,
66,
19,
14,
70,
358,
272,
340,
15666,
3460,
493,
3108,
1347,
304,
267,
289,
275,
1551,
8,
1375,
2584,
87,
358,
267,
289,
14,
952,
8,
329,
66,
19,
63,
70,
9,
267,
289,
14,
1600,
342,
272,
372,
359,
1375,
61,
199,
199,
318,
2897,
8,
1708,
63,
2491,
4581,
2119,
63,
515,
29,
403,
304,
272,
687,
2680,
14,
13350,
14,
9923,
63,
1974,
492,
11595,
272,
1101,
275,
11595,
360,
2268,
63,
832,
297,
1708,
63,
2491,
12,
2119,
63,
515,
9,
272,
1101,
14,
525,
63,
3435,
360,
329,
66,
19,
297,
586,
359,
1365,
63,
1532,
61,
586,
776,
272,
372,
1101,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
687,
2680,
14,
13350,
14,
1018,
492,
3272,
272,
3272,
8,
4758,
29,
4758,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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script works with Python 2.6, 2.7, 3.3 and 3.4.
"""
from __future__ import print_function
import re
import sys
# Python 2/3 compatibility:
# - iterating through bytes is different
# - codepoint2name lives in a different module
import platform
if platform.python_version_tuple()[0] == '2':
bytes_cons = lambda val, enc=None: bytearray(val)
from htmlentitydefs import codepoint2name
elif platform.python_version_tuple()[0] == '3':
bytes_cons = bytes
from html.entities import codepoint2name
# end compatibility code
codepoint2name[ord('-')] = 'hyphen';
# add some custom names to map characters that aren't in HTML
codepoint2name[ord(' ')] = 'space'
codepoint2name[ord('\'')] = 'squot'
codepoint2name[ord(',')] = 'comma'
codepoint2name[ord('.')] = 'dot'
codepoint2name[ord(':')] = 'colon'
codepoint2name[ord(';')] = 'semicolon'
codepoint2name[ord('/')] = 'slash'
codepoint2name[ord('%')] = 'percent'
codepoint2name[ord('#')] = 'hash'
codepoint2name[ord('(')] = 'paren_open'
codepoint2name[ord(')')] = 'paren_close'
codepoint2name[ord('[')] = 'bracket_open'
codepoint2name[ord(']')] = 'bracket_close'
codepoint2name[ord('{')] = 'brace_open'
codepoint2name[ord('}')] = 'brace_close'
codepoint2name[ord('*')] = 'star'
codepoint2name[ord('!')] = 'bang'
codepoint2name[ord('\\')] = 'backslash'
codepoint2name[ord('+')] = 'plus'
codepoint2name[ord('$')] = 'dollar'
codepoint2name[ord('=')] = 'equals'
codepoint2name[ord('?')] = 'question'
codepoint2name[ord('@')] = 'at_sign'
codepoint2name[ord('^')] = 'caret'
codepoint2name[ord('|')] = 'pipe'
codepoint2name[ord('~')] = 'tilde'
# this must match the equivalent function in qstr.c
def compute_hash(qstr, bytes_hash):
hash = 5381
for b in qstr:
hash = (hash * 33) ^ b
# Make sure that valid hash is never zero, zero means "hash not computed"
return (hash & ((1 << (8 * bytes_hash)) - 1)) or 1
def qstr_escape(qst):
def esc_char(m):
c = ord(m.group(0))
try:
name = codepoint2name[c]
except KeyError:
name = '0x%02x' % c
return "_" + name + '_'
return re.sub(r'[^A-Za-z0-9_]', esc_char, qst)
def parse_input_headers(infiles):
# read the qstrs in from the input files
qcfgs = {}
qstrs = {}
for infile in infiles:
with open(infile, 'rt') as f:
for line in f:
line = line.strip()
# is this a config line?
match = re.match(r'^QCFG\((.+), (.+)\)', line)
if match:
value = match.group(2)
if value[0] == '(' and value[-1] == ')':
# strip parenthesis from config value
value = value[1:-1]
qcfgs[match.group(1)] = value
continue
# is this a QSTR line?
match = re.match(r'^Q\((.*)\)$', line)
if not match:
continue
# get the qstr value
qstr = match.group(1)
# special case to specify control characters
if qstr == '\\n':
qstr = '\n'
# work out the corresponding qstr name
ident = qstr_escape(qstr)
# don't add duplicates
if ident in qstrs:
continue
# add the qstr to the list, with order number to retain original order in file
qstrs[ident] = (len(qstrs), ident, qstr)
if not qcfgs:
sys.stderr.write("ERROR: Empty preprocessor output - check for errors above\n")
sys.exit(1)
return qcfgs, qstrs
def make_bytes(cfg_bytes_len, cfg_bytes_hash, qstr):
qbytes = bytes_cons(qstr, 'utf8')
qlen = len(qbytes)
qhash = compute_hash(qbytes, cfg_bytes_hash)
if all(32 <= ord(c) <= 126 and c != '\\' and c != '"' for c in qstr):
# qstr is all printable ASCII so render it as-is (for easier debugging)
qdata = qstr
else:
# qstr contains non-printable codes so render entire thing as hex pairs
qdata = ''.join(('\\x%02x' % b) for b in qbytes)
if qlen >= (1 << (8 * cfg_bytes_len)):
print('qstr is too long:', qstr)
assert False
qlen_str = ('\\x%02x' * cfg_bytes_len) % tuple(((qlen >> (8 * i)) & 0xff) for i in range(cfg_bytes_len))
qhash_str = ('\\x%02x' * cfg_bytes_hash) % tuple(((qhash >> (8 * i)) & 0xff) for i in range(cfg_bytes_hash))
return '(const byte*)"%s%s" "%s"' % (qhash_str, qlen_str, qdata)
def print_qstr_data(qcfgs, qstrs):
# get config variables
cfg_bytes_len = int(qcfgs['BYTES_IN_LEN'])
cfg_bytes_hash = int(qcfgs['BYTES_IN_HASH'])
# print out the starter of the generated C header file
print('// This file was automatically generated by makeqstrdata.py')
print('')
# add NULL qstr with no hash or data
print('QDEF(MP_QSTR_NULL, (const byte*)"%s%s" "")' % ('\\x00' * cfg_bytes_hash, '\\x00' * cfg_bytes_len))
# go through each qstr and print it out
for order, ident, qstr in sorted(qstrs.values(), key=lambda x: x[0]):
qbytes = make_bytes(cfg_bytes_len, cfg_bytes_hash, qstr)
print('QDEF(MP_QSTR_%s, %s)' % (ident, qbytes))
def do_work(infiles):
qcfgs, qstrs = parse_input_headers(infiles)
print_qstr_data(qcfgs, qstrs)
if __name__ == "__main__":
do_work(sys.argv[1:])
|
mit
|
[
624,
199,
3498,
3066,
1894,
495,
570,
436,
1072,
1894,
495,
666,
543,
2582,
12,
2631,
436,
666,
2783,
14,
199,
199,
2765,
2884,
5419,
543,
2018,
499,
14,
22,
12,
499,
14,
23,
12,
650,
14,
19,
436,
650,
14,
20,
14,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
295,
199,
646,
984,
199,
199,
3,
2018,
499,
15,
19,
7163,
26,
199,
3,
257,
446,
25012,
4012,
2783,
365,
3365,
199,
3,
257,
446,
1233,
1403,
18,
354,
27576,
315,
282,
3365,
859,
199,
646,
4298,
199,
692,
4298,
14,
1548,
63,
1023,
63,
2960,
3430,
16,
61,
508,
283,
18,
356,
272,
2783,
63,
8704,
275,
2400,
1139,
12,
12011,
29,
403,
26,
11640,
8,
637,
9,
272,
687,
30010,
552,
1701,
8710,
492,
1233,
1403,
18,
354,
199,
4164,
4298,
14,
1548,
63,
1023,
63,
2960,
3430,
16,
61,
508,
283,
19,
356,
272,
2783,
63,
8704,
275,
2783,
272,
687,
3517,
14,
8327,
492,
1233,
1403,
18,
354,
199,
3,
1284,
7163,
1233,
199,
199,
19300,
18,
354,
59,
2181,
3654,
5440,
275,
283,
30215,
13619,
199,
199,
3,
1050,
2005,
3537,
1561,
370,
2341,
4110,
626,
10621,
1133,
315,
4163,
199,
19300,
18,
354,
59,
2181,
360,
283,
1874,
275,
283,
2638,
7,
199,
19300,
18,
354,
59,
2181,
2258,
7,
5440,
275,
283,
83,
5184,
7,
199,
19300,
18,
354,
59,
2181,
29972,
275,
283,
13184,
7,
199,
19300,
18,
354,
59,
2181,
7563,
61,
275,
283,
3287,
7,
199,
19300,
18,
354,
59,
2181,
6176,
5440,
275,
283,
12167,
7,
199,
19300,
18,
354,
59,
2181,
25282,
5440,
275,
283,
19290,
12167,
7,
199,
19300,
18,
354,
59,
2181,
2336,
5440,
275,
283,
7001,
7,
199,
19300,
18,
354,
59,
2181,
3508,
5440,
275,
283,
7045,
7,
199,
19300,
18,
354,
59,
2181,
7863,
5440,
275,
283,
2227,
7,
199,
19300,
18,
354,
59,
2181,
14097,
5440,
275,
283,
9575,
63,
1490,
7,
199,
19300,
18,
354,
59,
2181,
15938,
5440,
275,
283,
9575,
63,
1600,
7,
199,
19300,
18,
354,
59,
2181,
11894,
5440,
275,
283,
14594,
63,
1490,
7,
199,
19300,
18,
354,
59,
2181,
360,
61,
5440,
275,
283,
14594,
63,
1600,
7,
199,
19300,
18,
354,
59,
2181,
11117,
5440,
275,
283,
22359,
63,
1490,
7,
199,
19300,
18,
354,
59,
2181,
360,
93,
5440,
275,
283,
22359,
63,
1600,
7,
199,
19300,
18,
354,
59,
2181,
18225,
5440,
275,
283,
7848,
7,
199,
19300,
18,
354,
59,
2181,
16157,
5440,
275,
283,
66,
621,
7,
199,
19300,
18,
354,
59,
2181,
11671,
5440,
275,
283,
21509,
7,
199,
19300,
18,
354,
59,
2181,
19975,
5440,
275,
283,
6666,
7,
199,
19300,
18,
354,
59,
2181,
14676,
5440,
275,
283,
68,
25317,
7,
199,
19300,
18,
354,
59,
2181,
26800,
5440,
275,
283,
11332,
7,
199,
19300,
18,
354,
59,
2181,
360,
31,
5440,
275,
283,
4790,
7,
199,
19300,
18,
354,
59,
2181,
16591,
5440,
275,
283,
292,
63,
1037,
7,
199,
19300,
18,
354,
59,
2181,
9097,
5440,
275,
283,
696,
3292,
7,
199,
19300,
18,
354,
59,
2181,
20137,
5440,
275,
283,
4990,
7,
199,
19300,
18,
354,
59,
2181,
21114,
5440,
275,
283,
16488,
7,
199,
199,
3,
642,
1471,
1336,
314,
7353,
805,
315,
1894,
495,
14,
67,
199,
318,
4526,
63,
2227,
8,
81,
495,
12,
2783,
63,
2227,
304,
272,
2631,
275,
959,
16706,
272,
367,
330,
315,
1894,
495,
26,
267,
2631,
275,
334,
2227,
627,
9404,
9,
7167,
330,
272,
327,
4155,
3238,
626,
1686,
2631,
365,
7078,
4697,
12,
4697,
4910,
298,
2227,
440,
9235,
2,
272,
372,
334,
2227,
1253,
3666,
17,
5213,
334,
24,
627,
2783,
63,
2227,
430,
446,
413,
430,
503,
413,
199,
199,
318,
1894,
495,
63,
3765,
8,
81,
270,
304,
272,
347,
14683,
63,
1560,
8,
77,
304,
267,
286,
275,
6206,
8,
77,
14,
923,
8,
16,
430,
267,
862,
26,
288,
536,
275,
1233,
1403,
18,
354,
59,
67,
61,
267,
871,
4067,
26,
288,
536,
275,
283,
16,
88,
5,
996,
88,
7,
450,
286,
267,
372,
14220,
435,
536,
435,
14135,
272,
372,
295,
14,
954,
8,
82,
16122,
33,
13,
13163,
13,
90,
16,
13,
25,
63,
4300,
14683,
63,
1560,
12,
1894,
270,
9,
199,
199,
318,
2198,
63,
1210,
63,
2139,
8,
262,
1725,
304,
272,
327,
1586,
314,
1894,
16144,
315,
687,
314,
1324,
1584,
272,
1894,
2177,
458,
275,
1052,
272,
1894,
16144,
275,
1052,
272,
367,
14734,
315,
315,
1725,
26,
267,
543,
1551,
8,
13880,
12,
283,
2591,
358,
465,
289,
26,
288,
367,
1004,
315,
289,
26,
355,
1004,
275,
1004,
14,
1913,
342,
2234,
327,
365,
642,
282,
1101,
1004,
31,
355,
1336,
275,
295,
14,
1431,
8,
82,
4289,
49,
10118,
60,
1332,
6977,
395,
334,
6977,
2862,
3196,
1004,
9,
355,
340,
1336,
26,
490,
574,
275,
1336,
14,
923,
8,
18,
9,
490,
340,
574,
59,
16,
61,
508,
16746,
436,
574,
1988,
17,
61,
508,
5320,
356,
717,
327,
6202,
32002,
687,
1101,
574,
717,
574,
275,
574,
59,
17,
6809,
17,
61,
490,
1894,
2177,
458,
59,
1431,
14,
923,
8,
17,
1874,
275,
574,
490,
1980,
2234,
327,
365,
642,
282,
1413,
3027,
1004,
31,
355,
1336,
275,
295,
14,
1431,
8,
82,
4289,
49,
60,
1332,
2795,
2862,
29150,
1004,
9,
355,
340,
440,
1336,
26,
490,
1980,
2234,
327,
664,
314,
1894,
495,
574,
355,
1894,
495,
275,
1336,
14,
923,
8,
17,
9,
2234,
327,
4539,
1930,
370,
4165,
3304,
4110,
355,
340,
1894,
495,
508,
6468,
78,
356,
490,
1894,
495,
275,
1557,
78,
7,
2234,
327,
1736,
734,
314,
5226,
1894,
495,
536,
355,
12893,
275,
1894,
495,
63,
3765,
8,
81,
495,
9,
2234,
327,
2793,
1133,
1050,
15755,
355,
340,
12893,
315,
1894,
16144,
26,
490,
1980,
2234,
327,
1050,
314,
1894,
495,
370,
314,
769,
12,
543,
1865,
1329,
370,
8074,
3379,
1865,
315,
570,
355,
1894,
16144,
59,
5425,
61,
275,
334,
552,
8,
81,
16144,
395,
12893,
12,
1894,
495,
9,
339,
340,
440,
1894,
2177,
458,
26
] |
[
199,
3498,
3066,
1894,
495,
570,
436,
1072,
1894,
495,
666,
543,
2582,
12,
2631,
436,
666,
2783,
14,
199,
199,
2765,
2884,
5419,
543,
2018,
499,
14,
22,
12,
499,
14,
23,
12,
650,
14,
19,
436,
650,
14,
20,
14,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
295,
199,
646,
984,
199,
199,
3,
2018,
499,
15,
19,
7163,
26,
199,
3,
257,
446,
25012,
4012,
2783,
365,
3365,
199,
3,
257,
446,
1233,
1403,
18,
354,
27576,
315,
282,
3365,
859,
199,
646,
4298,
199,
692,
4298,
14,
1548,
63,
1023,
63,
2960,
3430,
16,
61,
508,
283,
18,
356,
272,
2783,
63,
8704,
275,
2400,
1139,
12,
12011,
29,
403,
26,
11640,
8,
637,
9,
272,
687,
30010,
552,
1701,
8710,
492,
1233,
1403,
18,
354,
199,
4164,
4298,
14,
1548,
63,
1023,
63,
2960,
3430,
16,
61,
508,
283,
19,
356,
272,
2783,
63,
8704,
275,
2783,
272,
687,
3517,
14,
8327,
492,
1233,
1403,
18,
354,
199,
3,
1284,
7163,
1233,
199,
199,
19300,
18,
354,
59,
2181,
3654,
5440,
275,
283,
30215,
13619,
199,
199,
3,
1050,
2005,
3537,
1561,
370,
2341,
4110,
626,
10621,
1133,
315,
4163,
199,
19300,
18,
354,
59,
2181,
360,
283,
1874,
275,
283,
2638,
7,
199,
19300,
18,
354,
59,
2181,
2258,
7,
5440,
275,
283,
83,
5184,
7,
199,
19300,
18,
354,
59,
2181,
29972,
275,
283,
13184,
7,
199,
19300,
18,
354,
59,
2181,
7563,
61,
275,
283,
3287,
7,
199,
19300,
18,
354,
59,
2181,
6176,
5440,
275,
283,
12167,
7,
199,
19300,
18,
354,
59,
2181,
25282,
5440,
275,
283,
19290,
12167,
7,
199,
19300,
18,
354,
59,
2181,
2336,
5440,
275,
283,
7001,
7,
199,
19300,
18,
354,
59,
2181,
3508,
5440,
275,
283,
7045,
7,
199,
19300,
18,
354,
59,
2181,
7863,
5440,
275,
283,
2227,
7,
199,
19300,
18,
354,
59,
2181,
14097,
5440,
275,
283,
9575,
63,
1490,
7,
199,
19300,
18,
354,
59,
2181,
15938,
5440,
275,
283,
9575,
63,
1600,
7,
199,
19300,
18,
354,
59,
2181,
11894,
5440,
275,
283,
14594,
63,
1490,
7,
199,
19300,
18,
354,
59,
2181,
360,
61,
5440,
275,
283,
14594,
63,
1600,
7,
199,
19300,
18,
354,
59,
2181,
11117,
5440,
275,
283,
22359,
63,
1490,
7,
199,
19300,
18,
354,
59,
2181,
360,
93,
5440,
275,
283,
22359,
63,
1600,
7,
199,
19300,
18,
354,
59,
2181,
18225,
5440,
275,
283,
7848,
7,
199,
19300,
18,
354,
59,
2181,
16157,
5440,
275,
283,
66,
621,
7,
199,
19300,
18,
354,
59,
2181,
11671,
5440,
275,
283,
21509,
7,
199,
19300,
18,
354,
59,
2181,
19975,
5440,
275,
283,
6666,
7,
199,
19300,
18,
354,
59,
2181,
14676,
5440,
275,
283,
68,
25317,
7,
199,
19300,
18,
354,
59,
2181,
26800,
5440,
275,
283,
11332,
7,
199,
19300,
18,
354,
59,
2181,
360,
31,
5440,
275,
283,
4790,
7,
199,
19300,
18,
354,
59,
2181,
16591,
5440,
275,
283,
292,
63,
1037,
7,
199,
19300,
18,
354,
59,
2181,
9097,
5440,
275,
283,
696,
3292,
7,
199,
19300,
18,
354,
59,
2181,
20137,
5440,
275,
283,
4990,
7,
199,
19300,
18,
354,
59,
2181,
21114,
5440,
275,
283,
16488,
7,
199,
199,
3,
642,
1471,
1336,
314,
7353,
805,
315,
1894,
495,
14,
67,
199,
318,
4526,
63,
2227,
8,
81,
495,
12,
2783,
63,
2227,
304,
272,
2631,
275,
959,
16706,
272,
367,
330,
315,
1894,
495,
26,
267,
2631,
275,
334,
2227,
627,
9404,
9,
7167,
330,
272,
327,
4155,
3238,
626,
1686,
2631,
365,
7078,
4697,
12,
4697,
4910,
298,
2227,
440,
9235,
2,
272,
372,
334,
2227,
1253,
3666,
17,
5213,
334,
24,
627,
2783,
63,
2227,
430,
446,
413,
430,
503,
413,
199,
199,
318,
1894,
495,
63,
3765,
8,
81,
270,
304,
272,
347,
14683,
63,
1560,
8,
77,
304,
267,
286,
275,
6206,
8,
77,
14,
923,
8,
16,
430,
267,
862,
26,
288,
536,
275,
1233,
1403,
18,
354,
59,
67,
61,
267,
871,
4067,
26,
288,
536,
275,
283,
16,
88,
5,
996,
88,
7,
450,
286,
267,
372,
14220,
435,
536,
435,
14135,
272,
372,
295,
14,
954,
8,
82,
16122,
33,
13,
13163,
13,
90,
16,
13,
25,
63,
4300,
14683,
63,
1560,
12,
1894,
270,
9,
199,
199,
318,
2198,
63,
1210,
63,
2139,
8,
262,
1725,
304,
272,
327,
1586,
314,
1894,
16144,
315,
687,
314,
1324,
1584,
272,
1894,
2177,
458,
275,
1052,
272,
1894,
16144,
275,
1052,
272,
367,
14734,
315,
315,
1725,
26,
267,
543,
1551,
8,
13880,
12,
283,
2591,
358,
465,
289,
26,
288,
367,
1004,
315,
289,
26,
355,
1004,
275,
1004,
14,
1913,
342,
2234,
327,
365,
642,
282,
1101,
1004,
31,
355,
1336,
275,
295,
14,
1431,
8,
82,
4289,
49,
10118,
60,
1332,
6977,
395,
334,
6977,
2862,
3196,
1004,
9,
355,
340,
1336,
26,
490,
574,
275,
1336,
14,
923,
8,
18,
9,
490,
340,
574,
59,
16,
61,
508,
16746,
436,
574,
1988,
17,
61,
508,
5320,
356,
717,
327,
6202,
32002,
687,
1101,
574,
717,
574,
275,
574,
59,
17,
6809,
17,
61,
490,
1894,
2177,
458,
59,
1431,
14,
923,
8,
17,
1874,
275,
574,
490,
1980,
2234,
327,
365,
642,
282,
1413,
3027,
1004,
31,
355,
1336,
275,
295,
14,
1431,
8,
82,
4289,
49,
60,
1332,
2795,
2862,
29150,
1004,
9,
355,
340,
440,
1336,
26,
490,
1980,
2234,
327,
664,
314,
1894,
495,
574,
355,
1894,
495,
275,
1336,
14,
923,
8,
17,
9,
2234,
327,
4539,
1930,
370,
4165,
3304,
4110,
355,
340,
1894,
495,
508,
6468,
78,
356,
490,
1894,
495,
275,
1557,
78,
7,
2234,
327,
1736,
734,
314,
5226,
1894,
495,
536,
355,
12893,
275,
1894,
495,
63,
3765,
8,
81,
495,
9,
2234,
327,
2793,
1133,
1050,
15755,
355,
340,
12893,
315,
1894,
16144,
26,
490,
1980,
2234,
327,
1050,
314,
1894,
495,
370,
314,
769,
12,
543,
1865,
1329,
370,
8074,
3379,
1865,
315,
570,
355,
1894,
16144,
59,
5425,
61,
275,
334,
552,
8,
81,
16144,
395,
12893,
12,
1894,
495,
9,
339,
340,
440,
1894,
2177,
458,
26,
0
] |
[
1,
1,
1,
1,
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elephant
|
elephant/test/test_change_point_detection.py
|
2
|
8884
|
# -*- coding: utf-8 -*-
import unittest
import neo
import numpy as np
import quantities as pq
from numpy.testing import assert_array_almost_equal, assert_allclose
import elephant.change_point_detection as mft
class FilterTestCase(unittest.TestCase):
def setUp(self):
self.test_array = [0.4, 0.5, 0.65, 0.7, 0.9, 1.15, 1.2, 1.9]
# spks_ri = [0.9, 1.15, 1.2]
# spk_le = [0.4, 0.5, 0.65, 0.7]
mu_ri = (0.25 + 0.05) / 2
mu_le = (0.1 + 0.15 + 0.05) / 3
sigma_ri = ((0.25 - 0.15) ** 2 + (0.05 - 0.15) ** 2) / 2
sigma_le = ((0.1 - 0.1) ** 2 + (0.15 - 0.1) ** 2 + (
0.05 - 0.1) ** 2) / 3
self.targ_t08_h025 = 0
self.targ_t08_h05 = (3 - 4) / np.sqrt(
(sigma_ri / mu_ri ** 3) * 0.5 + (sigma_le / mu_le ** 3) * 0.5)
# Window Large #
def test_filter_with_spiketrain_h05(self):
st = neo.SpikeTrain(self.test_array, units='s', t_stop=2.0)
target = self.targ_t08_h05
res = mft._filter(0.8 * pq.s, 0.5 * pq.s, st)
assert_array_almost_equal(res, target, decimal=9)
self.assertRaises(ValueError, mft._filter, 0.8, 0.5 * pq.s, st)
self.assertRaises(ValueError, mft._filter, 0.8 * pq.s, 0.5, st)
self.assertRaises(ValueError, mft._filter, 0.8 * pq.s, 0.5 * pq.s,
self.test_array)
# Window Small #
def test_filter_with_spiketrain_h025(self):
st = neo.SpikeTrain(self.test_array, units='s', t_stop=2.0)
target = self.targ_t08_h025
res = mft._filter(0.8 * pq.s, 0.25 * pq.s, st)
assert_array_almost_equal(res, target, decimal=9)
def test_filter_with_quantities_h025(self):
st = pq.Quantity(self.test_array, units='s')
target = self.targ_t08_h025
res = mft._filter(0.8 * pq.s, 0.25 * pq.s, st)
assert_array_almost_equal(res, target, decimal=9)
def test_filter_with_plain_array_h025(self):
st = self.test_array
target = self.targ_t08_h025
res = mft._filter(0.8 * pq.s, 0.25 * pq.s, st * pq.s)
assert_array_almost_equal(res, target, decimal=9)
def test_isi_with_quantities_h05(self):
st = pq.Quantity(self.test_array, units='s')
target = self.targ_t08_h05
res = mft._filter(0.8 * pq.s, 0.5 * pq.s, st)
assert_array_almost_equal(res, target, decimal=9)
def test_isi_with_plain_array_h05(self):
st = self.test_array
target = self.targ_t08_h05
res = mft._filter(0.8 * pq.s, 0.5 * pq.s, st * pq.s)
assert_array_almost_equal(res, target, decimal=9)
class FilterProcessTestCase(unittest.TestCase):
def setUp(self):
self.test_array = [1.1, 1.2, 1.4, 1.6, 1.7, 1.75, 1.8, 1.85, 1.9, 1.95]
x = (7 - 3) / np.sqrt(
(0.0025 / 0.15 ** 3) * 0.5 + (0.0003472 / 0.05833 ** 3) * 0.5)
self.targ_h05 = [[0.5, 1, 1.5],
[(0 - 1.7) / np.sqrt(0.4), (0 - 1.7) / np.sqrt(0.4),
(x - 1.7) / np.sqrt(0.4)]]
def test_filter_process_with_spiketrain_h05(self):
st = neo.SpikeTrain(self.test_array, units='s', t_stop=2.1)
target = self.targ_h05
res = mft._filter_process(0.5 * pq.s, 0.5 * pq.s, st, 2.01 * pq.s,
np.array([[0.5], [1.7], [0.4]]))
assert_array_almost_equal(res[1], target[1], decimal=3)
self.assertRaises(ValueError, mft._filter_process, 0.5, 0.5 * pq.s,
st, 2.01 * pq.s, np.array([[0.5], [1.7], [0.4]]))
self.assertRaises(ValueError, mft._filter_process, 0.5 * pq.s, 0.5,
st, 2.01 * pq.s, np.array([[0.5], [1.7], [0.4]]))
self.assertRaises(ValueError, mft._filter_process, 0.5 * pq.s,
0.5 * pq.s, self.test_array, 2.01 * pq.s,
np.array([[0.5], [1.7], [0.4]]))
def test_filter_proces_with_quantities_h05(self):
st = pq.Quantity(self.test_array, units='s')
target = self.targ_h05
res = mft._filter_process(0.5 * pq.s, 0.5 * pq.s, st, 2.01 * pq.s,
np.array([[0.5], [1.7], [0.4]]))
assert_array_almost_equal(res[0], target[0], decimal=3)
def test_filter_proces_with_plain_array_h05(self):
st = self.test_array
target = self.targ_h05
res = mft._filter_process(0.5 * pq.s, 0.5 * pq.s, st * pq.s,
2.01 * pq.s, np.array([[0.5], [1.7], [0.4]]))
self.assertNotIsInstance(res, pq.Quantity)
assert_array_almost_equal(res, target, decimal=3)
class MultipleFilterAlgorithmTestCase(unittest.TestCase):
def setUp(self):
self.test_array = [1.1, 1.2, 1.4, 1.6, 1.7, 1.75, 1.8, 1.85, 1.9, 1.95]
self.targ_h05_dt05 = [1.5 * pq.s]
# to speed up the test, the following `test_param` and `test_quantile`
# paramters have been calculated offline using the function:
# empirical_parameters([10, 25, 50, 75, 100, 125, 150]*pq.s,700*pq.s,5,
# 10000)
# the user should do the same, if the metohd has to be applied to
# several spike trains of the same length `T` and with the same set of
# window.
self.test_param = np.array([[10.,
25.,
50.,
75.,
100.,
125.,
150.],
[3.167,
2.955,
2.721,
2.548,
2.412,
2.293,
2.180],
[0.150,
0.185,
0.224,
0.249,
0.269,
0.288,
0.301]])
self.test_quantile = 2.75
def test_MultipleFilterAlgorithm_with_spiketrain_h05(self):
st = neo.SpikeTrain(self.test_array, units='s', t_stop=2.1)
target = [self.targ_h05_dt05]
res = mft.multiple_filter_test([0.5] * pq.s, st, 2.1 * pq.s, 5, 100,
time_step=0.1 * pq.s)
assert_array_almost_equal(res, target, decimal=9)
def test_MultipleFilterAlgorithm_with_quantities_h05(self):
st = pq.Quantity(self.test_array, units='s')
target = [self.targ_h05_dt05]
res = mft.multiple_filter_test([0.5] * pq.s, st, 2.1 * pq.s, 5, 100,
time_step=0.5 * pq.s)
self.assertNotIsInstance(res, pq.Quantity)
assert_array_almost_equal(res, target, decimal=9)
def test_MultipleFilterAlgorithm_with_longdata(self):
def gamma_train(k, teta, tmax):
x = np.random.gamma(k, teta, int(tmax * (k * teta) ** (-1) * 3))
s = np.cumsum(x)
idx = np.where(s < tmax)
s = s[idx] # gamma process
return s
def alternative_hypothesis(k1, teta1, c1, k2, teta2, c2, k3, teta3, c3,
k4, teta4, T):
s1 = gamma_train(k1, teta1, c1)
s2 = gamma_train(k2, teta2, c2) + c1
s3 = gamma_train(k3, teta3, c3) + c1 + c2
s4 = gamma_train(k4, teta4, T) + c1 + c2 + c3
return np.concatenate((s1, s2, s3, s4)), [s1[-1], s2[-1], s3[-1]]
st = self.h1 = alternative_hypothesis(1, 1 / 4., 150, 2, 1 / 26., 30,
1, 1 / 36., 320,
2, 1 / 33., 200)[0]
window_size = [10, 25, 50, 75, 100, 125, 150] * pq.s
self.target_points = [150, 180, 500]
target = self.target_points
result = mft.multiple_filter_test(
window_size,
st * pq.s,
700 * pq.s,
5,
10000,
test_quantile=self.test_quantile,
test_param=self.test_param,
time_step=1 * pq.s)
self.assertNotIsInstance(result, pq.Quantity)
result_concatenated = []
for i in result:
result_concatenated = np.hstack([result_concatenated, i])
result_concatenated = np.sort(result_concatenated)
assert_allclose(result_concatenated[:3], target[:3], rtol=0,
atol=5)
print('detected {0} cps: {1}'.format(len(result_concatenated),
result_concatenated))
if __name__ == '__main__':
unittest.main()
|
bsd-3-clause
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
646,
2882,
199,
199,
646,
1279,
79,
199,
646,
2680,
465,
980,
199,
646,
13621,
1417,
465,
29158,
199,
504,
2680,
14,
4776,
492,
702,
63,
1144,
63,
4398,
63,
1452,
12,
702,
63,
7520,
199,
199,
646,
12993,
838,
867,
14,
1461,
63,
1403,
63,
11934,
465,
333,
856,
421,
199,
533,
9388,
1746,
8,
2796,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
396,
63,
1144,
275,
359,
16,
14,
20,
12,
378,
14,
21,
12,
378,
14,
2182,
12,
378,
14,
23,
12,
378,
14,
25,
12,
413,
14,
1046,
12,
413,
14,
18,
12,
413,
14,
25,
61,
267,
327,
308,
27323,
63,
322,
275,
359,
16,
14,
25,
12,
413,
14,
1046,
12,
413,
14,
18,
61,
267,
327,
308,
2051,
63,
274,
275,
359,
16,
14,
20,
12,
378,
14,
21,
12,
378,
14,
2182,
12,
378,
14,
23,
61,
267,
8504,
63,
322,
275,
334,
16,
14,
821,
435,
378,
14,
1717,
9,
1182,
499,
267,
8504,
63,
274,
275,
334,
16,
14,
17,
435,
378,
14,
1046,
435,
378,
14,
1717,
9,
1182,
650,
267,
10819,
63,
322,
275,
3666,
16,
14,
821,
446,
378,
14,
1046,
9,
1011,
499,
435,
334,
16,
14,
1717,
446,
378,
14,
1046,
9,
1011,
499,
9,
1182,
499,
267,
10819,
63,
274,
275,
3666,
16,
14,
17,
446,
378,
14,
17,
9,
1011,
499,
435,
334,
16,
14,
1046,
446,
378,
14,
17,
9,
1011,
499,
435,
334,
288,
378,
14,
1717,
446,
378,
14,
17,
9,
1011,
499,
9,
1182,
650,
267,
291,
14,
29919,
63,
84,
2036,
63,
72,
18823,
275,
378,
267,
291,
14,
29919,
63,
84,
2036,
63,
72,
1717,
275,
334,
19,
446,
841,
9,
1182,
980,
14,
5079,
8,
288,
334,
9412,
63,
322,
1182,
8504,
63,
322,
1011,
650,
9,
627,
378,
14,
21,
435,
334,
9412,
63,
274,
1182,
8504,
63,
274,
1011,
650,
9,
627,
378,
14,
21,
9,
339,
327,
15689,
29095,
327,
272,
347,
511,
63,
1541,
63,
1045,
63,
32757,
386,
6322,
63,
72,
1717,
8,
277,
304,
267,
410,
275,
1279,
79,
14,
51,
1038,
415,
18591,
8,
277,
14,
396,
63,
1144,
12,
6204,
534,
83,
297,
307,
63,
2379,
29,
18,
14,
16,
9,
267,
1347,
275,
291,
14,
29919,
63,
84,
2036,
63,
72,
1717,
267,
522,
275,
333,
856,
423,
1541,
8,
16,
14,
24,
627,
29158,
14,
83,
12,
378,
14,
21,
627,
29158,
14,
83,
12,
410,
9,
267,
702,
63,
1144,
63,
4398,
63,
1452,
8,
470,
12,
1347,
12,
6107,
29,
25,
9,
267,
291,
14,
1855,
8,
3393,
12,
333,
856,
423,
1541,
12,
378,
14,
24,
12,
378,
14,
21,
627,
29158,
14,
83,
12,
410,
9,
267,
291,
14,
1855,
8,
3393,
12,
333,
856,
423,
1541,
12,
378,
14,
24,
627,
29158,
14,
83,
12,
378,
14,
21,
12,
410,
9,
267,
291,
14,
1855,
8,
3393,
12,
333,
856,
423,
1541,
12,
378,
14,
24,
627,
29158,
14,
83,
12,
378,
14,
21,
627,
29158,
14,
83,
12,
2079,
291,
14,
396,
63,
1144,
9,
339,
327,
15689,
23704,
327,
272,
347,
511,
63,
1541,
63,
1045,
63,
32757,
386,
6322,
63,
72,
18823,
8,
277,
304,
267,
410,
275,
1279,
79,
14,
51,
1038,
415,
18591,
8,
277,
14,
396,
63,
1144,
12,
6204,
534,
83,
297,
307,
63,
2379,
29,
18,
14,
16,
9,
267,
1347,
275,
291,
14,
29919,
63,
84,
2036,
63,
72,
18823,
267,
522,
275,
333,
856,
423,
1541,
8,
16,
14,
24,
627,
29158,
14,
83,
12,
378,
14,
821,
627,
29158,
14,
83,
12,
410,
9,
267,
702,
63,
1144,
63,
4398,
63,
1452,
8,
470,
12,
1347,
12,
6107,
29,
25,
9,
339,
347,
511,
63,
1541,
63,
1045,
63,
12316,
1417,
63,
72,
18823,
8,
277,
304,
267,
410,
275,
29158,
14,
19703,
8,
277,
14,
396,
63,
1144,
12,
6204,
534,
83,
358,
267,
1347,
275,
291,
14,
29919,
63,
84,
2036,
63,
72,
18823,
267,
522,
275,
333,
856,
423,
1541,
8,
16,
14,
24,
627,
29158,
14,
83,
12,
378,
14,
821,
627,
29158,
14,
83,
12,
410,
9,
267,
702,
63,
1144,
63,
4398,
63,
1452,
8,
470,
12,
1347,
12,
6107,
29,
25,
9,
339,
347,
511,
63,
1541,
63,
1045,
63,
6104,
63,
1144,
63,
72,
18823,
8,
277,
304,
267,
410,
275,
291,
14,
396,
63,
1144,
267,
1347,
275,
291,
14,
29919,
63,
84,
2036,
63,
72,
18823,
267,
522,
275,
333,
856,
423,
1541,
8,
16,
14,
24,
627,
29158,
14,
83,
12,
378,
14,
821,
627,
29158,
14,
83,
12,
410,
627,
29158,
14,
83,
9,
267,
702,
63,
1144,
63,
4398,
63,
1452,
8,
470,
12,
1347,
12,
6107,
29,
25,
9,
339,
347,
511,
63,
29022,
63,
1045,
63,
12316,
1417,
63,
72,
1717,
8,
277,
304,
267,
410,
275,
29158,
14,
19703,
8,
277,
14,
396,
63,
1144,
12,
6204,
534,
83,
358,
267,
1347,
275,
291,
14,
29919,
63,
84,
2036,
63,
72,
1717,
267,
522,
275,
333,
856,
423,
1541,
8,
16,
14,
24,
627,
29158,
14,
83,
12,
378,
14,
21,
627,
29158,
14,
83,
12,
410,
9,
267,
702,
63,
1144,
63,
4398,
63,
1452,
8,
470,
12,
1347,
12,
6107,
29,
25,
9,
339,
347,
511,
63,
29022,
63,
1045,
63,
6104,
63,
1144,
63,
72,
1717,
8,
277,
304,
267,
410,
275,
291,
14,
396,
63,
1144,
267,
1347,
275,
291,
14,
29919,
63,
84,
2036,
63,
72,
1717,
267,
522,
275,
333,
856,
423,
1541,
8,
16,
14,
24,
627,
29158,
14,
83,
12,
378,
14,
21,
627,
29158,
14,
83,
12,
410,
627,
29158,
14,
83,
9,
267,
702,
63,
1144,
63,
4398,
63,
1452,
8,
470,
12,
1347,
12,
6107,
29,
25,
9,
421,
199,
533,
9388,
3498,
1746,
8,
2796,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
396,
63,
1144,
275,
359,
17,
14,
17,
12,
413,
14,
18,
12,
413,
14,
20,
12,
413,
14,
22,
12,
413,
14,
23,
12
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
646,
2882,
199,
199,
646,
1279,
79,
199,
646,
2680,
465,
980,
199,
646,
13621,
1417,
465,
29158,
199,
504,
2680,
14,
4776,
492,
702,
63,
1144,
63,
4398,
63,
1452,
12,
702,
63,
7520,
199,
199,
646,
12993,
838,
867,
14,
1461,
63,
1403,
63,
11934,
465,
333,
856,
421,
199,
533,
9388,
1746,
8,
2796,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
396,
63,
1144,
275,
359,
16,
14,
20,
12,
378,
14,
21,
12,
378,
14,
2182,
12,
378,
14,
23,
12,
378,
14,
25,
12,
413,
14,
1046,
12,
413,
14,
18,
12,
413,
14,
25,
61,
267,
327,
308,
27323,
63,
322,
275,
359,
16,
14,
25,
12,
413,
14,
1046,
12,
413,
14,
18,
61,
267,
327,
308,
2051,
63,
274,
275,
359,
16,
14,
20,
12,
378,
14,
21,
12,
378,
14,
2182,
12,
378,
14,
23,
61,
267,
8504,
63,
322,
275,
334,
16,
14,
821,
435,
378,
14,
1717,
9,
1182,
499,
267,
8504,
63,
274,
275,
334,
16,
14,
17,
435,
378,
14,
1046,
435,
378,
14,
1717,
9,
1182,
650,
267,
10819,
63,
322,
275,
3666,
16,
14,
821,
446,
378,
14,
1046,
9,
1011,
499,
435,
334,
16,
14,
1717,
446,
378,
14,
1046,
9,
1011,
499,
9,
1182,
499,
267,
10819,
63,
274,
275,
3666,
16,
14,
17,
446,
378,
14,
17,
9,
1011,
499,
435,
334,
16,
14,
1046,
446,
378,
14,
17,
9,
1011,
499,
435,
334,
288,
378,
14,
1717,
446,
378,
14,
17,
9,
1011,
499,
9,
1182,
650,
267,
291,
14,
29919,
63,
84,
2036,
63,
72,
18823,
275,
378,
267,
291,
14,
29919,
63,
84,
2036,
63,
72,
1717,
275,
334,
19,
446,
841,
9,
1182,
980,
14,
5079,
8,
288,
334,
9412,
63,
322,
1182,
8504,
63,
322,
1011,
650,
9,
627,
378,
14,
21,
435,
334,
9412,
63,
274,
1182,
8504,
63,
274,
1011,
650,
9,
627,
378,
14,
21,
9,
339,
327,
15689,
29095,
327,
272,
347,
511,
63,
1541,
63,
1045,
63,
32757,
386,
6322,
63,
72,
1717,
8,
277,
304,
267,
410,
275,
1279,
79,
14,
51,
1038,
415,
18591,
8,
277,
14,
396,
63,
1144,
12,
6204,
534,
83,
297,
307,
63,
2379,
29,
18,
14,
16,
9,
267,
1347,
275,
291,
14,
29919,
63,
84,
2036,
63,
72,
1717,
267,
522,
275,
333,
856,
423,
1541,
8,
16,
14,
24,
627,
29158,
14,
83,
12,
378,
14,
21,
627,
29158,
14,
83,
12,
410,
9,
267,
702,
63,
1144,
63,
4398,
63,
1452,
8,
470,
12,
1347,
12,
6107,
29,
25,
9,
267,
291,
14,
1855,
8,
3393,
12,
333,
856,
423,
1541,
12,
378,
14,
24,
12,
378,
14,
21,
627,
29158,
14,
83,
12,
410,
9,
267,
291,
14,
1855,
8,
3393,
12,
333,
856,
423,
1541,
12,
378,
14,
24,
627,
29158,
14,
83,
12,
378,
14,
21,
12,
410,
9,
267,
291,
14,
1855,
8,
3393,
12,
333,
856,
423,
1541,
12,
378,
14,
24,
627,
29158,
14,
83,
12,
378,
14,
21,
627,
29158,
14,
83,
12,
2079,
291,
14,
396,
63,
1144,
9,
339,
327,
15689,
23704,
327,
272,
347,
511,
63,
1541,
63,
1045,
63,
32757,
386,
6322,
63,
72,
18823,
8,
277,
304,
267,
410,
275,
1279,
79,
14,
51,
1038,
415,
18591,
8,
277,
14,
396,
63,
1144,
12,
6204,
534,
83,
297,
307,
63,
2379,
29,
18,
14,
16,
9,
267,
1347,
275,
291,
14,
29919,
63,
84,
2036,
63,
72,
18823,
267,
522,
275,
333,
856,
423,
1541,
8,
16,
14,
24,
627,
29158,
14,
83,
12,
378,
14,
821,
627,
29158,
14,
83,
12,
410,
9,
267,
702,
63,
1144,
63,
4398,
63,
1452,
8,
470,
12,
1347,
12,
6107,
29,
25,
9,
339,
347,
511,
63,
1541,
63,
1045,
63,
12316,
1417,
63,
72,
18823,
8,
277,
304,
267,
410,
275,
29158,
14,
19703,
8,
277,
14,
396,
63,
1144,
12,
6204,
534,
83,
358,
267,
1347,
275,
291,
14,
29919,
63,
84,
2036,
63,
72,
18823,
267,
522,
275,
333,
856,
423,
1541,
8,
16,
14,
24,
627,
29158,
14,
83,
12,
378,
14,
821,
627,
29158,
14,
83,
12,
410,
9,
267,
702,
63,
1144,
63,
4398,
63,
1452,
8,
470,
12,
1347,
12,
6107,
29,
25,
9,
339,
347,
511,
63,
1541,
63,
1045,
63,
6104,
63,
1144,
63,
72,
18823,
8,
277,
304,
267,
410,
275,
291,
14,
396,
63,
1144,
267,
1347,
275,
291,
14,
29919,
63,
84,
2036,
63,
72,
18823,
267,
522,
275,
333,
856,
423,
1541,
8,
16,
14,
24,
627,
29158,
14,
83,
12,
378,
14,
821,
627,
29158,
14,
83,
12,
410,
627,
29158,
14,
83,
9,
267,
702,
63,
1144,
63,
4398,
63,
1452,
8,
470,
12,
1347,
12,
6107,
29,
25,
9,
339,
347,
511,
63,
29022,
63,
1045,
63,
12316,
1417,
63,
72,
1717,
8,
277,
304,
267,
410,
275,
29158,
14,
19703,
8,
277,
14,
396,
63,
1144,
12,
6204,
534,
83,
358,
267,
1347,
275,
291,
14,
29919,
63,
84,
2036,
63,
72,
1717,
267,
522,
275,
333,
856,
423,
1541,
8,
16,
14,
24,
627,
29158,
14,
83,
12,
378,
14,
21,
627,
29158,
14,
83,
12,
410,
9,
267,
702,
63,
1144,
63,
4398,
63,
1452,
8,
470,
12,
1347,
12,
6107,
29,
25,
9,
339,
347,
511,
63,
29022,
63,
1045,
63,
6104,
63,
1144,
63,
72,
1717,
8,
277,
304,
267,
410,
275,
291,
14,
396,
63,
1144,
267,
1347,
275,
291,
14,
29919,
63,
84,
2036,
63,
72,
1717,
267,
522,
275,
333,
856,
423,
1541,
8,
16,
14,
24,
627,
29158,
14,
83,
12,
378,
14,
21,
627,
29158,
14,
83,
12,
410,
627,
29158,
14,
83,
9,
267,
702,
63,
1144,
63,
4398,
63,
1452,
8,
470,
12,
1347,
12,
6107,
29,
25,
9,
421,
199,
533,
9388,
3498,
1746,
8,
2796,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
396,
63,
1144,
275,
359,
17,
14,
17,
12,
413,
14,
18,
12,
413,
14,
20,
12,
413,
14,
22,
12,
413,
14,
23,
12,
0
] |
[
1,
1,
1,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keystone
|
keystone/tests/test_singular_plural.py
|
8
|
2293
|
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2012 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import ast
from keystone.contrib.admin_crud import core as admin_crud_core
from keystone.contrib.s3 import core as s3_core
from keystone.contrib.stats import core as stats_core
from keystone.contrib.user_crud import core as user_crud_core
from keystone.identity import core as identity_core
from keystone import service
class TestSingularPlural(object):
def test_keyword_arg_condition_or_methods(self):
"""Raise if we see a keyword arg called 'condition' or 'methods'."""
modules = [admin_crud_core, s3_core, stats_core,
user_crud_core, identity_core, service]
for module in modules:
filename = module.__file__
if filename.endswith(".pyc"):
# In Python 2, the .py and .pyc files are in the same dir.
filename = filename[:-1]
with open(filename) as fil:
source = fil.read()
module = ast.parse(source, filename)
last_stmt_or_expr = None
for node in ast.walk(module):
if isinstance(node, ast.stmt) or isinstance(node, ast.expr):
# keyword nodes don't have line numbers, so we need to
# get that information from the parent stmt or expr.
last_stmt_or_expr = node
elif isinstance(node, ast.keyword):
for bad_word in ["condition", "methods"]:
if node.arg == bad_word:
raise AssertionError(
"Suspicious name '%s' at %s line %s" %
(bad_word, filename, last_stmt_or_expr.lineno))
|
apache-2.0
|
[
3,
6695,
26,
20849,
29,
20,
20105,
29,
20,
25966,
29,
20,
199,
199,
3,
1898,
6029,
9572,
13002,
12,
3277,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
420,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
199,
646,
6073,
199,
199,
504,
19395,
14,
2828,
14,
2113,
63,
28941,
492,
6170,
465,
4628,
63,
28941,
63,
1018,
199,
504,
19395,
14,
2828,
14,
83,
19,
492,
6170,
465,
308,
19,
63,
1018,
199,
504,
19395,
14,
2828,
14,
3200,
492,
6170,
465,
5020,
63,
1018,
199,
504,
19395,
14,
2828,
14,
751,
63,
28941,
492,
6170,
465,
922,
63,
28941,
63,
1018,
199,
504,
19395,
14,
5582,
492,
6170,
465,
8503,
63,
1018,
199,
504,
19395,
492,
2435,
421,
199,
533,
1379,
51,
14257,
3714,
4889,
8,
785,
304,
272,
347,
511,
63,
6691,
63,
1273,
63,
5394,
63,
269,
63,
2474,
8,
277,
304,
267,
408,
18111,
340,
781,
1937,
282,
4252,
1680,
2797,
283,
5394,
7,
503,
283,
2474,
23690,
267,
4621,
275,
359,
2113,
63,
28941,
63,
1018,
12,
308,
19,
63,
1018,
12,
5020,
63,
1018,
12,
673,
922,
63,
28941,
63,
1018,
12,
8503,
63,
1018,
12,
2435,
61,
267,
367,
859,
315,
4621,
26,
288,
1788,
275,
859,
855,
493,
363,
288,
340,
1788,
14,
4130,
9520,
11357,
2349,
355,
327,
1010,
2018,
499,
12,
314,
1275,
647,
436,
1275,
11357,
1584,
787,
315,
314,
2011,
2935,
14,
355,
1788,
275,
1788,
4439,
17,
61,
288,
543,
1551,
8,
1501,
9,
465,
1794,
26,
355,
1350,
275,
1794,
14,
739,
342,
288,
859,
275,
6073,
14,
1122,
8,
1365,
12,
1788,
9,
288,
2061,
63,
9649,
63,
269,
63,
3684,
275,
488,
288,
367,
1031,
315,
6073,
14,
7757,
8,
578,
304,
355,
340,
1228,
8,
932,
12,
6073,
14,
9649,
9,
503,
1228,
8,
932,
12,
6073,
14,
3684,
304,
490,
327,
4252,
3380,
2793,
1133,
1172,
1004,
5579,
12,
880,
781,
1929,
370,
490,
327,
664,
626,
2556,
687,
314,
1676,
12284,
503,
5348,
14,
490,
2061,
63,
9649,
63,
269,
63,
3684,
275,
1031,
355,
916,
1228,
8,
932,
12,
6073,
14,
6691,
304,
490,
367,
4875,
63,
1027,
315,
2097,
5394,
401,
298,
2474,
6229,
717,
340,
1031,
14,
1273,
508,
4875,
63,
1027,
26,
1169,
746,
9070,
8,
1816,
298,
51,
28651,
536,
1543,
83,
7,
737,
450,
83,
1004,
450,
83,
2,
450,
1816,
334,
4087,
63,
1027,
12,
1788,
12,
2061,
63,
9649,
63,
269,
63,
3684,
14,
3469,
430,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
6695,
26,
20849,
29,
20,
20105,
29,
20,
25966,
29,
20,
199,
199,
3,
1898,
6029,
9572,
13002,
12,
3277,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
420,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
199,
646,
6073,
199,
199,
504,
19395,
14,
2828,
14,
2113,
63,
28941,
492,
6170,
465,
4628,
63,
28941,
63,
1018,
199,
504,
19395,
14,
2828,
14,
83,
19,
492,
6170,
465,
308,
19,
63,
1018,
199,
504,
19395,
14,
2828,
14,
3200,
492,
6170,
465,
5020,
63,
1018,
199,
504,
19395,
14,
2828,
14,
751,
63,
28941,
492,
6170,
465,
922,
63,
28941,
63,
1018,
199,
504,
19395,
14,
5582,
492,
6170,
465,
8503,
63,
1018,
199,
504,
19395,
492,
2435,
421,
199,
533,
1379,
51,
14257,
3714,
4889,
8,
785,
304,
272,
347,
511,
63,
6691,
63,
1273,
63,
5394,
63,
269,
63,
2474,
8,
277,
304,
267,
408,
18111,
340,
781,
1937,
282,
4252,
1680,
2797,
283,
5394,
7,
503,
283,
2474,
23690,
267,
4621,
275,
359,
2113,
63,
28941,
63,
1018,
12,
308,
19,
63,
1018,
12,
5020,
63,
1018,
12,
673,
922,
63,
28941,
63,
1018,
12,
8503,
63,
1018,
12,
2435,
61,
267,
367,
859,
315,
4621,
26,
288,
1788,
275,
859,
855,
493,
363,
288,
340,
1788,
14,
4130,
9520,
11357,
2349,
355,
327,
1010,
2018,
499,
12,
314,
1275,
647,
436,
1275,
11357,
1584,
787,
315,
314,
2011,
2935,
14,
355,
1788,
275,
1788,
4439,
17,
61,
288,
543,
1551,
8,
1501,
9,
465,
1794,
26,
355,
1350,
275,
1794,
14,
739,
342,
288,
859,
275,
6073,
14,
1122,
8,
1365,
12,
1788,
9,
288,
2061,
63,
9649,
63,
269,
63,
3684,
275,
488,
288,
367,
1031,
315,
6073,
14,
7757,
8,
578,
304,
355,
340,
1228,
8,
932,
12,
6073,
14,
9649,
9,
503,
1228,
8,
932,
12,
6073,
14,
3684,
304,
490,
327,
4252,
3380,
2793,
1133,
1172,
1004,
5579,
12,
880,
781,
1929,
370,
490,
327,
664,
626,
2556,
687,
314,
1676,
12284,
503,
5348,
14,
490,
2061,
63,
9649,
63,
269,
63,
3684,
275,
1031,
355,
916,
1228,
8,
932,
12,
6073,
14,
6691,
304,
490,
367,
4875,
63,
1027,
315,
2097,
5394,
401,
298,
2474,
6229,
717,
340,
1031,
14,
1273,
508,
4875,
63,
1027,
26,
1169,
746,
9070,
8,
1816,
298,
51,
28651,
536,
1543,
83,
7,
737,
450,
83,
1004,
450,
83,
2,
450,
1816,
334,
4087,
63,
1027,
12,
1788,
12,
2061,
63,
9649,
63,
269,
63,
3684,
14,
3469,
430,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
aspidites/django
|
tests/app_loading/tests.py
|
288
|
3113
|
from __future__ import unicode_literals
import os
from django.apps import apps
from django.test import SimpleTestCase
from django.test.utils import extend_sys_path
from django.utils import six
from django.utils._os import upath
class EggLoadingTest(SimpleTestCase):
def setUp(self):
self.egg_dir = '%s/eggs' % os.path.dirname(upath(__file__))
def tearDown(self):
apps.clear_cache()
def test_egg1(self):
"""Models module can be loaded from an app in an egg"""
egg_name = '%s/modelapp.egg' % self.egg_dir
with extend_sys_path(egg_name):
with self.settings(INSTALLED_APPS=['app_with_models']):
models_module = apps.get_app_config('app_with_models').models_module
self.assertIsNotNone(models_module)
del apps.all_models['app_with_models']
def test_egg2(self):
"""Loading an app from an egg that has no models returns no models (and no error)"""
egg_name = '%s/nomodelapp.egg' % self.egg_dir
with extend_sys_path(egg_name):
with self.settings(INSTALLED_APPS=['app_no_models']):
models_module = apps.get_app_config('app_no_models').models_module
self.assertIsNone(models_module)
del apps.all_models['app_no_models']
def test_egg3(self):
"""Models module can be loaded from an app located under an egg's top-level package"""
egg_name = '%s/omelet.egg' % self.egg_dir
with extend_sys_path(egg_name):
with self.settings(INSTALLED_APPS=['omelet.app_with_models']):
models_module = apps.get_app_config('app_with_models').models_module
self.assertIsNotNone(models_module)
del apps.all_models['app_with_models']
def test_egg4(self):
"""Loading an app with no models from under the top-level egg package generates no error"""
egg_name = '%s/omelet.egg' % self.egg_dir
with extend_sys_path(egg_name):
with self.settings(INSTALLED_APPS=['omelet.app_no_models']):
models_module = apps.get_app_config('app_no_models').models_module
self.assertIsNone(models_module)
del apps.all_models['app_no_models']
def test_egg5(self):
"""Loading an app from an egg that has an import error in its models module raises that error"""
egg_name = '%s/brokenapp.egg' % self.egg_dir
with extend_sys_path(egg_name):
with six.assertRaisesRegex(self, ImportError, 'modelz'):
with self.settings(INSTALLED_APPS=['broken_app']):
pass
class GetModelsTest(SimpleTestCase):
def setUp(self):
from .not_installed import models
self.not_installed_module = models
def test_get_model_only_returns_installed_models(self):
with self.assertRaises(LookupError):
apps.get_model("not_installed", "NotInstalledModel")
def test_get_models_only_returns_installed_models(self):
self.assertNotIn(
"NotInstalledModel",
[m.__name__ for m in apps.get_models()])
|
bsd-3-clause
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
747,
199,
199,
504,
1639,
14,
5181,
492,
8686,
199,
504,
1639,
14,
396,
492,
24424,
199,
504,
1639,
14,
396,
14,
1208,
492,
12247,
63,
1274,
63,
515,
199,
504,
1639,
14,
1208,
492,
3816,
199,
504,
1639,
14,
1208,
423,
736,
492,
1536,
1619,
421,
199,
533,
662,
2721,
19236,
774,
8,
17968,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
5799,
63,
694,
275,
1543,
83,
15,
14488,
7,
450,
747,
14,
515,
14,
3475,
8,
384,
1619,
3460,
493,
8964,
339,
347,
6766,
8,
277,
304,
267,
8686,
14,
3584,
63,
1637,
342,
339,
347,
511,
63,
5799,
17,
8,
277,
304,
267,
408,
20474,
859,
883,
506,
6511,
687,
376,
1145,
315,
376,
11393,
624,
267,
11393,
63,
354,
275,
1543,
83,
15,
632,
416,
802,
14,
5799,
7,
450,
291,
14,
5799,
63,
694,
267,
543,
12247,
63,
1274,
63,
515,
8,
5799,
63,
354,
304,
288,
543,
291,
14,
1751,
8,
15942,
63,
14219,
2968,
571,
63,
1045,
63,
992,
9090,
355,
1709,
63,
578,
275,
8686,
14,
362,
63,
571,
63,
888,
360,
571,
63,
1045,
63,
992,
1959,
992,
63,
578,
355,
291,
14,
10389,
8,
992,
63,
578,
9,
267,
2150,
8686,
14,
452,
63,
992,
459,
571,
63,
1045,
63,
992,
418,
339,
347,
511,
63,
5799,
18,
8,
277,
304,
267,
408,
19236,
376,
1145,
687,
376,
11393,
626,
965,
949,
1709,
2529,
949,
1709,
334,
460,
949,
1125,
9471,
267,
11393,
63,
354,
275,
1543,
83,
15,
889,
632,
416,
802,
14,
5799,
7,
450,
291,
14,
5799,
63,
694,
267,
543,
12247,
63,
1274,
63,
515,
8,
5799,
63,
354,
304,
288,
543,
291,
14,
1751,
8,
15942,
63,
14219,
2968,
571,
63,
889,
63,
992,
9090,
355,
1709,
63,
578,
275,
8686,
14,
362,
63,
571,
63,
888,
360,
571,
63,
889,
63,
992,
1959,
992,
63,
578,
355,
291,
14,
7702,
8,
992,
63,
578,
9,
267,
2150,
8686,
14,
452,
63,
992,
459,
571,
63,
889,
63,
992,
418,
339,
347,
511,
63,
5799,
19,
8,
277,
304,
267,
408,
20474,
859,
883,
506,
6511,
687,
376,
1145,
16180,
1334,
376,
11393,
1159,
2746,
13,
1896,
2559,
624,
267,
11393,
63,
354,
275,
1543,
83,
15,
1377,
2723,
14,
5799,
7,
450,
291,
14,
5799,
63,
694,
267,
543,
12247,
63,
1274,
63,
515,
8,
5799,
63,
354,
304,
288,
543,
291,
14,
1751,
8,
15942,
63,
14219,
2968,
1377,
2723,
14,
571,
63,
1045,
63,
992,
9090,
355,
1709,
63,
578,
275,
8686,
14,
362,
63,
571,
63,
888,
360,
571,
63,
1045,
63,
992,
1959,
992,
63,
578,
355,
291,
14,
10389,
8,
992,
63,
578,
9,
267,
2150,
8686,
14,
452,
63,
992,
459,
571,
63,
1045,
63,
992,
418,
339,
347,
511,
63,
5799,
20,
8,
277,
304,
267,
408,
19236,
376,
1145,
543,
949,
1709,
687,
1334,
314,
2746,
13,
1896,
11393,
2559,
12821,
949,
1125,
624,
267,
11393,
63,
354,
275,
1543,
83,
15,
1377,
2723,
14,
5799,
7,
450,
291,
14,
5799,
63,
694,
267,
543,
12247,
63,
1274,
63,
515,
8,
5799,
63,
354,
304,
288,
543,
291,
14,
1751,
8,
15942,
63,
14219,
2968,
1377,
2723,
14,
571,
63,
889,
63,
992,
9090,
355,
1709,
63,
578,
275,
8686,
14,
362,
63,
571,
63,
888,
360,
571,
63,
889,
63,
992,
1959,
992,
63,
578,
355,
291,
14,
7702,
8,
992,
63,
578,
9,
267,
2150,
8686,
14,
452,
63,
992,
459,
571,
63,
889,
63,
992,
418,
339,
347,
511,
63,
5799,
21,
8,
277,
304,
267,
408,
19236,
376,
1145,
687,
376,
11393,
626,
965,
376,
492,
1125,
315,
2399,
1709,
859,
6534,
626,
1125,
624,
267,
11393,
63,
354,
275,
1543,
83,
15,
15697,
571,
14,
5799,
7,
450,
291,
14,
5799,
63,
694,
267,
543,
12247,
63,
1274,
63,
515,
8,
5799,
63,
354,
304,
288,
543,
3816,
14,
16499,
8,
277,
12,
3545,
12,
283,
1238,
90,
735,
355,
543,
291,
14,
1751,
8,
15942,
63,
14219,
2968,
15697,
63,
571,
9090,
490,
986,
421,
199,
533,
2372,
20474,
774,
8,
17968,
304,
272,
347,
3613,
8,
277,
304,
267,
687,
1275,
1397,
63,
7657,
492,
1709,
267,
291,
14,
1397,
63,
7657,
63,
578,
275,
1709,
339,
347,
511,
63,
362,
63,
1238,
63,
2118,
63,
5808,
63,
7657,
63,
992,
8,
277,
304,
267,
543,
291,
14,
1855,
8,
32060,
304,
288,
8686,
14,
362,
63,
1238,
480,
1397,
63,
7657,
401,
298,
1763,
21268,
1685,
531,
339,
347,
511,
63,
362,
63,
992,
63,
2118,
63,
5808,
63,
7657,
63,
992,
8,
277,
304,
267,
291,
14,
8795,
8,
288,
298,
1763,
21268,
1685,
401,
288,
359,
77,
855,
354,
363,
367,
333,
315,
8686,
14,
362,
63,
992,
9383,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
747,
199,
199,
504,
1639,
14,
5181,
492,
8686,
199,
504,
1639,
14,
396,
492,
24424,
199,
504,
1639,
14,
396,
14,
1208,
492,
12247,
63,
1274,
63,
515,
199,
504,
1639,
14,
1208,
492,
3816,
199,
504,
1639,
14,
1208,
423,
736,
492,
1536,
1619,
421,
199,
533,
662,
2721,
19236,
774,
8,
17968,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
5799,
63,
694,
275,
1543,
83,
15,
14488,
7,
450,
747,
14,
515,
14,
3475,
8,
384,
1619,
3460,
493,
8964,
339,
347,
6766,
8,
277,
304,
267,
8686,
14,
3584,
63,
1637,
342,
339,
347,
511,
63,
5799,
17,
8,
277,
304,
267,
408,
20474,
859,
883,
506,
6511,
687,
376,
1145,
315,
376,
11393,
624,
267,
11393,
63,
354,
275,
1543,
83,
15,
632,
416,
802,
14,
5799,
7,
450,
291,
14,
5799,
63,
694,
267,
543,
12247,
63,
1274,
63,
515,
8,
5799,
63,
354,
304,
288,
543,
291,
14,
1751,
8,
15942,
63,
14219,
2968,
571,
63,
1045,
63,
992,
9090,
355,
1709,
63,
578,
275,
8686,
14,
362,
63,
571,
63,
888,
360,
571,
63,
1045,
63,
992,
1959,
992,
63,
578,
355,
291,
14,
10389,
8,
992,
63,
578,
9,
267,
2150,
8686,
14,
452,
63,
992,
459,
571,
63,
1045,
63,
992,
418,
339,
347,
511,
63,
5799,
18,
8,
277,
304,
267,
408,
19236,
376,
1145,
687,
376,
11393,
626,
965,
949,
1709,
2529,
949,
1709,
334,
460,
949,
1125,
9471,
267,
11393,
63,
354,
275,
1543,
83,
15,
889,
632,
416,
802,
14,
5799,
7,
450,
291,
14,
5799,
63,
694,
267,
543,
12247,
63,
1274,
63,
515,
8,
5799,
63,
354,
304,
288,
543,
291,
14,
1751,
8,
15942,
63,
14219,
2968,
571,
63,
889,
63,
992,
9090,
355,
1709,
63,
578,
275,
8686,
14,
362,
63,
571,
63,
888,
360,
571,
63,
889,
63,
992,
1959,
992,
63,
578,
355,
291,
14,
7702,
8,
992,
63,
578,
9,
267,
2150,
8686,
14,
452,
63,
992,
459,
571,
63,
889,
63,
992,
418,
339,
347,
511,
63,
5799,
19,
8,
277,
304,
267,
408,
20474,
859,
883,
506,
6511,
687,
376,
1145,
16180,
1334,
376,
11393,
1159,
2746,
13,
1896,
2559,
624,
267,
11393,
63,
354,
275,
1543,
83,
15,
1377,
2723,
14,
5799,
7,
450,
291,
14,
5799,
63,
694,
267,
543,
12247,
63,
1274,
63,
515,
8,
5799,
63,
354,
304,
288,
543,
291,
14,
1751,
8,
15942,
63,
14219,
2968,
1377,
2723,
14,
571,
63,
1045,
63,
992,
9090,
355,
1709,
63,
578,
275,
8686,
14,
362,
63,
571,
63,
888,
360,
571,
63,
1045,
63,
992,
1959,
992,
63,
578,
355,
291,
14,
10389,
8,
992,
63,
578,
9,
267,
2150,
8686,
14,
452,
63,
992,
459,
571,
63,
1045,
63,
992,
418,
339,
347,
511,
63,
5799,
20,
8,
277,
304,
267,
408,
19236,
376,
1145,
543,
949,
1709,
687,
1334,
314,
2746,
13,
1896,
11393,
2559,
12821,
949,
1125,
624,
267,
11393,
63,
354,
275,
1543,
83,
15,
1377,
2723,
14,
5799,
7,
450,
291,
14,
5799,
63,
694,
267,
543,
12247,
63,
1274,
63,
515,
8,
5799,
63,
354,
304,
288,
543,
291,
14,
1751,
8,
15942,
63,
14219,
2968,
1377,
2723,
14,
571,
63,
889,
63,
992,
9090,
355,
1709,
63,
578,
275,
8686,
14,
362,
63,
571,
63,
888,
360,
571,
63,
889,
63,
992,
1959,
992,
63,
578,
355,
291,
14,
7702,
8,
992,
63,
578,
9,
267,
2150,
8686,
14,
452,
63,
992,
459,
571,
63,
889,
63,
992,
418,
339,
347,
511,
63,
5799,
21,
8,
277,
304,
267,
408,
19236,
376,
1145,
687,
376,
11393,
626,
965,
376,
492,
1125,
315,
2399,
1709,
859,
6534,
626,
1125,
624,
267,
11393,
63,
354,
275,
1543,
83,
15,
15697,
571,
14,
5799,
7,
450,
291,
14,
5799,
63,
694,
267,
543,
12247,
63,
1274,
63,
515,
8,
5799,
63,
354,
304,
288,
543,
3816,
14,
16499,
8,
277,
12,
3545,
12,
283,
1238,
90,
735,
355,
543,
291,
14,
1751,
8,
15942,
63,
14219,
2968,
15697,
63,
571,
9090,
490,
986,
421,
199,
533,
2372,
20474,
774,
8,
17968,
304,
272,
347,
3613,
8,
277,
304,
267,
687,
1275,
1397,
63,
7657,
492,
1709,
267,
291,
14,
1397,
63,
7657,
63,
578,
275,
1709,
339,
347,
511,
63,
362,
63,
1238,
63,
2118,
63,
5808,
63,
7657,
63,
992,
8,
277,
304,
267,
543,
291,
14,
1855,
8,
32060,
304,
288,
8686,
14,
362,
63,
1238,
480,
1397,
63,
7657,
401,
298,
1763,
21268,
1685,
531,
339,
347,
511,
63,
362,
63,
992,
63,
2118,
63,
5808,
63,
7657,
63,
992,
8,
277,
304,
267,
291,
14,
8795,
8,
288,
298,
1763,
21268,
1685,
401,
288,
359,
77,
855,
354,
363,
367,
333,
315,
8686,
14,
362,
63,
992,
9383,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
DANCEcollaborative/forum-xblock
|
XBlock Integration Files/xdjangobb/xblock/lib/python2.7/site-packages/django/views/csrf.py
|
91
|
3798
|
from django.http import HttpResponseForbidden
from django.template import Context, Template
from django.conf import settings
# We include the template inline since we need to be able to reliably display
# this error message, especially for the sake of developers, and there isn't any
# other way of making it available independent of what is in the settings file.
CSRF_FAILURE_TEMPLATE = """
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="robots" content="NONE,NOARCHIVE">
<title>403 Forbidden</title>
<style type="text/css">
html * { padding:0; margin:0; }
body * { padding:10px 20px; }
body * * { padding:0; }
body { font:small sans-serif; background:#eee; }
body>div { border-bottom:1px solid #ddd; }
h1 { font-weight:normal; margin-bottom:.4em; }
h1 span { font-size:60%; color:#666; font-weight:normal; }
#info { background:#f6f6f6; }
#info ul { margin: 0.5em 4em; }
#info p, #summary p { padding-top:10px; }
#summary { background: #ffc; }
#explanation { background:#eee; border-bottom: 0px none; }
</style>
</head>
<body>
<div id="summary">
<h1>Forbidden <span>(403)</span></h1>
<p>CSRF verification failed. Request aborted.</p>
{% if no_referer %}
<p>You are seeing this message because this HTTPS site requires a 'Referer
header' to be sent by your Web browser, but none was sent. This header is
required for security reasons, to ensure that your browser is not being
hijacked by third parties.</p>
<p>If you have configured your browser to disable 'Referer' headers, please
re-enable them, at least for this site, or for HTTPS connections, or for
'same-origin' requests.</p>
{% endif %}
</div>
{% if DEBUG %}
<div id="info">
<h2>Help</h2>
{% if reason %}
<p>Reason given for failure:</p>
<pre>
{{ reason }}
</pre>
{% endif %}
<p>In general, this can occur when there is a genuine Cross Site Request Forgery, or when
<a
href='http://docs.djangoproject.com/en/dev/ref/contrib/csrf/#ref-contrib-csrf'>Django's
CSRF mechanism</a> has not been used correctly. For POST forms, you need to
ensure:</p>
<ul>
<li>Your browser is accepting cookies.</li>
<li>The view function uses <a
href='http://docs.djangoproject.com/en/dev/ref/templates/api/#subclassing-context-requestcontext'><code>RequestContext</code></a>
for the template, instead of <code>Context</code>.</li>
<li>In the template, there is a <code>{% templatetag openblock %} csrf_token
{% templatetag closeblock %}</code> template tag inside each POST form that
targets an internal URL.</li>
<li>If you are not using <code>CsrfViewMiddleware</code>, then you must use
<code>csrf_protect</code> on any views that use the <code>csrf_token</code>
template tag, as well as those that accept the POST data.</li>
</ul>
<p>You're seeing the help section of this page because you have <code>DEBUG =
True</code> in your Django settings file. Change that to <code>False</code>,
and only the initial error message will be displayed. </p>
<p>You can customize this page using the CSRF_FAILURE_VIEW setting.</p>
</div>
{% else %}
<div id="explanation">
<p><small>More information is available with DEBUG=True.</small></p>
</div>
{% endif %}
</body>
</html>
"""
def csrf_failure(request, reason=""):
"""
Default view used when request fails CSRF protection
"""
from django.middleware.csrf import REASON_NO_REFERER
t = Template(CSRF_FAILURE_TEMPLATE)
c = Context({'DEBUG': settings.DEBUG,
'reason': reason,
'no_referer': reason == REASON_NO_REFERER
})
return HttpResponseForbidden(t.render(c), mimetype='text/html')
|
mit
|
[
504,
1639,
14,
1014,
492,
6183,
17454,
199,
504,
1639,
14,
1160,
492,
9470,
12,
5458,
199,
504,
1639,
14,
2190,
492,
2202,
199,
199,
3,
2136,
2387,
314,
1978,
8308,
3967,
781,
1929,
370,
506,
7688,
370,
16492,
6665,
2929,
199,
3,
642,
1125,
1245,
12,
24002,
367,
314,
308,
1728,
402,
19782,
12,
436,
2337,
5712,
1133,
1263,
199,
3,
1163,
4340,
402,
10663,
652,
2808,
12717,
402,
4052,
365,
315,
314,
2202,
570,
14,
199,
199,
26405,
63,
13989,
63,
7433,
275,
408,
199,
11230,
16556,
3517,
30,
199,
28,
1360,
6339,
628,
287,
1743,
199,
28,
2993,
30,
523,
665,
2024,
1455,
13,
20146,
628,
1317,
13,
466,
2,
1564,
628,
505,
15,
1360,
27,
5960,
29,
1624,
13,
24,
1743,
523,
665,
2024,
536,
628,
28889,
2,
1564,
628,
9185,
12,
2826,
28800,
1743,
523,
665,
1213,
30,
13353,
2104,
10912,
1108,
1213,
30,
523,
665,
2487,
730,
628,
505,
15,
3919,
1743,
272,
3517,
627,
469,
6273,
26,
16,
27,
11042,
26,
16,
27,
789,
272,
2396,
627,
469,
6273,
26,
709,
5326,
3388,
5326,
27,
789,
272,
2396,
627,
627,
469,
6273,
26,
16,
27,
789,
272,
2396,
469,
5023,
26,
7241,
308,
796,
13,
24977,
27,
8020,
15596,
18777,
27,
789,
272,
2396,
30,
3015,
469,
9162,
13,
8305,
26,
17,
5326,
18609,
327,
15389,
27,
789,
272,
394,
17,
469,
5023,
13,
3463,
26,
3302,
27,
11042,
13,
8305,
14010,
20,
5633,
27,
789,
272,
394,
17,
13598,
469,
5023,
13,
890,
26,
2259,
5,
27,
3164,
15596,
11829,
27,
5023,
13,
3463,
26,
3302,
27,
789,
272,
327,
815,
469,
8020,
15596,
70,
22,
70,
22,
70,
22,
27,
789,
272,
327,
815,
12581,
469,
11042,
26,
378,
14,
21,
5633,
841,
5633,
27,
789,
272,
327,
815,
299,
12,
327,
4705,
299,
469,
6273,
13,
2119,
26,
709,
5326,
27,
789,
272,
327,
4705,
469,
8020,
26,
327,
26299,
27,
789,
272,
327,
15228,
469,
8020,
15596,
18777,
27,
9162,
13,
8305,
26,
378,
5326,
7179,
27,
789,
523,
3068,
2487,
30,
199,
1108,
2993,
30,
199,
28,
2030,
30,
199,
28,
3015,
1305,
628,
4705,
1743,
523,
665,
72,
17,
30,
17454,
665,
3751,
13661,
13353,
15939,
3751,
2957,
72,
17,
30,
523,
665,
80,
30,
26405,
14786,
3405,
14,
4784,
26815,
9758,
80,
30,
199,
3996,
340,
949,
63,
20996,
3674,
523,
665,
80,
30,
5556,
787,
1937,
316,
642,
1245,
2952,
642,
14147,
4770,
5074,
282,
283,
28900,
2043,
1406,
7,
370,
506,
4847,
701,
2195,
6001,
7042,
12,
1325,
7179,
1990,
4847,
14,
961,
1406,
365,
2043,
1415,
367,
6391,
14872,
12,
370,
4868,
626,
2195,
7042,
365,
440,
3769,
2043,
394,
7879,
564,
379,
701,
10919,
623,
1417,
9758,
80,
30,
819,
665,
80,
30,
3917,
1265,
1172,
7526,
2195,
7042,
370,
3507,
283,
28900,
7,
2323,
12,
8749,
2043,
295,
13,
4296,
3062,
12,
737,
5210,
367,
642,
4770,
12,
503,
367,
14147,
6947,
12,
503,
367,
2043,
283,
7191,
13,
6493,
7,
4145,
9758,
80,
30,
199,
3996,
14454,
3674,
199,
1108,
3015,
30,
199,
3996,
340,
10990,
3674,
199,
28,
3015,
1305,
628,
815,
1743,
523,
665,
72,
18,
30,
8673,
1108,
72,
18,
30,
272,
7749,
340,
4499,
3674,
272,
665,
80,
30,
16148,
1627,
367,
5988,
9919,
80,
30,
272,
665,
657,
30,
272,
8448,
4499,
3586,
272,
3068,
657,
30,
272,
7749,
14454,
3674,
819,
665,
80,
30,
607,
8605,
12,
642,
883,
4781,
1380,
2337,
365,
282,
3805,
85,
1132,
28965,
11666,
4784,
2104,
836,
89,
12,
503,
1380,
523,
665,
65,
523,
4369,
534,
1014,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
2374,
15,
1121,
15,
2828,
15,
10088,
12645,
1121,
13,
2828,
13,
10088,
8423,
9323,
1159,
523,
22468,
14729,
1108,
65,
30,
965,
440,
2757,
1202,
6657,
14,
221,
2104,
8761,
4513,
12,
1265,
1929,
370,
523,
4868,
9919,
80,
30,
819,
665,
348,
30,
272,
665,
317,
30,
14398,
7042,
365,
32163,
10049,
9758,
317,
30,
339,
665,
317,
30,
1918,
2455,
805,
4440,
665,
65,
272,
4369,
534,
1014,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
2374,
15,
1121,
15,
5876,
15,
1246,
12645,
27904,
13,
1100,
13,
1069,
1100,
7,
2535,
600,
30,
17679,
1108,
600,
2957,
65,
30,
272,
367,
314,
1978,
12,
3140,
402,
665,
600,
30,
2998,
1108,
600,
30,
9758,
317,
30,
339,
665,
317,
30,
607,
314,
1978,
12,
2337,
365,
282,
665,
600,
30,
3996,
1978,
1450,
1551,
1457,
3674,
19213,
63,
1418,
272,
7749,
1978,
1450,
4002,
1457,
3674,
1108,
600,
30,
1978,
1947,
6272,
1924,
8761,
1824,
626,
272,
4545,
376,
5007,
2851,
9758,
317,
30,
339,
665,
317,
30,
3917,
1265,
787,
440,
1808,
665,
600,
30,
13912,
25322,
1108,
600,
6244,
2066,
1265,
1471,
675,
272,
665,
600,
30,
10088,
63,
18292,
1108,
600,
30,
641,
1263,
6858,
626,
675,
314,
665,
600,
30,
10088,
63,
1418,
1108,
600,
30,
272,
1978,
1947,
12,
465,
5521,
465,
5204,
626,
4729,
314,
8761,
666,
9758,
317,
30,
819,
3068,
348,
30,
819,
665,
80,
30,
5556,
3984,
1937,
316,
314,
1720,
3420,
402,
642,
2034,
2952,
1265,
1172,
665,
600,
30,
5287,
275,
523,
715,
1108,
600,
30,
315,
2195,
5634,
2202,
570,
14,
7743,
626,
370,
665,
600,
30,
797,
1108,
600,
6244,
523,
436,
1454,
314,
2536,
1125,
1245,
911,
506,
9080,
14,
221,
3068,
80,
30,
819,
665,
80,
30,
5556,
883,
17551,
642,
2034,
1808,
314,
22468,
63,
13989,
63,
12058,
4260,
9758,
80,
30,
199,
1108,
3015,
30,
199,
3996,
587,
3674,
199,
28,
3015,
1305,
628,
15228,
1743,
523,
665,
80,
2535,
7241,
30,
11053,
2556,
365,
2808,
543,
10990,
29,
549,
9758,
7241,
2957,
80,
30,
199,
1108,
3015,
30,
199,
3996,
14454,
3674,
199,
1108,
2030,
30,
199,
1108,
1360,
30,
199,
624,
199,
199,
318,
19213,
63,
5328,
8,
1069,
12,
4499,
17364,
272,
408,
272,
3758,
2455,
1202,
1380,
1056,
6918,
22468,
23977,
272,
408,
272,
687,
1639,
14,
5754,
14,
10088,
492,
5363,
28883,
63,
2826,
63,
19494,
540,
272,
307,
275,
5458,
8,
26405,
63,
13989,
63,
7433,
9,
272
] |
[
1639,
14,
1014,
492,
6183,
17454,
199,
504,
1639,
14,
1160,
492,
9470,
12,
5458,
199,
504,
1639,
14,
2190,
492,
2202,
199,
199,
3,
2136,
2387,
314,
1978,
8308,
3967,
781,
1929,
370,
506,
7688,
370,
16492,
6665,
2929,
199,
3,
642,
1125,
1245,
12,
24002,
367,
314,
308,
1728,
402,
19782,
12,
436,
2337,
5712,
1133,
1263,
199,
3,
1163,
4340,
402,
10663,
652,
2808,
12717,
402,
4052,
365,
315,
314,
2202,
570,
14,
199,
199,
26405,
63,
13989,
63,
7433,
275,
408,
199,
11230,
16556,
3517,
30,
199,
28,
1360,
6339,
628,
287,
1743,
199,
28,
2993,
30,
523,
665,
2024,
1455,
13,
20146,
628,
1317,
13,
466,
2,
1564,
628,
505,
15,
1360,
27,
5960,
29,
1624,
13,
24,
1743,
523,
665,
2024,
536,
628,
28889,
2,
1564,
628,
9185,
12,
2826,
28800,
1743,
523,
665,
1213,
30,
13353,
2104,
10912,
1108,
1213,
30,
523,
665,
2487,
730,
628,
505,
15,
3919,
1743,
272,
3517,
627,
469,
6273,
26,
16,
27,
11042,
26,
16,
27,
789,
272,
2396,
627,
469,
6273,
26,
709,
5326,
3388,
5326,
27,
789,
272,
2396,
627,
627,
469,
6273,
26,
16,
27,
789,
272,
2396,
469,
5023,
26,
7241,
308,
796,
13,
24977,
27,
8020,
15596,
18777,
27,
789,
272,
2396,
30,
3015,
469,
9162,
13,
8305,
26,
17,
5326,
18609,
327,
15389,
27,
789,
272,
394,
17,
469,
5023,
13,
3463,
26,
3302,
27,
11042,
13,
8305,
14010,
20,
5633,
27,
789,
272,
394,
17,
13598,
469,
5023,
13,
890,
26,
2259,
5,
27,
3164,
15596,
11829,
27,
5023,
13,
3463,
26,
3302,
27,
789,
272,
327,
815,
469,
8020,
15596,
70,
22,
70,
22,
70,
22,
27,
789,
272,
327,
815,
12581,
469,
11042,
26,
378,
14,
21,
5633,
841,
5633,
27,
789,
272,
327,
815,
299,
12,
327,
4705,
299,
469,
6273,
13,
2119,
26,
709,
5326,
27,
789,
272,
327,
4705,
469,
8020,
26,
327,
26299,
27,
789,
272,
327,
15228,
469,
8020,
15596,
18777,
27,
9162,
13,
8305,
26,
378,
5326,
7179,
27,
789,
523,
3068,
2487,
30,
199,
1108,
2993,
30,
199,
28,
2030,
30,
199,
28,
3015,
1305,
628,
4705,
1743,
523,
665,
72,
17,
30,
17454,
665,
3751,
13661,
13353,
15939,
3751,
2957,
72,
17,
30,
523,
665,
80,
30,
26405,
14786,
3405,
14,
4784,
26815,
9758,
80,
30,
199,
3996,
340,
949,
63,
20996,
3674,
523,
665,
80,
30,
5556,
787,
1937,
316,
642,
1245,
2952,
642,
14147,
4770,
5074,
282,
283,
28900,
2043,
1406,
7,
370,
506,
4847,
701,
2195,
6001,
7042,
12,
1325,
7179,
1990,
4847,
14,
961,
1406,
365,
2043,
1415,
367,
6391,
14872,
12,
370,
4868,
626,
2195,
7042,
365,
440,
3769,
2043,
394,
7879,
564,
379,
701,
10919,
623,
1417,
9758,
80,
30,
819,
665,
80,
30,
3917,
1265,
1172,
7526,
2195,
7042,
370,
3507,
283,
28900,
7,
2323,
12,
8749,
2043,
295,
13,
4296,
3062,
12,
737,
5210,
367,
642,
4770,
12,
503,
367,
14147,
6947,
12,
503,
367,
2043,
283,
7191,
13,
6493,
7,
4145,
9758,
80,
30,
199,
3996,
14454,
3674,
199,
1108,
3015,
30,
199,
3996,
340,
10990,
3674,
199,
28,
3015,
1305,
628,
815,
1743,
523,
665,
72,
18,
30,
8673,
1108,
72,
18,
30,
272,
7749,
340,
4499,
3674,
272,
665,
80,
30,
16148,
1627,
367,
5988,
9919,
80,
30,
272,
665,
657,
30,
272,
8448,
4499,
3586,
272,
3068,
657,
30,
272,
7749,
14454,
3674,
819,
665,
80,
30,
607,
8605,
12,
642,
883,
4781,
1380,
2337,
365,
282,
3805,
85,
1132,
28965,
11666,
4784,
2104,
836,
89,
12,
503,
1380,
523,
665,
65,
523,
4369,
534,
1014,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
2374,
15,
1121,
15,
2828,
15,
10088,
12645,
1121,
13,
2828,
13,
10088,
8423,
9323,
1159,
523,
22468,
14729,
1108,
65,
30,
965,
440,
2757,
1202,
6657,
14,
221,
2104,
8761,
4513,
12,
1265,
1929,
370,
523,
4868,
9919,
80,
30,
819,
665,
348,
30,
272,
665,
317,
30,
14398,
7042,
365,
32163,
10049,
9758,
317,
30,
339,
665,
317,
30,
1918,
2455,
805,
4440,
665,
65,
272,
4369,
534,
1014,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
2374,
15,
1121,
15,
5876,
15,
1246,
12645,
27904,
13,
1100,
13,
1069,
1100,
7,
2535,
600,
30,
17679,
1108,
600,
2957,
65,
30,
272,
367,
314,
1978,
12,
3140,
402,
665,
600,
30,
2998,
1108,
600,
30,
9758,
317,
30,
339,
665,
317,
30,
607,
314,
1978,
12,
2337,
365,
282,
665,
600,
30,
3996,
1978,
1450,
1551,
1457,
3674,
19213,
63,
1418,
272,
7749,
1978,
1450,
4002,
1457,
3674,
1108,
600,
30,
1978,
1947,
6272,
1924,
8761,
1824,
626,
272,
4545,
376,
5007,
2851,
9758,
317,
30,
339,
665,
317,
30,
3917,
1265,
787,
440,
1808,
665,
600,
30,
13912,
25322,
1108,
600,
6244,
2066,
1265,
1471,
675,
272,
665,
600,
30,
10088,
63,
18292,
1108,
600,
30,
641,
1263,
6858,
626,
675,
314,
665,
600,
30,
10088,
63,
1418,
1108,
600,
30,
272,
1978,
1947,
12,
465,
5521,
465,
5204,
626,
4729,
314,
8761,
666,
9758,
317,
30,
819,
3068,
348,
30,
819,
665,
80,
30,
5556,
3984,
1937,
316,
314,
1720,
3420,
402,
642,
2034,
2952,
1265,
1172,
665,
600,
30,
5287,
275,
523,
715,
1108,
600,
30,
315,
2195,
5634,
2202,
570,
14,
7743,
626,
370,
665,
600,
30,
797,
1108,
600,
6244,
523,
436,
1454,
314,
2536,
1125,
1245,
911,
506,
9080,
14,
221,
3068,
80,
30,
819,
665,
80,
30,
5556,
883,
17551,
642,
2034,
1808,
314,
22468,
63,
13989,
63,
12058,
4260,
9758,
80,
30,
199,
1108,
3015,
30,
199,
3996,
587,
3674,
199,
28,
3015,
1305,
628,
15228,
1743,
523,
665,
80,
2535,
7241,
30,
11053,
2556,
365,
2808,
543,
10990,
29,
549,
9758,
7241,
2957,
80,
30,
199,
1108,
3015,
30,
199,
3996,
14454,
3674,
199,
1108,
2030,
30,
199,
1108,
1360,
30,
199,
624,
199,
199,
318,
19213,
63,
5328,
8,
1069,
12,
4499,
17364,
272,
408,
272,
3758,
2455,
1202,
1380,
1056,
6918,
22468,
23977,
272,
408,
272,
687,
1639,
14,
5754,
14,
10088,
492,
5363,
28883,
63,
2826,
63,
19494,
540,
272,
307,
275,
5458,
8,
26405,
63,
13989,
63,
7433,
9,
272,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
allenlavoie/tensorflow
|
tensorflow/contrib/receptive_field/python/util/examples/write_inception_resnet_v2_graph.py
|
49
|
2032
|
# Copyright 2017 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Simple script to write Inception-ResNet-v2 model to graph file.
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import argparse
import sys
from tensorflow.python.framework import dtypes
from tensorflow.python.framework import graph_io
from tensorflow.python.framework import ops
from tensorflow.python.ops import array_ops
from tensorflow.python.platform import app
from nets import inception
cmd_args = None
def main(unused_argv):
# Model definition.
g = ops.Graph()
with g.as_default():
images = array_ops.placeholder(
dtypes.float32, shape=(1, None, None, 3), name='input_image')
inception.inception_resnet_v2_base(images)
graph_io.write_graph(g.as_graph_def(), cmd_args.graph_dir,
cmd_args.graph_filename)
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.register('type', 'bool', lambda v: v.lower() == 'true')
parser.add_argument(
'--graph_dir',
type=str,
default='/tmp',
help='Directory where graph will be saved.')
parser.add_argument(
'--graph_filename',
type=str,
default='graph.pbtxt',
help='Filename of graph that will be saved.')
cmd_args, unparsed = parser.parse_known_args()
app.run(main=main, argv=[sys.argv[0]] + unparsed)
|
apache-2.0
|
[
3,
1898,
9708,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
3184,
2884,
370,
2218,
1010,
814,
13,
1322,
2480,
13,
86,
18,
1402,
370,
3343,
570,
14,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
7534,
199,
646,
984,
199,
199,
504,
3228,
14,
1548,
14,
4857,
492,
6674,
199,
504,
3228,
14,
1548,
14,
4857,
492,
3343,
63,
2308,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1625,
63,
1483,
199,
504,
3228,
14,
1548,
14,
3246,
492,
1145,
199,
504,
1851,
83,
492,
315,
814,
199,
199,
1760,
63,
589,
275,
488,
421,
199,
318,
2446,
8,
8618,
63,
3020,
304,
523,
327,
5822,
5492,
14,
523,
486,
275,
4156,
14,
4578,
342,
523,
543,
486,
14,
305,
63,
885,
837,
272,
5935,
275,
1625,
63,
1483,
14,
6199,
8,
267,
6674,
14,
1609,
708,
12,
2215,
2687,
17,
12,
488,
12,
488,
12,
650,
395,
536,
534,
1210,
63,
1569,
358,
272,
315,
814,
14,
262,
814,
63,
28998,
63,
86,
18,
63,
1095,
8,
4782,
9,
819,
3343,
63,
2308,
14,
952,
63,
2180,
8,
71,
14,
305,
63,
2180,
63,
318,
1062,
2088,
63,
589,
14,
2180,
63,
694,
12,
2432,
2088,
63,
589,
14,
2180,
63,
1501,
9,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
1798,
275,
7534,
14,
10730,
342,
523,
1798,
14,
2683,
360,
466,
297,
283,
2245,
297,
2400,
373,
26,
373,
14,
2325,
342,
508,
283,
2052,
358,
523,
1798,
14,
525,
63,
2094,
8,
489,
2850,
2180,
63,
694,
297,
489,
730,
29,
495,
12,
489,
849,
8805,
2791,
297,
489,
1720,
534,
6231,
2382,
3343,
911,
506,
6290,
2659,
523,
1798,
14,
525,
63,
2094,
8,
489,
2850,
2180,
63,
1501,
297,
489,
730,
29,
495,
12,
489,
849,
534,
2180,
14,
3317,
2424,
297,
489,
1720,
534,
8117,
402,
3343,
626,
911,
506,
6290,
2659,
523,
2088,
63,
589,
12,
31857,
275,
1798,
14,
1122,
63,
3159,
63,
589,
342,
523,
1145,
14,
1065,
8,
973,
29,
973,
12,
9238,
1524,
1274,
14,
3020,
59,
16,
2677,
435,
31857,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
9708,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
3184,
2884,
370,
2218,
1010,
814,
13,
1322,
2480,
13,
86,
18,
1402,
370,
3343,
570,
14,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
7534,
199,
646,
984,
199,
199,
504,
3228,
14,
1548,
14,
4857,
492,
6674,
199,
504,
3228,
14,
1548,
14,
4857,
492,
3343,
63,
2308,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1625,
63,
1483,
199,
504,
3228,
14,
1548,
14,
3246,
492,
1145,
199,
504,
1851,
83,
492,
315,
814,
199,
199,
1760,
63,
589,
275,
488,
421,
199,
318,
2446,
8,
8618,
63,
3020,
304,
523,
327,
5822,
5492,
14,
523,
486,
275,
4156,
14,
4578,
342,
523,
543,
486,
14,
305,
63,
885,
837,
272,
5935,
275,
1625,
63,
1483,
14,
6199,
8,
267,
6674,
14,
1609,
708,
12,
2215,
2687,
17,
12,
488,
12,
488,
12,
650,
395,
536,
534,
1210,
63,
1569,
358,
272,
315,
814,
14,
262,
814,
63,
28998,
63,
86,
18,
63,
1095,
8,
4782,
9,
819,
3343,
63,
2308,
14,
952,
63,
2180,
8,
71,
14,
305,
63,
2180,
63,
318,
1062,
2088,
63,
589,
14,
2180,
63,
694,
12,
2432,
2088,
63,
589,
14,
2180,
63,
1501,
9,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
1798,
275,
7534,
14,
10730,
342,
523,
1798,
14,
2683,
360,
466,
297,
283,
2245,
297,
2400,
373,
26,
373,
14,
2325,
342,
508,
283,
2052,
358,
523,
1798,
14,
525,
63,
2094,
8,
489,
2850,
2180,
63,
694,
297,
489,
730,
29,
495,
12,
489,
849,
8805,
2791,
297,
489,
1720,
534,
6231,
2382,
3343,
911,
506,
6290,
2659,
523,
1798,
14,
525,
63,
2094,
8,
489,
2850,
2180,
63,
1501,
297,
489,
730,
29,
495,
12,
489,
849,
534,
2180,
14,
3317,
2424,
297,
489,
1720,
534,
8117,
402,
3343,
626,
911,
506,
6290,
2659,
523,
2088,
63,
589,
12,
31857,
275,
1798,
14,
1122,
63,
3159,
63,
589,
342,
523,
1145,
14,
1065,
8,
973,
29,
973,
12,
9238,
1524,
1274,
14,
3020,
59,
16,
2677,
435,
31857,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
simongibbons/numpy
|
numpy/polynomial/tests/test_polynomial.py
|
10
|
20035
|
"""Tests for polynomial module.
"""
from functools import reduce
import numpy as np
import numpy.polynomial.polynomial as poly
from numpy.testing import (
assert_almost_equal, assert_raises, assert_equal, assert_,
assert_warns, assert_array_equal, assert_raises_regex)
def trim(x):
return poly.polytrim(x, tol=1e-6)
T0 = [1]
T1 = [0, 1]
T2 = [-1, 0, 2]
T3 = [0, -3, 0, 4]
T4 = [1, 0, -8, 0, 8]
T5 = [0, 5, 0, -20, 0, 16]
T6 = [-1, 0, 18, 0, -48, 0, 32]
T7 = [0, -7, 0, 56, 0, -112, 0, 64]
T8 = [1, 0, -32, 0, 160, 0, -256, 0, 128]
T9 = [0, 9, 0, -120, 0, 432, 0, -576, 0, 256]
Tlist = [T0, T1, T2, T3, T4, T5, T6, T7, T8, T9]
class TestConstants:
def test_polydomain(self):
assert_equal(poly.polydomain, [-1, 1])
def test_polyzero(self):
assert_equal(poly.polyzero, [0])
def test_polyone(self):
assert_equal(poly.polyone, [1])
def test_polyx(self):
assert_equal(poly.polyx, [0, 1])
class TestArithmetic:
def test_polyadd(self):
for i in range(5):
for j in range(5):
msg = f"At i={i}, j={j}"
tgt = np.zeros(max(i, j) + 1)
tgt[i] += 1
tgt[j] += 1
res = poly.polyadd([0]*i + [1], [0]*j + [1])
assert_equal(trim(res), trim(tgt), err_msg=msg)
def test_polysub(self):
for i in range(5):
for j in range(5):
msg = f"At i={i}, j={j}"
tgt = np.zeros(max(i, j) + 1)
tgt[i] += 1
tgt[j] -= 1
res = poly.polysub([0]*i + [1], [0]*j + [1])
assert_equal(trim(res), trim(tgt), err_msg=msg)
def test_polymulx(self):
assert_equal(poly.polymulx([0]), [0])
assert_equal(poly.polymulx([1]), [0, 1])
for i in range(1, 5):
ser = [0]*i + [1]
tgt = [0]*(i + 1) + [1]
assert_equal(poly.polymulx(ser), tgt)
def test_polymul(self):
for i in range(5):
for j in range(5):
msg = f"At i={i}, j={j}"
tgt = np.zeros(i + j + 1)
tgt[i + j] += 1
res = poly.polymul([0]*i + [1], [0]*j + [1])
assert_equal(trim(res), trim(tgt), err_msg=msg)
def test_polydiv(self):
# check zero division
assert_raises(ZeroDivisionError, poly.polydiv, [1], [0])
# check scalar division
quo, rem = poly.polydiv([2], [2])
assert_equal((quo, rem), (1, 0))
quo, rem = poly.polydiv([2, 2], [2])
assert_equal((quo, rem), ((1, 1), 0))
# check rest.
for i in range(5):
for j in range(5):
msg = f"At i={i}, j={j}"
ci = [0]*i + [1, 2]
cj = [0]*j + [1, 2]
tgt = poly.polyadd(ci, cj)
quo, rem = poly.polydiv(tgt, ci)
res = poly.polyadd(poly.polymul(quo, ci), rem)
assert_equal(res, tgt, err_msg=msg)
def test_polypow(self):
for i in range(5):
for j in range(5):
msg = f"At i={i}, j={j}"
c = np.arange(i + 1)
tgt = reduce(poly.polymul, [c]*j, np.array([1]))
res = poly.polypow(c, j)
assert_equal(trim(res), trim(tgt), err_msg=msg)
class TestEvaluation:
# coefficients of 1 + 2*x + 3*x**2
c1d = np.array([1., 2., 3.])
c2d = np.einsum('i,j->ij', c1d, c1d)
c3d = np.einsum('i,j,k->ijk', c1d, c1d, c1d)
# some random values in [-1, 1)
x = np.random.random((3, 5))*2 - 1
y = poly.polyval(x, [1., 2., 3.])
def test_polyval(self):
#check empty input
assert_equal(poly.polyval([], [1]).size, 0)
#check normal input)
x = np.linspace(-1, 1)
y = [x**i for i in range(5)]
for i in range(5):
tgt = y[i]
res = poly.polyval(x, [0]*i + [1])
assert_almost_equal(res, tgt)
tgt = x*(x**2 - 1)
res = poly.polyval(x, [0, -1, 0, 1])
assert_almost_equal(res, tgt)
#check that shape is preserved
for i in range(3):
dims = [2]*i
x = np.zeros(dims)
assert_equal(poly.polyval(x, [1]).shape, dims)
assert_equal(poly.polyval(x, [1, 0]).shape, dims)
assert_equal(poly.polyval(x, [1, 0, 0]).shape, dims)
#check masked arrays are processed correctly
mask = [False, True, False]
mx = np.ma.array([1, 2, 3], mask=mask)
res = np.polyval([7, 5, 3], mx)
assert_array_equal(res.mask, mask)
#check subtypes of ndarray are preserved
class C(np.ndarray):
pass
cx = np.array([1, 2, 3]).view(C)
assert_equal(type(np.polyval([2, 3, 4], cx)), C)
def test_polyvalfromroots(self):
# check exception for broadcasting x values over root array with
# too few dimensions
assert_raises(ValueError, poly.polyvalfromroots,
[1], [1], tensor=False)
# check empty input
assert_equal(poly.polyvalfromroots([], [1]).size, 0)
assert_(poly.polyvalfromroots([], [1]).shape == (0,))
# check empty input + multidimensional roots
assert_equal(poly.polyvalfromroots([], [[1] * 5]).size, 0)
assert_(poly.polyvalfromroots([], [[1] * 5]).shape == (5, 0))
# check scalar input
assert_equal(poly.polyvalfromroots(1, 1), 0)
assert_(poly.polyvalfromroots(1, np.ones((3, 3))).shape == (3,))
# check normal input)
x = np.linspace(-1, 1)
y = [x**i for i in range(5)]
for i in range(1, 5):
tgt = y[i]
res = poly.polyvalfromroots(x, [0]*i)
assert_almost_equal(res, tgt)
tgt = x*(x - 1)*(x + 1)
res = poly.polyvalfromroots(x, [-1, 0, 1])
assert_almost_equal(res, tgt)
# check that shape is preserved
for i in range(3):
dims = [2]*i
x = np.zeros(dims)
assert_equal(poly.polyvalfromroots(x, [1]).shape, dims)
assert_equal(poly.polyvalfromroots(x, [1, 0]).shape, dims)
assert_equal(poly.polyvalfromroots(x, [1, 0, 0]).shape, dims)
# check compatibility with factorization
ptest = [15, 2, -16, -2, 1]
r = poly.polyroots(ptest)
x = np.linspace(-1, 1)
assert_almost_equal(poly.polyval(x, ptest),
poly.polyvalfromroots(x, r))
# check multidimensional arrays of roots and values
# check tensor=False
rshape = (3, 5)
x = np.arange(-3, 2)
r = np.random.randint(-5, 5, size=rshape)
res = poly.polyvalfromroots(x, r, tensor=False)
tgt = np.empty(r.shape[1:])
for ii in range(tgt.size):
tgt[ii] = poly.polyvalfromroots(x[ii], r[:, ii])
assert_equal(res, tgt)
# check tensor=True
x = np.vstack([x, 2*x])
res = poly.polyvalfromroots(x, r, tensor=True)
tgt = np.empty(r.shape[1:] + x.shape)
for ii in range(r.shape[1]):
for jj in range(x.shape[0]):
tgt[ii, jj, :] = poly.polyvalfromroots(x[jj], r[:, ii])
assert_equal(res, tgt)
def test_polyval2d(self):
x1, x2, x3 = self.x
y1, y2, y3 = self.y
#test exceptions
assert_raises_regex(ValueError, 'incompatible',
poly.polyval2d, x1, x2[:2], self.c2d)
#test values
tgt = y1*y2
res = poly.polyval2d(x1, x2, self.c2d)
assert_almost_equal(res, tgt)
#test shape
z = np.ones((2, 3))
res = poly.polyval2d(z, z, self.c2d)
assert_(res.shape == (2, 3))
def test_polyval3d(self):
x1, x2, x3 = self.x
y1, y2, y3 = self.y
#test exceptions
assert_raises_regex(ValueError, 'incompatible',
poly.polyval3d, x1, x2, x3[:2], self.c3d)
#test values
tgt = y1*y2*y3
res = poly.polyval3d(x1, x2, x3, self.c3d)
assert_almost_equal(res, tgt)
#test shape
z = np.ones((2, 3))
res = poly.polyval3d(z, z, z, self.c3d)
assert_(res.shape == (2, 3))
def test_polygrid2d(self):
x1, x2, x3 = self.x
y1, y2, y3 = self.y
#test values
tgt = np.einsum('i,j->ij', y1, y2)
res = poly.polygrid2d(x1, x2, self.c2d)
assert_almost_equal(res, tgt)
#test shape
z = np.ones((2, 3))
res = poly.polygrid2d(z, z, self.c2d)
assert_(res.shape == (2, 3)*2)
def test_polygrid3d(self):
x1, x2, x3 = self.x
y1, y2, y3 = self.y
#test values
tgt = np.einsum('i,j,k->ijk', y1, y2, y3)
res = poly.polygrid3d(x1, x2, x3, self.c3d)
assert_almost_equal(res, tgt)
#test shape
z = np.ones((2, 3))
res = poly.polygrid3d(z, z, z, self.c3d)
assert_(res.shape == (2, 3)*3)
class TestIntegral:
def test_polyint(self):
# check exceptions
assert_raises(TypeError, poly.polyint, [0], .5)
assert_raises(ValueError, poly.polyint, [0], -1)
assert_raises(ValueError, poly.polyint, [0], 1, [0, 0])
assert_raises(ValueError, poly.polyint, [0], lbnd=[0])
assert_raises(ValueError, poly.polyint, [0], scl=[0])
assert_raises(TypeError, poly.polyint, [0], axis=.5)
with assert_warns(DeprecationWarning):
poly.polyint([1, 1], 1.)
# test integration of zero polynomial
for i in range(2, 5):
k = [0]*(i - 2) + [1]
res = poly.polyint([0], m=i, k=k)
assert_almost_equal(res, [0, 1])
# check single integration with integration constant
for i in range(5):
scl = i + 1
pol = [0]*i + [1]
tgt = [i] + [0]*i + [1/scl]
res = poly.polyint(pol, m=1, k=[i])
assert_almost_equal(trim(res), trim(tgt))
# check single integration with integration constant and lbnd
for i in range(5):
scl = i + 1
pol = [0]*i + [1]
res = poly.polyint(pol, m=1, k=[i], lbnd=-1)
assert_almost_equal(poly.polyval(-1, res), i)
# check single integration with integration constant and scaling
for i in range(5):
scl = i + 1
pol = [0]*i + [1]
tgt = [i] + [0]*i + [2/scl]
res = poly.polyint(pol, m=1, k=[i], scl=2)
assert_almost_equal(trim(res), trim(tgt))
# check multiple integrations with default k
for i in range(5):
for j in range(2, 5):
pol = [0]*i + [1]
tgt = pol[:]
for k in range(j):
tgt = poly.polyint(tgt, m=1)
res = poly.polyint(pol, m=j)
assert_almost_equal(trim(res), trim(tgt))
# check multiple integrations with defined k
for i in range(5):
for j in range(2, 5):
pol = [0]*i + [1]
tgt = pol[:]
for k in range(j):
tgt = poly.polyint(tgt, m=1, k=[k])
res = poly.polyint(pol, m=j, k=list(range(j)))
assert_almost_equal(trim(res), trim(tgt))
# check multiple integrations with lbnd
for i in range(5):
for j in range(2, 5):
pol = [0]*i + [1]
tgt = pol[:]
for k in range(j):
tgt = poly.polyint(tgt, m=1, k=[k], lbnd=-1)
res = poly.polyint(pol, m=j, k=list(range(j)), lbnd=-1)
assert_almost_equal(trim(res), trim(tgt))
# check multiple integrations with scaling
for i in range(5):
for j in range(2, 5):
pol = [0]*i + [1]
tgt = pol[:]
for k in range(j):
tgt = poly.polyint(tgt, m=1, k=[k], scl=2)
res = poly.polyint(pol, m=j, k=list(range(j)), scl=2)
assert_almost_equal(trim(res), trim(tgt))
def test_polyint_axis(self):
# check that axis keyword works
c2d = np.random.random((3, 4))
tgt = np.vstack([poly.polyint(c) for c in c2d.T]).T
res = poly.polyint(c2d, axis=0)
assert_almost_equal(res, tgt)
tgt = np.vstack([poly.polyint(c) for c in c2d])
res = poly.polyint(c2d, axis=1)
assert_almost_equal(res, tgt)
tgt = np.vstack([poly.polyint(c, k=3) for c in c2d])
res = poly.polyint(c2d, k=3, axis=1)
assert_almost_equal(res, tgt)
class TestDerivative:
def test_polyder(self):
# check exceptions
assert_raises(TypeError, poly.polyder, [0], .5)
assert_raises(ValueError, poly.polyder, [0], -1)
# check that zeroth derivative does nothing
for i in range(5):
tgt = [0]*i + [1]
res = poly.polyder(tgt, m=0)
assert_equal(trim(res), trim(tgt))
# check that derivation is the inverse of integration
for i in range(5):
for j in range(2, 5):
tgt = [0]*i + [1]
res = poly.polyder(poly.polyint(tgt, m=j), m=j)
assert_almost_equal(trim(res), trim(tgt))
# check derivation with scaling
for i in range(5):
for j in range(2, 5):
tgt = [0]*i + [1]
res = poly.polyder(poly.polyint(tgt, m=j, scl=2), m=j, scl=.5)
assert_almost_equal(trim(res), trim(tgt))
def test_polyder_axis(self):
# check that axis keyword works
c2d = np.random.random((3, 4))
tgt = np.vstack([poly.polyder(c) for c in c2d.T]).T
res = poly.polyder(c2d, axis=0)
assert_almost_equal(res, tgt)
tgt = np.vstack([poly.polyder(c) for c in c2d])
res = poly.polyder(c2d, axis=1)
assert_almost_equal(res, tgt)
class TestVander:
# some random values in [-1, 1)
x = np.random.random((3, 5))*2 - 1
def test_polyvander(self):
# check for 1d x
x = np.arange(3)
v = poly.polyvander(x, 3)
assert_(v.shape == (3, 4))
for i in range(4):
coef = [0]*i + [1]
assert_almost_equal(v[..., i], poly.polyval(x, coef))
# check for 2d x
x = np.array([[1, 2], [3, 4], [5, 6]])
v = poly.polyvander(x, 3)
assert_(v.shape == (3, 2, 4))
for i in range(4):
coef = [0]*i + [1]
assert_almost_equal(v[..., i], poly.polyval(x, coef))
def test_polyvander2d(self):
# also tests polyval2d for non-square coefficient array
x1, x2, x3 = self.x
c = np.random.random((2, 3))
van = poly.polyvander2d(x1, x2, [1, 2])
tgt = poly.polyval2d(x1, x2, c)
res = np.dot(van, c.flat)
assert_almost_equal(res, tgt)
# check shape
van = poly.polyvander2d([x1], [x2], [1, 2])
assert_(van.shape == (1, 5, 6))
def test_polyvander3d(self):
# also tests polyval3d for non-square coefficient array
x1, x2, x3 = self.x
c = np.random.random((2, 3, 4))
van = poly.polyvander3d(x1, x2, x3, [1, 2, 3])
tgt = poly.polyval3d(x1, x2, x3, c)
res = np.dot(van, c.flat)
assert_almost_equal(res, tgt)
# check shape
van = poly.polyvander3d([x1], [x2], [x3], [1, 2, 3])
assert_(van.shape == (1, 5, 24))
class TestCompanion:
def test_raises(self):
assert_raises(ValueError, poly.polycompanion, [])
assert_raises(ValueError, poly.polycompanion, [1])
def test_dimensions(self):
for i in range(1, 5):
coef = [0]*i + [1]
assert_(poly.polycompanion(coef).shape == (i, i))
def test_linear_root(self):
assert_(poly.polycompanion([1, 2])[0, 0] == -.5)
class TestMisc:
def test_polyfromroots(self):
res = poly.polyfromroots([])
assert_almost_equal(trim(res), [1])
for i in range(1, 5):
roots = np.cos(np.linspace(-np.pi, 0, 2*i + 1)[1::2])
tgt = Tlist[i]
res = poly.polyfromroots(roots)*2**(i-1)
assert_almost_equal(trim(res), trim(tgt))
def test_polyroots(self):
assert_almost_equal(poly.polyroots([1]), [])
assert_almost_equal(poly.polyroots([1, 2]), [-.5])
for i in range(2, 5):
tgt = np.linspace(-1, 1, i)
res = poly.polyroots(poly.polyfromroots(tgt))
assert_almost_equal(trim(res), trim(tgt))
def test_polyfit(self):
def f(x):
return x*(x - 1)*(x - 2)
def f2(x):
return x**4 + x**2 + 1
# Test exceptions
assert_raises(ValueError, poly.polyfit, [1], [1], -1)
assert_raises(TypeError, poly.polyfit, [[1]], [1], 0)
assert_raises(TypeError, poly.polyfit, [], [1], 0)
assert_raises(TypeError, poly.polyfit, [1], [[[1]]], 0)
assert_raises(TypeError, poly.polyfit, [1, 2], [1], 0)
assert_raises(TypeError, poly.polyfit, [1], [1, 2], 0)
assert_raises(TypeError, poly.polyfit, [1], [1], 0, w=[[1]])
assert_raises(TypeError, poly.polyfit, [1], [1], 0, w=[1, 1])
assert_raises(ValueError, poly.polyfit, [1], [1], [-1,])
assert_raises(ValueError, poly.polyfit, [1], [1], [2, -1, 6])
assert_raises(TypeError, poly.polyfit, [1], [1], [])
# Test fit
x = np.linspace(0, 2)
y = f(x)
#
coef3 = poly.polyfit(x, y, 3)
assert_equal(len(coef3), 4)
assert_almost_equal(poly.polyval(x, coef3), y)
coef3 = poly.polyfit(x, y, [0, 1, 2, 3])
assert_equal(len(coef3), 4)
assert_almost_equal(poly.polyval(x, coef3), y)
#
coef4 = poly.polyfit(x, y, 4)
assert_equal(len(coef4), 5)
assert_almost_equal(poly.polyval(x, coef4), y)
coef4 = poly.polyfit(x, y, [0, 1, 2, 3, 4])
assert_equal(len(coef4), 5)
assert_almost_equal(poly.polyval(x, coef4), y)
#
coef2d = poly.polyfit(x, np.array([y, y]).T, 3)
assert_almost_equal(coef2d, np.array([coef3, coef3]).T)
coef2d = poly.polyfit(x, np.array([y, y]).T, [0, 1, 2, 3])
assert_almost_equal(coef2d, np.array([coef3, coef3]).T)
# test weighting
w = np.zeros_like(x)
yw = y.copy()
w[1::2] = 1
yw[0::2] = 0
wcoef3 = poly.polyfit(x, yw, 3, w=w)
assert_almost_equal(wcoef3, coef3)
wcoef3 = poly.polyfit(x, yw, [0, 1, 2, 3], w=w)
assert_almost_equal(wcoef3, coef3)
#
wcoef2d = poly.polyfit(x, np.array([yw, yw]).T, 3, w=w)
assert_almost_equal(wcoef2d, np.array([coef3, coef3]).T)
wcoef2d = poly.polyfit(x, np.array([yw, yw]).T, [0, 1, 2, 3], w=w)
assert_almost_equal(wcoef2d, np.array([coef3, coef3]).T)
# test scaling with complex values x points whose square
# is zero when summed.
x = [1, 1j, -1, -1j]
assert_almost_equal(poly.polyfit(x, x, 1), [0, 1])
assert_almost_equal(poly.polyfit(x, x, [0, 1]), [0, 1])
# test fitting only even Polyendre polynomials
x = np.linspace(-1, 1)
y = f2(x)
coef1 = poly.polyfit(x, y, 4)
assert_almost_equal(poly.polyval(x, coef1), y)
coef2 = poly.polyfit(x, y, [0, 2, 4])
assert_almost_equal(poly.polyval(x, coef2), y)
assert_almost_equal(coef1, coef2)
def test_polytrim(self):
coef = [2, -1, 1, 0]
# Test exceptions
assert_raises(ValueError, poly.polytrim, coef, -1)
# Test results
assert_equal(poly.polytrim(coef), coef[:-1])
assert_equal(poly.polytrim(coef, 1), coef[:-3])
assert_equal(poly.polytrim(coef, 2), [0])
def test_polyline(self):
assert_equal(poly.polyline(3, 4), [3, 4])
|
bsd-3-clause
|
[
624,
2925,
367,
11849,
859,
14,
199,
199,
624,
199,
504,
9143,
492,
7114,
199,
199,
646,
2680,
465,
980,
199,
646,
2680,
14,
22104,
14,
22104,
465,
8446,
199,
504,
2680,
14,
4776,
492,
334,
272,
702,
63,
4398,
63,
1452,
12,
702,
63,
3536,
12,
702,
63,
1452,
12,
702,
3131,
272,
702,
63,
19811,
12,
702,
63,
1144,
63,
1452,
12,
702,
63,
3536,
63,
3821,
9,
421,
199,
318,
11639,
8,
88,
304,
272,
372,
8446,
14,
6023,
12263,
8,
88,
12,
9561,
29,
17,
69,
13,
22,
9,
199,
199,
52,
16,
275,
359,
17,
61,
199,
52,
17,
275,
359,
16,
12,
413,
61,
199,
52,
18,
275,
5243,
17,
12,
378,
12,
499,
61,
199,
52,
19,
275,
359,
16,
12,
446,
19,
12,
378,
12,
841,
61,
199,
52,
20,
275,
359,
17,
12,
378,
12,
446,
24,
12,
378,
12,
1695,
61,
199,
52,
21,
275,
359,
16,
12,
959,
12,
378,
12,
446,
1165,
12,
378,
12,
3193,
61,
199,
52,
22,
275,
5243,
17,
12,
378,
12,
6155,
12,
378,
12,
446,
2006,
12,
378,
12,
4337,
61,
199,
52,
23,
275,
359,
16,
12,
446,
23,
12,
378,
12,
12001,
12,
378,
12,
446,
6094,
12,
378,
12,
5049,
61,
199,
52,
24,
275,
359,
17,
12,
378,
12,
446,
708,
12,
378,
12,
21235,
12,
378,
12,
446,
3912,
12,
378,
12,
7960,
61,
199,
52,
25,
275,
359,
16,
12,
1749,
12,
378,
12,
446,
6708,
12,
378,
12,
841,
708,
12,
378,
12,
446,
12255,
12,
378,
12,
7633,
61,
199,
199,
52,
513,
275,
359,
52,
16,
12,
377,
17,
12,
377,
18,
12,
377,
19,
12,
377,
20,
12,
377,
21,
12,
377,
22,
12,
377,
23,
12,
377,
24,
12,
377,
25,
61,
421,
199,
533,
1379,
22185,
26,
339,
347,
511,
63,
6023,
2261,
8,
277,
304,
267,
702,
63,
1452,
8,
6023,
14,
6023,
2261,
12,
5243,
17,
12,
413,
566,
339,
347,
511,
63,
6023,
4262,
8,
277,
304,
267,
702,
63,
1452,
8,
6023,
14,
6023,
4262,
12,
359,
16,
566,
339,
347,
511,
63,
6023,
368,
8,
277,
304,
267,
702,
63,
1452,
8,
6023,
14,
6023,
368,
12,
359,
17,
566,
339,
347,
511,
63,
6023,
88,
8,
277,
304,
267,
702,
63,
1452,
8,
6023,
14,
6023,
88,
12,
359,
16,
12,
413,
566,
421,
199,
533,
1379,
26291,
18764,
26,
339,
347,
511,
63,
6023,
525,
8,
277,
304,
267,
367,
284,
315,
1425,
8,
21,
304,
288,
367,
1335,
315,
1425,
8,
21,
304,
355,
1499,
275,
289,
2,
1271,
284,
3126,
73,
1386,
1335,
3126,
74,
7063,
355,
11967,
275,
980,
14,
4250,
8,
988,
8,
73,
12,
1335,
9,
435,
413,
9,
355,
11967,
59,
73,
61,
847,
413,
355,
11967,
59,
74,
61,
847,
413,
355,
522,
275,
8446,
14,
6023,
525,
779,
16,
3672,
73,
435,
359,
17,
467,
359,
16,
3672,
74,
435,
359,
17,
566,
355,
702,
63,
1452,
8,
12263,
8,
470,
395,
11639,
8,
15328,
395,
2329,
63,
1328,
29,
1328,
9,
339,
347,
511,
63,
15743,
456,
8,
277,
304,
267,
367,
284,
315,
1425,
8,
21,
304,
288,
367,
1335,
315,
1425,
8,
21,
304,
355,
1499,
275,
289,
2,
1271,
284,
3126,
73,
1386,
1335,
3126,
74,
7063,
355,
11967,
275,
980,
14,
4250,
8,
988,
8,
73,
12,
1335,
9,
435,
413,
9,
355,
11967,
59,
73,
61,
847,
413,
355,
11967,
59,
74,
61,
4862,
413,
355,
522,
275,
8446,
14,
15743,
456,
779,
16,
3672,
73,
435,
359,
17,
467,
359,
16,
3672,
74,
435,
359,
17,
566,
355,
702,
63,
1452,
8,
12263,
8,
470,
395,
11639,
8,
15328,
395,
2329,
63,
1328,
29,
1328,
9,
339,
347,
511,
63,
6023,
3703,
88,
8,
277,
304,
267,
702,
63,
1452,
8,
6023,
14,
6023,
3703,
88,
779,
16,
2522,
359,
16,
566,
267,
702,
63,
1452,
8,
6023,
14,
6023,
3703,
88,
779,
17,
2522,
359,
16,
12,
413,
566,
267,
367,
284,
315,
1425,
8,
17,
12,
959,
304,
288,
8926,
275,
359,
16,
3672,
73,
435,
359,
17,
61,
288,
11967,
275,
359,
16,
3672,
8,
73,
435,
413,
9,
435,
359,
17,
61,
288,
702,
63,
1452,
8,
6023,
14,
6023,
3703,
88,
8,
332,
395,
11967,
9,
339,
347,
511,
63,
6023,
3703,
8,
277,
304,
267,
367,
284,
315,
1425,
8,
21,
304,
288,
367,
1335,
315,
1425,
8,
21,
304,
355,
1499,
275,
289,
2,
1271,
284,
3126,
73,
1386,
1335,
3126,
74,
7063,
355,
11967,
275,
980,
14,
4250,
8,
73,
435,
1335,
435,
413,
9,
355,
11967,
59,
73,
435,
1335,
61,
847,
413,
355,
522,
275,
8446,
14,
6023,
3703,
779,
16,
3672,
73,
435,
359,
17,
467,
359,
16,
3672,
74,
435,
359,
17,
566,
355,
702,
63,
1452,
8,
12263,
8,
470,
395,
11639,
8,
15328,
395,
2329,
63,
1328,
29,
1328,
9,
339,
347,
511,
63,
6023,
3015,
8,
277,
304,
267,
327,
1104,
4697,
4629,
267,
702,
63,
3536,
8,
31000,
12,
8446,
14,
6023,
3015,
12,
359,
17,
467,
359,
16,
566,
398,
327,
1104,
6917,
4629,
267,
28419,
12,
18798,
275,
8446,
14,
6023,
3015,
779,
18,
467,
359,
18,
566,
267,
702,
63,
1452,
1332,
14209,
12,
18798,
395,
334,
17,
12,
378,
430,
267,
28419,
12,
18798,
275,
8446,
14,
6023,
3015,
779,
18,
12,
499,
467,
359,
18,
566,
267,
702,
63,
1452,
1332,
14209,
12,
18798,
395,
3666,
17,
12,
413,
395,
378,
430,
398,
327,
1104,
4618,
14,
267,
367,
284,
315,
1425,
8,
21,
304,
288,
367,
1335,
315,
1425,
8,
21,
304,
355,
1499,
275,
289,
2,
1271,
284,
3126,
73,
1386,
1335,
3126,
74,
7063,
355,
16279,
275,
359,
16,
3672,
73,
435,
359,
17,
12,
499,
61,
355,
286,
74,
275,
359,
16,
3672,
74,
435,
359,
17,
12,
499,
61,
355,
11967,
275,
8446,
14,
6023,
525,
8,
559,
12,
286,
74,
9,
355,
28419,
12,
18798,
275,
8446,
14,
6023,
3015,
8,
15328,
12,
16279,
9,
355,
522,
275,
8446,
14,
6023,
525,
8,
6023,
14
] |
[
2925,
367,
11849,
859,
14,
199,
199,
624,
199,
504,
9143,
492,
7114,
199,
199,
646,
2680,
465,
980,
199,
646,
2680,
14,
22104,
14,
22104,
465,
8446,
199,
504,
2680,
14,
4776,
492,
334,
272,
702,
63,
4398,
63,
1452,
12,
702,
63,
3536,
12,
702,
63,
1452,
12,
702,
3131,
272,
702,
63,
19811,
12,
702,
63,
1144,
63,
1452,
12,
702,
63,
3536,
63,
3821,
9,
421,
199,
318,
11639,
8,
88,
304,
272,
372,
8446,
14,
6023,
12263,
8,
88,
12,
9561,
29,
17,
69,
13,
22,
9,
199,
199,
52,
16,
275,
359,
17,
61,
199,
52,
17,
275,
359,
16,
12,
413,
61,
199,
52,
18,
275,
5243,
17,
12,
378,
12,
499,
61,
199,
52,
19,
275,
359,
16,
12,
446,
19,
12,
378,
12,
841,
61,
199,
52,
20,
275,
359,
17,
12,
378,
12,
446,
24,
12,
378,
12,
1695,
61,
199,
52,
21,
275,
359,
16,
12,
959,
12,
378,
12,
446,
1165,
12,
378,
12,
3193,
61,
199,
52,
22,
275,
5243,
17,
12,
378,
12,
6155,
12,
378,
12,
446,
2006,
12,
378,
12,
4337,
61,
199,
52,
23,
275,
359,
16,
12,
446,
23,
12,
378,
12,
12001,
12,
378,
12,
446,
6094,
12,
378,
12,
5049,
61,
199,
52,
24,
275,
359,
17,
12,
378,
12,
446,
708,
12,
378,
12,
21235,
12,
378,
12,
446,
3912,
12,
378,
12,
7960,
61,
199,
52,
25,
275,
359,
16,
12,
1749,
12,
378,
12,
446,
6708,
12,
378,
12,
841,
708,
12,
378,
12,
446,
12255,
12,
378,
12,
7633,
61,
199,
199,
52,
513,
275,
359,
52,
16,
12,
377,
17,
12,
377,
18,
12,
377,
19,
12,
377,
20,
12,
377,
21,
12,
377,
22,
12,
377,
23,
12,
377,
24,
12,
377,
25,
61,
421,
199,
533,
1379,
22185,
26,
339,
347,
511,
63,
6023,
2261,
8,
277,
304,
267,
702,
63,
1452,
8,
6023,
14,
6023,
2261,
12,
5243,
17,
12,
413,
566,
339,
347,
511,
63,
6023,
4262,
8,
277,
304,
267,
702,
63,
1452,
8,
6023,
14,
6023,
4262,
12,
359,
16,
566,
339,
347,
511,
63,
6023,
368,
8,
277,
304,
267,
702,
63,
1452,
8,
6023,
14,
6023,
368,
12,
359,
17,
566,
339,
347,
511,
63,
6023,
88,
8,
277,
304,
267,
702,
63,
1452,
8,
6023,
14,
6023,
88,
12,
359,
16,
12,
413,
566,
421,
199,
533,
1379,
26291,
18764,
26,
339,
347,
511,
63,
6023,
525,
8,
277,
304,
267,
367,
284,
315,
1425,
8,
21,
304,
288,
367,
1335,
315,
1425,
8,
21,
304,
355,
1499,
275,
289,
2,
1271,
284,
3126,
73,
1386,
1335,
3126,
74,
7063,
355,
11967,
275,
980,
14,
4250,
8,
988,
8,
73,
12,
1335,
9,
435,
413,
9,
355,
11967,
59,
73,
61,
847,
413,
355,
11967,
59,
74,
61,
847,
413,
355,
522,
275,
8446,
14,
6023,
525,
779,
16,
3672,
73,
435,
359,
17,
467,
359,
16,
3672,
74,
435,
359,
17,
566,
355,
702,
63,
1452,
8,
12263,
8,
470,
395,
11639,
8,
15328,
395,
2329,
63,
1328,
29,
1328,
9,
339,
347,
511,
63,
15743,
456,
8,
277,
304,
267,
367,
284,
315,
1425,
8,
21,
304,
288,
367,
1335,
315,
1425,
8,
21,
304,
355,
1499,
275,
289,
2,
1271,
284,
3126,
73,
1386,
1335,
3126,
74,
7063,
355,
11967,
275,
980,
14,
4250,
8,
988,
8,
73,
12,
1335,
9,
435,
413,
9,
355,
11967,
59,
73,
61,
847,
413,
355,
11967,
59,
74,
61,
4862,
413,
355,
522,
275,
8446,
14,
15743,
456,
779,
16,
3672,
73,
435,
359,
17,
467,
359,
16,
3672,
74,
435,
359,
17,
566,
355,
702,
63,
1452,
8,
12263,
8,
470,
395,
11639,
8,
15328,
395,
2329,
63,
1328,
29,
1328,
9,
339,
347,
511,
63,
6023,
3703,
88,
8,
277,
304,
267,
702,
63,
1452,
8,
6023,
14,
6023,
3703,
88,
779,
16,
2522,
359,
16,
566,
267,
702,
63,
1452,
8,
6023,
14,
6023,
3703,
88,
779,
17,
2522,
359,
16,
12,
413,
566,
267,
367,
284,
315,
1425,
8,
17,
12,
959,
304,
288,
8926,
275,
359,
16,
3672,
73,
435,
359,
17,
61,
288,
11967,
275,
359,
16,
3672,
8,
73,
435,
413,
9,
435,
359,
17,
61,
288,
702,
63,
1452,
8,
6023,
14,
6023,
3703,
88,
8,
332,
395,
11967,
9,
339,
347,
511,
63,
6023,
3703,
8,
277,
304,
267,
367,
284,
315,
1425,
8,
21,
304,
288,
367,
1335,
315,
1425,
8,
21,
304,
355,
1499,
275,
289,
2,
1271,
284,
3126,
73,
1386,
1335,
3126,
74,
7063,
355,
11967,
275,
980,
14,
4250,
8,
73,
435,
1335,
435,
413,
9,
355,
11967,
59,
73,
435,
1335,
61,
847,
413,
355,
522,
275,
8446,
14,
6023,
3703,
779,
16,
3672,
73,
435,
359,
17,
467,
359,
16,
3672,
74,
435,
359,
17,
566,
355,
702,
63,
1452,
8,
12263,
8,
470,
395,
11639,
8,
15328,
395,
2329,
63,
1328,
29,
1328,
9,
339,
347,
511,
63,
6023,
3015,
8,
277,
304,
267,
327,
1104,
4697,
4629,
267,
702,
63,
3536,
8,
31000,
12,
8446,
14,
6023,
3015,
12,
359,
17,
467,
359,
16,
566,
398,
327,
1104,
6917,
4629,
267,
28419,
12,
18798,
275,
8446,
14,
6023,
3015,
779,
18,
467,
359,
18,
566,
267,
702,
63,
1452,
1332,
14209,
12,
18798,
395,
334,
17,
12,
378,
430,
267,
28419,
12,
18798,
275,
8446,
14,
6023,
3015,
779,
18,
12,
499,
467,
359,
18,
566,
267,
702,
63,
1452,
1332,
14209,
12,
18798,
395,
3666,
17,
12,
413,
395,
378,
430,
398,
327,
1104,
4618,
14,
267,
367,
284,
315,
1425,
8,
21,
304,
288,
367,
1335,
315,
1425,
8,
21,
304,
355,
1499,
275,
289,
2,
1271,
284,
3126,
73,
1386,
1335,
3126,
74,
7063,
355,
16279,
275,
359,
16,
3672,
73,
435,
359,
17,
12,
499,
61,
355,
286,
74,
275,
359,
16,
3672,
74,
435,
359,
17,
12,
499,
61,
355,
11967,
275,
8446,
14,
6023,
525,
8,
559,
12,
286,
74,
9,
355,
28419,
12,
18798,
275,
8446,
14,
6023,
3015,
8,
15328,
12,
16279,
9,
355,
522,
275,
8446,
14,
6023,
525,
8,
6023,
14,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
xiongzhenggang/xiongzhenggang.github.io
|
AI/data/deeplearning24054/planar_utils.py
|
2
|
2271
|
import matplotlib.pyplot as plt
import numpy as np
import sklearn
import sklearn.datasets
import sklearn.linear_model
def plot_decision_boundary(model, X, Y):
# Set min and max values and give it some padding
x_min, x_max = X[0, :].min() - 1, X[0, :].max() + 1
y_min, y_max = X[1, :].min() - 1, X[1, :].max() + 1
h = 0.01
# Generate a grid of points with distance h between them
xx, yy = np.meshgrid(np.arange(x_min, x_max, h), np.arange(y_min, y_max, h))
# Predict the function value for the whole grid
Z = model(np.c_[xx.ravel(), yy.ravel()])
Z = Z.reshape(xx.shape)
# Plot the contour and training examples
plt.contourf(xx, yy, Z, cmap=plt.cm.Spectral)
plt.ylabel('x2')
plt.xlabel('x1')
plt.scatter(X[0, :], X[1, :], c=Y.reshape(X[0,:].shape), cmap=plt.cm.Spectral)
def sigmoid(x):
"""
Compute the sigmoid of x
Arguments:
x -- A scalar or numpy array of any size.
Return:
s -- sigmoid(x)
"""
s = 1/(1+np.exp(-x))
return s
def load_planar_dataset():
np.random.seed(1)
m = 400 # number of examples
N = int(m/2) # number of points per class
D = 2 # dimensionality
X = np.zeros((m,D)) # data matrix where each row is a single example
Y = np.zeros((m,1), dtype='uint8') # labels vector (0 for red, 1 for blue)
a = 4 # maximum ray of the flower
for j in range(2):
ix = range(N*j,N*(j+1))
t = np.linspace(j*3.12,(j+1)*3.12,N) + np.random.randn(N)*0.2 # theta
r = a*np.sin(4*t) + np.random.randn(N)*0.2 # radius
X[ix] = np.c_[r*np.sin(t), r*np.cos(t)]
Y[ix] = j
X = X.T
Y = Y.T
return X, Y
def load_extra_datasets():
N = 200
noisy_circles = sklearn.datasets.make_circles(n_samples=N, factor=.5, noise=.3)
noisy_moons = sklearn.datasets.make_moons(n_samples=N, noise=.2)
blobs = sklearn.datasets.make_blobs(n_samples=N, random_state=5, n_features=2, centers=6)
gaussian_quantiles = sklearn.datasets.make_gaussian_quantiles(mean=None, cov=0.5, n_samples=N, n_features=2, n_classes=2, shuffle=True, random_state=None)
no_structure = np.random.rand(N, 2), np.random.rand(N, 2)
return noisy_circles, noisy_moons, blobs, gaussian_quantiles, no_structure
|
gpl-3.0
|
[
646,
8027,
14,
13563,
465,
4488,
199,
646,
2680,
465,
980,
199,
646,
6357,
199,
646,
6357,
14,
12281,
199,
646,
6357,
14,
6676,
63,
1238,
199,
199,
318,
5137,
63,
16622,
63,
9891,
8,
1238,
12,
1323,
12,
1488,
304,
272,
327,
2494,
1748,
436,
1390,
1338,
436,
8120,
652,
2005,
6273,
272,
671,
63,
827,
12,
671,
63,
988,
275,
1323,
59,
16,
12,
520,
1055,
827,
342,
446,
413,
12,
1323,
59,
16,
12,
520,
1055,
988,
342,
435,
413,
272,
612,
63,
827,
12,
612,
63,
988,
275,
1323,
59,
17,
12,
520,
1055,
827,
342,
446,
413,
12,
1323,
59,
17,
12,
520,
1055,
988,
342,
435,
413,
272,
394,
275,
378,
14,
614,
272,
327,
7958,
282,
6068,
402,
4501,
543,
6033,
394,
3382,
3062,
272,
19379,
12,
20435,
275,
980,
14,
6480,
3825,
8,
1590,
14,
5605,
8,
88,
63,
827,
12,
671,
63,
988,
12,
394,
395,
980,
14,
5605,
8,
89,
63,
827,
12,
612,
63,
988,
12,
394,
430,
272,
327,
5543,
807,
314,
805,
574,
367,
314,
8852,
6068,
272,
3107,
275,
1402,
8,
1590,
14,
67,
9925,
2154,
14,
11186,
1062,
20435,
14,
11186,
9383,
272,
3107,
275,
3107,
14,
5217,
8,
2154,
14,
1392,
9,
272,
327,
14794,
314,
23176,
436,
6093,
7251,
272,
4488,
14,
17798,
70,
8,
2154,
12,
20435,
12,
3107,
12,
14920,
29,
6003,
14,
4400,
14,
51,
15832,
9,
272,
4488,
14,
13849,
360,
88,
18,
358,
272,
4488,
14,
14168,
360,
88,
17,
358,
272,
4488,
14,
13512,
8,
56,
59,
16,
12,
26450,
1323,
59,
17,
12,
26450,
286,
29,
57,
14,
5217,
8,
56,
59,
16,
12,
11455,
1392,
395,
14920,
29,
6003,
14,
4400,
14,
51,
15832,
9,
421,
199,
318,
28886,
8,
88,
304,
272,
408,
272,
8354,
314,
28886,
402,
671,
339,
7628,
26,
272,
671,
1553,
437,
6917,
503,
2680,
1625,
402,
1263,
1568,
14,
339,
1432,
26,
272,
308,
1553,
28886,
8,
88,
9,
272,
408,
272,
308,
275,
413,
7985,
17,
11,
1590,
14,
1474,
2801,
88,
430,
272,
372,
308,
199,
199,
318,
2248,
63,
5140,
285,
63,
5214,
837,
272,
980,
14,
2355,
14,
5176,
8,
17,
9,
272,
333,
275,
8290,
327,
1329,
402,
7251,
272,
653,
275,
1109,
8,
77,
15,
18,
9,
327,
1329,
402,
4501,
1126,
1021,
272,
577,
275,
499,
327,
6240,
6712,
272,
1323,
275,
980,
14,
4250,
1332,
77,
12,
36,
430,
327,
666,
3634,
2382,
1924,
1962,
365,
282,
2849,
2893,
272,
1488,
275,
980,
14,
4250,
1332,
77,
12,
17,
395,
2152,
534,
1635,
24,
358,
327,
3628,
5477,
334,
16,
367,
8992,
12,
413,
367,
10030,
9,
272,
282,
275,
841,
327,
5696,
22059,
402,
314,
289,
2325,
339,
367,
1335,
315,
1425,
8,
18,
304,
267,
20593,
275,
1425,
8,
46,
10,
74,
12,
46,
5830,
74,
11,
17,
430,
267,
307,
275,
980,
14,
11649,
8,
74,
10,
19,
14,
713,
12803,
74,
11,
17,
3342,
19,
14,
713,
12,
46,
9,
435,
980,
14,
2355,
14,
10843,
8,
46,
3342,
16,
14,
18,
327,
12724,
267,
519,
275,
282,
10,
1590,
14,
5911,
8,
20,
10,
84,
9,
435,
980,
14,
2355,
14,
10843,
8,
46,
3342,
16,
14,
18,
327,
9362,
267,
1323,
59,
1148,
61,
275,
980,
14,
67,
9925,
82,
10,
1590,
14,
5911,
8,
84,
395,
519,
10,
1590,
14,
5197,
8,
84,
1874,
267,
1488,
59,
1148,
61,
275,
1335,
5493,
1323,
275,
1323,
14,
52,
272,
1488,
275,
1488,
14,
52,
339,
372,
1323,
12,
1488,
199,
199,
318,
2248,
63,
2911,
63,
12281,
837,
23855,
653,
275,
1926,
272,
949,
19765,
63,
6092,
2978,
275,
6357,
14,
12281,
14,
1875,
63,
6092,
2978,
8,
78,
63,
3356,
29,
46,
12,
6535,
15856,
21,
12,
11145,
15856,
19,
9,
272,
949,
19765,
63,
573,
4654,
275,
6357,
14,
12281,
14,
1875,
63,
573,
4654,
8,
78,
63,
3356,
29,
46,
12,
11145,
15856,
18,
9,
272,
9182,
83,
275,
6357,
14,
12281,
14,
1875,
63,
21893,
8,
78,
63,
3356,
29,
46,
12,
2196,
63,
929,
29,
21,
12,
302,
63,
3179,
29,
18,
12,
19190,
29,
22,
9,
272,
28912,
63,
12316,
2978,
275,
6357,
14,
12281,
14,
1875,
63,
22911,
63,
12316,
2978,
8,
3670,
29,
403,
12,
13786,
29,
16,
14,
21,
12,
302,
63,
3356,
29,
46,
12,
302,
63,
3179,
29,
18,
12,
302,
63,
2888,
29,
18,
12,
13031,
29,
549,
12,
2196,
63,
929,
29,
403,
9,
272,
949,
63,
6976,
275,
980,
14,
2355,
14,
3759,
8,
46,
12,
499,
395,
980,
14,
2355,
14,
3759,
8,
46,
12,
499,
9,
2286,
372,
949,
19765,
63,
6092,
2978,
12,
949,
19765,
63,
573,
4654,
12,
9182,
83,
12,
28912,
63,
12316,
2978,
12,
949,
63,
6976,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
8027,
14,
13563,
465,
4488,
199,
646,
2680,
465,
980,
199,
646,
6357,
199,
646,
6357,
14,
12281,
199,
646,
6357,
14,
6676,
63,
1238,
199,
199,
318,
5137,
63,
16622,
63,
9891,
8,
1238,
12,
1323,
12,
1488,
304,
272,
327,
2494,
1748,
436,
1390,
1338,
436,
8120,
652,
2005,
6273,
272,
671,
63,
827,
12,
671,
63,
988,
275,
1323,
59,
16,
12,
520,
1055,
827,
342,
446,
413,
12,
1323,
59,
16,
12,
520,
1055,
988,
342,
435,
413,
272,
612,
63,
827,
12,
612,
63,
988,
275,
1323,
59,
17,
12,
520,
1055,
827,
342,
446,
413,
12,
1323,
59,
17,
12,
520,
1055,
988,
342,
435,
413,
272,
394,
275,
378,
14,
614,
272,
327,
7958,
282,
6068,
402,
4501,
543,
6033,
394,
3382,
3062,
272,
19379,
12,
20435,
275,
980,
14,
6480,
3825,
8,
1590,
14,
5605,
8,
88,
63,
827,
12,
671,
63,
988,
12,
394,
395,
980,
14,
5605,
8,
89,
63,
827,
12,
612,
63,
988,
12,
394,
430,
272,
327,
5543,
807,
314,
805,
574,
367,
314,
8852,
6068,
272,
3107,
275,
1402,
8,
1590,
14,
67,
9925,
2154,
14,
11186,
1062,
20435,
14,
11186,
9383,
272,
3107,
275,
3107,
14,
5217,
8,
2154,
14,
1392,
9,
272,
327,
14794,
314,
23176,
436,
6093,
7251,
272,
4488,
14,
17798,
70,
8,
2154,
12,
20435,
12,
3107,
12,
14920,
29,
6003,
14,
4400,
14,
51,
15832,
9,
272,
4488,
14,
13849,
360,
88,
18,
358,
272,
4488,
14,
14168,
360,
88,
17,
358,
272,
4488,
14,
13512,
8,
56,
59,
16,
12,
26450,
1323,
59,
17,
12,
26450,
286,
29,
57,
14,
5217,
8,
56,
59,
16,
12,
11455,
1392,
395,
14920,
29,
6003,
14,
4400,
14,
51,
15832,
9,
421,
199,
318,
28886,
8,
88,
304,
272,
408,
272,
8354,
314,
28886,
402,
671,
339,
7628,
26,
272,
671,
1553,
437,
6917,
503,
2680,
1625,
402,
1263,
1568,
14,
339,
1432,
26,
272,
308,
1553,
28886,
8,
88,
9,
272,
408,
272,
308,
275,
413,
7985,
17,
11,
1590,
14,
1474,
2801,
88,
430,
272,
372,
308,
199,
199,
318,
2248,
63,
5140,
285,
63,
5214,
837,
272,
980,
14,
2355,
14,
5176,
8,
17,
9,
272,
333,
275,
8290,
327,
1329,
402,
7251,
272,
653,
275,
1109,
8,
77,
15,
18,
9,
327,
1329,
402,
4501,
1126,
1021,
272,
577,
275,
499,
327,
6240,
6712,
272,
1323,
275,
980,
14,
4250,
1332,
77,
12,
36,
430,
327,
666,
3634,
2382,
1924,
1962,
365,
282,
2849,
2893,
272,
1488,
275,
980,
14,
4250,
1332,
77,
12,
17,
395,
2152,
534,
1635,
24,
358,
327,
3628,
5477,
334,
16,
367,
8992,
12,
413,
367,
10030,
9,
272,
282,
275,
841,
327,
5696,
22059,
402,
314,
289,
2325,
339,
367,
1335,
315,
1425,
8,
18,
304,
267,
20593,
275,
1425,
8,
46,
10,
74,
12,
46,
5830,
74,
11,
17,
430,
267,
307,
275,
980,
14,
11649,
8,
74,
10,
19,
14,
713,
12803,
74,
11,
17,
3342,
19,
14,
713,
12,
46,
9,
435,
980,
14,
2355,
14,
10843,
8,
46,
3342,
16,
14,
18,
327,
12724,
267,
519,
275,
282,
10,
1590,
14,
5911,
8,
20,
10,
84,
9,
435,
980,
14,
2355,
14,
10843,
8,
46,
3342,
16,
14,
18,
327,
9362,
267,
1323,
59,
1148,
61,
275,
980,
14,
67,
9925,
82,
10,
1590,
14,
5911,
8,
84,
395,
519,
10,
1590,
14,
5197,
8,
84,
1874,
267,
1488,
59,
1148,
61,
275,
1335,
5493,
1323,
275,
1323,
14,
52,
272,
1488,
275,
1488,
14,
52,
339,
372,
1323,
12,
1488,
199,
199,
318,
2248,
63,
2911,
63,
12281,
837,
23855,
653,
275,
1926,
272,
949,
19765,
63,
6092,
2978,
275,
6357,
14,
12281,
14,
1875,
63,
6092,
2978,
8,
78,
63,
3356,
29,
46,
12,
6535,
15856,
21,
12,
11145,
15856,
19,
9,
272,
949,
19765,
63,
573,
4654,
275,
6357,
14,
12281,
14,
1875,
63,
573,
4654,
8,
78,
63,
3356,
29,
46,
12,
11145,
15856,
18,
9,
272,
9182,
83,
275,
6357,
14,
12281,
14,
1875,
63,
21893,
8,
78,
63,
3356,
29,
46,
12,
2196,
63,
929,
29,
21,
12,
302,
63,
3179,
29,
18,
12,
19190,
29,
22,
9,
272,
28912,
63,
12316,
2978,
275,
6357,
14,
12281,
14,
1875,
63,
22911,
63,
12316,
2978,
8,
3670,
29,
403,
12,
13786,
29,
16,
14,
21,
12,
302,
63,
3356,
29,
46,
12,
302,
63,
3179,
29,
18,
12,
302,
63,
2888,
29,
18,
12,
13031,
29,
549,
12,
2196,
63,
929,
29,
403,
9,
272,
949,
63,
6976,
275,
980,
14,
2355,
14,
3759,
8,
46,
12,
499,
395,
980,
14,
2355,
14,
3759,
8,
46,
12,
499,
9,
2286,
372,
949,
19765,
63,
6092,
2978,
12,
949,
19765,
63,
573,
4654,
12,
9182,
83,
12,
28912,
63,
12316,
2978,
12,
949,
63,
6976,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
allevin/PyGithub
|
tests/SourceImport.py
|
2
|
3879
|
# -*- coding: utf-8 -*-
############################ Copyrights and license ############################
# #
# Copyright 2018 Hayden Fuss <wifu1234@gmail.com> #
# #
# This file is part of PyGithub. #
# http://pygithub.readthedocs.io/ #
# #
# PyGithub is free software: you can redistribute it and/or modify it under #
# the terms of the GNU Lesser General Public License as published by the Free #
# Software Foundation, either version 3 of the License, or (at your option) #
# any later version. #
# #
# PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY #
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more #
# details. #
# #
# You should have received a copy of the GNU Lesser General Public License #
# along with PyGithub. If not, see <http://www.gnu.org/licenses/>. #
# #
################################################################################
from . import Framework
class SourceImport(Framework.TestCase):
def setUp(self):
super().setUp()
self.user = self.g.get_user("brix4dayz")
self.repo = self.user.get_repo("source-import-test")
self.source_import = self.repo.get_source_import()
def testAttributes(self):
self.assertEqual(self.source_import.authors_count, 1)
self.assertEqual(
self.source_import.authors_url,
"https://api.github.com/repos/brix4dayz/source-import-test/import/authors",
)
self.assertEqual(self.source_import.has_large_files, False)
self.assertEqual(
self.source_import.html_url,
"https://github.com/brix4dayz/source-import-test/import",
)
self.assertEqual(self.source_import.large_files_count, 0)
self.assertEqual(self.source_import.large_files_size, 0)
self.assertEqual(
self.source_import.repository_url,
"https://api.github.com/repos/brix4dayz/source-import-test",
)
self.assertEqual(self.source_import.status, "complete")
self.assertEqual(self.source_import.status_text, "Done")
self.assertEqual(
self.source_import.url,
"https://api.github.com/repos/brix4dayz/source-import-test/import",
)
self.assertEqual(self.source_import.use_lfs, "undecided")
self.assertEqual(self.source_import.vcs, "mercurial")
self.assertEqual(
self.source_import.vcs_url, "https://bitbucket.org/hfuss/source-import-test"
)
self.assertEqual(
self.source_import.__repr__(),
'SourceImport(vcs_url="https://bitbucket.org/hfuss/source-import-test", url="https://api.github.com/repos/brix4dayz/source-import-test/import", status="complete", repository_url="https://api.github.com/repos/brix4dayz/source-import-test")',
)
def testUpdate(self):
# The real test is that update() method passes the header
update_ret = self.source_import.update()
self.assertTrue(update_ret)
self.assertEqual(self.source_import.status, "complete")
|
lgpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
6565,
381,
1898,
83,
436,
4190,
11945,
381,
199,
3,
26209,
327,
199,
3,
1898,
14894,
869,
1187,
848,
481,
27678,
665,
87,
692,
85,
4321,
32,
6799,
14,
957,
30,
19242,
327,
199,
3,
26209,
327,
199,
3,
961,
570,
365,
1777,
402,
1611,
14772,
14,
2476,
5185,
327,
199,
3,
1455,
921,
647,
5031,
14,
25085,
14,
2308,
15,
2476,
4519,
327,
199,
3,
26209,
327,
199,
3,
1611,
14772,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
1334,
259,
327,
199,
3,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
844,
465,
3267,
701,
314,
2868,
221,
327,
199,
3,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
259,
327,
199,
3,
1263,
2945,
1015,
14,
2476,
13235,
327,
199,
3,
26209,
327,
199,
3,
1611,
14772,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
2428,
1821,
221,
327,
199,
3,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
3169,
503,
3092,
259,
327,
199,
3,
2381,
437,
3115,
3104,
14,
1666,
314,
1664,
6401,
1696,
1684,
844,
367,
1655,
327,
199,
3,
2436,
14,
6208,
258,
327,
199,
3,
26209,
327,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
844,
258,
327,
199,
3,
3180,
543,
1611,
14772,
14,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
3777,
327,
199,
3,
26209,
327,
199,
13289,
199,
199,
504,
1275,
492,
22545,
421,
199,
533,
5800,
6295,
8,
16442,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
1613,
1252,
5996,
342,
267,
291,
14,
751,
275,
291,
14,
71,
14,
362,
63,
751,
480,
66,
1904,
20,
2977,
90,
531,
267,
291,
14,
3417,
275,
291,
14,
751,
14,
362,
63,
3417,
480,
1365,
13,
646,
13,
396,
531,
267,
291,
14,
1365,
63,
646,
275,
291,
14,
3417,
14,
362,
63,
1365,
63,
646,
342,
339,
347,
511,
5379,
8,
277,
304,
267,
291,
14,
629,
8,
277,
14,
1365,
63,
646,
14,
8149,
63,
835,
12,
413,
9,
267,
291,
14,
629,
8,
288,
291,
14,
1365,
63,
646,
14,
8149,
63,
633,
12,
288,
298,
2859,
921,
1246,
14,
5031,
14,
957,
15,
11857,
15,
66,
1904,
20,
2977,
90,
15,
1365,
13,
646,
13,
396,
15,
646,
15,
8149,
401,
267,
776,
267,
291,
14,
629,
8,
277,
14,
1365,
63,
646,
14,
1989,
63,
9629,
63,
1725,
12,
756,
9,
267,
291,
14,
629,
8,
288,
291,
14,
1365,
63,
646,
14,
1360,
63,
633,
12,
288,
298,
2859,
921,
5031,
14,
957,
15,
66,
1904,
20,
2977,
90,
15,
1365,
13,
646,
13,
396,
15,
646,
401,
267,
776,
267,
291,
14,
629,
8,
277,
14,
1365,
63,
646,
14,
9629,
63,
1725,
63,
835,
12,
378,
9,
267,
291,
14,
629,
8,
277,
14,
1365,
63,
646,
14,
9629,
63,
1725,
63,
890,
12,
378,
9,
267,
291,
14,
629,
8,
288,
291,
14,
1365,
63,
646,
14,
8421,
63,
633,
12,
288,
298,
2859,
921,
1246,
14,
5031,
14,
957,
15,
11857,
15,
66,
1904,
20,
2977,
90,
15,
1365,
13,
646,
13,
396,
401,
267,
776,
267,
291,
14,
629,
8,
277,
14,
1365,
63,
646,
14,
1205,
12,
298,
4883,
531,
267,
291,
14,
629,
8,
277,
14,
1365,
63,
646,
14,
1205,
63,
505,
12,
298,
10759,
531,
267,
291,
14,
629,
8,
288,
291,
14,
1365,
63,
646,
14,
633,
12,
288,
298,
2859,
921,
1246,
14,
5031,
14,
957,
15,
11857,
15,
66,
1904,
20,
2977,
90,
15,
1365,
13,
646,
13,
396,
15,
646,
401,
267,
776,
267,
291,
14,
629,
8,
277,
14,
1365,
63,
646,
14,
1180,
63,
276,
83,
12,
298,
324,
22612,
770,
531,
267,
291,
14,
629,
8,
277,
14,
1365,
63,
646,
14,
15525,
12,
298,
2626,
18977,
531,
267,
291,
14,
629,
8,
288,
291,
14,
1365,
63,
646,
14,
15525,
63,
633,
12,
298,
2859,
921,
25668,
14,
1308,
15,
9188,
27678,
15,
1365,
13,
646,
13,
396,
2,
267,
776,
398,
291,
14,
629,
8,
288,
291,
14,
1365,
63,
646,
855,
2722,
29709,
288,
283,
2980,
6295,
8,
15525,
63,
633,
628,
2859,
921,
25668,
14,
1308,
15,
9188,
27678,
15,
1365,
13,
646,
13,
396,
401,
1166,
628,
2859,
921,
1246,
14,
5031,
14,
957,
15,
11857,
15,
66,
1904,
20,
2977,
90,
15,
1365,
13,
646,
13,
396,
15,
646,
401,
2004,
628,
4883,
401,
7611,
63,
633,
628,
2859,
921,
1246,
14,
5031,
14,
957,
15,
11857,
15,
66,
1904,
20,
2977,
90,
15,
1365,
13,
646,
13,
396,
30901,
267,
776,
339,
347,
511,
4152,
8,
277,
304,
267,
327,
710,
3363,
511,
365,
626,
1678,
342,
1083,
14933,
314,
1406,
267,
1678,
63,
3292,
275,
291,
14,
1365,
63,
646,
14,
873,
342,
267,
291,
14,
1815,
8,
873,
63,
3292,
9,
267,
291,
14,
629,
8,
277,
14,
1365,
63,
646,
14,
1205,
12,
298,
4883,
531,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
6565,
381,
1898,
83,
436,
4190,
11945,
381,
199,
3,
26209,
327,
199,
3,
1898,
14894,
869,
1187,
848,
481,
27678,
665,
87,
692,
85,
4321,
32,
6799,
14,
957,
30,
19242,
327,
199,
3,
26209,
327,
199,
3,
961,
570,
365,
1777,
402,
1611,
14772,
14,
2476,
5185,
327,
199,
3,
1455,
921,
647,
5031,
14,
25085,
14,
2308,
15,
2476,
4519,
327,
199,
3,
26209,
327,
199,
3,
1611,
14772,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
1334,
259,
327,
199,
3,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
844,
465,
3267,
701,
314,
2868,
221,
327,
199,
3,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
259,
327,
199,
3,
1263,
2945,
1015,
14,
2476,
13235,
327,
199,
3,
26209,
327,
199,
3,
1611,
14772,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
2428,
1821,
221,
327,
199,
3,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
3169,
503,
3092,
259,
327,
199,
3,
2381,
437,
3115,
3104,
14,
1666,
314,
1664,
6401,
1696,
1684,
844,
367,
1655,
327,
199,
3,
2436,
14,
6208,
258,
327,
199,
3,
26209,
327,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
844,
258,
327,
199,
3,
3180,
543,
1611,
14772,
14,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
3777,
327,
199,
3,
26209,
327,
199,
13289,
199,
199,
504,
1275,
492,
22545,
421,
199,
533,
5800,
6295,
8,
16442,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
1613,
1252,
5996,
342,
267,
291,
14,
751,
275,
291,
14,
71,
14,
362,
63,
751,
480,
66,
1904,
20,
2977,
90,
531,
267,
291,
14,
3417,
275,
291,
14,
751,
14,
362,
63,
3417,
480,
1365,
13,
646,
13,
396,
531,
267,
291,
14,
1365,
63,
646,
275,
291,
14,
3417,
14,
362,
63,
1365,
63,
646,
342,
339,
347,
511,
5379,
8,
277,
304,
267,
291,
14,
629,
8,
277,
14,
1365,
63,
646,
14,
8149,
63,
835,
12,
413,
9,
267,
291,
14,
629,
8,
288,
291,
14,
1365,
63,
646,
14,
8149,
63,
633,
12,
288,
298,
2859,
921,
1246,
14,
5031,
14,
957,
15,
11857,
15,
66,
1904,
20,
2977,
90,
15,
1365,
13,
646,
13,
396,
15,
646,
15,
8149,
401,
267,
776,
267,
291,
14,
629,
8,
277,
14,
1365,
63,
646,
14,
1989,
63,
9629,
63,
1725,
12,
756,
9,
267,
291,
14,
629,
8,
288,
291,
14,
1365,
63,
646,
14,
1360,
63,
633,
12,
288,
298,
2859,
921,
5031,
14,
957,
15,
66,
1904,
20,
2977,
90,
15,
1365,
13,
646,
13,
396,
15,
646,
401,
267,
776,
267,
291,
14,
629,
8,
277,
14,
1365,
63,
646,
14,
9629,
63,
1725,
63,
835,
12,
378,
9,
267,
291,
14,
629,
8,
277,
14,
1365,
63,
646,
14,
9629,
63,
1725,
63,
890,
12,
378,
9,
267,
291,
14,
629,
8,
288,
291,
14,
1365,
63,
646,
14,
8421,
63,
633,
12,
288,
298,
2859,
921,
1246,
14,
5031,
14,
957,
15,
11857,
15,
66,
1904,
20,
2977,
90,
15,
1365,
13,
646,
13,
396,
401,
267,
776,
267,
291,
14,
629,
8,
277,
14,
1365,
63,
646,
14,
1205,
12,
298,
4883,
531,
267,
291,
14,
629,
8,
277,
14,
1365,
63,
646,
14,
1205,
63,
505,
12,
298,
10759,
531,
267,
291,
14,
629,
8,
288,
291,
14,
1365,
63,
646,
14,
633,
12,
288,
298,
2859,
921,
1246,
14,
5031,
14,
957,
15,
11857,
15,
66,
1904,
20,
2977,
90,
15,
1365,
13,
646,
13,
396,
15,
646,
401,
267,
776,
267,
291,
14,
629,
8,
277,
14,
1365,
63,
646,
14,
1180,
63,
276,
83,
12,
298,
324,
22612,
770,
531,
267,
291,
14,
629,
8,
277,
14,
1365,
63,
646,
14,
15525,
12,
298,
2626,
18977,
531,
267,
291,
14,
629,
8,
288,
291,
14,
1365,
63,
646,
14,
15525,
63,
633,
12,
298,
2859,
921,
25668,
14,
1308,
15,
9188,
27678,
15,
1365,
13,
646,
13,
396,
2,
267,
776,
398,
291,
14,
629,
8,
288,
291,
14,
1365,
63,
646,
855,
2722,
29709,
288,
283,
2980,
6295,
8,
15525,
63,
633,
628,
2859,
921,
25668,
14,
1308,
15,
9188,
27678,
15,
1365,
13,
646,
13,
396,
401,
1166,
628,
2859,
921,
1246,
14,
5031,
14,
957,
15,
11857,
15,
66,
1904,
20,
2977,
90,
15,
1365,
13,
646,
13,
396,
15,
646,
401,
2004,
628,
4883,
401,
7611,
63,
633,
628,
2859,
921,
1246,
14,
5031,
14,
957,
15,
11857,
15,
66,
1904,
20,
2977,
90,
15,
1365,
13,
646,
13,
396,
30901,
267,
776,
339,
347,
511,
4152,
8,
277,
304,
267,
327,
710,
3363,
511,
365,
626,
1678,
342,
1083,
14933,
314,
1406,
267,
1678,
63,
3292,
275,
291,
14,
1365,
63,
646,
14,
873,
342,
267,
291,
14,
1815,
8,
873,
63,
3292,
9,
267,
291,
14,
629,
8,
277,
14,
1365,
63,
646,
14,
1205,
12,
298,
4883,
531,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
bchareyre/ratchet
|
gui/qt4/SerializableEditor.py
|
1
|
34633
|
# encoding: utf-8
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4 import QtGui
import re,itertools
import logging
logging.trace=logging.debug
logging.basicConfig(level=logging.INFO)
from yade import *
import yade.qt
try:
from minieigen import *
except ImportError:
from miniEigen import *
seqSerializableShowType=True # show type headings in serializable sequences (takes vertical space, but makes the type hyperlinked)
# BUG: cursor is moved to the beginnign of the input field even if it has focus
#
# checking for focus seems to return True always and cursor is never moved
#
# the 'True or' part effectively disables the condition (so that the cursor is moved always), but it might be fixed in the future somehow
#
# if True or w.hasFocus(): w.home(False)
#
#
def makeWrapperHref(text,className,attr=None,static=False):
"""Create clickable HTML hyperlink to a Yade class or its attribute.
:param className: name of the class to link to.
:param attr: attribute to link to. If given, must exist directly in given *className*; if not given or empty, link to the class itself is created and *attr* is ignored.
:return: HTML with the hyperref.
"""
if not static: return '<a href="%s#yade.wrapper.%s%s">%s</a>'%(yade.qt.sphinxDocWrapperPage,className,(('.'+attr) if attr else ''),text)
else: return '<a href="%s#ystaticattr-%s.%s">%s</a>'%(yade.qt.sphinxDocWrapperPage,className,attr,text)
def serializableHref(ser,attr=None,text=None):
"""Return HTML href to a *ser* optionally to the attribute *attr*.
The class hierarchy is crawled upwards to find out in which parent class is *attr* defined,
so that the href target is a valid link. In that case, only single inheritace is assumed and
the first class from the top defining *attr* is used.
:param ser: object of class deriving from :yref:`Serializable`, or string; if string, *attr* must be empty.
:param attr: name of the attribute to link to; if empty, linke to the class itself is created.
:param text: visible text of the hyperlink; if not given, either class name or attribute name without class name (when *attr* is not given) is used.
:returns: HTML with the hyperref.
"""
# klass is a class name given as string
if isinstance(ser,str):
if attr: raise InvalidArgument("When *ser* is a string, *attr* must be empty (only class link can be created)")
return makeWrapperHref(text if text else ser,ser)
# klass is a type object
if attr:
klass=ser.__class__
while attr in dir(klass.__bases__[0]): klass=klass.__bases__[0]
if not text: text=attr
else:
klass=ser.__class__
if not text: text=klass.__name__
return makeWrapperHref(text,klass.__name__,attr,static=(attr and getattr(klass,attr)==getattr(ser,attr)))
class AttrEditor():
"""Abstract base class handing some aspects common to all attribute editors.
Holds exacly one attribute which is updated whenever it changes."""
def __init__(self,getter=None,setter=None):
self.getter,self.setter=getter,setter
self.hot,self.focused=False,False
self.widget=None
def refresh(self): pass
def update(self): pass
def isHot(self,hot=True):
"Called when the widget gets focus; mark it hot, change colors etc."
if hot==self.hot: return
self.hot=hot
if hot: self.setStyleSheet('QWidget { background: red }')
else: self.setStyleSheet('QWidget { background: none }')
def sizeHint(self): return QSize(150,12)
def trySetter(self,val):
try: self.setter(val)
except AttributeError: self.setEnabled(False)
self.isHot(False)
class AttrEditor_Bool(AttrEditor,QFrame):
def __init__(self,parent,getter,setter):
AttrEditor.__init__(self,getter,setter)
QFrame.__init__(self,parent)
self.checkBox=QCheckBox(self)
lay=QVBoxLayout(self); lay.setSpacing(0); lay.setMargin(0); lay.addStretch(1); lay.addWidget(self.checkBox); lay.addStretch(1)
self.checkBox.clicked.connect(self.update)
def refresh(self): self.checkBox.setChecked(self.getter())
def update(self): self.trySetter(self.checkBox.isChecked())
class AttrEditor_Int(AttrEditor,QSpinBox):
def __init__(self,parent,getter,setter):
AttrEditor.__init__(self,getter,setter)
QSpinBox.__init__(self,parent)
self.setRange(int(-1e9),int(1e9)); self.setSingleStep(1);
self.valueChanged.connect(self.update)
def refresh(self): self.setValue(self.getter())
def update(self): self.trySetter(self.value())
class AttrEditor_Str(AttrEditor,QLineEdit):
def __init__(self,parent,getter,setter):
AttrEditor.__init__(self,getter,setter)
QLineEdit.__init__(self,parent)
self.textEdited.connect(self.isHot)
self.selectionChanged.connect(self.isHot)
self.editingFinished.connect(self.update)
def refresh(self): self.setText(self.getter())
def update(self): self.trySetter(str(self.text()))
class AttrEditor_Float(AttrEditor,QLineEdit):
def __init__(self,parent,getter,setter):
AttrEditor.__init__(self,getter,setter)
QLineEdit.__init__(self,parent)
self.textEdited.connect(self.isHot)
self.selectionChanged.connect(self.isHot)
self.editingFinished.connect(self.update)
def refresh(self):
self.setText(str(self.getter()));
if True or not self.hasFocus(): self.home(False)
def update(self):
try: self.trySetter(float(self.text()))
except ValueError: self.refresh()
class AttrEditor_Quaternion(AttrEditor,QFrame):
def __init__(self,parent,getter,setter):
AttrEditor.__init__(self,getter,setter)
QFrame.__init__(self,parent)
self.grid=QHBoxLayout(self); self.grid.setSpacing(0); self.grid.setMargin(0)
for i in range(4):
if i==3:
f=QFrame(self); f.setFrameShape(QFrame.VLine); f.setFrameShadow(QFrame.Sunken); f.setFixedWidth(4) # add vertical divider (axis | angle)
self.grid.addWidget(f)
w=QLineEdit('')
self.grid.addWidget(w);
w.textEdited.connect(self.isHot)
w.selectionChanged.connect(self.isHot)
w.editingFinished.connect(self.update)
def refresh(self):
val=self.getter(); axis,angle=val.toAxisAngle()
for i in (0,1,2,4):
w=self.grid.itemAt(i).widget(); w.setText(str(axis[i] if i<3 else angle));
if True or not w.hasFocus(): w.home(False)
def update(self):
try:
x=[float((self.grid.itemAt(i).widget().text())) for i in (0,1,2,4)]
except ValueError: self.refresh()
q=Quaternion(Vector3(x[0],x[1],x[2]),x[3]); q.normalize() # from axis-angle
self.trySetter(q)
def setFocus(self): self.grid.itemAt(0).widget().setFocus()
class AttrEditor_Se3(AttrEditor,QFrame):
def __init__(self,parent,getter,setter):
AttrEditor.__init__(self,getter,setter)
QFrame.__init__(self,parent)
self.grid=QGridLayout(self); self.grid.setSpacing(0); self.grid.setMargin(0)
for row,col in itertools.product(range(2),range(5)): # one additional column for vertical line in quaternion
if (row,col)==(0,3): continue
if (row,col)==(0,4): self.grid.addWidget(QLabel(u'←<i>pos</i> ↙<i>ori</i>',self),row,col); continue
if (row,col)==(1,3):
f=QFrame(self); f.setFrameShape(QFrame.VLine); f.setFrameShadow(QFrame.Sunken); f.setFixedWidth(4); self.grid.addWidget(f,row,col); continue
w=QLineEdit('')
self.grid.addWidget(w,row,col);
w.textEdited.connect(self.isHot)
w.selectionChanged.connect(self.isHot)
w.editingFinished.connect(self.update)
def refresh(self):
pos,ori=self.getter(); axis,angle=ori.toAxisAngle()
for i in (0,1,2,4):
w=self.grid.itemAtPosition(1,i).widget(); w.setText(str(axis[i] if i<3 else angle));
if True or not w.hasFocus(): w.home(False)
for i in (0,1,2):
w=self.grid.itemAtPosition(0,i).widget(); w.setText(str(pos[i]));
if True or not w.hasFocus(): w.home(False)
def update(self):
try:
q=[float((self.grid.itemAtPosition(1,i).widget().text())) for i in (0,1,2,4)]
v=[float((self.grid.itemAtPosition(0,i).widget().text())) for i in (0,1,2)]
except ValueError: self.refresh()
qq=Quaternion(Vector3(q[0],q[1],q[2]),q[3]); qq.normalize() # from axis-angle
self.trySetter((v,qq))
def setFocus(self): self.grid.itemAtPosition(0,0).widget().setFocus()
class AttrEditor_MatrixX(AttrEditor,QFrame):
def __init__(self,parent,getter,setter,rows,cols,idxConverter):
'idxConverter converts row,col tuple to either (row,col), (col) etc depending on what access is used for []'
AttrEditor.__init__(self,getter,setter)
QFrame.__init__(self,parent)
self.rows,self.cols=rows,cols
self.idxConverter=idxConverter
self.setContentsMargins(0,0,0,0)
val=self.getter()
self.grid=QGridLayout(self); self.grid.setSpacing(0); self.grid.setMargin(0)
for row,col in itertools.product(range(self.rows),range(self.cols)):
w=QLineEdit('')
self.grid.addWidget(w,row,col);
w.textEdited.connect(self.isHot)
w.selectionChanged.connect(self.isHot)
w.editingFinished.connect(self.update)
def refresh(self):
val=self.getter()
for row,col in itertools.product(range(self.rows),range(self.cols)):
w=self.grid.itemAtPosition(row,col).widget()
w.setText(str(val[self.idxConverter(row,col)]))
if True or not w.hasFocus: w.home(False) # make the left-most part visible, if the text is wider than the widget
def update(self):
try:
val=self.getter()
for row,col in itertools.product(range(self.rows),range(self.cols)):
w=self.grid.itemAtPosition(row,col).widget()
if w.isModified(): val[self.idxConverter(row,col)]=float(w.text())
logging.debug('setting'+str(val))
self.trySetter(val)
except ValueError: self.refresh()
def setFocus(self): self.grid.itemAtPosition(0,0).widget().setFocus()
class AttrEditor_MatrixXi(AttrEditor,QFrame):
def __init__(self,parent,getter,setter,rows,cols,idxConverter):
'idxConverter converts row,col tuple to either (row,col), (col) etc depending on what access is used for []'
AttrEditor.__init__(self,getter,setter)
QFrame.__init__(self,parent)
self.rows,self.cols=rows,cols
self.idxConverter=idxConverter
self.setContentsMargins(0,0,0,0)
self.grid=QGridLayout(self); self.grid.setSpacing(0); self.grid.setMargin(0)
for row,col in itertools.product(range(self.rows),range(self.cols)):
w=QSpinBox()
w.setRange(int(-1e9),int(1e9)); w.setSingleStep(1);
self.grid.addWidget(w,row,col);
self.refresh() # refresh before connecting signals!
for row,col in itertools.product(range(self.rows),range(self.cols)):
self.grid.itemAtPosition(row,col).widget().valueChanged.connect(self.update)
def refresh(self):
val=self.getter()
for row,col in itertools.product(range(self.rows),range(self.cols)):
w=self.grid.itemAtPosition(row,col).widget().setValue(val[self.idxConverter(row,col)])
def update(self):
val=self.getter(); modified=False
for row,col in itertools.product(range(self.rows),range(self.cols)):
w=self.grid.itemAtPosition(row,col).widget()
if w.value()!=val[self.idxConverter(row,col)]:
modified=True; val[self.idxConverter(row,col)]=w.value()
if not modified: return
logging.debug('setting'+str(val))
self.trySetter(val)
def setFocus(self): self.grid.itemAtPosition(0,0).widget().setFocus()
class AttrEditor_Vector6i(AttrEditor_MatrixXi):
def __init__(self,parent,getter,setter):
AttrEditor_MatrixXi.__init__(self,parent,getter,setter,1,6,lambda r,c:c)
class AttrEditor_Vector3i(AttrEditor_MatrixXi):
def __init__(self,parent,getter,setter):
AttrEditor_MatrixXi.__init__(self,parent,getter,setter,1,3,lambda r,c:c)
class AttrEditor_Vector2i(AttrEditor_MatrixXi):
def __init__(self,parent,getter,setter):
AttrEditor_MatrixXi.__init__(self,parent,getter,setter,1,2,lambda r,c:c)
class AttrEditor_Vector6(AttrEditor_MatrixX):
def __init__(self,parent,getter,setter):
AttrEditor_MatrixX.__init__(self,parent,getter,setter,1,6,lambda r,c:c)
class AttrEditor_Vector3(AttrEditor_MatrixX):
def __init__(self,parent,getter,setter):
AttrEditor_MatrixX.__init__(self,parent,getter,setter,1,3,lambda r,c:c)
class AttrEditor_Vector2(AttrEditor_MatrixX):
def __init__(self,parent,getter,setter):
AttrEditor_MatrixX.__init__(self,parent,getter,setter,1,2,lambda r,c:c)
class AttrEditor_Matrix3(AttrEditor_MatrixX):
def __init__(self,parent,getter,setter):
AttrEditor_MatrixX.__init__(self,parent,getter,setter,3,3,lambda r,c:(r,c))
class Se3FakeType: pass
_fundamentalEditorMap={bool:AttrEditor_Bool,str:AttrEditor_Str,int:AttrEditor_Int,float:AttrEditor_Float,Quaternion:AttrEditor_Quaternion,Vector2:AttrEditor_Vector2,Vector3:AttrEditor_Vector3,Vector6:AttrEditor_Vector6,Matrix3:AttrEditor_Matrix3,Vector6i:AttrEditor_Vector6i,Vector3i:AttrEditor_Vector3i,Vector2i:AttrEditor_Vector2i,Se3FakeType:AttrEditor_Se3}
_fundamentalInitValues={bool:True,str:'',int:0,float:0.0,Quaternion:Quaternion((0,1,0),0.0),Vector3:Vector3.Zero,Matrix3:Matrix3.Zero,Vector6:Vector6.Zero,Vector6i:Vector6i.Zero,Vector3i:Vector3i.Zero,Vector2i:Vector2i.Zero,Vector2:Vector2.Zero,Se3FakeType:(Vector3.Zero,Quaternion((0,1,0),0.0))}
class SerQLabel(QLabel):
def __init__(self,parent,label,tooltip,path):
QLabel.__init__(self,parent)
self.path=path
self.setText(label)
if tooltip or path: self.setToolTip(('<b>'+path+'</b><br>' if self.path else '')+(tooltip if tooltip else ''))
self.linkActivated.connect(yade.qt.openUrl)
def mousePressEvent(self,event):
if event.button()!=Qt.MidButton:
event.ignore(); return
# middle button clicked, paste pasteText to clipboard
cb=QApplication.clipboard()
cb.setText(self.path,mode=QClipboard.Clipboard)
cb.setText(self.path,mode=QClipboard.Selection) # X11 global selection buffer
event.accept()
class SerializableEditor(QFrame):
"Class displaying and modifying serializable attributes of a yade object."
import collections
import logging
# each attribute has one entry associated with itself
class EntryData:
def __init__(self,name,T,flags=0):
self.name,self.T,self.flags=name,T,flags
self.lineNo,self.widget=None,None
def __init__(self,ser,parent=None,ignoredAttrs=set(),showType=False,path=None):
"Construct window, *ser* is the object we want to show."
QtGui.QFrame.__init__(self,parent)
self.ser=ser
self.path=(ser.label if (hasattr(ser,'label') and ser.label) else path)
self.showType=showType
self.hot=False
self.entries=[]
self.ignoredAttrs=ignoredAttrs
logging.debug('New Serializable of type %s'%ser.__class__.__name__)
self.setWindowTitle(str(ser))
self.mkWidgets()
self.refreshTimer=QTimer(self)
self.refreshTimer.timeout.connect(self.refreshEvent)
self.refreshTimer.start(500)
def getListTypeFromDocstring(self,attr):
"Guess type of array by scanning docstring for :yattrtype: and parsing its argument; ugly, but works."
doc=getattr(self.ser.__class__,attr).__doc__
if doc==None:
logging.error("Attribute %s has no docstring."%attr)
return None
m=re.search(r':yattrtype:`([^`]*)`',doc)
if not m:
logging.error("Attribute %s does not contain :yattrtype:`....` (docstring is '%s'"%(attr,doc))
return None
cxxT=m.group(1)
logging.debug('Got type "%s" from :yattrtype:'%cxxT)
def vecTest(T,cxxT):
#regexp=r'^\s*(std\s*::)?\s*vector\s*<\s*(std\s*::)?\s*('+T+r')\s*>\s*$'
regexp=r'^\s*(std\s*::)?\s*vector\s*<\s*(shared_ptr\s*<\s*)?\s*(std\s*::)?\s*('+T+r')(\s*>)?\s*>\s*$'
m=re.match(regexp,cxxT)
return m
vecMap={
'bool':bool,'int':int,'long':int,'Body::id_t':long,'size_t':long,
'Real':float,'float':float,'double':float,
'Vector6r':Vector6,'Vector6i':Vector6i,'Vector3i':Vector3i,'Vector2r':Vector2,'Vector2i':Vector2i,
'Vector3r':Vector3,'Matrix3r':Matrix3,'Se3r':Se3FakeType,
'string':str,
#'BodyCallback':BodyCallback,
'IntrCallback':IntrCallback,'BoundFunctor':BoundFunctor,'IGeomFunctor':IGeomFunctor,'IPhysFunctor':IPhysFunctor,'LawFunctor':LawFunctor,'KinematicEngine':KinematicEngine,
'GlShapeFunctor':GlShapeFunctor,'GlStateFunctor':GlStateFunctor,'GlIGeomFunctor':GlIGeomFunctor,'GlIPhysFunctor':GlIPhysFunctor,'GlBoundFunctor':GlBoundFunctor,'GlExtraDrawer':GlExtraDrawer
}
for T,ret in vecMap.items():
if vecTest(T,cxxT):
logging.debug("Got type %s from cxx type %s"%(repr(ret),cxxT))
return (ret,)
logging.error("Unable to guess python type from cxx type '%s'"%cxxT)
return None
def mkAttrEntries(self):
if self.ser==None: return
try:
d=self.ser.dict()
except TypeError:
logging.error('TypeError when getting attributes of '+str(self.ser)+',skipping. ')
import traceback
traceback.print_exc()
attrs=self.ser.dict().keys(); attrs.sort()
for attr in attrs:
val=getattr(self.ser,attr) # get the value using serattr, as it might be different from what the dictionary provides (e.g. Body.blockedDOFs)
t=None
doc=getattr(self.ser.__class__,attr).__doc__;
if '|yhidden|' in doc: continue
if attr in self.ignoredAttrs: continue
if isinstance(val,list):
t=self.getListTypeFromDocstring(attr)
if not t and len(val)==0: t=(val[0].__class__,) # 1-tuple is list of the contained type
#if not t: raise RuntimeError('Unable to guess type of '+str(self.ser)+'.'+attr)
# hack for Se3, which is returned as (Vector3,Quaternion) in python
elif isinstance(val,tuple) and len(val)==2 and val[0].__class__==Vector3 and val[1].__class__==Quaternion: t=Se3FakeType
else: t=val.__class__
match=re.search(':yattrflags:`\s*([0-9]+)\s*`',doc) # non-empty attribute
flags=int(match.group(1)) if match else 0
#logging.debug('Attr %s is of type %s'%(attr,((t[0].__name__,) if isinstance(t,tuple) else t.__name__)))
self.entries.append(self.EntryData(name=attr,T=t))
def getDocstring(self,attr=None):
"If attr is *None*, return docstring of the Serializable itself"
doc=(getattr(self.ser.__class__,attr).__doc__ if attr else self.ser.__class__.__doc__)
if not doc: return ''
doc=re.sub(':y(attrtype|default|attrflags):`[^`]*`','',doc)
statAttr=re.compile('^.. ystaticattr::.*$',re.MULTILINE|re.DOTALL)
doc=re.sub(statAttr,'',doc) # static classes have their proper docs at the beginning, discard static memeber docs
# static: attribute of the type is the same object as attribute of the instance
# in that case, get docstring from the class documentation by parsing it
if attr and getattr(self.ser.__class__,attr)==getattr(self.ser,attr): doc=self.getStaticAttrDocstring(attr)
doc=re.sub(':yref:`([^`]*)`','\\1',doc)
import textwrap
wrapper=textwrap.TextWrapper(replace_whitespace=False)
return wrapper.fill(textwrap.dedent(doc))
def getStaticAttrDocstring(self,attr):
ret=''; c=self.ser.__class__
while hasattr(c,attr) and hasattr(c.__base__,attr): c=c.__base__
start='.. ystaticattr:: %s.%s('%(c.__name__,attr)
if start in c.__doc__:
ll=c.__doc__.split('\n')
for i in range(len(ll)):
if ll[i].startswith(start): break
for i in range(i+1,len(ll)):
if len(ll[i])>0 and ll[i][0] not in ' \t': break
ret+=ll[i]
return ret
else: return '[no documentation found]'
def mkWidget(self,entry):
if not entry.T: return None
# single fundamental object
Klass=_fundamentalEditorMap.get(entry.T,None)
getter,setter=lambda: getattr(self.ser,entry.name), lambda x: setattr(self.ser,entry.name,x)
if Klass:
widget=Klass(self,getter=getter,setter=setter)
widget.setFocusPolicy(Qt.StrongFocus)
if (entry.flags & AttrFlags.readonly): widget.setEnabled(False)
return widget
# sequences
if entry.T.__class__==tuple:
assert(len(entry.T)==1) # we don't handle tuples of other lenghts
# sequence of serializables
T=entry.T[0]
if (issubclass(T,Serializable) or T==Serializable):
widget=SeqSerializable(self,getter,setter,T,path=(self.path+'.'+entry.name if self.path else None),shrink=True)
return widget
if (T in _fundamentalEditorMap):
widget=SeqFundamentalEditor(self,getter,setter,T)
return widget
return None
# a serializable
if issubclass(entry.T,Serializable) or entry.T==Serializable:
obj=getattr(self.ser,entry.name)
if hasattr(obj,'label') and obj.label: path=obj.label
elif self.path: path=self.path+'.'+entry.name
else: path=None
widget=SerializableEditor(getattr(self.ser,entry.name),parent=self,showType=self.showType,path=(self.path+'.'+entry.name if self.path else None))
widget.setFrameShape(QFrame.Box); widget.setFrameShadow(QFrame.Raised); widget.setLineWidth(1)
return widget
return None
def mkWidgets(self):
self.mkAttrEntries()
grid=QFormLayout()
grid.setContentsMargins(2,2,2,2)
grid.setVerticalSpacing(0)
grid.setLabelAlignment(Qt.AlignRight)
if self.showType:
lab=SerQLabel(self,makeSerializableLabel(self.ser,addr=True,href=True),tooltip=self.getDocstring(),path=self.path)
lab.setFrameShape(QFrame.Box); lab.setFrameShadow(QFrame.Sunken); lab.setLineWidth(2); lab.setAlignment(Qt.AlignHCenter); lab.linkActivated.connect(yade.qt.openUrl)
grid.setWidget(0,QFormLayout.SpanningRole,lab)
for entry in self.entries:
entry.widget=self.mkWidget(entry)
objPath=(self.path+'.'+entry.name) if self.path else None
label=SerQLabel(self,serializableHref(self.ser,entry.name),tooltip=self.getDocstring(entry.name),path=objPath)
grid.addRow(label,entry.widget if entry.widget else QLabel('<i>unhandled type</i>'))
self.setLayout(grid)
self.refreshEvent()
def refreshEvent(self):
for e in self.entries:
if e.widget and not e.widget.hot: e.widget.refresh()
def refresh(self): pass
def makeSerializableLabel(ser,href=False,addr=True,boldHref=True,num=-1,count=-1):
ret=u''
if num>=0:
if count>=0: ret+=u'%d/%d. '%(num,count)
else: ret+=u'%d. '%num
if href: ret+=(u' <b>' if boldHref else u' ')+serializableHref(ser)+(u'</b> ' if boldHref else u' ')
else: ret+=ser.__class__.__name__+' '
if hasattr(ser,'label') and ser.label: ret+=u' “'+unicode(ser.label)+u'”'
# do not show address if there is a label already
elif addr:
import re
ss=unicode(ser); m=re.match(u'<(.*) instance at (0x.*)>',ss)
if m: ret+=m.group(2)
else: logging.warning(u"Serializable converted to str ('%s') does not contain 'instance at 0x…'"%ss)
return ret
class SeqSerializableComboBox(QFrame):
def __init__(self,parent,getter,setter,serType,path=None,shrink=False):
QFrame.__init__(self,parent)
self.getter,self.setter,self.serType,self.path,self.shrink=getter,setter,serType,path,shrink
self.layout=QVBoxLayout(self)
topLineFrame=QFrame(self)
topLineLayout=QHBoxLayout(topLineFrame);
for l in self.layout, topLineLayout: l.setSpacing(0); l.setContentsMargins(0,0,0,0)
topLineFrame.setLayout(topLineLayout)
buttons=(self.newButton,self.killButton,self.upButton,self.downButton)=[QPushButton(label,self) for label in (u'☘',u'☠',u'↑',u'↓')]
buttonSlots=(self.newSlot,self.killSlot,self.upSlot,self.downSlot) # same order as buttons
for b in buttons: b.setStyleSheet('QPushButton { font-size: 15pt; }'); b.setFixedWidth(30); b.setFixedHeight(30)
self.combo=QComboBox(self)
self.combo.setSizeAdjustPolicy(QComboBox.AdjustToContents)
for w in buttons[0:2]+[self.combo,]+buttons[2:4]: topLineLayout.addWidget(w)
self.layout.addWidget(topLineFrame) # nested layout
self.scroll=QScrollArea(self); self.scroll.setWidgetResizable(True)
self.layout.addWidget(self.scroll)
self.seqEdit=None # currently edited serializable
self.setLayout(self.layout)
self.hot=None # API compat with SerializableEditor
self.setFrameShape(QFrame.Box); self.setFrameShadow(QFrame.Raised); self.setLineWidth(1)
# signals
for b,slot in zip(buttons,buttonSlots): b.clicked.connect(slot)
self.combo.currentIndexChanged.connect(self.comboIndexSlot)
self.refreshEvent()
# periodic refresh
self.refreshTimer=QTimer(self)
self.refreshTimer.timeout.connect(self.refreshEvent)
self.refreshTimer.start(1000) # 1s should be enough
#print 'SeqSerializable path is',self.path
def comboIndexSlot(self,ix): # different seq item selected
currSeq=self.getter();
if len(currSeq)==0: ix=-1
logging.debug('%s comboIndexSlot len=%d, ix=%d'%(self.serType.__name__,len(currSeq),ix))
self.downButton.setEnabled(ix<len(currSeq)-1)
self.upButton.setEnabled(ix>0)
self.combo.setEnabled(ix>=0)
if ix>=0:
ser=currSeq[ix]
self.seqEdit=SerializableEditor(ser,parent=self,showType=seqSerializableShowType,path=(self.path+'['+str(ix)+']') if self.path else None)
self.scroll.setWidget(self.seqEdit)
if self.shrink:
self.sizeHint=lambda: QSize(100,1000)
self.scroll.sizeHint=lambda: QSize(100,1000)
self.sizePolicy().setVerticalPolicy(QSizePolicy.Expanding)
self.scroll.sizePolicy().setVerticalPolicy(QSizePolicy.Expanding)
self.setMinimumHeight(min(300,self.seqEdit.height()+self.combo.height()+10))
self.setMaximumHeight(100000)
self.scroll.setMaximumHeight(100000)
else:
self.scroll.setWidget(QFrame())
if self.shrink:
self.setMaximumHeight(self.combo.height()+10);
self.scroll.setMaximumHeight(0)
def serLabel(self,ser,i=-1):
return ('' if i<0 else str(i)+'. ')+str(ser)[1:-1].replace('instance at ','')
def refreshEvent(self,forceIx=-1):
currSeq=self.getter()
comboEnabled=self.combo.isEnabled()
if comboEnabled and len(currSeq)==0: self.comboIndexSlot(-1) # force refresh, otherwise would not happen from the initially empty state
ix,cnt=self.combo.currentIndex(),self.combo.count()
# serializable currently being edited (which can be absent) or the one of which index is forced
ser=(self.seqEdit.ser if self.seqEdit else None) if forceIx<0 else currSeq[forceIx]
if comboEnabled and len(currSeq)==cnt and (ix<0 or ser==currSeq[ix]): return
if not comboEnabled and len(currSeq)==0: return
logging.debug(self.serType.__name__+' rebuilding list from scratch')
self.combo.clear()
if len(currSeq)>0:
prevIx=-1
for i,s in enumerate(currSeq):
self.combo.addItem(makeSerializableLabel(s,num=i,count=len(currSeq),addr=False))
if s==ser: prevIx=i
if forceIx>=0: newIx=forceIx # force the index (used from newSlot to make the new element active)
elif prevIx>=0: newIx=prevIx # if found what was active before, use it
elif ix>=0: newIx=ix # otherwise use the previous index (e.g. after deletion)
else: newIx=0 # fallback to 0
logging.debug('%s setting index %d'%(self.serType.__name__,newIx))
self.combo.setCurrentIndex(newIx)
else:
logging.debug('%s EMPTY, setting index 0'%(self.serType.__name__))
self.combo.setCurrentIndex(-1)
self.killButton.setEnabled(len(currSeq)>0)
def newSlot(self):
dialog=NewSerializableDialog(self,self.serType.__name__)
if not dialog.exec_(): return # cancelled
ser=dialog.result()
ix=self.combo.currentIndex()
currSeq=self.getter(); currSeq.insert(ix,ser); self.setter(currSeq)
logging.debug('%s new item created at index %d'%(self.serType.__name__,ix))
self.refreshEvent(forceIx=ix)
def killSlot(self):
ix=self.combo.currentIndex()
currSeq=self.getter(); del currSeq[ix]; self.setter(currSeq)
self.refreshEvent()
def upSlot(self):
i=self.combo.currentIndex()
assert(i>0)
currSeq=self.getter();
prev,curr=currSeq[i-1:i+1]; currSeq[i-1],currSeq[i]=curr,prev; self.setter(currSeq)
self.refreshEvent(forceIx=i-1)
def downSlot(self):
i=self.combo.currentIndex()
currSeq=self.getter(); assert(i<len(currSeq)-1);
curr,nxt=currSeq[i:i+2]; currSeq[i],currSeq[i+1]=nxt,curr; self.setter(currSeq)
self.refreshEvent(forceIx=i+1)
def refresh(self): pass # API compat with SerializableEditor
SeqSerializable=SeqSerializableComboBox
class NewFundamentalDialog(QDialog):
def __init__(self,parent,attrName,typeObj,typeStr):
QDialog.__init__(self,parent)
self.setWindowTitle('%s (type %s)'%(attrName,typeStr))
self.layout=QVBoxLayout(self)
self.scroll=QScrollArea(self)
self.scroll.setWidgetResizable(True)
self.buttons=QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel);
self.buttons.accepted.connect(self.accept)
self.buttons.rejected.connect(self.reject)
self.layout.addWidget(self.scroll)
self.layout.addWidget(self.buttons)
self.setWindowModality(Qt.WindowModal)
class FakeObjClass: pass
self.fakeObj=FakeObjClass()
self.attrName=attrName
Klass=_fundamentalEditorMap.get(typeObj,None)
initValue=_fundamentalInitValues.get(typeObj,typeObj())
setattr(self.fakeObj,attrName,initValue)
if Klass:
self.widget=Klass(None,self.fakeObj,attrName)
self.scroll.setWidget(self.widget)
self.scroll.show()
self.widget.refresh()
else: raise RuntimeError("Unable to construct new dialog for type %s"%(typeStr))
def result(self):
self.widget.update()
return getattr(self.fakeObj,self.attrName)
class NewSerializableDialog(QDialog):
def __init__(self,parent,baseClassName,includeBase=True):
import yade.system
QDialog.__init__(self,parent)
self.setWindowTitle('Create new object of type %s'%baseClassName)
self.layout=QVBoxLayout(self)
self.combo=QComboBox(self)
childs=list(yade.system.childClasses(baseClassName,includeBase=False)); childs.sort()
if includeBase:
self.combo.addItem(baseClassName)
self.combo.insertSeparator(1000)
self.combo.addItems(childs)
self.combo.currentIndexChanged.connect(self.comboSlot)
self.scroll=QScrollArea(self)
self.scroll.setWidgetResizable(True)
self.buttons=QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel);
self.buttons.accepted.connect(self.accept)
self.buttons.rejected.connect(self.reject)
self.layout.addWidget(self.combo)
self.layout.addWidget(self.scroll)
self.layout.addWidget(self.buttons)
self.ser=None
self.combo.setCurrentIndex(0); self.comboSlot(0)
self.setWindowModality(Qt.WindowModal)
def comboSlot(self,index):
item=str(self.combo.itemText(index))
self.ser=eval(item+'()')
self.scroll.setWidget(SerializableEditor(self.ser,self.scroll,showType=True))
self.scroll.show()
def result(self): return self.ser
def sizeHint(self): return QSize(180,400)
class SeqFundamentalEditor(QFrame):
def __init__(self,parent,getter,setter,itemType):
QFrame.__init__(self,parent)
self.getter,self.setter,self.itemType=getter,setter,itemType
self.layout=QVBoxLayout()
topLineFrame=QFrame(self); topLineLayout=QHBoxLayout(topLineFrame)
self.form=QFormLayout()
self.form.setContentsMargins(0,0,0,0)
self.form.setVerticalSpacing(0)
self.form.setLabelAlignment(Qt.AlignLeft)
self.formFrame=QFrame(self); self.formFrame.setLayout(self.form)
self.layout.addWidget(self.formFrame)
self.setLayout(self.layout)
# SerializableEditor API compat
self.hot=False
self.rebuild()
# periodic refresh
self.refreshTimer=QTimer(self)
self.refreshTimer.timeout.connect(self.refreshEvent)
self.refreshTimer.start(1000) # 1s should be enough
def contextMenuEvent(self, event):
index=self.localPositionToIndex(event.pos())
seq=self.getter()
if len(seq)==0: index=-1
field=self.form.itemAt(index,QFormLayout.LabelRole).widget() if index>=0 else None
menu=QMenu(self)
actNew,actKill,actUp,actDown=[menu.addAction(name) for name in (u'☘ New',u'☠ Remove',u'↑ Up',u'↓ Down')]
if index<0: [a.setEnabled(False) for a in actKill,actUp,actDown]
if index==len(seq)-1: actDown.setEnabled(False)
if index==0: actUp.setEnabled(False)
if field: field.setStyleSheet('QWidget { background: green }')
act=menu.exec_(self.mapToGlobal(event.pos()))
if field: field.setStyleSheet('QWidget { background: none }')
if not act: return
if act==actNew: self.newSlot(index)
elif act==actKill: self.killSlot(index)
elif act==actUp: self.upSlot(index)
elif act==actDown: self.downSlot(index)
def localPositionToIndex(self,pos):
gp=self.mapToGlobal(pos)
for row in range(self.form.count()/2):
w,i=self.form.itemAt(row,QFormLayout.FieldRole),self.form.itemAt(row,QFormLayout.LabelRole)
for wi in w.widget(),i.widget():
x0,y0,x1,y1=wi.geometry().getCoords(); globG=QRect(self.mapToGlobal(QPoint(x0,y0)),self.mapToGlobal(QPoint(x1,y1)))
if globG.contains(gp):
return row
return -1
def newSlot(self,i):
seq=self.getter();
seq.insert(i,_fundamentalInitValues.get(self.itemType,self.itemType()))
self.setter(seq)
self.rebuild()
def killSlot(self,i):
seq=self.getter(); assert(i<len(seq)); del seq[i]; self.setter(seq)
self.refreshEvent()
def upSlot(self,i):
seq=self.getter(); assert(i<len(seq));
prev,curr=seq[i-1:i+1]; seq[i-1],seq[i]=curr,prev; self.setter(seq)
self.refreshEvent(forceIx=i-1)
def downSlot(self,i):
seq=self.getter(); assert(i<len(seq)-1);
curr,nxt=seq[i:i+2]; seq[i],seq[i+1]=nxt,curr; self.setter(seq)
self.refreshEvent(forceIx=i+1)
def rebuild(self):
currSeq=self.getter()
# clear everything
rows=self.form.count()/2
for row in range(rows):
logging.trace('counts',self.form.rowCount(),self.form.count())
for wi in self.form.itemAt(row,QFormLayout.FieldRole),self.form.itemAt(row,QFormLayout.LabelRole):
self.form.removeItem(wi)
logging.trace('deleting widget',wi.widget())
widget=wi.widget(); widget.hide(); del widget # for some reason, deleting does not make the thing disappear visually; hiding does, however
logging.trace('counts after ',self.form.rowCount(),self.form.count())
logging.debug('cleared')
# add everything
Klass=_fundamentalEditorMap.get(self.itemType,None)
if not Klass:
errMsg=QTextEdit(self)
errMsg.setReadOnly(True); errMsg.setText("Sorry, editing sequences of %s's is not (yet?) implemented."%(self.itemType.__name__))
self.form.insertRow(0,'<b>Error</b>',errMsg)
return
class ItemGetter():
def __init__(self,getter,index): self.getter,self.index=getter,index
def __call__(self): return self.getter()[self.index]
class ItemSetter():
def __init__(self,getter,setter,index): self.getter,self.setter,self.index=getter,setter,index
def __call__(self,val): seq=self.getter(); seq[self.index]=val; self.setter(seq)
for i,item in enumerate(currSeq):
widget=Klass(self,ItemGetter(self.getter,i),ItemSetter(self.getter,self.setter,i)) #proxy,'value')
self.form.insertRow(i,'%d. '%i,widget)
logging.debug('added item %d %s'%(i,str(widget)))
if len(currSeq)==0: self.form.insertRow(0,'<i>empty</i>',QLabel('<i>(right-click for menu)</i>'))
logging.debug('rebuilt, will refresh now')
self.refreshEvent(dontRebuild=True) # avoid infinite recursion it the length would change meanwhile
def refreshEvent(self,dontRebuild=False,forceIx=-1):
currSeq=self.getter()
if len(currSeq)!=self.form.count()/2: #rowCount():
if dontRebuild: return # length changed behind our back, just pretend nothing happened and update next time instead
self.rebuild()
currSeq=self.getter()
for i in range(len(currSeq)):
item=self.form.itemAt(i,QFormLayout.FieldRole)
logging.trace('got item #%d %s'%(i,str(item.widget())))
widget=item.widget()
if not widget.hot:
widget.refresh()
if forceIx>=0 and forceIx==i: widget.setFocus()
def refresh(self): pass # SerializableEditor API
|
gpl-2.0
|
[
3,
2644,
26,
2774,
13,
24,
199,
504,
14084,
20,
14,
10901,
492,
627,
199,
504,
14084,
20,
14,
10604,
492,
627,
199,
504,
14084,
20,
492,
5928,
199,
199,
646,
295,
12,
17691,
199,
646,
2050,
199,
4806,
14,
3446,
29,
4806,
14,
1757,
199,
4806,
14,
19602,
8,
1896,
29,
4806,
14,
4531,
9,
199,
199,
504,
612,
9587,
492,
627,
199,
646,
612,
9587,
14,
8440,
199,
199,
893,
26,
523,
687,
1748,
1873,
8478,
492,
627,
199,
2590,
3545,
26,
523,
687,
20536,
37,
8478,
492,
627,
199,
199,
3610,
3571,
14065,
6824,
804,
29,
549,
327,
2498,
730,
26967,
315,
31244,
8013,
334,
31613,
13763,
4601,
12,
1325,
7704,
314,
730,
10342,
12751,
9,
199,
199,
3,
699,
10134,
26,
3920,
365,
12155,
370,
314,
5386,
78,
1030,
402,
314,
1324,
901,
2755,
340,
652,
965,
16470,
199,
3,
199,
3,
7907,
367,
16470,
12237,
370,
372,
715,
3544,
436,
3920,
365,
7078,
12155,
199,
3,
199,
3,
314,
283,
549,
503,
7,
1777,
27881,
28421,
314,
5558,
334,
1152,
626,
314,
3920,
365,
12155,
3544,
395,
1325,
652,
5594,
506,
6317,
315,
314,
6466,
29437,
199,
3,
199,
3,
340,
715,
503,
336,
14,
1989,
17310,
837,
336,
14,
4219,
8,
797,
9,
199,
3,
199,
3,
199,
199,
318,
1852,
4590,
40,
1121,
8,
505,
12,
533,
985,
12,
962,
29,
403,
12,
1986,
29,
797,
304,
199,
198,
624,
2499,
8968,
461,
4163,
10342,
1073,
370,
282,
1488,
9587,
1021,
503,
2399,
2225,
14,
8299,
198,
26,
635,
1021,
985,
26,
536,
402,
314,
1021,
370,
2142,
370,
14,
199,
198,
26,
635,
1921,
26,
2225,
370,
2142,
370,
14,
982,
1627,
12,
1471,
2187,
5370,
315,
1627,
627,
533,
985,
10,
27,
340,
440,
1627,
503,
2701,
12,
2142,
370,
314,
1021,
6337,
365,
2737,
436,
627,
962,
10,
365,
5525,
14,
199,
198,
26,
1107,
26,
4163,
543,
314,
10342,
1121,
14,
199,
198,
624,
199,
198,
692,
440,
2955,
26,
372,
2650,
65,
4369,
5961,
83,
3,
89,
9587,
14,
5029,
4111,
83,
5,
83,
14423,
83,
1108,
65,
3524,
2840,
89,
9587,
14,
8440,
14,
8008,
3768,
4590,
3276,
12,
533,
985,
12,
4725,
3530,
11,
962,
9,
340,
1921,
587,
9929,
505,
9,
199,
198,
2836,
26,
3515,
372,
2650,
65,
4369,
5961,
83,
3,
89,
1986,
962,
3295,
83,
4111,
83,
14423,
83,
1108,
65,
3524,
2840,
89,
9587,
14,
8440,
14,
8008,
3768,
4590,
3276,
12,
533,
985,
12,
962,
12,
505,
9,
199,
199,
318,
31244,
40,
1121,
8,
332,
12,
962,
29,
403,
12,
505,
29,
403,
304,
199,
198,
624,
1767,
4163,
4369,
370,
282,
627,
332,
10,
14190,
370,
314,
2225,
627,
962,
4856,
199,
198,
1918,
1021,
14446,
365,
286,
1773,
1146,
1536,
4751,
370,
2342,
734,
315,
1314,
1676,
1021,
365,
627,
962,
10,
3247,
12,
199,
198,
1152,
626,
314,
4369,
1347,
365,
282,
1686,
2142,
14,
1010,
626,
1930,
12,
1454,
2849,
8287,
7984,
365,
10826,
436,
199,
198,
1589,
1642,
1021,
687,
314,
2746,
12669,
627,
962,
10,
365,
1202,
14,
421,
198,
26,
635,
8926,
26,
909,
402,
1021,
5405,
4007,
687,
520,
89,
1121,
1705,
3571,
14065,
3559,
503,
1059,
27,
340,
1059,
12,
627,
962,
10,
1471,
506,
2701,
14,
199,
198,
26,
635,
1921,
26,
536,
402,
314,
2225,
370,
2142,
370,
27,
340,
2701,
12,
7403,
415,
370,
314,
1021,
6337,
365,
2737,
14,
199,
198,
26,
635,
1318,
26,
8917,
1318,
402,
314,
10342,
1073,
27,
340,
440,
1627,
12,
1902,
1021,
536,
503,
2225,
536,
1928,
1021,
536,
334,
6526,
627,
962,
10,
365,
440,
1627,
9,
365,
1202,
14,
421,
198,
26,
5808,
26,
4163,
543,
314,
10342,
1121,
14,
199,
198,
624,
199,
198,
3,
8531,
365,
282,
1021,
536,
1627,
465,
1059,
199,
198,
692,
1228,
8,
332,
12,
495,
304,
507,
198,
692,
1921,
26,
746,
6378,
5201,
480,
11423,
627,
332,
10,
365,
282,
1059,
12,
627,
962,
10,
1471,
506,
2701,
334,
2118,
1021,
2142,
883,
506,
2737,
6320,
507,
198,
1107,
1852,
4590,
40,
1121,
8,
505,
340,
1318,
587,
8926,
12,
332,
9,
199,
198,
3,
8531,
365,
282,
730,
909,
199,
198,
692,
1921,
26,
507,
198,
11645,
29,
332,
855,
533,
363,
507,
198,
6710,
1921,
315,
2935,
8,
11645,
855,
12087,
12298,
16,
4682,
8531,
29,
11645,
855,
12087,
12298,
16,
61,
507,
198,
692,
440,
1318,
26,
1318,
29,
962,
199,
198,
2836,
26,
507,
198,
11645,
29,
332,
855,
533,
363,
507,
198,
692,
440,
1318,
26,
1318,
29,
11645,
855,
354,
363,
199,
198,
1107,
1852,
4590,
40,
1121,
8,
505,
12,
11645,
855,
354,
3108,
962,
12,
1986,
2687,
962,
436,
2519,
8,
11645,
12,
962,
12694,
5675,
8,
332,
12,
962,
1724,
199,
199,
533,
20516,
10423,
837,
199,
198,
624,
8458,
1300,
1021,
4926,
316,
2005,
17435,
83,
2863,
370,
1006,
2225,
5283,
1384,
14,
199,
198,
40,
8250,
444,
5853,
89,
1373,
2225,
1314,
365,
4588,
18119,
652,
4493,
1041,
199,
198,
318,
636,
826,
721,
277,
12,
7416,
29,
403,
12,
8345,
29,
403,
304,
507,
198,
277,
14,
7416,
12,
277,
14,
8345,
29,
7416,
12,
8345,
507,
198,
277,
14,
8885,
12,
277,
14,
32621,
29,
797,
12,
797,
507,
198,
277,
14,
3440,
29,
403,
199,
198,
318,
9236,
8,
277,
304,
986,
199,
198,
318,
1678,
8,
277,
304,
986,
199,
198,
318,
365,
19942,
8,
277,
12,
8885,
29,
549,
304,
507,
198,
2,
10474,
1380,
314,
3938,
7545,
16470,
27,
2216,
652,
18469,
12,
1570,
9229,
5423,
2122,
507,
198,
692,
18469,
389,
277,
14,
8885,
26,
372,
507,
198,
277,
14,
8885,
29,
8885,
507,
198,
692,
18469,
26,
291,
14,
31091,
16715,
360,
23894,
469,
8020,
26,
8992,
789,
358,
507,
198,
2836,
26,
291,
14,
31091,
16715,
360,
23894,
469,
8020,
26,
7179,
789,
358,
199,
198,
318,
1568,
20891,
8,
277,
304,
372,
1413,
2320,
8,
8251,
12,
713,
9,
199,
198,
318,
862,
27575,
8,
277,
12,
637,
304,
507,
198,
893,
26,
291,
14,
8345,
8,
637,
9,
507,
198,
2590,
4281
] |
[
2644,
26,
2774,
13,
24,
199,
504,
14084,
20,
14,
10901,
492,
627,
199,
504,
14084,
20,
14,
10604,
492,
627,
199,
504,
14084,
20,
492,
5928,
199,
199,
646,
295,
12,
17691,
199,
646,
2050,
199,
4806,
14,
3446,
29,
4806,
14,
1757,
199,
4806,
14,
19602,
8,
1896,
29,
4806,
14,
4531,
9,
199,
199,
504,
612,
9587,
492,
627,
199,
646,
612,
9587,
14,
8440,
199,
199,
893,
26,
523,
687,
1748,
1873,
8478,
492,
627,
199,
2590,
3545,
26,
523,
687,
20536,
37,
8478,
492,
627,
199,
199,
3610,
3571,
14065,
6824,
804,
29,
549,
327,
2498,
730,
26967,
315,
31244,
8013,
334,
31613,
13763,
4601,
12,
1325,
7704,
314,
730,
10342,
12751,
9,
199,
199,
3,
699,
10134,
26,
3920,
365,
12155,
370,
314,
5386,
78,
1030,
402,
314,
1324,
901,
2755,
340,
652,
965,
16470,
199,
3,
199,
3,
7907,
367,
16470,
12237,
370,
372,
715,
3544,
436,
3920,
365,
7078,
12155,
199,
3,
199,
3,
314,
283,
549,
503,
7,
1777,
27881,
28421,
314,
5558,
334,
1152,
626,
314,
3920,
365,
12155,
3544,
395,
1325,
652,
5594,
506,
6317,
315,
314,
6466,
29437,
199,
3,
199,
3,
340,
715,
503,
336,
14,
1989,
17310,
837,
336,
14,
4219,
8,
797,
9,
199,
3,
199,
3,
199,
199,
318,
1852,
4590,
40,
1121,
8,
505,
12,
533,
985,
12,
962,
29,
403,
12,
1986,
29,
797,
304,
199,
198,
624,
2499,
8968,
461,
4163,
10342,
1073,
370,
282,
1488,
9587,
1021,
503,
2399,
2225,
14,
8299,
198,
26,
635,
1021,
985,
26,
536,
402,
314,
1021,
370,
2142,
370,
14,
199,
198,
26,
635,
1921,
26,
2225,
370,
2142,
370,
14,
982,
1627,
12,
1471,
2187,
5370,
315,
1627,
627,
533,
985,
10,
27,
340,
440,
1627,
503,
2701,
12,
2142,
370,
314,
1021,
6337,
365,
2737,
436,
627,
962,
10,
365,
5525,
14,
199,
198,
26,
1107,
26,
4163,
543,
314,
10342,
1121,
14,
199,
198,
624,
199,
198,
692,
440,
2955,
26,
372,
2650,
65,
4369,
5961,
83,
3,
89,
9587,
14,
5029,
4111,
83,
5,
83,
14423,
83,
1108,
65,
3524,
2840,
89,
9587,
14,
8440,
14,
8008,
3768,
4590,
3276,
12,
533,
985,
12,
4725,
3530,
11,
962,
9,
340,
1921,
587,
9929,
505,
9,
199,
198,
2836,
26,
3515,
372,
2650,
65,
4369,
5961,
83,
3,
89,
1986,
962,
3295,
83,
4111,
83,
14423,
83,
1108,
65,
3524,
2840,
89,
9587,
14,
8440,
14,
8008,
3768,
4590,
3276,
12,
533,
985,
12,
962,
12,
505,
9,
199,
199,
318,
31244,
40,
1121,
8,
332,
12,
962,
29,
403,
12,
505,
29,
403,
304,
199,
198,
624,
1767,
4163,
4369,
370,
282,
627,
332,
10,
14190,
370,
314,
2225,
627,
962,
4856,
199,
198,
1918,
1021,
14446,
365,
286,
1773,
1146,
1536,
4751,
370,
2342,
734,
315,
1314,
1676,
1021,
365,
627,
962,
10,
3247,
12,
199,
198,
1152,
626,
314,
4369,
1347,
365,
282,
1686,
2142,
14,
1010,
626,
1930,
12,
1454,
2849,
8287,
7984,
365,
10826,
436,
199,
198,
1589,
1642,
1021,
687,
314,
2746,
12669,
627,
962,
10,
365,
1202,
14,
421,
198,
26,
635,
8926,
26,
909,
402,
1021,
5405,
4007,
687,
520,
89,
1121,
1705,
3571,
14065,
3559,
503,
1059,
27,
340,
1059,
12,
627,
962,
10,
1471,
506,
2701,
14,
199,
198,
26,
635,
1921,
26,
536,
402,
314,
2225,
370,
2142,
370,
27,
340,
2701,
12,
7403,
415,
370,
314,
1021,
6337,
365,
2737,
14,
199,
198,
26,
635,
1318,
26,
8917,
1318,
402,
314,
10342,
1073,
27,
340,
440,
1627,
12,
1902,
1021,
536,
503,
2225,
536,
1928,
1021,
536,
334,
6526,
627,
962,
10,
365,
440,
1627,
9,
365,
1202,
14,
421,
198,
26,
5808,
26,
4163,
543,
314,
10342,
1121,
14,
199,
198,
624,
199,
198,
3,
8531,
365,
282,
1021,
536,
1627,
465,
1059,
199,
198,
692,
1228,
8,
332,
12,
495,
304,
507,
198,
692,
1921,
26,
746,
6378,
5201,
480,
11423,
627,
332,
10,
365,
282,
1059,
12,
627,
962,
10,
1471,
506,
2701,
334,
2118,
1021,
2142,
883,
506,
2737,
6320,
507,
198,
1107,
1852,
4590,
40,
1121,
8,
505,
340,
1318,
587,
8926,
12,
332,
9,
199,
198,
3,
8531,
365,
282,
730,
909,
199,
198,
692,
1921,
26,
507,
198,
11645,
29,
332,
855,
533,
363,
507,
198,
6710,
1921,
315,
2935,
8,
11645,
855,
12087,
12298,
16,
4682,
8531,
29,
11645,
855,
12087,
12298,
16,
61,
507,
198,
692,
440,
1318,
26,
1318,
29,
962,
199,
198,
2836,
26,
507,
198,
11645,
29,
332,
855,
533,
363,
507,
198,
692,
440,
1318,
26,
1318,
29,
11645,
855,
354,
363,
199,
198,
1107,
1852,
4590,
40,
1121,
8,
505,
12,
11645,
855,
354,
3108,
962,
12,
1986,
2687,
962,
436,
2519,
8,
11645,
12,
962,
12694,
5675,
8,
332,
12,
962,
1724,
199,
199,
533,
20516,
10423,
837,
199,
198,
624,
8458,
1300,
1021,
4926,
316,
2005,
17435,
83,
2863,
370,
1006,
2225,
5283,
1384,
14,
199,
198,
40,
8250,
444,
5853,
89,
1373,
2225,
1314,
365,
4588,
18119,
652,
4493,
1041,
199,
198,
318,
636,
826,
721,
277,
12,
7416,
29,
403,
12,
8345,
29,
403,
304,
507,
198,
277,
14,
7416,
12,
277,
14,
8345,
29,
7416,
12,
8345,
507,
198,
277,
14,
8885,
12,
277,
14,
32621,
29,
797,
12,
797,
507,
198,
277,
14,
3440,
29,
403,
199,
198,
318,
9236,
8,
277,
304,
986,
199,
198,
318,
1678,
8,
277,
304,
986,
199,
198,
318,
365,
19942,
8,
277,
12,
8885,
29,
549,
304,
507,
198,
2,
10474,
1380,
314,
3938,
7545,
16470,
27,
2216,
652,
18469,
12,
1570,
9229,
5423,
2122,
507,
198,
692,
18469,
389,
277,
14,
8885,
26,
372,
507,
198,
277,
14,
8885,
29,
8885,
507,
198,
692,
18469,
26,
291,
14,
31091,
16715,
360,
23894,
469,
8020,
26,
8992,
789,
358,
507,
198,
2836,
26,
291,
14,
31091,
16715,
360,
23894,
469,
8020,
26,
7179,
789,
358,
199,
198,
318,
1568,
20891,
8,
277,
304,
372,
1413,
2320,
8,
8251,
12,
713,
9,
199,
198,
318,
862,
27575,
8,
277,
12,
637,
304,
507,
198,
893,
26,
291,
14,
8345,
8,
637,
9,
507,
198,
2590,
4281,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
kalahbrown/HueBigSQL
|
desktop/core/ext-py/requests-2.6.0/requests/packages/chardet/mbcsgroupprober.py
|
2769
|
1967
|
######################## BEGIN LICENSE BLOCK ########################
# The Original Code is Mozilla Universal charset detector code.
#
# The Initial Developer of the Original Code is
# Netscape Communications Corporation.
# Portions created by the Initial Developer are Copyright (C) 2001
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Mark Pilgrim - port to Python
# Shy Shalom - original C code
# Proofpoint, Inc.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA
######################### END LICENSE BLOCK #########################
from .charsetgroupprober import CharSetGroupProber
from .utf8prober import UTF8Prober
from .sjisprober import SJISProber
from .eucjpprober import EUCJPProber
from .gb2312prober import GB2312Prober
from .euckrprober import EUCKRProber
from .cp949prober import CP949Prober
from .big5prober import Big5Prober
from .euctwprober import EUCTWProber
class MBCSGroupProber(CharSetGroupProber):
def __init__(self):
CharSetGroupProber.__init__(self)
self._mProbers = [
UTF8Prober(),
SJISProber(),
EUCJPProber(),
GB2312Prober(),
EUCKRProber(),
CP949Prober(),
Big5Prober(),
EUCTWProber()
]
self.reset()
|
apache-2.0
|
[
6565,
16427,
5113,
8068,
11945,
199,
3,
710,
12769,
5495,
365,
17728,
29347,
5960,
17842,
1233,
14,
199,
3,
199,
3,
710,
6026,
9607,
402,
314,
12769,
5495,
365,
199,
3,
20433,
18686,
11098,
14,
199,
3,
20825,
2737,
701,
314,
6026,
9607,
787,
1898,
334,
35,
9,
12521,
199,
3,
314,
6026,
9607,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
17636,
8,
83,
304,
199,
3,
257,
7173,
19641,
446,
1844,
370,
2018,
199,
3,
257,
428,
3577,
5244,
279,
676,
446,
3379,
445,
1233,
199,
3,
257,
2165,
1618,
1403,
12,
3277,
14,
199,
3,
199,
3,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
1933,
12,
12066,
11844,
12,
8226,
12,
4828,
199,
3,
11315,
13,
10067,
221,
8217,
199,
19054,
7729,
5113,
8068,
21186,
199,
199,
504,
1275,
6043,
923,
19903,
492,
6659,
1084,
2448,
8029,
199,
504,
1275,
1624,
24,
19903,
492,
9094,
24,
8029,
199,
504,
1275,
83,
18941,
19903,
492,
428,
22290,
8029,
199,
504,
1275,
15149,
11538,
19903,
492,
662,
13371,
15819,
8029,
199,
504,
1275,
4908,
16909,
19903,
492,
18553,
16909,
8029,
199,
504,
1275,
69,
10112,
82,
19903,
492,
26007,
27373,
8029,
199,
504,
1275,
1850,
15674,
19903,
492,
19701,
15674,
8029,
199,
504,
1275,
5076,
21,
19903,
492,
13123,
21,
8029,
199,
504,
1275,
69,
918,
87,
19903,
492,
662,
27120,
8029,
421,
199,
533,
19487,
3298,
2448,
8029,
8,
1610,
1084,
2448,
8029,
304,
272,
347,
636,
826,
721,
277,
304,
267,
6659,
1084,
2448,
8029,
855,
826,
721,
277,
9,
267,
291,
423,
77,
8029,
83,
275,
359,
288,
9094,
24,
8029,
1062,
288,
428,
22290,
8029,
1062,
288,
662,
13371,
15819,
8029,
1062,
288,
18553,
16909,
8029,
1062,
288,
26007,
27373,
8029,
1062,
288,
19701,
15674,
8029,
1062,
288,
13123,
21,
8029,
1062,
288,
662,
27120,
8029,
342,
267,
1622,
267,
291,
14,
3958,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
16427,
5113,
8068,
11945,
199,
3,
710,
12769,
5495,
365,
17728,
29347,
5960,
17842,
1233,
14,
199,
3,
199,
3,
710,
6026,
9607,
402,
314,
12769,
5495,
365,
199,
3,
20433,
18686,
11098,
14,
199,
3,
20825,
2737,
701,
314,
6026,
9607,
787,
1898,
334,
35,
9,
12521,
199,
3,
314,
6026,
9607,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
17636,
8,
83,
304,
199,
3,
257,
7173,
19641,
446,
1844,
370,
2018,
199,
3,
257,
428,
3577,
5244,
279,
676,
446,
3379,
445,
1233,
199,
3,
257,
2165,
1618,
1403,
12,
3277,
14,
199,
3,
199,
3,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
1933,
12,
12066,
11844,
12,
8226,
12,
4828,
199,
3,
11315,
13,
10067,
221,
8217,
199,
19054,
7729,
5113,
8068,
21186,
199,
199,
504,
1275,
6043,
923,
19903,
492,
6659,
1084,
2448,
8029,
199,
504,
1275,
1624,
24,
19903,
492,
9094,
24,
8029,
199,
504,
1275,
83,
18941,
19903,
492,
428,
22290,
8029,
199,
504,
1275,
15149,
11538,
19903,
492,
662,
13371,
15819,
8029,
199,
504,
1275,
4908,
16909,
19903,
492,
18553,
16909,
8029,
199,
504,
1275,
69,
10112,
82,
19903,
492,
26007,
27373,
8029,
199,
504,
1275,
1850,
15674,
19903,
492,
19701,
15674,
8029,
199,
504,
1275,
5076,
21,
19903,
492,
13123,
21,
8029,
199,
504,
1275,
69,
918,
87,
19903,
492,
662,
27120,
8029,
421,
199,
533,
19487,
3298,
2448,
8029,
8,
1610,
1084,
2448,
8029,
304,
272,
347,
636,
826,
721,
277,
304,
267,
6659,
1084,
2448,
8029,
855,
826,
721,
277,
9,
267,
291,
423,
77,
8029,
83,
275,
359,
288,
9094,
24,
8029,
1062,
288,
428,
22290,
8029,
1062,
288,
662,
13371,
15819,
8029,
1062,
288,
18553,
16909,
8029,
1062,
288,
26007,
27373,
8029,
1062,
288,
19701,
15674,
8029,
1062,
288,
13123,
21,
8029,
1062,
288,
662,
27120,
8029,
342,
267,
1622,
267,
291,
14,
3958,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
chenbojian/SU2
|
SU2_PY/parallel_computation.py
|
1
|
3981
|
#!/usr/bin/env python
## \file parallel_computation.py
# \brief Python script for doing the continuous adjoint computation using the SU2 suite.
# \author T. Economon, T. Lukaczyk, F. Palacios
# \version 3.2.9 "eagle"
#
# SU2 Lead Developers: Dr. Francisco Palacios (Francisco.D.Palacios@boeing.com).
# Dr. Thomas D. Economon (economon@stanford.edu).
#
# SU2 Developers: Prof. Juan J. Alonso's group at Stanford University.
# Prof. Piero Colonna's group at Delft University of Technology.
# Prof. Nicolas R. Gauger's group at Kaiserslautern University of Technology.
# Prof. Alberto Guardone's group at Polytechnic University of Milan.
# Prof. Rafael Palacios' group at Imperial College London.
#
# Copyright (C) 2012-2015 SU2, the open-source CFD code.
#
# SU2 is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# SU2 is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with SU2. If not, see <http://www.gnu.org/licenses/>.
import os, sys, shutil, copy
from optparse import OptionParser
sys.path.append(os.environ['SU2_RUN'])
import SU2
# -------------------------------------------------------------------
# Main
# -------------------------------------------------------------------
def main():
# Command Line Options
parser=OptionParser()
parser.add_option("-f", "--file", dest="filename",
help="read config from FILE", metavar="FILE")
parser.add_option("-n", "--partitions", dest="partitions", default=2,
help="number of PARTITIONS", metavar="PARTITIONS")
parser.add_option("-c", "--compute", dest="compute", default="True",
help="COMPUTE direct and adjoint problem", metavar="COMPUTE")
(options, args)=parser.parse_args()
options.partitions = int( options.partitions )
options.compute = options.compute.upper() == 'TRUE'
if options.filename == None:
raise Exception("No config file provided. Use -f flag")
parallel_computation( options.filename ,
options.partitions ,
options.compute )
#: def main()
# -------------------------------------------------------------------
# CFD Solution
# -------------------------------------------------------------------
def parallel_computation( filename ,
partitions = 0 ,
compute = True ):
# Config
config = SU2.io.Config(filename)
config.NUMBER_PART = partitions
# State
state = SU2.io.State()
# check for existing files
if not compute:
state.find_files(config)
else:
state.FILES.MESH = config.MESH_FILENAME
# CFD Solution (direct or adjoint)
info = SU2.run.CFD(config)
state.update(info)
# Solution merging
if config.MATH_PROBLEM == 'DIRECT':
config.SOLUTION_FLOW_FILENAME = config.RESTART_FLOW_FILENAME
elif config.MATH_PROBLEM == 'ADJOINT':
config.SOLUTION_ADJ_FILENAME = config.RESTART_ADJ_FILENAME
info = SU2.run.merge(config)
state.update(info)
return state
#: parallel_computation()
# -------------------------------------------------------------------
# Run Main Program
# -------------------------------------------------------------------
# this is only accessed if running from command prompt
if __name__ == '__main__':
main()
|
lgpl-2.1
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
9948,
199,
309,
971,
493,
9861,
63,
31598,
14,
647,
199,
3,
221,
971,
19127,
2018,
2884,
367,
9689,
314,
19922,
24132,
14009,
1808,
314,
5698,
18,
5241,
14,
199,
3,
221,
971,
2502,
377,
14,
662,
25129,
265,
12,
377,
14,
491,
3210,
645,
3605,
75,
12,
481,
14,
510,
14774,
559,
736,
199,
3,
221,
971,
1023,
650,
14,
18,
14,
25,
298,
69,
643,
274,
2,
199,
3,
199,
3,
5698,
18,
7005,
350,
23493,
26,
577,
82,
14,
481,
1312,
19597,
510,
14774,
559,
736,
334,
38,
1312,
19597,
14,
36,
14,
48,
14774,
559,
736,
32,
656,
69,
316,
14,
957,
680,
199,
3,
10473,
577,
82,
14,
27864,
577,
14,
662,
25129,
265,
334,
69,
25129,
265,
32,
9746,
18090,
14,
8654,
680,
199,
3,
199,
3,
5698,
18,
23493,
26,
2165,
70,
14,
1603,
7856,
1603,
14,
4580,
265,
1152,
1159,
1572,
737,
1933,
290,
18090,
15904,
14,
199,
3,
463,
2165,
70,
14,
19835,
3478,
3626,
265,
3540,
1159,
1572,
737,
1487,
32462,
15904,
402,
21580,
14,
199,
3,
463,
2165,
70,
14,
30650,
761,
305,
820,
14,
598,
3844,
836,
1159,
1572,
737,
1804,
5789,
21317,
416,
85,
1203,
15904,
402,
21580,
14,
199,
3,
463,
2165,
70,
14,
4580,
605,
475,
12436,
1005,
368,
1159,
1572,
737,
16869,
266,
11019,
530,
15904,
402,
603,
382,
290,
14,
199,
3,
463,
2165,
70,
14,
3898,
667,
352,
510,
14774,
559,
736,
7,
1572,
737,
8362,
281,
2380,
3626,
274,
303,
491,
7835,
265,
14,
199,
3,
199,
3,
1898,
334,
35,
9,
6029,
13,
7806,
5698,
18,
12,
314,
1551,
13,
1365,
6035,
36,
1233,
14,
199,
3,
199,
3,
5698,
18,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
5698,
18,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
1666,
314,
1664,
199,
3,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
5698,
18,
14,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
646,
747,
12,
984,
12,
5145,
12,
1331,
199,
504,
8691,
492,
13491,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
2314,
459,
6195,
18,
63,
9390,
1105,
199,
646,
5698,
18,
199,
199,
3,
5620,
2595,
199,
3,
221,
11298,
221,
199,
3,
5620,
2595,
199,
199,
318,
2446,
837,
2286,
327,
5817,
7030,
8394,
272,
1798,
29,
14553,
342,
272,
1798,
14,
525,
63,
1422,
6096,
70,
401,
4320,
493,
401,
755,
2053,
628,
1501,
401,
1993,
1720,
628,
739,
1101,
687,
13024,
401,
8214,
628,
3817,
531,
272,
1798,
14,
525,
63,
1422,
6096,
78,
401,
4320,
12553,
401,
2053,
628,
12553,
401,
849,
29,
18,
12,
1993,
1720,
628,
1955,
402,
3076,
649,
2823,
401,
8214,
628,
14848,
649,
2823,
531,
272,
1798,
14,
525,
63,
1422,
6096,
67,
401,
4320,
3357,
401,
259,
2053,
628,
3357,
401,
259,
849,
628,
549,
401,
1993,
1720,
628,
6790,
4586,
4125,
436,
24132,
5160,
401,
8214,
628,
6790,
4586,
531,
2432,
272,
334,
1419,
12,
1249,
23397,
2087,
14,
1122,
63,
589,
342,
272,
1511,
14,
12553,
221,
275,
1109,
8,
1511,
14,
12553,
776,
272,
1511,
14,
3357,
258,
275,
1511,
14,
3357,
14,
4142,
342,
508,
283,
15064,
7,
339,
340,
1511,
14,
1501,
508,
488,
26,
267,
746,
2186,
480,
1944,
1101,
570,
2741,
14,
3645,
446,
70,
3305,
531,
2286,
9861,
63,
31598,
8,
1511,
14,
1501,
259,
2360,
2079,
1511,
14,
12553,
221,
2360,
2079,
1511,
14,
3357,
420,
776,
268,
199,
12573,
347,
2446,
342,
421,
199,
3,
5620,
2595,
199,
3,
221,
6035,
36,
9274,
199,
3,
5620,
2595,
199,
199,
318,
9861,
63,
31598,
8,
1788,
3698,
2360,
221,
2079,
16394,
221,
275,
378,
259,
2360,
221,
2079,
4526,
258,
275,
715,
221,
3461,
2286,
327,
4094,
272,
1101,
275,
5698,
18,
14,
2308,
14,
2028,
8,
1501,
9,
272,
1101,
14,
9190,
63,
14848,
275,
16394,
2286,
327,
8511,
272,
1174,
275,
5698,
18,
14,
2308,
14,
2223,
342,
2286,
327,
1104,
367,
3411,
1584,
272,
340,
440,
4526,
26,
267,
1174,
14,
1623,
63,
1725,
8,
888,
9,
272,
587,
26,
267,
1174,
14,
9472,
14,
22076,
40,
275,
1101,
14,
22076,
40,
63,
15440,
2286,
327,
6035,
36,
9274,
334,
2275,
503,
24132,
9,
272,
2256,
275,
5698,
18,
14,
1065,
14,
5487,
36,
8,
888,
9,
5591,
1174,
14,
873,
8,
815,
9,
339,
327,
9274,
22537,
272,
340,
1101,
14,
45,
11695,
63,
30533,
25847,
508,
283,
6098,
356,
267,
1101,
14,
15096,
27129,
63,
17114,
63,
15440,
275,
1101,
14,
15740,
2294,
63,
17114,
63,
15440,
272,
916,
1101,
14,
45,
11695,
63,
30533,
25847,
508,
283,
1554,
24931,
356,
267,
1101,
14,
15096,
27129,
63,
1554,
42,
63,
15440,
275,
1101,
14,
15740,
2294,
63,
1554,
42,
63,
15440,
272,
2256,
275,
5698,
18,
14,
1065,
14,
5628,
8,
888,
9,
272,
1174,
14,
873,
8,
815,
9,
2043,
272,
372,
1174,
199,
199,
12573,
9861,
63,
31598,
342,
421,
199,
3,
5620,
2595,
199,
3,
221,
3378,
11298,
18841,
199,
3,
5620,
2595,
199,
199,
3,
642,
365,
1454,
13810,
340,
3879,
687,
1414,
8457,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2446,
342,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
9948,
199,
309,
971,
493,
9861,
63,
31598,
14,
647,
199,
3,
221,
971,
19127,
2018,
2884,
367,
9689,
314,
19922,
24132,
14009,
1808,
314,
5698,
18,
5241,
14,
199,
3,
221,
971,
2502,
377,
14,
662,
25129,
265,
12,
377,
14,
491,
3210,
645,
3605,
75,
12,
481,
14,
510,
14774,
559,
736,
199,
3,
221,
971,
1023,
650,
14,
18,
14,
25,
298,
69,
643,
274,
2,
199,
3,
199,
3,
5698,
18,
7005,
350,
23493,
26,
577,
82,
14,
481,
1312,
19597,
510,
14774,
559,
736,
334,
38,
1312,
19597,
14,
36,
14,
48,
14774,
559,
736,
32,
656,
69,
316,
14,
957,
680,
199,
3,
10473,
577,
82,
14,
27864,
577,
14,
662,
25129,
265,
334,
69,
25129,
265,
32,
9746,
18090,
14,
8654,
680,
199,
3,
199,
3,
5698,
18,
23493,
26,
2165,
70,
14,
1603,
7856,
1603,
14,
4580,
265,
1152,
1159,
1572,
737,
1933,
290,
18090,
15904,
14,
199,
3,
463,
2165,
70,
14,
19835,
3478,
3626,
265,
3540,
1159,
1572,
737,
1487,
32462,
15904,
402,
21580,
14,
199,
3,
463,
2165,
70,
14,
30650,
761,
305,
820,
14,
598,
3844,
836,
1159,
1572,
737,
1804,
5789,
21317,
416,
85,
1203,
15904,
402,
21580,
14,
199,
3,
463,
2165,
70,
14,
4580,
605,
475,
12436,
1005,
368,
1159,
1572,
737,
16869,
266,
11019,
530,
15904,
402,
603,
382,
290,
14,
199,
3,
463,
2165,
70,
14,
3898,
667,
352,
510,
14774,
559,
736,
7,
1572,
737,
8362,
281,
2380,
3626,
274,
303,
491,
7835,
265,
14,
199,
3,
199,
3,
1898,
334,
35,
9,
6029,
13,
7806,
5698,
18,
12,
314,
1551,
13,
1365,
6035,
36,
1233,
14,
199,
3,
199,
3,
5698,
18,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
5698,
18,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
1666,
314,
1664,
199,
3,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
5698,
18,
14,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
646,
747,
12,
984,
12,
5145,
12,
1331,
199,
504,
8691,
492,
13491,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
2314,
459,
6195,
18,
63,
9390,
1105,
199,
646,
5698,
18,
199,
199,
3,
5620,
2595,
199,
3,
221,
11298,
221,
199,
3,
5620,
2595,
199,
199,
318,
2446,
837,
2286,
327,
5817,
7030,
8394,
272,
1798,
29,
14553,
342,
272,
1798,
14,
525,
63,
1422,
6096,
70,
401,
4320,
493,
401,
755,
2053,
628,
1501,
401,
1993,
1720,
628,
739,
1101,
687,
13024,
401,
8214,
628,
3817,
531,
272,
1798,
14,
525,
63,
1422,
6096,
78,
401,
4320,
12553,
401,
2053,
628,
12553,
401,
849,
29,
18,
12,
1993,
1720,
628,
1955,
402,
3076,
649,
2823,
401,
8214,
628,
14848,
649,
2823,
531,
272,
1798,
14,
525,
63,
1422,
6096,
67,
401,
4320,
3357,
401,
259,
2053,
628,
3357,
401,
259,
849,
628,
549,
401,
1993,
1720,
628,
6790,
4586,
4125,
436,
24132,
5160,
401,
8214,
628,
6790,
4586,
531,
2432,
272,
334,
1419,
12,
1249,
23397,
2087,
14,
1122,
63,
589,
342,
272,
1511,
14,
12553,
221,
275,
1109,
8,
1511,
14,
12553,
776,
272,
1511,
14,
3357,
258,
275,
1511,
14,
3357,
14,
4142,
342,
508,
283,
15064,
7,
339,
340,
1511,
14,
1501,
508,
488,
26,
267,
746,
2186,
480,
1944,
1101,
570,
2741,
14,
3645,
446,
70,
3305,
531,
2286,
9861,
63,
31598,
8,
1511,
14,
1501,
259,
2360,
2079,
1511,
14,
12553,
221,
2360,
2079,
1511,
14,
3357,
420,
776,
268,
199,
12573,
347,
2446,
342,
421,
199,
3,
5620,
2595,
199,
3,
221,
6035,
36,
9274,
199,
3,
5620,
2595,
199,
199,
318,
9861,
63,
31598,
8,
1788,
3698,
2360,
221,
2079,
16394,
221,
275,
378,
259,
2360,
221,
2079,
4526,
258,
275,
715,
221,
3461,
2286,
327,
4094,
272,
1101,
275,
5698,
18,
14,
2308,
14,
2028,
8,
1501,
9,
272,
1101,
14,
9190,
63,
14848,
275,
16394,
2286,
327,
8511,
272,
1174,
275,
5698,
18,
14,
2308,
14,
2223,
342,
2286,
327,
1104,
367,
3411,
1584,
272,
340,
440,
4526,
26,
267,
1174,
14,
1623,
63,
1725,
8,
888,
9,
272,
587,
26,
267,
1174,
14,
9472,
14,
22076,
40,
275,
1101,
14,
22076,
40,
63,
15440,
2286,
327,
6035,
36,
9274,
334,
2275,
503,
24132,
9,
272,
2256,
275,
5698,
18,
14,
1065,
14,
5487,
36,
8,
888,
9,
5591,
1174,
14,
873,
8,
815,
9,
339,
327,
9274,
22537,
272,
340,
1101,
14,
45,
11695,
63,
30533,
25847,
508,
283,
6098,
356,
267,
1101,
14,
15096,
27129,
63,
17114,
63,
15440,
275,
1101,
14,
15740,
2294,
63,
17114,
63,
15440,
272,
916,
1101,
14,
45,
11695,
63,
30533,
25847,
508,
283,
1554,
24931,
356,
267,
1101,
14,
15096,
27129,
63,
1554,
42,
63,
15440,
275,
1101,
14,
15740,
2294,
63,
1554,
42,
63,
15440,
272,
2256,
275,
5698,
18,
14,
1065,
14,
5628,
8,
888,
9,
272,
1174,
14,
873,
8,
815,
9,
2043,
272,
372,
1174,
199,
199,
12573,
9861,
63,
31598,
342,
421,
199,
3,
5620,
2595,
199,
3,
221,
3378,
11298,
18841,
199,
3,
5620,
2595,
199,
199,
3,
642,
365,
1454,
13810,
340,
3879,
687,
1414,
8457,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2446,
342,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
citrix-openstack-build/keystoneauth
|
keystoneauth1/service_providers.py
|
6
|
1590
|
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from keystoneauth1 import exceptions
class ServiceProviders(object):
"""Helper methods for dealing with Service Providers."""
@classmethod
def from_token(cls, token):
if 'token' not in token:
raise ValueError('Token format does not support service'
'providers.')
return cls(token['token'].get('service_providers', []))
def __init__(self, service_providers):
def normalize(service_providers_list):
return dict((sp['id'], sp) for sp in service_providers_list
if 'id' in sp)
self._service_providers = normalize(service_providers)
def _get_service_provider(self, sp_id):
try:
return self._service_providers[sp_id]
except KeyError:
raise exceptions.ServiceProviderNotFound(sp_id)
def get_sp_url(self, sp_id):
return self._get_service_provider(sp_id).get('sp_url')
def get_auth_url(self, sp_id):
return self._get_service_provider(sp_id).get('auth_url')
|
apache-2.0
|
[
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
504,
19395,
1178,
17,
492,
4967,
421,
199,
533,
7591,
6663,
83,
8,
785,
304,
272,
408,
4433,
3102,
367,
23654,
543,
7591,
18489,
83,
1041,
339,
768,
3744,
272,
347,
687,
63,
1418,
8,
1886,
12,
1526,
304,
267,
340,
283,
1418,
7,
440,
315,
1526,
26,
288,
746,
1722,
360,
3264,
1475,
1630,
440,
2291,
2435,
7,
2490,
283,
9710,
2659,
398,
372,
843,
8,
1418,
459,
1418,
2278,
362,
360,
1364,
63,
9710,
297,
15927,
339,
347,
636,
826,
721,
277,
12,
2435,
63,
9710,
304,
398,
347,
7666,
8,
1364,
63,
9710,
63,
513,
304,
288,
372,
1211,
1332,
681,
459,
344,
995,
2249,
9,
367,
2249,
315,
2435,
63,
9710,
63,
513,
717,
340,
283,
344,
7,
315,
2249,
9,
267,
291,
423,
1364,
63,
9710,
275,
7666,
8,
1364,
63,
9710,
9,
339,
347,
485,
362,
63,
1364,
63,
3780,
8,
277,
12,
2249,
63,
344,
304,
267,
862,
26,
288,
372,
291,
423,
1364,
63,
9710,
59,
681,
63,
344,
61,
267,
871,
4067,
26,
288,
746,
4967,
14,
3167,
6663,
4667,
8,
681,
63,
344,
9,
339,
347,
664,
63,
681,
63,
633,
8,
277,
12,
2249,
63,
344,
304,
267,
372,
291,
423,
362,
63,
1364,
63,
3780,
8,
681,
63,
344,
680,
362,
360,
681,
63,
633,
358,
339,
347,
664,
63,
1178,
63,
633,
8,
277,
12,
2249,
63,
344,
304,
267,
372,
291,
423,
362,
63,
1364,
63,
3780,
8,
681,
63,
344,
680,
362,
360,
1178,
63,
633,
358,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
504,
19395,
1178,
17,
492,
4967,
421,
199,
533,
7591,
6663,
83,
8,
785,
304,
272,
408,
4433,
3102,
367,
23654,
543,
7591,
18489,
83,
1041,
339,
768,
3744,
272,
347,
687,
63,
1418,
8,
1886,
12,
1526,
304,
267,
340,
283,
1418,
7,
440,
315,
1526,
26,
288,
746,
1722,
360,
3264,
1475,
1630,
440,
2291,
2435,
7,
2490,
283,
9710,
2659,
398,
372,
843,
8,
1418,
459,
1418,
2278,
362,
360,
1364,
63,
9710,
297,
15927,
339,
347,
636,
826,
721,
277,
12,
2435,
63,
9710,
304,
398,
347,
7666,
8,
1364,
63,
9710,
63,
513,
304,
288,
372,
1211,
1332,
681,
459,
344,
995,
2249,
9,
367,
2249,
315,
2435,
63,
9710,
63,
513,
717,
340,
283,
344,
7,
315,
2249,
9,
267,
291,
423,
1364,
63,
9710,
275,
7666,
8,
1364,
63,
9710,
9,
339,
347,
485,
362,
63,
1364,
63,
3780,
8,
277,
12,
2249,
63,
344,
304,
267,
862,
26,
288,
372,
291,
423,
1364,
63,
9710,
59,
681,
63,
344,
61,
267,
871,
4067,
26,
288,
746,
4967,
14,
3167,
6663,
4667,
8,
681,
63,
344,
9,
339,
347,
664,
63,
681,
63,
633,
8,
277,
12,
2249,
63,
344,
304,
267,
372,
291,
423,
362,
63,
1364,
63,
3780,
8,
681,
63,
344,
680,
362,
360,
681,
63,
633,
358,
339,
347,
664,
63,
1178,
63,
633,
8,
277,
12,
2249,
63,
344,
304,
267,
372,
291,
423,
362,
63,
1364,
63,
3780,
8,
681,
63,
344,
680,
362,
360,
1178,
63,
633,
358,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
midniteio/npm
|
node_modules/node-gyp/gyp/pylib/gyp/__init__.py
|
1524
|
22178
|
#!/usr/bin/env python
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import copy
import gyp.input
import optparse
import os.path
import re
import shlex
import sys
import traceback
from gyp.common import GypError
# Default debug modes for GYP
debug = {}
# List of "official" debug modes, but you can use anything you like.
DEBUG_GENERAL = 'general'
DEBUG_VARIABLES = 'variables'
DEBUG_INCLUDES = 'includes'
def DebugOutput(mode, message, *args):
if 'all' in gyp.debug or mode in gyp.debug:
ctx = ('unknown', 0, 'unknown')
try:
f = traceback.extract_stack(limit=2)
if f:
ctx = f[0][:3]
except:
pass
if args:
message %= args
print '%s:%s:%d:%s %s' % (mode.upper(), os.path.basename(ctx[0]),
ctx[1], ctx[2], message)
def FindBuildFiles():
extension = '.gyp'
files = os.listdir(os.getcwd())
build_files = []
for file in files:
if file.endswith(extension):
build_files.append(file)
return build_files
def Load(build_files, format, default_variables={},
includes=[], depth='.', params=None, check=False,
circular_check=True, duplicate_basename_check=True):
"""
Loads one or more specified build files.
default_variables and includes will be copied before use.
Returns the generator for the specified format and the
data returned by loading the specified build files.
"""
if params is None:
params = {}
if '-' in format:
format, params['flavor'] = format.split('-', 1)
default_variables = copy.copy(default_variables)
# Default variables provided by this program and its modules should be
# named WITH_CAPITAL_LETTERS to provide a distinct "best practice" namespace,
# avoiding collisions with user and automatic variables.
default_variables['GENERATOR'] = format
default_variables['GENERATOR_FLAVOR'] = params.get('flavor', '')
# Format can be a custom python file, or by default the name of a module
# within gyp.generator.
if format.endswith('.py'):
generator_name = os.path.splitext(format)[0]
path, generator_name = os.path.split(generator_name)
# Make sure the path to the custom generator is in sys.path
# Don't worry about removing it once we are done. Keeping the path
# to each generator that is used in sys.path is likely harmless and
# arguably a good idea.
path = os.path.abspath(path)
if path not in sys.path:
sys.path.insert(0, path)
else:
generator_name = 'gyp.generator.' + format
# These parameters are passed in order (as opposed to by key)
# because ActivePython cannot handle key parameters to __import__.
generator = __import__(generator_name, globals(), locals(), generator_name)
for (key, val) in generator.generator_default_variables.items():
default_variables.setdefault(key, val)
# Give the generator the opportunity to set additional variables based on
# the params it will receive in the output phase.
if getattr(generator, 'CalculateVariables', None):
generator.CalculateVariables(default_variables, params)
# Give the generator the opportunity to set generator_input_info based on
# the params it will receive in the output phase.
if getattr(generator, 'CalculateGeneratorInputInfo', None):
generator.CalculateGeneratorInputInfo(params)
# Fetch the generator specific info that gets fed to input, we use getattr
# so we can default things and the generators only have to provide what
# they need.
generator_input_info = {
'non_configuration_keys':
getattr(generator, 'generator_additional_non_configuration_keys', []),
'path_sections':
getattr(generator, 'generator_additional_path_sections', []),
'extra_sources_for_rules':
getattr(generator, 'generator_extra_sources_for_rules', []),
'generator_supports_multiple_toolsets':
getattr(generator, 'generator_supports_multiple_toolsets', False),
'generator_wants_static_library_dependencies_adjusted':
getattr(generator,
'generator_wants_static_library_dependencies_adjusted', True),
'generator_wants_sorted_dependencies':
getattr(generator, 'generator_wants_sorted_dependencies', False),
'generator_filelist_paths':
getattr(generator, 'generator_filelist_paths', None),
}
# Process the input specific to this generator.
result = gyp.input.Load(build_files, default_variables, includes[:],
depth, generator_input_info, check, circular_check,
duplicate_basename_check,
params['parallel'], params['root_targets'])
return [generator] + result
def NameValueListToDict(name_value_list):
"""
Takes an array of strings of the form 'NAME=VALUE' and creates a dictionary
of the pairs. If a string is simply NAME, then the value in the dictionary
is set to True. If VALUE can be converted to an integer, it is.
"""
result = { }
for item in name_value_list:
tokens = item.split('=', 1)
if len(tokens) == 2:
# If we can make it an int, use that, otherwise, use the string.
try:
token_value = int(tokens[1])
except ValueError:
token_value = tokens[1]
# Set the variable to the supplied value.
result[tokens[0]] = token_value
else:
# No value supplied, treat it as a boolean and set it.
result[tokens[0]] = True
return result
def ShlexEnv(env_name):
flags = os.environ.get(env_name, [])
if flags:
flags = shlex.split(flags)
return flags
def FormatOpt(opt, value):
if opt.startswith('--'):
return '%s=%s' % (opt, value)
return opt + value
def RegenerateAppendFlag(flag, values, predicate, env_name, options):
"""Regenerate a list of command line flags, for an option of action='append'.
The |env_name|, if given, is checked in the environment and used to generate
an initial list of options, then the options that were specified on the
command line (given in |values|) are appended. This matches the handling of
environment variables and command line flags where command line flags override
the environment, while not requiring the environment to be set when the flags
are used again.
"""
flags = []
if options.use_environment and env_name:
for flag_value in ShlexEnv(env_name):
value = FormatOpt(flag, predicate(flag_value))
if value in flags:
flags.remove(value)
flags.append(value)
if values:
for flag_value in values:
flags.append(FormatOpt(flag, predicate(flag_value)))
return flags
def RegenerateFlags(options):
"""Given a parsed options object, and taking the environment variables into
account, returns a list of flags that should regenerate an equivalent options
object (even in the absence of the environment variables.)
Any path options will be normalized relative to depth.
The format flag is not included, as it is assumed the calling generator will
set that as appropriate.
"""
def FixPath(path):
path = gyp.common.FixIfRelativePath(path, options.depth)
if not path:
return os.path.curdir
return path
def Noop(value):
return value
# We always want to ignore the environment when regenerating, to avoid
# duplicate or changed flags in the environment at the time of regeneration.
flags = ['--ignore-environment']
for name, metadata in options._regeneration_metadata.iteritems():
opt = metadata['opt']
value = getattr(options, name)
value_predicate = metadata['type'] == 'path' and FixPath or Noop
action = metadata['action']
env_name = metadata['env_name']
if action == 'append':
flags.extend(RegenerateAppendFlag(opt, value, value_predicate,
env_name, options))
elif action in ('store', None): # None is a synonym for 'store'.
if value:
flags.append(FormatOpt(opt, value_predicate(value)))
elif options.use_environment and env_name and os.environ.get(env_name):
flags.append(FormatOpt(opt, value_predicate(os.environ.get(env_name))))
elif action in ('store_true', 'store_false'):
if ((action == 'store_true' and value) or
(action == 'store_false' and not value)):
flags.append(opt)
elif options.use_environment and env_name:
print >>sys.stderr, ('Warning: environment regeneration unimplemented '
'for %s flag %r env_name %r' % (action, opt,
env_name))
else:
print >>sys.stderr, ('Warning: regeneration unimplemented for action %r '
'flag %r' % (action, opt))
return flags
class RegeneratableOptionParser(optparse.OptionParser):
def __init__(self):
self.__regeneratable_options = {}
optparse.OptionParser.__init__(self)
def add_option(self, *args, **kw):
"""Add an option to the parser.
This accepts the same arguments as OptionParser.add_option, plus the
following:
regenerate: can be set to False to prevent this option from being included
in regeneration.
env_name: name of environment variable that additional values for this
option come from.
type: adds type='path', to tell the regenerator that the values of
this option need to be made relative to options.depth
"""
env_name = kw.pop('env_name', None)
if 'dest' in kw and kw.pop('regenerate', True):
dest = kw['dest']
# The path type is needed for regenerating, for optparse we can just treat
# it as a string.
type = kw.get('type')
if type == 'path':
kw['type'] = 'string'
self.__regeneratable_options[dest] = {
'action': kw.get('action'),
'type': type,
'env_name': env_name,
'opt': args[0],
}
optparse.OptionParser.add_option(self, *args, **kw)
def parse_args(self, *args):
values, args = optparse.OptionParser.parse_args(self, *args)
values._regeneration_metadata = self.__regeneratable_options
return values, args
def gyp_main(args):
my_name = os.path.basename(sys.argv[0])
parser = RegeneratableOptionParser()
usage = 'usage: %s [options ...] [build_file ...]'
parser.set_usage(usage.replace('%s', '%prog'))
parser.add_option('--build', dest='configs', action='append',
help='configuration for build after project generation')
parser.add_option('--check', dest='check', action='store_true',
help='check format of gyp files')
parser.add_option('--config-dir', dest='config_dir', action='store',
env_name='GYP_CONFIG_DIR', default=None,
help='The location for configuration files like '
'include.gypi.')
parser.add_option('-d', '--debug', dest='debug', metavar='DEBUGMODE',
action='append', default=[], help='turn on a debugging '
'mode for debugging GYP. Supported modes are "variables", '
'"includes" and "general" or "all" for all of them.')
parser.add_option('-D', dest='defines', action='append', metavar='VAR=VAL',
env_name='GYP_DEFINES',
help='sets variable VAR to value VAL')
parser.add_option('--depth', dest='depth', metavar='PATH', type='path',
help='set DEPTH gyp variable to a relative path to PATH')
parser.add_option('-f', '--format', dest='formats', action='append',
env_name='GYP_GENERATORS', regenerate=False,
help='output formats to generate')
parser.add_option('-G', dest='generator_flags', action='append', default=[],
metavar='FLAG=VAL', env_name='GYP_GENERATOR_FLAGS',
help='sets generator flag FLAG to VAL')
parser.add_option('--generator-output', dest='generator_output',
action='store', default=None, metavar='DIR', type='path',
env_name='GYP_GENERATOR_OUTPUT',
help='puts generated build files under DIR')
parser.add_option('--ignore-environment', dest='use_environment',
action='store_false', default=True, regenerate=False,
help='do not read options from environment variables')
parser.add_option('-I', '--include', dest='includes', action='append',
metavar='INCLUDE', type='path',
help='files to include in all loaded .gyp files')
# --no-circular-check disables the check for circular relationships between
# .gyp files. These relationships should not exist, but they've only been
# observed to be harmful with the Xcode generator. Chromium's .gyp files
# currently have some circular relationships on non-Mac platforms, so this
# option allows the strict behavior to be used on Macs and the lenient
# behavior to be used elsewhere.
# TODO(mark): Remove this option when http://crbug.com/35878 is fixed.
parser.add_option('--no-circular-check', dest='circular_check',
action='store_false', default=True, regenerate=False,
help="don't check for circular relationships between files")
# --no-duplicate-basename-check disables the check for duplicate basenames
# in a static_library/shared_library project. Visual C++ 2008 generator
# doesn't support this configuration. Libtool on Mac also generates warnings
# when duplicate basenames are passed into Make generator on Mac.
# TODO(yukawa): Remove this option when these legacy generators are
# deprecated.
parser.add_option('--no-duplicate-basename-check',
dest='duplicate_basename_check', action='store_false',
default=True, regenerate=False,
help="don't check for duplicate basenames")
parser.add_option('--no-parallel', action='store_true', default=False,
help='Disable multiprocessing')
parser.add_option('-S', '--suffix', dest='suffix', default='',
help='suffix to add to generated files')
parser.add_option('--toplevel-dir', dest='toplevel_dir', action='store',
default=None, metavar='DIR', type='path',
help='directory to use as the root of the source tree')
parser.add_option('-R', '--root-target', dest='root_targets',
action='append', metavar='TARGET',
help='include only TARGET and its deep dependencies')
options, build_files_arg = parser.parse_args(args)
build_files = build_files_arg
# Set up the configuration directory (defaults to ~/.gyp)
if not options.config_dir:
home = None
home_dot_gyp = None
if options.use_environment:
home_dot_gyp = os.environ.get('GYP_CONFIG_DIR', None)
if home_dot_gyp:
home_dot_gyp = os.path.expanduser(home_dot_gyp)
if not home_dot_gyp:
home_vars = ['HOME']
if sys.platform in ('cygwin', 'win32'):
home_vars.append('USERPROFILE')
for home_var in home_vars:
home = os.getenv(home_var)
if home != None:
home_dot_gyp = os.path.join(home, '.gyp')
if not os.path.exists(home_dot_gyp):
home_dot_gyp = None
else:
break
else:
home_dot_gyp = os.path.expanduser(options.config_dir)
if home_dot_gyp and not os.path.exists(home_dot_gyp):
home_dot_gyp = None
if not options.formats:
# If no format was given on the command line, then check the env variable.
generate_formats = []
if options.use_environment:
generate_formats = os.environ.get('GYP_GENERATORS', [])
if generate_formats:
generate_formats = re.split(r'[\s,]', generate_formats)
if generate_formats:
options.formats = generate_formats
else:
# Nothing in the variable, default based on platform.
if sys.platform == 'darwin':
options.formats = ['xcode']
elif sys.platform in ('win32', 'cygwin'):
options.formats = ['msvs']
else:
options.formats = ['make']
if not options.generator_output and options.use_environment:
g_o = os.environ.get('GYP_GENERATOR_OUTPUT')
if g_o:
options.generator_output = g_o
options.parallel = not options.no_parallel
for mode in options.debug:
gyp.debug[mode] = 1
# Do an extra check to avoid work when we're not debugging.
if DEBUG_GENERAL in gyp.debug:
DebugOutput(DEBUG_GENERAL, 'running with these options:')
for option, value in sorted(options.__dict__.items()):
if option[0] == '_':
continue
if isinstance(value, basestring):
DebugOutput(DEBUG_GENERAL, " %s: '%s'", option, value)
else:
DebugOutput(DEBUG_GENERAL, " %s: %s", option, value)
if not build_files:
build_files = FindBuildFiles()
if not build_files:
raise GypError((usage + '\n\n%s: error: no build_file') %
(my_name, my_name))
# TODO(mark): Chromium-specific hack!
# For Chromium, the gyp "depth" variable should always be a relative path
# to Chromium's top-level "src" directory. If no depth variable was set
# on the command line, try to find a "src" directory by looking at the
# absolute path to each build file's directory. The first "src" component
# found will be treated as though it were the path used for --depth.
if not options.depth:
for build_file in build_files:
build_file_dir = os.path.abspath(os.path.dirname(build_file))
build_file_dir_components = build_file_dir.split(os.path.sep)
components_len = len(build_file_dir_components)
for index in xrange(components_len - 1, -1, -1):
if build_file_dir_components[index] == 'src':
options.depth = os.path.sep.join(build_file_dir_components)
break
del build_file_dir_components[index]
# If the inner loop found something, break without advancing to another
# build file.
if options.depth:
break
if not options.depth:
raise GypError('Could not automatically locate src directory. This is'
'a temporary Chromium feature that will be removed. Use'
'--depth as a workaround.')
# If toplevel-dir is not set, we assume that depth is the root of our source
# tree.
if not options.toplevel_dir:
options.toplevel_dir = options.depth
# -D on the command line sets variable defaults - D isn't just for define,
# it's for default. Perhaps there should be a way to force (-F?) a
# variable's value so that it can't be overridden by anything else.
cmdline_default_variables = {}
defines = []
if options.use_environment:
defines += ShlexEnv('GYP_DEFINES')
if options.defines:
defines += options.defines
cmdline_default_variables = NameValueListToDict(defines)
if DEBUG_GENERAL in gyp.debug:
DebugOutput(DEBUG_GENERAL,
"cmdline_default_variables: %s", cmdline_default_variables)
# Set up includes.
includes = []
# If ~/.gyp/include.gypi exists, it'll be forcibly included into every
# .gyp file that's loaded, before anything else is included.
if home_dot_gyp != None:
default_include = os.path.join(home_dot_gyp, 'include.gypi')
if os.path.exists(default_include):
print 'Using overrides found in ' + default_include
includes.append(default_include)
# Command-line --include files come after the default include.
if options.includes:
includes.extend(options.includes)
# Generator flags should be prefixed with the target generator since they
# are global across all generator runs.
gen_flags = []
if options.use_environment:
gen_flags += ShlexEnv('GYP_GENERATOR_FLAGS')
if options.generator_flags:
gen_flags += options.generator_flags
generator_flags = NameValueListToDict(gen_flags)
if DEBUG_GENERAL in gyp.debug.keys():
DebugOutput(DEBUG_GENERAL, "generator_flags: %s", generator_flags)
# Generate all requested formats (use a set in case we got one format request
# twice)
for format in set(options.formats):
params = {'options': options,
'build_files': build_files,
'generator_flags': generator_flags,
'cwd': os.getcwd(),
'build_files_arg': build_files_arg,
'gyp_binary': sys.argv[0],
'home_dot_gyp': home_dot_gyp,
'parallel': options.parallel,
'root_targets': options.root_targets,
'target_arch': cmdline_default_variables.get('target_arch', '')}
# Start with the default variables from the command line.
[generator, flat_list, targets, data] = Load(
build_files, format, cmdline_default_variables, includes, options.depth,
params, options.check, options.circular_check,
options.duplicate_basename_check)
# TODO(mark): Pass |data| for now because the generator needs a list of
# build files that came in. In the future, maybe it should just accept
# a list, and not the whole data dict.
# NOTE: flat_list is the flattened dependency graph specifying the order
# that targets may be built. Build systems that operate serially or that
# need to have dependencies defined before dependents reference them should
# generate targets in the order specified in flat_list.
generator.GenerateOutput(flat_list, targets, data, params)
if options.configs:
valid_configs = targets[flat_list[0]]['configurations'].keys()
for conf in options.configs:
if conf not in valid_configs:
raise GypError('Invalid config specified via --build: %s' % conf)
generator.PerformBuild(data, options.configs, params)
# Done
return 0
def main(args):
try:
return gyp_main(args)
except GypError, e:
sys.stderr.write("gyp: %s\n" % e)
return 1
# NOTE: setuptools generated console_scripts calls function with no arguments
def script_main():
return main(sys.argv[1:])
if __name__ == '__main__':
sys.exit(script_main())
|
artistic-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
1898,
334,
67,
9,
6029,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
646,
1331,
199,
646,
4902,
14,
1210,
199,
646,
8691,
199,
646,
747,
14,
515,
199,
646,
295,
199,
646,
16701,
199,
646,
984,
199,
646,
5190,
199,
504,
4902,
14,
2330,
492,
18151,
199,
199,
3,
3758,
3105,
12404,
367,
25686,
199,
1757,
275,
1052,
199,
199,
3,
3820,
402,
298,
29260,
2,
3105,
12404,
12,
1325,
1265,
883,
675,
7003,
1265,
2839,
14,
199,
5287,
63,
31548,
275,
283,
10706,
7,
199,
5287,
63,
21161,
275,
283,
3669,
7,
199,
5287,
63,
568,
29992,
275,
283,
9441,
7,
421,
199,
318,
14245,
2959,
8,
632,
12,
1245,
12,
627,
589,
304,
523,
340,
283,
452,
7,
315,
4902,
14,
1757,
503,
818,
315,
4902,
14,
1757,
26,
272,
4027,
275,
661,
5187,
297,
378,
12,
283,
5187,
358,
272,
862,
26,
489,
289,
275,
5190,
14,
5005,
63,
2340,
8,
3097,
29,
18,
9,
489,
340,
289,
26,
267,
4027,
275,
289,
59,
16,
19663,
19,
61,
272,
871,
26,
489,
986,
272,
340,
1249,
26,
489,
1245,
450,
29,
1249,
272,
870,
1543,
83,
2689,
83,
2689,
68,
2689,
83,
450,
83,
7,
450,
334,
632,
14,
4142,
1062,
747,
14,
515,
14,
4846,
8,
3799,
59,
16,
2522,
2892,
4027,
59,
17,
467,
4027,
59,
18,
467,
1245,
9,
199,
199,
318,
6668,
3425,
5535,
837,
523,
3329,
275,
1987,
6179,
7,
523,
1584,
275,
747,
14,
7374,
8,
736,
14,
9458,
1012,
523,
1900,
63,
1725,
275,
942,
523,
367,
570,
315,
1584,
26,
272,
340,
570,
14,
4130,
8,
3435,
304,
489,
1900,
63,
1725,
14,
740,
8,
493,
9,
523,
372,
1900,
63,
1725,
421,
199,
318,
7190,
8,
1506,
63,
1725,
12,
1475,
12,
849,
63,
3669,
10324,
268,
6952,
6034,
5818,
534,
3130,
1862,
29,
403,
12,
1104,
29,
797,
12,
268,
15032,
63,
1074,
29,
549,
12,
9250,
63,
4846,
63,
1074,
29,
549,
304,
523,
408,
523,
30367,
1373,
503,
1655,
2013,
1900,
1584,
14,
523,
849,
63,
3669,
436,
6952,
911,
506,
8876,
2544,
675,
14,
523,
1803,
314,
4306,
367,
314,
2013,
1475,
436,
314,
523,
666,
2138,
701,
8697,
314,
2013,
1900,
1584,
14,
523,
408,
523,
340,
1862,
365,
488,
26,
272,
1862,
275,
1052,
819,
340,
10791,
315,
1475,
26,
272,
1475,
12,
1862,
459,
6081,
418,
275,
1475,
14,
1294,
13858,
413,
9,
819,
849,
63,
3669,
275,
1331,
14,
1574,
8,
885,
63,
3669,
9,
819,
327,
3758,
2860,
2741,
701,
642,
2240,
436,
2399,
4621,
1077,
506,
523,
327,
4310,
1663,
63,
35,
2669,
63,
44,
1573,
51,
370,
5647,
282,
15392,
298,
7010,
24471,
2,
3231,
12,
523,
327,
5126,
316,
30063,
543,
922,
436,
4834,
2860,
14,
523,
849,
63,
3669,
459,
12795,
6467,
418,
275,
1475,
523,
849,
63,
3669,
459,
12795,
6467,
63,
3143,
6087,
726,
418,
275,
1862,
14,
362,
360,
6081,
297,
4074,
819,
327,
9701,
883,
506,
282,
3537,
2366,
570,
12,
503,
701,
849,
314,
536,
402,
282,
859,
523,
327,
4453,
4902,
14,
4679,
14,
523,
340,
1475,
14,
4130,
5175,
647,
735,
272,
4306,
63,
354,
275,
747,
14,
515,
14,
7973,
8,
908,
2788,
16,
61,
272,
931,
12,
4306,
63,
354,
275,
747,
14,
515,
14,
1294,
8,
4679,
63,
354,
9,
339,
327,
4155,
3238,
314,
931,
370,
314,
3537,
4306,
365,
315,
984,
14,
515,
272,
327,
7529,
1133,
30944,
3595,
12881,
652,
5403,
781,
787,
4224,
14,
221,
1804,
1024,
4073,
314,
931,
272,
327,
370,
1924,
4306,
626,
365,
1202,
315,
984,
14,
515,
365,
12060,
394,
5362,
2003,
436,
272,
327,
1680,
85,
6665,
282,
6954,
16819,
14,
272,
931,
275,
747,
14,
515,
14,
4832,
8,
515,
9,
272,
340,
931,
440,
315,
984,
14,
515,
26,
489,
984,
14,
515,
14,
3176,
8,
16,
12,
931,
9,
523,
587,
26,
272,
4306,
63,
354,
275,
283,
6179,
14,
4679,
3530,
435,
1475,
819,
327,
5723,
2633,
787,
3032,
315,
1865,
334,
305,
25068,
370,
701,
790,
9,
523,
327,
2952,
23241,
4718,
3913,
2429,
790,
2633,
370,
636,
646,
4343,
523,
4306,
275,
636,
646,
721,
4679,
63,
354,
12,
7992,
1062,
9480,
1062,
4306,
63,
354,
9,
523,
367,
334,
498,
12,
1139,
9,
315,
4306,
14,
4679,
63,
885,
63,
3669,
14,
1744,
837,
272,
849,
63,
3669,
14,
5486,
8,
498,
12,
1139,
9,
819,
327,
25495,
314,
4306,
314,
30914,
370,
663,
4722,
2860,
4079,
641,
523,
327,
314,
1862,
652,
911,
9128,
315,
314,
1072,
7669,
14,
523,
340,
2519,
8,
4679,
12,
283,
14860,
11458,
297,
488,
304,
272,
4306,
14,
14860,
11458,
8,
885,
63,
3669,
12,
1862,
9,
819,
327,
25495,
314,
4306,
314,
30914,
370,
663,
4306,
63,
1210,
63,
815,
4079,
641,
523,
327,
314,
1862,
652,
911,
9128,
315,
314,
1072,
7669,
14,
523,
340,
2519,
8,
4679,
12,
283,
14860,
7599,
3205,
2354,
297,
488,
304,
272,
4306,
14,
14860,
7599,
3205,
2354,
8,
1162,
9,
819,
327,
16347,
314,
4306,
2488,
2256,
626,
7545,
23036,
370,
1324,
12,
781,
675,
2519,
523,
327,
880,
781,
883,
849,
7645,
436,
314,
16952,
1454,
1172,
370,
5647,
4052,
523,
327,
2985,
1929,
14,
523,
4306,
63,
1210,
63,
815,
275,
469,
272,
283,
2865,
63,
4758,
63,
1612,
356,
267,
2519,
8,
4679,
12,
283,
4679,
63,
8460,
63,
2865,
63,
4758,
63,
1612,
297,
14431,
272,
283,
515,
63,
7786,
356,
267,
2519,
8,
4679,
12,
283,
4679,
63,
8460,
63,
515,
63,
7786,
297,
14431,
272,
283,
2911,
63,
4553,
63,
509,
63,
4423,
356,
267,
2519,
8,
4679,
12,
283,
4679,
63,
2911,
63,
4553,
63,
509,
63,
4423,
297,
14431,
272,
283,
4679,
63,
9823,
63,
6048,
63,
30116,
356,
267,
2519,
8,
4679,
12,
283,
4679,
63,
9823,
63,
6048,
63,
30116,
297,
756,
395,
272,
283,
4679,
63,
28789
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
1898,
334,
67,
9,
6029,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
646,
1331,
199,
646,
4902,
14,
1210,
199,
646,
8691,
199,
646,
747,
14,
515,
199,
646,
295,
199,
646,
16701,
199,
646,
984,
199,
646,
5190,
199,
504,
4902,
14,
2330,
492,
18151,
199,
199,
3,
3758,
3105,
12404,
367,
25686,
199,
1757,
275,
1052,
199,
199,
3,
3820,
402,
298,
29260,
2,
3105,
12404,
12,
1325,
1265,
883,
675,
7003,
1265,
2839,
14,
199,
5287,
63,
31548,
275,
283,
10706,
7,
199,
5287,
63,
21161,
275,
283,
3669,
7,
199,
5287,
63,
568,
29992,
275,
283,
9441,
7,
421,
199,
318,
14245,
2959,
8,
632,
12,
1245,
12,
627,
589,
304,
523,
340,
283,
452,
7,
315,
4902,
14,
1757,
503,
818,
315,
4902,
14,
1757,
26,
272,
4027,
275,
661,
5187,
297,
378,
12,
283,
5187,
358,
272,
862,
26,
489,
289,
275,
5190,
14,
5005,
63,
2340,
8,
3097,
29,
18,
9,
489,
340,
289,
26,
267,
4027,
275,
289,
59,
16,
19663,
19,
61,
272,
871,
26,
489,
986,
272,
340,
1249,
26,
489,
1245,
450,
29,
1249,
272,
870,
1543,
83,
2689,
83,
2689,
68,
2689,
83,
450,
83,
7,
450,
334,
632,
14,
4142,
1062,
747,
14,
515,
14,
4846,
8,
3799,
59,
16,
2522,
2892,
4027,
59,
17,
467,
4027,
59,
18,
467,
1245,
9,
199,
199,
318,
6668,
3425,
5535,
837,
523,
3329,
275,
1987,
6179,
7,
523,
1584,
275,
747,
14,
7374,
8,
736,
14,
9458,
1012,
523,
1900,
63,
1725,
275,
942,
523,
367,
570,
315,
1584,
26,
272,
340,
570,
14,
4130,
8,
3435,
304,
489,
1900,
63,
1725,
14,
740,
8,
493,
9,
523,
372,
1900,
63,
1725,
421,
199,
318,
7190,
8,
1506,
63,
1725,
12,
1475,
12,
849,
63,
3669,
10324,
268,
6952,
6034,
5818,
534,
3130,
1862,
29,
403,
12,
1104,
29,
797,
12,
268,
15032,
63,
1074,
29,
549,
12,
9250,
63,
4846,
63,
1074,
29,
549,
304,
523,
408,
523,
30367,
1373,
503,
1655,
2013,
1900,
1584,
14,
523,
849,
63,
3669,
436,
6952,
911,
506,
8876,
2544,
675,
14,
523,
1803,
314,
4306,
367,
314,
2013,
1475,
436,
314,
523,
666,
2138,
701,
8697,
314,
2013,
1900,
1584,
14,
523,
408,
523,
340,
1862,
365,
488,
26,
272,
1862,
275,
1052,
819,
340,
10791,
315,
1475,
26,
272,
1475,
12,
1862,
459,
6081,
418,
275,
1475,
14,
1294,
13858,
413,
9,
819,
849,
63,
3669,
275,
1331,
14,
1574,
8,
885,
63,
3669,
9,
819,
327,
3758,
2860,
2741,
701,
642,
2240,
436,
2399,
4621,
1077,
506,
523,
327,
4310,
1663,
63,
35,
2669,
63,
44,
1573,
51,
370,
5647,
282,
15392,
298,
7010,
24471,
2,
3231,
12,
523,
327,
5126,
316,
30063,
543,
922,
436,
4834,
2860,
14,
523,
849,
63,
3669,
459,
12795,
6467,
418,
275,
1475,
523,
849,
63,
3669,
459,
12795,
6467,
63,
3143,
6087,
726,
418,
275,
1862,
14,
362,
360,
6081,
297,
4074,
819,
327,
9701,
883,
506,
282,
3537,
2366,
570,
12,
503,
701,
849,
314,
536,
402,
282,
859,
523,
327,
4453,
4902,
14,
4679,
14,
523,
340,
1475,
14,
4130,
5175,
647,
735,
272,
4306,
63,
354,
275,
747,
14,
515,
14,
7973,
8,
908,
2788,
16,
61,
272,
931,
12,
4306,
63,
354,
275,
747,
14,
515,
14,
1294,
8,
4679,
63,
354,
9,
339,
327,
4155,
3238,
314,
931,
370,
314,
3537,
4306,
365,
315,
984,
14,
515,
272,
327,
7529,
1133,
30944,
3595,
12881,
652,
5403,
781,
787,
4224,
14,
221,
1804,
1024,
4073,
314,
931,
272,
327,
370,
1924,
4306,
626,
365,
1202,
315,
984,
14,
515,
365,
12060,
394,
5362,
2003,
436,
272,
327,
1680,
85,
6665,
282,
6954,
16819,
14,
272,
931,
275,
747,
14,
515,
14,
4832,
8,
515,
9,
272,
340,
931,
440,
315,
984,
14,
515,
26,
489,
984,
14,
515,
14,
3176,
8,
16,
12,
931,
9,
523,
587,
26,
272,
4306,
63,
354,
275,
283,
6179,
14,
4679,
3530,
435,
1475,
819,
327,
5723,
2633,
787,
3032,
315,
1865,
334,
305,
25068,
370,
701,
790,
9,
523,
327,
2952,
23241,
4718,
3913,
2429,
790,
2633,
370,
636,
646,
4343,
523,
4306,
275,
636,
646,
721,
4679,
63,
354,
12,
7992,
1062,
9480,
1062,
4306,
63,
354,
9,
523,
367,
334,
498,
12,
1139,
9,
315,
4306,
14,
4679,
63,
885,
63,
3669,
14,
1744,
837,
272,
849,
63,
3669,
14,
5486,
8,
498,
12,
1139,
9,
819,
327,
25495,
314,
4306,
314,
30914,
370,
663,
4722,
2860,
4079,
641,
523,
327,
314,
1862,
652,
911,
9128,
315,
314,
1072,
7669,
14,
523,
340,
2519,
8,
4679,
12,
283,
14860,
11458,
297,
488,
304,
272,
4306,
14,
14860,
11458,
8,
885,
63,
3669,
12,
1862,
9,
819,
327,
25495,
314,
4306,
314,
30914,
370,
663,
4306,
63,
1210,
63,
815,
4079,
641,
523,
327,
314,
1862,
652,
911,
9128,
315,
314,
1072,
7669,
14,
523,
340,
2519,
8,
4679,
12,
283,
14860,
7599,
3205,
2354,
297,
488,
304,
272,
4306,
14,
14860,
7599,
3205,
2354,
8,
1162,
9,
819,
327,
16347,
314,
4306,
2488,
2256,
626,
7545,
23036,
370,
1324,
12,
781,
675,
2519,
523,
327,
880,
781,
883,
849,
7645,
436,
314,
16952,
1454,
1172,
370,
5647,
4052,
523,
327,
2985,
1929,
14,
523,
4306,
63,
1210,
63,
815,
275,
469,
272,
283,
2865,
63,
4758,
63,
1612,
356,
267,
2519,
8,
4679,
12,
283,
4679,
63,
8460,
63,
2865,
63,
4758,
63,
1612,
297,
14431,
272,
283,
515,
63,
7786,
356,
267,
2519,
8,
4679,
12,
283,
4679,
63,
8460,
63,
515,
63,
7786,
297,
14431,
272,
283,
2911,
63,
4553,
63,
509,
63,
4423,
356,
267,
2519,
8,
4679,
12,
283,
4679,
63,
2911,
63,
4553,
63,
509,
63,
4423,
297,
14431,
272,
283,
4679,
63,
9823,
63,
6048,
63,
30116,
356,
267,
2519,
8,
4679,
12,
283,
4679,
63,
9823,
63,
6048,
63,
30116,
297,
756,
395,
272,
283,
4679,
63,
28789,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
donaldharvey/snappy
|
snappy/utils.py
|
1
|
2623
|
import urllib2
import urllib
import os
from mimetools import choose_boundary
from mimetypes import guess_type
import stat
class Singleton(type):
def __init__(self, name, bases, dict):
super(Singleton, self).__init__(name, bases, dict)
self.instance = None
def __call__(self, *args, **kw):
if self.instance is None:
self.instance = super(Singleton, self).__call__(*args, **kw)
return self.instance
class MultipartDataHandler(urllib2.BaseHandler):
"""
A urllib2-based multipart/form-data poster, adapted slightly from
http://odin.himinbi.org/MultipartPostHandler.py and
http://code.activestate.com/recipes/146306/.
"""
handler_order = urllib2.HTTPHandler.handler_order - 20
def http_request(self, request):
data = request.get_data()
if data is not None and data is not str:
fields, files = [], []
for key, value in data.items():
if type(value) == file:
files.append((key, value))
else:
fields.append((key, value))
if not len(files):
# no files, so go straight ahead and encode the data
data = urllib.urlencode(fields, True)
else:
content_type, data = self._encode_multipart_formdata(fields, files)
req_content_type = request.get_header('Content-Type', '')
if 'multipart/form-data' in req_content_type:
request.set_header('Content-Type', content_type)
else:
request.add_unredirected_header('Content-Type', content_type)
request.add_data(data)
return request
https_request = http_request
def _encode_multipart_formdata(self, fields, files):
"""
fields is a sequence of (name, value) elements for regular form fields.
files is a sequence of (name, filename, value) elements for data to be uploaded as files
Return (content_type, body) ready for httplib.HTTP instance
"""
boundary = choose_boundary()
CRLF = '\r\n'
L = []
for (key, value) in fields:
L.append('--' + boundary)
L.append('Content-Disposition: form-data; name="%s"' % str(key))
L.append('')
L.append(str(value))
for (key, fd) in files:
L.append('--' + boundary)
filename = os.path.basename(fd.name)
filesize = os.fstat(fd.fileno())[stat.ST_SIZE]
L.append('Content-Disposition: form-data; name="%s"; filename="%s"' % (str(key), str(os.path.basename)))
mimetype = guess_type(filename)[0] or 'application/octet-stream'
L.append('Content-Type: %s' % mimetype)
L.append('Content-Length: %s' % filesize)
L.append('')
fd.seek(0)
L.append(fd.read())
L.append('--' + boundary + '--')
L.append('')
body = CRLF.join(L)
contenttype = 'multipart/form-data; boundary=%s' % boundary
return contenttype, body
|
gpl-3.0
|
[
646,
4011,
18,
199,
646,
4011,
199,
646,
747,
199,
504,
6660,
2537,
492,
11496,
63,
9891,
199,
504,
13290,
492,
9519,
63,
466,
199,
646,
5672,
199,
533,
13050,
1860,
8,
466,
304,
199,
198,
318,
636,
826,
721,
277,
12,
536,
12,
9768,
12,
1211,
304,
507,
198,
4792,
8,
28456,
12,
291,
2843,
826,
721,
354,
12,
9768,
12,
1211,
9,
507,
198,
277,
14,
842,
275,
488,
421,
198,
318,
636,
1250,
721,
277,
12,
627,
589,
12,
1011,
829,
304,
507,
198,
692,
291,
14,
842,
365,
488,
26,
686,
198,
277,
14,
842,
275,
1613,
8,
28456,
12,
291,
2843,
1250,
9308,
589,
12,
1011,
829,
9,
2742,
198,
1107,
291,
14,
842,
199,
199,
533,
6879,
2064,
1451,
2461,
8,
4078,
18,
14,
1563,
2461,
304,
199,
198,
624,
199,
198,
33,
4011,
18,
13,
6788,
15193,
15,
964,
13,
576,
2086,
351,
12,
26266,
18023,
687,
199,
198,
1014,
921,
364,
262,
14,
5812,
827,
4492,
14,
1308,
15,
27242,
6564,
2461,
14,
647,
436,
199,
198,
1014,
921,
600,
14,
32595,
14,
957,
15,
25200,
15,
11432,
11363,
8083,
199,
198,
624,
199,
198,
2232,
63,
1648,
275,
4011,
18,
14,
2856,
2461,
14,
2232,
63,
1648,
446,
3388,
421,
198,
318,
1455,
63,
1069,
8,
277,
12,
1056,
304,
507,
198,
576,
275,
1056,
14,
362,
63,
576,
342,
507,
198,
692,
666,
365,
440,
488,
436,
666,
365,
440,
620,
26,
686,
198,
955,
12,
1584,
275,
990,
942,
686,
198,
509,
790,
12,
574,
315,
666,
14,
1744,
837,
1585,
198,
692,
730,
8,
585,
9,
508,
570,
26,
1871,
198,
1725,
14,
740,
1332,
498,
12,
574,
430,
1585,
198,
2836,
26,
1871,
198,
955,
14,
740,
1332,
498,
12,
574,
430,
686,
198,
692,
440,
822,
8,
1725,
304,
1585,
198,
3,
949,
1584,
12,
880,
2621,
23669,
23417,
436,
3752,
314,
666,
1585,
198,
576,
275,
4011,
14,
10738,
8,
955,
12,
715,
9,
686,
198,
2836,
26,
1585,
198,
1317,
63,
466,
12,
666,
275,
291,
423,
2143,
63,
10123,
63,
30942,
8,
955,
12,
1584,
9,
1585,
198,
2103,
63,
1317,
63,
466,
275,
1056,
14,
362,
63,
1291,
360,
2714,
13,
804,
297,
4074,
1585,
198,
692,
283,
10123,
15,
964,
13,
576,
7,
315,
2648,
63,
1317,
63,
466,
26,
1871,
198,
1069,
14,
409,
63,
1291,
360,
2714,
13,
804,
297,
1564,
63,
466,
9,
1585,
198,
2836,
26,
1871,
198,
1069,
14,
525,
63,
324,
264,
12080,
63,
1291,
360,
2714,
13,
804,
297,
1564,
63,
466,
9,
686,
198,
1069,
14,
525,
63,
576,
8,
576,
9,
507,
198,
1107,
1056,
421,
198,
2859,
63,
1069,
275,
1455,
63,
1069,
421,
198,
318,
485,
2143,
63,
10123,
63,
30942,
8,
277,
12,
1504,
12,
1584,
304,
507,
198,
624,
507,
198,
955,
365,
282,
3414,
402,
334,
354,
12,
574,
9,
4008,
367,
5578,
1824,
1504,
14,
507,
198,
1725,
365,
282,
3414,
402,
334,
354,
12,
1788,
12,
574,
9,
4008,
367,
666,
370,
506,
14238,
465,
1584,
507,
198,
1767,
334,
1317,
63,
466,
12,
2396,
9,
10144,
367,
8809,
14,
2856,
1256,
507,
198,
624,
507,
198,
9891,
275,
11496,
63,
9891,
342,
507,
198,
35,
20190,
275,
1557,
82,
60,
78,
7,
507,
198,
44,
275,
942,
507,
198,
509,
334,
498,
12,
574,
9,
315,
1504,
26,
686,
198,
44,
14,
740,
4517,
7,
435,
8424,
9,
686,
198,
44,
14,
740,
360,
2714,
13,
15954,
26,
1824,
13,
576,
27,
536,
5961,
83,
4507,
450,
620,
8,
498,
430,
686,
198,
44,
14,
740,
8355,
686,
198,
44,
14,
740,
8,
495,
8,
585,
430,
507,
198,
509,
334,
498,
12,
6111,
9,
315,
1584,
26,
686,
198,
44,
14,
740,
4517,
7,
435,
8424,
9,
686,
198,
1501,
275,
747,
14,
515,
14,
4846,
8,
2592,
14,
354,
9,
686,
198,
19233,
275,
747,
14,
32127,
8,
2592,
14,
9843,
18756,
3736,
14,
840,
63,
4305,
61,
686,
198,
44,
14,
740,
360,
2714,
13,
15954,
26,
1824,
13,
576,
27,
536,
5961,
83,
11436,
1788,
5961,
83,
4507,
450,
334,
495,
8,
498,
395,
620,
8,
736,
14,
515,
14,
4846,
1724,
686,
198,
17450,
275,
9519,
63,
466,
8,
1501,
2788,
16,
61,
503,
283,
3578,
15,
18162,
13,
1745,
7,
686,
198,
44,
14,
740,
360,
2714,
13,
804,
26,
450,
83,
7,
450,
12200,
9,
686,
198,
44,
14,
740,
360,
2714,
13,
4625,
26,
450,
83,
7,
450,
23858,
9,
686,
198,
44,
14,
740,
8355,
686,
198,
2592,
14,
5507,
8,
16,
9,
686,
198,
44,
14,
740,
8,
2592,
14,
739,
1012,
507,
198,
44,
14,
740,
4517,
7,
435,
8424,
435,
2850,
358,
507,
198,
44,
14,
740,
8355,
507,
198,
2030,
275,
25862,
14,
904,
8,
44,
9,
507,
198,
20735,
275,
283,
10123,
15,
964,
13,
576,
27,
8424,
2458,
83,
7,
450,
8424,
507,
198,
1107,
1564,
466,
12,
2396,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
4011,
18,
199,
646,
4011,
199,
646,
747,
199,
504,
6660,
2537,
492,
11496,
63,
9891,
199,
504,
13290,
492,
9519,
63,
466,
199,
646,
5672,
199,
533,
13050,
1860,
8,
466,
304,
199,
198,
318,
636,
826,
721,
277,
12,
536,
12,
9768,
12,
1211,
304,
507,
198,
4792,
8,
28456,
12,
291,
2843,
826,
721,
354,
12,
9768,
12,
1211,
9,
507,
198,
277,
14,
842,
275,
488,
421,
198,
318,
636,
1250,
721,
277,
12,
627,
589,
12,
1011,
829,
304,
507,
198,
692,
291,
14,
842,
365,
488,
26,
686,
198,
277,
14,
842,
275,
1613,
8,
28456,
12,
291,
2843,
1250,
9308,
589,
12,
1011,
829,
9,
2742,
198,
1107,
291,
14,
842,
199,
199,
533,
6879,
2064,
1451,
2461,
8,
4078,
18,
14,
1563,
2461,
304,
199,
198,
624,
199,
198,
33,
4011,
18,
13,
6788,
15193,
15,
964,
13,
576,
2086,
351,
12,
26266,
18023,
687,
199,
198,
1014,
921,
364,
262,
14,
5812,
827,
4492,
14,
1308,
15,
27242,
6564,
2461,
14,
647,
436,
199,
198,
1014,
921,
600,
14,
32595,
14,
957,
15,
25200,
15,
11432,
11363,
8083,
199,
198,
624,
199,
198,
2232,
63,
1648,
275,
4011,
18,
14,
2856,
2461,
14,
2232,
63,
1648,
446,
3388,
421,
198,
318,
1455,
63,
1069,
8,
277,
12,
1056,
304,
507,
198,
576,
275,
1056,
14,
362,
63,
576,
342,
507,
198,
692,
666,
365,
440,
488,
436,
666,
365,
440,
620,
26,
686,
198,
955,
12,
1584,
275,
990,
942,
686,
198,
509,
790,
12,
574,
315,
666,
14,
1744,
837,
1585,
198,
692,
730,
8,
585,
9,
508,
570,
26,
1871,
198,
1725,
14,
740,
1332,
498,
12,
574,
430,
1585,
198,
2836,
26,
1871,
198,
955,
14,
740,
1332,
498,
12,
574,
430,
686,
198,
692,
440,
822,
8,
1725,
304,
1585,
198,
3,
949,
1584,
12,
880,
2621,
23669,
23417,
436,
3752,
314,
666,
1585,
198,
576,
275,
4011,
14,
10738,
8,
955,
12,
715,
9,
686,
198,
2836,
26,
1585,
198,
1317,
63,
466,
12,
666,
275,
291,
423,
2143,
63,
10123,
63,
30942,
8,
955,
12,
1584,
9,
1585,
198,
2103,
63,
1317,
63,
466,
275,
1056,
14,
362,
63,
1291,
360,
2714,
13,
804,
297,
4074,
1585,
198,
692,
283,
10123,
15,
964,
13,
576,
7,
315,
2648,
63,
1317,
63,
466,
26,
1871,
198,
1069,
14,
409,
63,
1291,
360,
2714,
13,
804,
297,
1564,
63,
466,
9,
1585,
198,
2836,
26,
1871,
198,
1069,
14,
525,
63,
324,
264,
12080,
63,
1291,
360,
2714,
13,
804,
297,
1564,
63,
466,
9,
686,
198,
1069,
14,
525,
63,
576,
8,
576,
9,
507,
198,
1107,
1056,
421,
198,
2859,
63,
1069,
275,
1455,
63,
1069,
421,
198,
318,
485,
2143,
63,
10123,
63,
30942,
8,
277,
12,
1504,
12,
1584,
304,
507,
198,
624,
507,
198,
955,
365,
282,
3414,
402,
334,
354,
12,
574,
9,
4008,
367,
5578,
1824,
1504,
14,
507,
198,
1725,
365,
282,
3414,
402,
334,
354,
12,
1788,
12,
574,
9,
4008,
367,
666,
370,
506,
14238,
465,
1584,
507,
198,
1767,
334,
1317,
63,
466,
12,
2396,
9,
10144,
367,
8809,
14,
2856,
1256,
507,
198,
624,
507,
198,
9891,
275,
11496,
63,
9891,
342,
507,
198,
35,
20190,
275,
1557,
82,
60,
78,
7,
507,
198,
44,
275,
942,
507,
198,
509,
334,
498,
12,
574,
9,
315,
1504,
26,
686,
198,
44,
14,
740,
4517,
7,
435,
8424,
9,
686,
198,
44,
14,
740,
360,
2714,
13,
15954,
26,
1824,
13,
576,
27,
536,
5961,
83,
4507,
450,
620,
8,
498,
430,
686,
198,
44,
14,
740,
8355,
686,
198,
44,
14,
740,
8,
495,
8,
585,
430,
507,
198,
509,
334,
498,
12,
6111,
9,
315,
1584,
26,
686,
198,
44,
14,
740,
4517,
7,
435,
8424,
9,
686,
198,
1501,
275,
747,
14,
515,
14,
4846,
8,
2592,
14,
354,
9,
686,
198,
19233,
275,
747,
14,
32127,
8,
2592,
14,
9843,
18756,
3736,
14,
840,
63,
4305,
61,
686,
198,
44,
14,
740,
360,
2714,
13,
15954,
26,
1824,
13,
576,
27,
536,
5961,
83,
11436,
1788,
5961,
83,
4507,
450,
334,
495,
8,
498,
395,
620,
8,
736,
14,
515,
14,
4846,
1724,
686,
198,
17450,
275,
9519,
63,
466,
8,
1501,
2788,
16,
61,
503,
283,
3578,
15,
18162,
13,
1745,
7,
686,
198,
44,
14,
740,
360,
2714,
13,
804,
26,
450,
83,
7,
450,
12200,
9,
686,
198,
44,
14,
740,
360,
2714,
13,
4625,
26,
450,
83,
7,
450,
23858,
9,
686,
198,
44,
14,
740,
8355,
686,
198,
2592,
14,
5507,
8,
16,
9,
686,
198,
44,
14,
740,
8,
2592,
14,
739,
1012,
507,
198,
44,
14,
740,
4517,
7,
435,
8424,
435,
2850,
358,
507,
198,
44,
14,
740,
8355,
507,
198,
2030,
275,
25862,
14,
904,
8,
44,
9,
507,
198,
20735,
275,
283,
10123,
15,
964,
13,
576,
27,
8424,
2458,
83,
7,
450,
8424,
507,
198,
1107,
1564,
466,
12,
2396,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
tjwei/jedi
|
sith.py
|
24
|
7100
|
#!/usr/bin/env python
"""
Sith attacks (and helps debugging) Jedi.
Randomly search Python files and run Jedi on it. Exception and used
arguments are recorded to ``./record.json`` (specified by --record)::
./sith.py random /path/to/sourcecode
Redo recorded exception::
./sith.py redo
Show recorded exception::
./sith.py show
Run a specific operation
./sith.py run <operation> </path/to/source/file.py> <line> <col>
Where operation is one of completions, goto_assignments, goto_definitions,
usages, or call_signatures.
Note: Line numbers start at 1; columns start at 0 (this is consistent with
many text editors, including Emacs).
Usage:
sith.py [--pdb|--ipdb|--pudb] [-d] [-n=<nr>] [-f] [--record=<file>] random [-s] [<path>]
sith.py [--pdb|--ipdb|--pudb] [-d] [-f] [--record=<file>] redo
sith.py [--pdb|--ipdb|--pudb] [-d] [-f] run <operation> <path> <line> <column>
sith.py show [--record=<file>]
sith.py -h | --help
Options:
-h --help Show this screen.
--record=<file> Exceptions are recorded in here [default: record.json].
-f, --fs-cache By default, file system cache is off for reproducibility.
-n, --maxtries=<nr> Maximum of random tries [default: 100]
-d, --debug Jedi print debugging when an error is raised.
-s Shows the path/line numbers of every completion before it starts.
--pdb Launch pdb when error is raised.
--ipdb Launch ipdb when error is raised.
--pudb Launch pudb when error is raised.
"""
from __future__ import print_function, division, unicode_literals
from docopt import docopt
import json
import os
import random
import sys
import traceback
import jedi
class SourceFinder(object):
_files = None
@staticmethod
def fetch(file_path):
if not os.path.isdir(file_path):
yield file_path
return
for root, dirnames, filenames in os.walk(file_path):
for name in filenames:
if name.endswith('.py'):
yield os.path.join(root, name)
@classmethod
def files(cls, file_path):
if cls._files is None:
cls._files = list(cls.fetch(file_path))
return cls._files
class TestCase(object):
def __init__(self, operation, path, line, column, traceback=None):
if operation not in self.operations:
raise ValueError("%s is not a valid operation" % operation)
# Set other attributes
self.operation = operation
self.path = path
self.line = line
self.column = column
self.traceback = traceback
@classmethod
def from_cache(cls, record):
with open(record) as f:
args = json.load(f)
return cls(*args)
operations = [
'completions', 'goto_assignments', 'goto_definitions', 'usages',
'call_signatures']
@classmethod
def generate(cls, file_path):
operation = random.choice(cls.operations)
path = random.choice(SourceFinder.files(file_path))
with open(path) as f:
source = f.read()
lines = source.splitlines()
if not lines:
lines = ['']
line = random.randint(1, len(lines))
column = random.randint(0, len(lines[line - 1]))
return cls(operation, path, line, column)
def run(self, debugger, record=None, print_result=False):
try:
with open(self.path) as f:
self.script = jedi.Script(f.read(), self.line, self.column, self.path)
self.objects = getattr(self.script, self.operation)()
if print_result:
print("{path}: Line {line} column {column}".format(**self.__dict__))
self.show_location(self.line, self.column)
self.show_operation()
except jedi.NotFoundError:
pass
except Exception:
self.traceback = traceback.format_exc()
if record is not None:
call_args = (self.operation, self.path, self.line, self.column, self.traceback)
with open(record, 'w') as f:
json.dump(call_args, f)
self.show_errors()
if debugger:
einfo = sys.exc_info()
pdb = __import__(debugger)
if debugger == 'pudb':
pdb.post_mortem(einfo[2], einfo[0], einfo[1])
else:
pdb.post_mortem(einfo[2])
exit(1)
def show_location(self, lineno, column, show=3):
# Three lines ought to be enough
lower = lineno - show if lineno - show > 0 else 0
prefix = ' |'
for i, line in enumerate(self.script.source.split('\n')[lower:lineno]):
print(prefix, lower + i + 1, line)
print(prefix, ' ', ' ' * (column + len(str(lineno))), '^')
def show_operation(self):
print("%s:\n" % self.operation.capitalize())
if self.operation == 'completions':
self.show_completions()
else:
self.show_definitions()
def show_completions(self):
for completion in self.objects:
print(completion.name)
def show_definitions(self):
for completion in self.objects:
print(completion.desc_with_module)
if completion.module_path is None:
continue
if os.path.abspath(completion.module_path) == os.path.abspath(self.path):
self.show_location(completion.line, completion.column)
def show_errors(self):
print(self.traceback)
print(("Error with running Script(...).{operation}() with\n"
"\tpath: {path}\n"
"\tline: {line}\n"
"\tcolumn: {column}").format(**self.__dict__))
def main(arguments):
debugger = 'pdb' if arguments['--pdb'] else \
'ipdb' if arguments['--ipdb'] else \
'pudb' if arguments['--pudb'] else None
record = arguments['--record']
jedi.settings.use_filesystem_cache = arguments['--fs-cache']
if arguments['--debug']:
jedi.set_debug_function()
if arguments['redo'] or arguments['show']:
t = TestCase.from_cache(record)
if arguments['show']:
t.show_errors()
else:
t.run(debugger)
elif arguments['run']:
TestCase(
arguments['<operation>'], arguments['<path>'],
int(arguments['<line>']), int(arguments['<column>'])
).run(debugger, print_result=True)
else:
for _ in range(int(arguments['--maxtries'])):
t = TestCase.generate(arguments['<path>'] or '.')
if arguments['-s']:
print('%s %s %s %s ' % (t.operation, t.path, t.line, t.column))
sys.stdout.flush()
else:
print('.', end='')
t.run(debugger, record)
sys.stdout.flush()
print()
if __name__ == '__main__':
arguments = docopt(__doc__)
main(arguments)
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
624,
199,
51,
448,
28140,
334,
460,
22577,
10201,
9,
1603,
6297,
14,
199,
199,
3883,
590,
2754,
2018,
1584,
436,
1255,
1603,
6297,
641,
652,
14,
221,
2186,
436,
1202,
199,
4958,
787,
18894,
370,
1124,
13186,
3059,
14,
1001,
1040,
334,
10085,
701,
1553,
3059,
304,
26,
339,
16605,
338,
273,
14,
647,
2196,
1182,
515,
15,
475,
15,
1365,
600,
199,
199,
10858,
79,
18894,
1919,
447,
339,
16605,
338,
273,
14,
647,
295,
1117,
199,
199,
6824,
18894,
1919,
447,
339,
16605,
338,
273,
14,
647,
2498,
199,
199,
2540,
282,
2488,
3439,
339,
16605,
338,
273,
14,
647,
1255,
665,
5735,
30,
3068,
515,
15,
475,
15,
1365,
15,
493,
14,
647,
30,
665,
604,
30,
665,
761,
30,
199,
199,
26493,
3439,
365,
1373,
402,
31516,
12,
18878,
63,
18922,
12,
18878,
63,
15388,
12,
199,
21503,
12,
503,
1240,
63,
15132,
14,
199,
199,
7443,
26,
7030,
5579,
1343,
737,
413,
27,
4362,
1343,
737,
378,
334,
3749,
365,
12137,
543,
199,
3479,
1318,
5283,
1384,
12,
5893,
662,
19309,
680,
199,
199,
7692,
26,
523,
308,
448,
14,
647,
19344,
10511,
92,
306,
711,
697,
92,
306,
3165,
697,
61,
5243,
68,
61,
5243,
78,
18987,
7865,
19109,
5243,
70,
61,
19344,
3059,
18987,
493,
19109,
2196,
5243,
83,
61,
24936,
515,
19109,
523,
308,
448,
14,
647,
19344,
10511,
92,
306,
711,
697,
92,
306,
3165,
697,
61,
5243,
68,
61,
5243,
70,
61,
19344,
3059,
18987,
493,
19109,
295,
1117,
523,
308,
448,
14,
647,
19344,
10511,
92,
306,
711,
697,
92,
306,
3165,
697,
61,
5243,
68,
61,
5243,
70,
61,
1255,
665,
5735,
30,
665,
515,
30,
665,
604,
30,
665,
2301,
30,
523,
308,
448,
14,
647,
2498,
19344,
3059,
18987,
493,
19109,
523,
308,
448,
14,
647,
446,
72,
1204,
1553,
3437,
199,
199,
4558,
26,
523,
446,
72,
1553,
3437,
3777,
12968,
642,
6426,
14,
523,
1553,
3059,
18987,
493,
30,
755,
24873,
787,
18894,
315,
2348,
359,
885,
26,
2777,
14,
1001,
1055,
523,
446,
70,
12,
1553,
2319,
13,
1637,
263,
4885,
849,
12,
570,
2656,
2581,
365,
2331,
367,
295,
496,
2033,
559,
3195,
14,
523,
446,
78,
12,
1553,
391,
400,
1996,
18987,
7865,
30,
257,
14212,
402,
2196,
11275,
359,
885,
26,
2948,
61,
523,
446,
68,
12,
1553,
1757,
3698,
1603,
6297,
870,
10201,
1380,
376,
1125,
365,
4915,
14,
523,
446,
83,
8540,
12968,
83,
314,
931,
15,
604,
5579,
402,
4036,
13659,
2544,
652,
9174,
14,
523,
1553,
10511,
463,
23615,
10543,
1380,
1125,
365,
4915,
14,
523,
1553,
711,
697,
4483,
23615,
3384,
697,
1380,
1125,
365,
4915,
14,
523,
1553,
3165,
697,
4483,
23615,
299,
8301,
1380,
1125,
365,
4915,
14,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
12,
4629,
12,
2649,
63,
5955,
199,
504,
886,
32626,
492,
886,
32626,
199,
199,
646,
2022,
199,
646,
747,
199,
646,
2196,
199,
646,
984,
199,
646,
5190,
199,
199,
646,
1335,
6297,
421,
199,
533,
5800,
11791,
8,
785,
304,
272,
485,
1725,
275,
488,
339,
768,
4639,
272,
347,
5267,
8,
493,
63,
515,
304,
267,
340,
440,
747,
14,
515,
14,
6027,
8,
493,
63,
515,
304,
288,
1995,
570,
63,
515,
288,
372,
267,
367,
1738,
12,
22310,
12,
6203,
315,
747,
14,
7757,
8,
493,
63,
515,
304,
288,
367,
536,
315,
6203,
26,
355,
340,
536,
14,
4130,
5175,
647,
735,
490,
1995,
747,
14,
515,
14,
904,
8,
1231,
12,
536,
9,
339,
768,
3744,
272,
347,
1584,
8,
1886,
12,
570,
63,
515,
304,
267,
340,
843,
423,
1725,
365,
488,
26,
288,
843,
423,
1725,
275,
769,
8,
1886,
14,
3535,
8,
493,
63,
515,
430,
267,
372,
843,
423,
1725,
421,
199,
533,
7640,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
3439,
12,
931,
12,
1004,
12,
2763,
12,
5190,
29,
403,
304,
267,
340,
3439,
440,
315,
291,
14,
8170,
26,
288,
746,
1722,
3647,
83,
365,
440,
282,
1686,
3439,
2,
450,
3439,
9,
398,
327,
2494,
1163,
3004,
267,
291,
14,
5735,
275,
3439,
267,
291,
14,
515,
275,
931,
267,
291,
14,
604,
275,
1004,
267,
291,
14,
2301,
275,
2763,
267,
291,
14,
6894,
275,
5190,
339,
768,
3744,
272,
347,
687,
63,
1637,
8,
1886,
12,
2777,
304,
267,
543,
1551,
8,
3059,
9,
465,
289,
26,
288,
1249,
275,
2022,
14,
912,
8,
70,
9,
267,
372,
843,
2031,
589,
9,
339,
5331,
275,
359,
267,
283,
28832,
297,
283,
14867,
63,
18922,
297,
283,
14867,
63,
15388,
297,
283,
21503,
297,
267,
283,
1250,
63,
15132,
418,
339,
768,
3744,
272,
347,
3550,
8,
1886,
12,
570,
63,
515,
304,
267,
3439,
275,
2196,
14,
5095,
8,
1886,
14,
8170,
9,
398,
931,
275,
2196,
14,
5095,
8,
2980,
11791,
14,
1725,
8,
493,
63,
515,
430,
267,
543,
1551,
8,
515,
9,
465,
289,
26,
288,
1350,
275,
289,
14,
739,
342,
288,
2385,
275,
1350,
14,
7644,
342,
398,
340,
440,
2385,
26,
288,
2385,
275,
24506,
267,
1004,
275,
2196,
14,
8393,
8,
17,
12,
822,
8,
1278,
430,
267,
2763,
275,
2196,
14,
8393,
8,
16,
12,
822,
8,
1278,
59,
604,
446,
413,
2459,
267,
372,
843,
8,
5735,
12,
931,
12,
1004,
12,
2763,
9,
339,
347,
1255,
8,
277,
12,
14958,
12,
2777,
29,
403,
12,
870,
63,
1099,
29,
797,
304,
267,
862,
26,
288,
543,
1551,
8,
277,
14,
515,
9,
465,
289,
26,
355,
291,
14,
1579,
275,
1335,
6297,
14,
5229,
8,
70,
14,
739,
1062,
291,
14,
604,
12,
291,
14,
2301,
12,
291,
14,
515,
9,
288,
291,
14,
1462,
275,
2519,
8,
277,
14,
1579,
12,
291,
14,
5735,
16315,
288,
340,
870,
63,
1099,
26,
355,
870,
13076,
515,
9160,
7030,
469,
604,
93,
2763,
469,
2301,
5469,
908,
3682,
277,
855,
807,
8964,
355,
291,
14,
2384,
63,
1985,
8,
277,
14,
604,
12,
291,
14,
2301,
9,
355,
291,
14,
2384,
63,
5735,
342,
267,
871,
1335,
6297
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
624,
199,
51,
448,
28140,
334,
460,
22577,
10201,
9,
1603,
6297,
14,
199,
199,
3883,
590,
2754,
2018,
1584,
436,
1255,
1603,
6297,
641,
652,
14,
221,
2186,
436,
1202,
199,
4958,
787,
18894,
370,
1124,
13186,
3059,
14,
1001,
1040,
334,
10085,
701,
1553,
3059,
304,
26,
339,
16605,
338,
273,
14,
647,
2196,
1182,
515,
15,
475,
15,
1365,
600,
199,
199,
10858,
79,
18894,
1919,
447,
339,
16605,
338,
273,
14,
647,
295,
1117,
199,
199,
6824,
18894,
1919,
447,
339,
16605,
338,
273,
14,
647,
2498,
199,
199,
2540,
282,
2488,
3439,
339,
16605,
338,
273,
14,
647,
1255,
665,
5735,
30,
3068,
515,
15,
475,
15,
1365,
15,
493,
14,
647,
30,
665,
604,
30,
665,
761,
30,
199,
199,
26493,
3439,
365,
1373,
402,
31516,
12,
18878,
63,
18922,
12,
18878,
63,
15388,
12,
199,
21503,
12,
503,
1240,
63,
15132,
14,
199,
199,
7443,
26,
7030,
5579,
1343,
737,
413,
27,
4362,
1343,
737,
378,
334,
3749,
365,
12137,
543,
199,
3479,
1318,
5283,
1384,
12,
5893,
662,
19309,
680,
199,
199,
7692,
26,
523,
308,
448,
14,
647,
19344,
10511,
92,
306,
711,
697,
92,
306,
3165,
697,
61,
5243,
68,
61,
5243,
78,
18987,
7865,
19109,
5243,
70,
61,
19344,
3059,
18987,
493,
19109,
2196,
5243,
83,
61,
24936,
515,
19109,
523,
308,
448,
14,
647,
19344,
10511,
92,
306,
711,
697,
92,
306,
3165,
697,
61,
5243,
68,
61,
5243,
70,
61,
19344,
3059,
18987,
493,
19109,
295,
1117,
523,
308,
448,
14,
647,
19344,
10511,
92,
306,
711,
697,
92,
306,
3165,
697,
61,
5243,
68,
61,
5243,
70,
61,
1255,
665,
5735,
30,
665,
515,
30,
665,
604,
30,
665,
2301,
30,
523,
308,
448,
14,
647,
2498,
19344,
3059,
18987,
493,
19109,
523,
308,
448,
14,
647,
446,
72,
1204,
1553,
3437,
199,
199,
4558,
26,
523,
446,
72,
1553,
3437,
3777,
12968,
642,
6426,
14,
523,
1553,
3059,
18987,
493,
30,
755,
24873,
787,
18894,
315,
2348,
359,
885,
26,
2777,
14,
1001,
1055,
523,
446,
70,
12,
1553,
2319,
13,
1637,
263,
4885,
849,
12,
570,
2656,
2581,
365,
2331,
367,
295,
496,
2033,
559,
3195,
14,
523,
446,
78,
12,
1553,
391,
400,
1996,
18987,
7865,
30,
257,
14212,
402,
2196,
11275,
359,
885,
26,
2948,
61,
523,
446,
68,
12,
1553,
1757,
3698,
1603,
6297,
870,
10201,
1380,
376,
1125,
365,
4915,
14,
523,
446,
83,
8540,
12968,
83,
314,
931,
15,
604,
5579,
402,
4036,
13659,
2544,
652,
9174,
14,
523,
1553,
10511,
463,
23615,
10543,
1380,
1125,
365,
4915,
14,
523,
1553,
711,
697,
4483,
23615,
3384,
697,
1380,
1125,
365,
4915,
14,
523,
1553,
3165,
697,
4483,
23615,
299,
8301,
1380,
1125,
365,
4915,
14,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
12,
4629,
12,
2649,
63,
5955,
199,
504,
886,
32626,
492,
886,
32626,
199,
199,
646,
2022,
199,
646,
747,
199,
646,
2196,
199,
646,
984,
199,
646,
5190,
199,
199,
646,
1335,
6297,
421,
199,
533,
5800,
11791,
8,
785,
304,
272,
485,
1725,
275,
488,
339,
768,
4639,
272,
347,
5267,
8,
493,
63,
515,
304,
267,
340,
440,
747,
14,
515,
14,
6027,
8,
493,
63,
515,
304,
288,
1995,
570,
63,
515,
288,
372,
267,
367,
1738,
12,
22310,
12,
6203,
315,
747,
14,
7757,
8,
493,
63,
515,
304,
288,
367,
536,
315,
6203,
26,
355,
340,
536,
14,
4130,
5175,
647,
735,
490,
1995,
747,
14,
515,
14,
904,
8,
1231,
12,
536,
9,
339,
768,
3744,
272,
347,
1584,
8,
1886,
12,
570,
63,
515,
304,
267,
340,
843,
423,
1725,
365,
488,
26,
288,
843,
423,
1725,
275,
769,
8,
1886,
14,
3535,
8,
493,
63,
515,
430,
267,
372,
843,
423,
1725,
421,
199,
533,
7640,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
3439,
12,
931,
12,
1004,
12,
2763,
12,
5190,
29,
403,
304,
267,
340,
3439,
440,
315,
291,
14,
8170,
26,
288,
746,
1722,
3647,
83,
365,
440,
282,
1686,
3439,
2,
450,
3439,
9,
398,
327,
2494,
1163,
3004,
267,
291,
14,
5735,
275,
3439,
267,
291,
14,
515,
275,
931,
267,
291,
14,
604,
275,
1004,
267,
291,
14,
2301,
275,
2763,
267,
291,
14,
6894,
275,
5190,
339,
768,
3744,
272,
347,
687,
63,
1637,
8,
1886,
12,
2777,
304,
267,
543,
1551,
8,
3059,
9,
465,
289,
26,
288,
1249,
275,
2022,
14,
912,
8,
70,
9,
267,
372,
843,
2031,
589,
9,
339,
5331,
275,
359,
267,
283,
28832,
297,
283,
14867,
63,
18922,
297,
283,
14867,
63,
15388,
297,
283,
21503,
297,
267,
283,
1250,
63,
15132,
418,
339,
768,
3744,
272,
347,
3550,
8,
1886,
12,
570,
63,
515,
304,
267,
3439,
275,
2196,
14,
5095,
8,
1886,
14,
8170,
9,
398,
931,
275,
2196,
14,
5095,
8,
2980,
11791,
14,
1725,
8,
493,
63,
515,
430,
267,
543,
1551,
8,
515,
9,
465,
289,
26,
288,
1350,
275,
289,
14,
739,
342,
288,
2385,
275,
1350,
14,
7644,
342,
398,
340,
440,
2385,
26,
288,
2385,
275,
24506,
267,
1004,
275,
2196,
14,
8393,
8,
17,
12,
822,
8,
1278,
430,
267,
2763,
275,
2196,
14,
8393,
8,
16,
12,
822,
8,
1278,
59,
604,
446,
413,
2459,
267,
372,
843,
8,
5735,
12,
931,
12,
1004,
12,
2763,
9,
339,
347,
1255,
8,
277,
12,
14958,
12,
2777,
29,
403,
12,
870,
63,
1099,
29,
797,
304,
267,
862,
26,
288,
543,
1551,
8,
277,
14,
515,
9,
465,
289,
26,
355,
291,
14,
1579,
275,
1335,
6297,
14,
5229,
8,
70,
14,
739,
1062,
291,
14,
604,
12,
291,
14,
2301,
12,
291,
14,
515,
9,
288,
291,
14,
1462,
275,
2519,
8,
277,
14,
1579,
12,
291,
14,
5735,
16315,
288,
340,
870,
63,
1099,
26,
355,
870,
13076,
515,
9160,
7030,
469,
604,
93,
2763,
469,
2301,
5469,
908,
3682,
277,
855,
807,
8964,
355,
291,
14,
2384,
63,
1985,
8,
277,
14,
604,
12,
291,
14,
2301,
9,
355,
291,
14,
2384,
63,
5735,
342,
267,
871,
1335,
6297,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
gonboy/sl4a
|
python/src/Lib/test/test_audioop.py
|
56
|
5833
|
import audioop
import unittest
from test.test_support import run_unittest
def gendata1():
return '\0\1\2'
def gendata2():
if audioop.getsample('\0\1', 2, 0) == 1:
return '\0\0\0\1\0\2'
else:
return '\0\0\1\0\2\0'
def gendata4():
if audioop.getsample('\0\0\0\1', 4, 0) == 1:
return '\0\0\0\0\0\0\0\1\0\0\0\2'
else:
return '\0\0\0\0\1\0\0\0\2\0\0\0'
data = [gendata1(), gendata2(), gendata4()]
class TestAudioop(unittest.TestCase):
def test_max(self):
self.assertEqual(audioop.max(data[0], 1), 2)
self.assertEqual(audioop.max(data[1], 2), 2)
self.assertEqual(audioop.max(data[2], 4), 2)
def test_minmax(self):
self.assertEqual(audioop.minmax(data[0], 1), (0, 2))
self.assertEqual(audioop.minmax(data[1], 2), (0, 2))
self.assertEqual(audioop.minmax(data[2], 4), (0, 2))
def test_maxpp(self):
self.assertEqual(audioop.maxpp(data[0], 1), 0)
self.assertEqual(audioop.maxpp(data[1], 2), 0)
self.assertEqual(audioop.maxpp(data[2], 4), 0)
def test_avg(self):
self.assertEqual(audioop.avg(data[0], 1), 1)
self.assertEqual(audioop.avg(data[1], 2), 1)
self.assertEqual(audioop.avg(data[2], 4), 1)
def test_avgpp(self):
self.assertEqual(audioop.avgpp(data[0], 1), 0)
self.assertEqual(audioop.avgpp(data[1], 2), 0)
self.assertEqual(audioop.avgpp(data[2], 4), 0)
def test_rms(self):
self.assertEqual(audioop.rms(data[0], 1), 1)
self.assertEqual(audioop.rms(data[1], 2), 1)
self.assertEqual(audioop.rms(data[2], 4), 1)
def test_cross(self):
self.assertEqual(audioop.cross(data[0], 1), 0)
self.assertEqual(audioop.cross(data[1], 2), 0)
self.assertEqual(audioop.cross(data[2], 4), 0)
def test_add(self):
data2 = []
for d in data:
str = ''
for s in d:
str = str + chr(ord(s)*2)
data2.append(str)
self.assertEqual(audioop.add(data[0], data[0], 1), data2[0])
self.assertEqual(audioop.add(data[1], data[1], 2), data2[1])
self.assertEqual(audioop.add(data[2], data[2], 4), data2[2])
def test_bias(self):
# Note: this test assumes that avg() works
d1 = audioop.bias(data[0], 1, 100)
d2 = audioop.bias(data[1], 2, 100)
d4 = audioop.bias(data[2], 4, 100)
self.assertEqual(audioop.avg(d1, 1), 101)
self.assertEqual(audioop.avg(d2, 2), 101)
self.assertEqual(audioop.avg(d4, 4), 101)
def test_lin2lin(self):
# too simple: we test only the size
for d1 in data:
for d2 in data:
got = len(d1)//3
wtd = len(d2)//3
self.assertEqual(len(audioop.lin2lin(d1, got, wtd)), len(d2))
def test_adpcm2lin(self):
# Very cursory test
self.assertEqual(audioop.adpcm2lin('\0\0', 1, None), ('\0\0\0\0', (0,0)))
def test_lin2adpcm(self):
# Very cursory test
self.assertEqual(audioop.lin2adpcm('\0\0\0\0', 1, None), ('\0\0', (0,0)))
def test_lin2alaw(self):
self.assertEqual(audioop.lin2alaw(data[0], 1), '\xd5\xc5\xf5')
self.assertEqual(audioop.lin2alaw(data[1], 2), '\xd5\xd5\xd5')
self.assertEqual(audioop.lin2alaw(data[2], 4), '\xd5\xd5\xd5')
def test_alaw2lin(self):
# Cursory
d = audioop.lin2alaw(data[0], 1)
self.assertEqual(audioop.alaw2lin(d, 1), data[0])
def test_lin2ulaw(self):
self.assertEqual(audioop.lin2ulaw(data[0], 1), '\xff\xe7\xdb')
self.assertEqual(audioop.lin2ulaw(data[1], 2), '\xff\xff\xff')
self.assertEqual(audioop.lin2ulaw(data[2], 4), '\xff\xff\xff')
def test_ulaw2lin(self):
# Cursory
d = audioop.lin2ulaw(data[0], 1)
self.assertEqual(audioop.ulaw2lin(d, 1), data[0])
def test_mul(self):
data2 = []
for d in data:
str = ''
for s in d:
str = str + chr(ord(s)*2)
data2.append(str)
self.assertEqual(audioop.mul(data[0], 1, 2), data2[0])
self.assertEqual(audioop.mul(data[1],2, 2), data2[1])
self.assertEqual(audioop.mul(data[2], 4, 2), data2[2])
def test_ratecv(self):
state = None
d1, state = audioop.ratecv(data[0], 1, 1, 8000, 16000, state)
d2, state = audioop.ratecv(data[0], 1, 1, 8000, 16000, state)
self.assertEqual(d1 + d2, '\000\000\001\001\002\001\000\000\001\001\002')
def test_reverse(self):
self.assertEqual(audioop.reverse(data[0], 1), '\2\1\0')
def test_tomono(self):
data2 = ''
for d in data[0]:
data2 = data2 + d + d
self.assertEqual(audioop.tomono(data2, 1, 0.5, 0.5), data[0])
def test_tostereo(self):
data2 = ''
for d in data[0]:
data2 = data2 + d + d
self.assertEqual(audioop.tostereo(data[0], 1, 1, 1), data2)
def test_findfactor(self):
self.assertEqual(audioop.findfactor(data[1], data[1]), 1.0)
def test_findfit(self):
self.assertEqual(audioop.findfit(data[1], data[1]), (0, 1.0))
def test_findmax(self):
self.assertEqual(audioop.findmax(data[1], 1), 2)
def test_getsample(self):
for i in range(3):
self.assertEqual(audioop.getsample(data[0], 1, i), i)
self.assertEqual(audioop.getsample(data[1], 2, i), i)
self.assertEqual(audioop.getsample(data[2], 4, i), i)
def test_negativelen(self):
# from issue 3306, previously it segfaulted
self.assertRaises(audioop.error,
audioop.findmax, ''.join( chr(x) for x in xrange(256)), -2392392)
def test_main():
run_unittest(TestAudioop)
if __name__ == '__main__':
test_main()
|
apache-2.0
|
[
646,
10491,
411,
199,
646,
2882,
199,
504,
511,
14,
396,
63,
4058,
492,
1255,
63,
2796,
421,
199,
318,
486,
500,
419,
17,
837,
272,
372,
1557,
16,
60,
17,
60,
18,
7,
199,
199,
318,
486,
500,
419,
18,
837,
272,
340,
10491,
411,
14,
362,
3271,
2258,
16,
60,
17,
297,
499,
12,
378,
9,
508,
413,
26,
267,
372,
1557,
16,
60,
16,
60,
16,
60,
17,
60,
16,
60,
18,
7,
272,
587,
26,
267,
372,
1557,
16,
60,
16,
60,
17,
60,
16,
60,
18,
60,
16,
7,
199,
199,
318,
486,
500,
419,
20,
837,
272,
340,
10491,
411,
14,
362,
3271,
2258,
16,
60,
16,
60,
16,
60,
17,
297,
841,
12,
378,
9,
508,
413,
26,
267,
372,
1557,
16,
60,
16,
60,
16,
60,
16,
60,
16,
60,
16,
60,
16,
60,
17,
60,
16,
60,
16,
60,
16,
60,
18,
7,
272,
587,
26,
267,
372,
1557,
16,
60,
16,
60,
16,
60,
16,
60,
17,
60,
16,
60,
16,
60,
16,
60,
18,
60,
16,
60,
16,
60,
16,
7,
199,
199,
576,
275,
359,
71,
500,
419,
17,
1062,
486,
500,
419,
18,
1062,
486,
500,
419,
20,
5106,
421,
199,
533,
1379,
15484,
411,
8,
2796,
14,
1746,
304,
339,
347,
511,
63,
988,
8,
277,
304,
267,
291,
14,
629,
8,
8130,
411,
14,
988,
8,
576,
59,
16,
467,
413,
395,
499,
9,
267,
291,
14,
629,
8,
8130,
411,
14,
988,
8,
576,
59,
17,
467,
499,
395,
499,
9,
267,
291,
14,
629,
8,
8130,
411,
14,
988,
8,
576,
59,
18,
467,
841,
395,
499,
9,
339,
347,
511,
63,
827,
988,
8,
277,
304,
267,
291,
14,
629,
8,
8130,
411,
14,
827,
988,
8,
576,
59,
16,
467,
413,
395,
334,
16,
12,
499,
430,
267,
291,
14,
629,
8,
8130,
411,
14,
827,
988,
8,
576,
59,
17,
467,
499,
395,
334,
16,
12,
499,
430,
267,
291,
14,
629,
8,
8130,
411,
14,
827,
988,
8,
576,
59,
18,
467,
841,
395,
334,
16,
12,
499,
430,
339,
347,
511,
63,
988,
802,
8,
277,
304,
267,
291,
14,
629,
8,
8130,
411,
14,
988,
802,
8,
576,
59,
16,
467,
413,
395,
378,
9,
267,
291,
14,
629,
8,
8130,
411,
14,
988,
802,
8,
576,
59,
17,
467,
499,
395,
378,
9,
267,
291,
14,
629,
8,
8130,
411,
14,
988,
802,
8,
576,
59,
18,
467,
841,
395,
378,
9,
339,
347,
511,
63,
8595,
8,
277,
304,
267,
291,
14,
629,
8,
8130,
411,
14,
8595,
8,
576,
59,
16,
467,
413,
395,
413,
9,
267,
291,
14,
629,
8,
8130,
411,
14,
8595,
8,
576,
59,
17,
467,
499,
395,
413,
9,
267,
291,
14,
629,
8,
8130,
411,
14,
8595,
8,
576,
59,
18,
467,
841,
395,
413,
9,
339,
347,
511,
63,
8595,
802,
8,
277,
304,
267,
291,
14,
629,
8,
8130,
411,
14,
8595,
802,
8,
576,
59,
16,
467,
413,
395,
378,
9,
267,
291,
14,
629,
8,
8130,
411,
14,
8595,
802,
8,
576,
59,
17,
467,
499,
395,
378,
9,
267,
291,
14,
629,
8,
8130,
411,
14,
8595,
802,
8,
576,
59,
18,
467,
841,
395,
378,
9,
339,
347,
511,
63,
24444,
8,
277,
304,
267,
291,
14,
629,
8,
8130,
411,
14,
24444,
8,
576,
59,
16,
467,
413,
395,
413,
9,
267,
291,
14,
629,
8,
8130,
411,
14,
24444,
8,
576,
59,
17,
467,
499,
395,
413,
9,
267,
291,
14,
629,
8,
8130,
411,
14,
24444,
8,
576,
59,
18,
467,
841,
395,
413,
9,
339,
347,
511,
63,
7925,
8,
277,
304,
267,
291,
14,
629,
8,
8130,
411,
14,
7925,
8,
576,
59,
16,
467,
413,
395,
378,
9,
267,
291,
14,
629,
8,
8130,
411,
14,
7925,
8,
576,
59,
17,
467,
499,
395,
378,
9,
267,
291,
14,
629,
8,
8130,
411,
14,
7925,
8,
576,
59,
18,
467,
841,
395,
378,
9,
339,
347,
511,
63,
525,
8,
277,
304,
267,
666,
18,
275,
942,
267,
367,
366,
315,
666,
26,
288,
620,
275,
2125,
288,
367,
308,
315,
366,
26,
355,
620,
275,
620,
435,
8678,
8,
2181,
8,
83,
3342,
18,
9,
288,
666,
18,
14,
740,
8,
495,
9,
267,
291,
14,
629,
8,
8130,
411,
14,
525,
8,
576,
59,
16,
467,
666,
59,
16,
467,
413,
395,
666,
18,
59,
16,
566,
267,
291,
14,
629,
8,
8130,
411,
14,
525,
8,
576,
59,
17,
467,
666,
59,
17,
467,
499,
395,
666,
18,
59,
17,
566,
267,
291,
14,
629,
8,
8130,
411,
14,
525,
8,
576,
59,
18,
467,
666,
59,
18,
467,
841,
395,
666,
18,
59,
18,
566,
339,
347,
511,
63,
8160,
8,
277,
304,
267,
327,
3390,
26,
642,
511,
15194,
626,
12402,
342,
5419,
267,
366,
17,
275,
10491,
411,
14,
8160,
8,
576,
59,
16,
467,
413,
12,
2948,
9,
267,
366,
18,
275,
10491,
411,
14,
8160,
8,
576,
59,
17,
467,
499,
12,
2948,
9,
267,
366,
20,
275,
10491,
411,
14,
8160,
8,
576,
59,
18,
467,
841,
12,
2948,
9,
267,
291,
14,
629,
8,
8130,
411,
14,
8595,
8,
68,
17,
12,
413,
395,
14313,
9,
267,
291,
14,
629,
8,
8130,
411,
14,
8595,
8,
68,
18,
12,
499,
395,
14313,
9,
267,
291,
14,
629,
8,
8130,
411,
14,
8595,
8,
68,
20,
12,
841,
395,
14313,
9,
339,
347,
511,
63,
472,
18,
472,
8,
277,
304,
267,
327,
4634,
3486,
26,
781,
511,
1454,
314,
1568,
267,
367,
366,
17,
315,
666,
26,
288,
367,
366,
18,
315,
666,
26,
355,
4788,
275,
822,
8,
68,
17,
28428,
19,
355,
336,
2076,
275,
822,
8,
68,
18,
28428,
19,
355,
291,
14,
629,
8,
552,
8,
8130,
411,
14,
472,
18,
472,
8,
68,
17,
12,
4788,
12,
336,
2076,
1826,
822,
8,
68,
18,
430,
339,
347,
511,
63,
350,
2352,
77,
18,
472,
8,
277,
304,
267,
327,
812,
994,
18809,
1089,
511,
267,
291,
14,
629,
8,
8130,
411,
14,
350,
2352,
77
] |
[
10491,
411,
199,
646,
2882,
199,
504,
511,
14,
396,
63,
4058,
492,
1255,
63,
2796,
421,
199,
318,
486,
500,
419,
17,
837,
272,
372,
1557,
16,
60,
17,
60,
18,
7,
199,
199,
318,
486,
500,
419,
18,
837,
272,
340,
10491,
411,
14,
362,
3271,
2258,
16,
60,
17,
297,
499,
12,
378,
9,
508,
413,
26,
267,
372,
1557,
16,
60,
16,
60,
16,
60,
17,
60,
16,
60,
18,
7,
272,
587,
26,
267,
372,
1557,
16,
60,
16,
60,
17,
60,
16,
60,
18,
60,
16,
7,
199,
199,
318,
486,
500,
419,
20,
837,
272,
340,
10491,
411,
14,
362,
3271,
2258,
16,
60,
16,
60,
16,
60,
17,
297,
841,
12,
378,
9,
508,
413,
26,
267,
372,
1557,
16,
60,
16,
60,
16,
60,
16,
60,
16,
60,
16,
60,
16,
60,
17,
60,
16,
60,
16,
60,
16,
60,
18,
7,
272,
587,
26,
267,
372,
1557,
16,
60,
16,
60,
16,
60,
16,
60,
17,
60,
16,
60,
16,
60,
16,
60,
18,
60,
16,
60,
16,
60,
16,
7,
199,
199,
576,
275,
359,
71,
500,
419,
17,
1062,
486,
500,
419,
18,
1062,
486,
500,
419,
20,
5106,
421,
199,
533,
1379,
15484,
411,
8,
2796,
14,
1746,
304,
339,
347,
511,
63,
988,
8,
277,
304,
267,
291,
14,
629,
8,
8130,
411,
14,
988,
8,
576,
59,
16,
467,
413,
395,
499,
9,
267,
291,
14,
629,
8,
8130,
411,
14,
988,
8,
576,
59,
17,
467,
499,
395,
499,
9,
267,
291,
14,
629,
8,
8130,
411,
14,
988,
8,
576,
59,
18,
467,
841,
395,
499,
9,
339,
347,
511,
63,
827,
988,
8,
277,
304,
267,
291,
14,
629,
8,
8130,
411,
14,
827,
988,
8,
576,
59,
16,
467,
413,
395,
334,
16,
12,
499,
430,
267,
291,
14,
629,
8,
8130,
411,
14,
827,
988,
8,
576,
59,
17,
467,
499,
395,
334,
16,
12,
499,
430,
267,
291,
14,
629,
8,
8130,
411,
14,
827,
988,
8,
576,
59,
18,
467,
841,
395,
334,
16,
12,
499,
430,
339,
347,
511,
63,
988,
802,
8,
277,
304,
267,
291,
14,
629,
8,
8130,
411,
14,
988,
802,
8,
576,
59,
16,
467,
413,
395,
378,
9,
267,
291,
14,
629,
8,
8130,
411,
14,
988,
802,
8,
576,
59,
17,
467,
499,
395,
378,
9,
267,
291,
14,
629,
8,
8130,
411,
14,
988,
802,
8,
576,
59,
18,
467,
841,
395,
378,
9,
339,
347,
511,
63,
8595,
8,
277,
304,
267,
291,
14,
629,
8,
8130,
411,
14,
8595,
8,
576,
59,
16,
467,
413,
395,
413,
9,
267,
291,
14,
629,
8,
8130,
411,
14,
8595,
8,
576,
59,
17,
467,
499,
395,
413,
9,
267,
291,
14,
629,
8,
8130,
411,
14,
8595,
8,
576,
59,
18,
467,
841,
395,
413,
9,
339,
347,
511,
63,
8595,
802,
8,
277,
304,
267,
291,
14,
629,
8,
8130,
411,
14,
8595,
802,
8,
576,
59,
16,
467,
413,
395,
378,
9,
267,
291,
14,
629,
8,
8130,
411,
14,
8595,
802,
8,
576,
59,
17,
467,
499,
395,
378,
9,
267,
291,
14,
629,
8,
8130,
411,
14,
8595,
802,
8,
576,
59,
18,
467,
841,
395,
378,
9,
339,
347,
511,
63,
24444,
8,
277,
304,
267,
291,
14,
629,
8,
8130,
411,
14,
24444,
8,
576,
59,
16,
467,
413,
395,
413,
9,
267,
291,
14,
629,
8,
8130,
411,
14,
24444,
8,
576,
59,
17,
467,
499,
395,
413,
9,
267,
291,
14,
629,
8,
8130,
411,
14,
24444,
8,
576,
59,
18,
467,
841,
395,
413,
9,
339,
347,
511,
63,
7925,
8,
277,
304,
267,
291,
14,
629,
8,
8130,
411,
14,
7925,
8,
576,
59,
16,
467,
413,
395,
378,
9,
267,
291,
14,
629,
8,
8130,
411,
14,
7925,
8,
576,
59,
17,
467,
499,
395,
378,
9,
267,
291,
14,
629,
8,
8130,
411,
14,
7925,
8,
576,
59,
18,
467,
841,
395,
378,
9,
339,
347,
511,
63,
525,
8,
277,
304,
267,
666,
18,
275,
942,
267,
367,
366,
315,
666,
26,
288,
620,
275,
2125,
288,
367,
308,
315,
366,
26,
355,
620,
275,
620,
435,
8678,
8,
2181,
8,
83,
3342,
18,
9,
288,
666,
18,
14,
740,
8,
495,
9,
267,
291,
14,
629,
8,
8130,
411,
14,
525,
8,
576,
59,
16,
467,
666,
59,
16,
467,
413,
395,
666,
18,
59,
16,
566,
267,
291,
14,
629,
8,
8130,
411,
14,
525,
8,
576,
59,
17,
467,
666,
59,
17,
467,
499,
395,
666,
18,
59,
17,
566,
267,
291,
14,
629,
8,
8130,
411,
14,
525,
8,
576,
59,
18,
467,
666,
59,
18,
467,
841,
395,
666,
18,
59,
18,
566,
339,
347,
511,
63,
8160,
8,
277,
304,
267,
327,
3390,
26,
642,
511,
15194,
626,
12402,
342,
5419,
267,
366,
17,
275,
10491,
411,
14,
8160,
8,
576,
59,
16,
467,
413,
12,
2948,
9,
267,
366,
18,
275,
10491,
411,
14,
8160,
8,
576,
59,
17,
467,
499,
12,
2948,
9,
267,
366,
20,
275,
10491,
411,
14,
8160,
8,
576,
59,
18,
467,
841,
12,
2948,
9,
267,
291,
14,
629,
8,
8130,
411,
14,
8595,
8,
68,
17,
12,
413,
395,
14313,
9,
267,
291,
14,
629,
8,
8130,
411,
14,
8595,
8,
68,
18,
12,
499,
395,
14313,
9,
267,
291,
14,
629,
8,
8130,
411,
14,
8595,
8,
68,
20,
12,
841,
395,
14313,
9,
339,
347,
511,
63,
472,
18,
472,
8,
277,
304,
267,
327,
4634,
3486,
26,
781,
511,
1454,
314,
1568,
267,
367,
366,
17,
315,
666,
26,
288,
367,
366,
18,
315,
666,
26,
355,
4788,
275,
822,
8,
68,
17,
28428,
19,
355,
336,
2076,
275,
822,
8,
68,
18,
28428,
19,
355,
291,
14,
629,
8,
552,
8,
8130,
411,
14,
472,
18,
472,
8,
68,
17,
12,
4788,
12,
336,
2076,
1826,
822,
8,
68,
18,
430,
339,
347,
511,
63,
350,
2352,
77,
18,
472,
8,
277,
304,
267,
327,
812,
994,
18809,
1089,
511,
267,
291,
14,
629,
8,
8130,
411,
14,
350,
2352,
77,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
bplancher/odoo
|
addons/web_editor/models/ir_ui_view.py
|
40
|
4947
|
# -*- coding: utf-8 -*-
import copy
import openerp
from openerp.exceptions import AccessError
from openerp.osv import osv
from lxml import etree, html
from openerp import api
class view(osv.osv):
_inherit = 'ir.ui.view'
@api.cr_uid_ids_context
def render(self, cr, uid, id_or_xml_id, values=None, engine='ir.qweb', context=None):
if not values:
values = {}
if values.get('editable'):
try:
if not isinstance(id_or_xml_id, (int, long)):
if '.' not in id_or_xml_id:
raise ValueError('Invalid template id: %r' % (id_or_xml_id,))
id_or_xml_id = self.get_view_id(cr, uid, id_or_xml_id, context=context)
self.check_access_rule(cr, uid, [id_or_xml_id], 'write', context=context)
except AccessError:
values['editable'] = False
return super(view, self).render(cr, uid, id_or_xml_id, values=values, engine=engine, context=context)
#------------------------------------------------------
# Save from html
#------------------------------------------------------
def extract_embedded_fields(self, cr, uid, arch, context=None):
return arch.xpath('//*[@data-oe-model != "ir.ui.view"]')
def save_embedded_field(self, cr, uid, el, context=None):
Model = self.pool[el.get('data-oe-model')]
field = el.get('data-oe-field')
converter = self.pool['ir.qweb'].get_converter_for(el.get('data-oe-type'))
value = converter.from_html(cr, uid, Model, Model._fields[field], el)
if value is not None:
# TODO: batch writes?
Model.write(cr, uid, [int(el.get('data-oe-id'))], {
field: value
}, context=context)
def _pretty_arch(self, arch):
# remove_blank_string does not seem to work on HTMLParser, and
# pretty-printing with lxml more or less requires stripping
# whitespace: http://lxml.de/FAQ.html#why-doesn-t-the-pretty-print-option-reformat-my-xml-output
# so serialize to XML, parse as XML (remove whitespace) then serialize
# as XML (pretty print)
arch_no_whitespace = etree.fromstring(
etree.tostring(arch, encoding='utf-8'),
parser=etree.XMLParser(encoding='utf-8', remove_blank_text=True))
return etree.tostring(
arch_no_whitespace, encoding='unicode', pretty_print=True)
def replace_arch_section(self, cr, uid, view_id, section_xpath, replacement, context=None):
# the root of the arch section shouldn't actually be replaced as it's
# not really editable itself, only the content truly is editable.
[view] = self.browse(cr, uid, [view_id], context=context)
arch = etree.fromstring(view.arch.encode('utf-8'))
# => get the replacement root
if not section_xpath:
root = arch
else:
# ensure there's only one match
[root] = arch.xpath(section_xpath)
root.text = replacement.text
root.tail = replacement.tail
# replace all children
del root[:]
for child in replacement:
root.append(copy.deepcopy(child))
return arch
def to_field_ref(self, cr, uid, el, context=None):
# filter out meta-information inserted in the document
attributes = dict((k, v) for k, v in el.items()
if not k.startswith('data-oe-'))
attributes['t-field'] = el.get('data-oe-expression')
out = html.html_parser.makeelement(el.tag, attrib=attributes)
out.tail = el.tail
return out
def save(self, cr, uid, res_id, value, xpath=None, context=None):
""" Update a view section. The view section may embed fields to write
:param str model:
:param int res_id:
:param str xpath: valid xpath to the tag to replace
"""
res_id = int(res_id)
arch_section = html.fromstring(
value, parser=html.HTMLParser(encoding='utf-8'))
if xpath is None:
# value is an embedded field on its own, not a view section
self.save_embedded_field(cr, uid, arch_section, context=context)
return
for el in self.extract_embedded_fields(cr, uid, arch_section, context=context):
self.save_embedded_field(cr, uid, el, context=context)
# transform embedded field back to t-field
el.getparent().replace(el, self.to_field_ref(cr, uid, el, context=context))
arch = self.replace_arch_section(cr, uid, res_id, xpath, arch_section, context=context)
self.write(cr, uid, res_id, {
'arch': self._pretty_arch(arch)
}, context=context)
view = self.browse(cr, openerp.SUPERUSER_ID, res_id, context=context)
if view.model_data_id:
view.model_data_id.write({'noupdate': True})
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
646,
1331,
199,
646,
5166,
199,
504,
5166,
14,
3924,
492,
11003,
547,
199,
504,
5166,
14,
4795,
492,
9506,
199,
504,
14490,
492,
7559,
12,
3517,
199,
504,
5166,
492,
2986,
421,
199,
533,
2455,
8,
4795,
14,
4795,
304,
272,
485,
6486,
275,
283,
723,
14,
1907,
14,
1345,
7,
339,
768,
1246,
14,
1556,
63,
1535,
63,
1580,
63,
1100,
272,
347,
3795,
8,
277,
12,
2467,
12,
1747,
12,
1305,
63,
269,
63,
1652,
63,
344,
12,
1338,
29,
403,
12,
6869,
534,
723,
14,
22600,
297,
1067,
29,
403,
304,
267,
340,
440,
1338,
26,
288,
1338,
275,
1052,
267,
340,
1338,
14,
362,
360,
10820,
735,
288,
862,
26,
355,
340,
440,
1228,
8,
344,
63,
269,
63,
1652,
63,
344,
12,
334,
442,
12,
1846,
2298,
490,
340,
7815,
440,
315,
1305,
63,
269,
63,
1652,
63,
344,
26,
717,
746,
1722,
360,
3364,
1978,
1305,
26,
450,
82,
7,
450,
334,
344,
63,
269,
63,
1652,
63,
344,
4641,
490,
1305,
63,
269,
63,
1652,
63,
344,
275,
291,
14,
362,
63,
1345,
63,
344,
8,
1556,
12,
1747,
12,
1305,
63,
269,
63,
1652,
63,
344,
12,
1067,
29,
1100,
9,
2234,
291,
14,
1074,
63,
2732,
63,
2200,
8,
1556,
12,
1747,
12,
359,
344,
63,
269,
63,
1652,
63,
344,
467,
283,
952,
297,
1067,
29,
1100,
9,
953,
871,
11003,
547,
26,
355,
1338,
459,
10820,
418,
275,
756,
398,
372,
1613,
8,
1345,
12,
291,
680,
3352,
8,
1556,
12,
1747,
12,
1305,
63,
269,
63,
1652,
63,
344,
12,
1338,
29,
1459,
12,
6869,
29,
3908,
12,
1067,
29,
1100,
9,
339,
27721,
8648,
272,
327,
11063,
687,
3517,
272,
27721,
8648,
339,
347,
5536,
63,
18757,
63,
955,
8,
277,
12,
2467,
12,
1747,
12,
3819,
12,
1067,
29,
403,
304,
267,
372,
3819,
14,
8006,
15079,
10,
14251,
576,
13,
13361,
13,
1238,
1137,
298,
723,
14,
1907,
14,
1345,
937,
358,
339,
347,
3354,
63,
18757,
63,
698,
8,
277,
12,
2467,
12,
1747,
12,
579,
12,
1067,
29,
403,
304,
267,
5822,
275,
291,
14,
2293,
59,
352,
14,
362,
360,
576,
13,
13361,
13,
1238,
5440,
267,
901,
275,
579,
14,
362,
360,
576,
13,
13361,
13,
698,
358,
398,
11109,
275,
291,
14,
2293,
459,
723,
14,
22600,
2278,
362,
63,
11256,
63,
509,
8,
352,
14,
362,
360,
576,
13,
13361,
13,
466,
1333,
267,
574,
275,
11109,
14,
504,
63,
1360,
8,
1556,
12,
1747,
12,
5822,
12,
5822,
423,
955,
59,
698,
467,
579,
9,
398,
340,
574,
365,
440,
488,
26,
288,
327,
3254,
26,
3522,
14511,
31,
288,
5822,
14,
952,
8,
1556,
12,
1747,
12,
359,
442,
8,
352,
14,
362,
360,
576,
13,
13361,
13,
344,
1333,
467,
469,
355,
901,
26,
574,
288,
1660,
1067,
29,
1100,
9,
339,
347,
485,
9118,
63,
1047,
8,
277,
12,
3819,
304,
267,
327,
2813,
63,
2500,
63,
875,
1630,
440,
17021,
370,
1736,
641,
24581,
12,
436,
267,
327,
7268,
13,
26514,
543,
14490,
1655,
503,
6656,
5074,
4024,
3637,
267,
327,
8139,
26,
1455,
921,
22899,
14,
271,
15,
2078,
49,
14,
1360,
3,
26460,
13,
30977,
13,
84,
13,
1589,
13,
9118,
13,
1361,
13,
1422,
13,
264,
908,
13,
1662,
13,
1652,
13,
1199,
267,
327,
880,
8437,
370,
4692,
12,
2198,
465,
4692,
334,
2168,
8139,
9,
2066,
8437,
267,
327,
465,
4692,
334,
9118,
870,
9,
267,
3819,
63,
889,
63,
8506,
275,
7559,
14,
13521,
8,
288,
7559,
14,
14028,
8,
1047,
12,
2644,
534,
1624,
13,
24,
659,
288,
1798,
29,
9464,
14,
4317,
2842,
8,
2991,
534,
1624,
13,
24,
297,
2813,
63,
2500,
63,
505,
29,
549,
430,
267,
372,
7559,
14,
14028,
8,
288,
3819,
63,
889,
63,
8506,
12,
2644,
534,
2975,
297,
7268,
63,
1361,
29,
549,
9,
339,
347,
3350,
63,
1047,
63,
2792,
8,
277,
12,
2467,
12,
1747,
12,
2455,
63,
344,
12,
3420,
63,
8006,
12,
8343,
12,
1067,
29,
403,
304,
267,
327,
314,
1738,
402,
314,
3819,
3420,
9296,
1133,
5965,
506,
8717,
465,
652,
1159,
267,
327,
440,
7710,
14783,
6337,
12,
1454,
314,
1564,
5651,
21797,
365,
14783,
14,
398,
359,
1345,
61,
275,
291,
14,
4570,
8,
1556,
12,
1747,
12,
359,
1345,
63,
344,
467,
1067,
29,
1100,
9,
267,
3819,
275,
7559,
14,
13521,
8,
1345,
14,
1047,
14,
2143,
360,
1624,
13,
24,
1333,
267,
327,
9265,
664,
314,
8343,
1738,
267,
340,
440,
3420,
63,
8006,
26,
288,
1738,
275,
3819,
267,
587,
26,
288,
327,
4868,
2337,
1159,
1454,
1373,
1336,
288,
359,
1231,
61,
275,
3819,
14,
8006,
8,
2792,
63,
8006,
9,
398,
1738,
14,
505,
275,
8343,
14,
505,
267,
1738,
14,
1521,
275,
8343,
14,
1521,
267,
327,
3350,
1006,
4978,
267,
2150,
1738,
5873,
267,
367,
1982,
315,
8343,
26,
288,
1738,
14,
740,
8,
1574,
14,
8293,
8,
1739,
430,
398,
372,
3819,
339,
347,
370,
63,
698,
63,
1121,
8,
277,
12,
2467,
12,
1747,
12,
579,
12,
1067,
29,
403,
304,
267,
327,
2457,
734,
3404,
13,
11697,
11788,
315,
314,
2213,
267,
3004,
275,
1211,
1332,
75,
12,
373,
9,
367,
1022,
12,
373,
315,
579,
14,
1744,
342,
2079,
340,
440,
1022,
14,
2460,
360,
576,
13,
13361,
13,
1333,
267,
3004,
459,
84,
13,
698,
418,
275,
579,
14,
362,
360,
576,
13,
13361,
13,
5599,
358,
398,
734,
275,
3517,
14,
1360,
63,
2087,
14,
1875,
2108,
8,
352,
14,
1450,
12,
14399,
29,
2987,
9,
267,
734,
14,
1521,
275,
579,
14,
1521,
267,
372,
734,
339,
347,
3354,
8,
277,
12,
2467,
12,
1747,
12,
522,
63,
344,
12,
574,
12,
14462,
29,
403,
12,
1067,
29,
403,
304,
267,
408,
6162,
282,
2455,
3420,
14,
710,
2455,
3420,
1443,
6441,
1504,
370,
2218,
398,
520,
635,
620,
1402,
26,
267,
520,
635,
1109,
522,
63,
344,
26,
267,
520,
635,
620,
14462,
26,
1686,
14462,
370,
314,
1947,
370,
3350,
267,
408,
267,
522,
63,
344,
275,
1109
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
646,
1331,
199,
646,
5166,
199,
504,
5166,
14,
3924,
492,
11003,
547,
199,
504,
5166,
14,
4795,
492,
9506,
199,
504,
14490,
492,
7559,
12,
3517,
199,
504,
5166,
492,
2986,
421,
199,
533,
2455,
8,
4795,
14,
4795,
304,
272,
485,
6486,
275,
283,
723,
14,
1907,
14,
1345,
7,
339,
768,
1246,
14,
1556,
63,
1535,
63,
1580,
63,
1100,
272,
347,
3795,
8,
277,
12,
2467,
12,
1747,
12,
1305,
63,
269,
63,
1652,
63,
344,
12,
1338,
29,
403,
12,
6869,
534,
723,
14,
22600,
297,
1067,
29,
403,
304,
267,
340,
440,
1338,
26,
288,
1338,
275,
1052,
267,
340,
1338,
14,
362,
360,
10820,
735,
288,
862,
26,
355,
340,
440,
1228,
8,
344,
63,
269,
63,
1652,
63,
344,
12,
334,
442,
12,
1846,
2298,
490,
340,
7815,
440,
315,
1305,
63,
269,
63,
1652,
63,
344,
26,
717,
746,
1722,
360,
3364,
1978,
1305,
26,
450,
82,
7,
450,
334,
344,
63,
269,
63,
1652,
63,
344,
4641,
490,
1305,
63,
269,
63,
1652,
63,
344,
275,
291,
14,
362,
63,
1345,
63,
344,
8,
1556,
12,
1747,
12,
1305,
63,
269,
63,
1652,
63,
344,
12,
1067,
29,
1100,
9,
2234,
291,
14,
1074,
63,
2732,
63,
2200,
8,
1556,
12,
1747,
12,
359,
344,
63,
269,
63,
1652,
63,
344,
467,
283,
952,
297,
1067,
29,
1100,
9,
953,
871,
11003,
547,
26,
355,
1338,
459,
10820,
418,
275,
756,
398,
372,
1613,
8,
1345,
12,
291,
680,
3352,
8,
1556,
12,
1747,
12,
1305,
63,
269,
63,
1652,
63,
344,
12,
1338,
29,
1459,
12,
6869,
29,
3908,
12,
1067,
29,
1100,
9,
339,
27721,
8648,
272,
327,
11063,
687,
3517,
272,
27721,
8648,
339,
347,
5536,
63,
18757,
63,
955,
8,
277,
12,
2467,
12,
1747,
12,
3819,
12,
1067,
29,
403,
304,
267,
372,
3819,
14,
8006,
15079,
10,
14251,
576,
13,
13361,
13,
1238,
1137,
298,
723,
14,
1907,
14,
1345,
937,
358,
339,
347,
3354,
63,
18757,
63,
698,
8,
277,
12,
2467,
12,
1747,
12,
579,
12,
1067,
29,
403,
304,
267,
5822,
275,
291,
14,
2293,
59,
352,
14,
362,
360,
576,
13,
13361,
13,
1238,
5440,
267,
901,
275,
579,
14,
362,
360,
576,
13,
13361,
13,
698,
358,
398,
11109,
275,
291,
14,
2293,
459,
723,
14,
22600,
2278,
362,
63,
11256,
63,
509,
8,
352,
14,
362,
360,
576,
13,
13361,
13,
466,
1333,
267,
574,
275,
11109,
14,
504,
63,
1360,
8,
1556,
12,
1747,
12,
5822,
12,
5822,
423,
955,
59,
698,
467,
579,
9,
398,
340,
574,
365,
440,
488,
26,
288,
327,
3254,
26,
3522,
14511,
31,
288,
5822,
14,
952,
8,
1556,
12,
1747,
12,
359,
442,
8,
352,
14,
362,
360,
576,
13,
13361,
13,
344,
1333,
467,
469,
355,
901,
26,
574,
288,
1660,
1067,
29,
1100,
9,
339,
347,
485,
9118,
63,
1047,
8,
277,
12,
3819,
304,
267,
327,
2813,
63,
2500,
63,
875,
1630,
440,
17021,
370,
1736,
641,
24581,
12,
436,
267,
327,
7268,
13,
26514,
543,
14490,
1655,
503,
6656,
5074,
4024,
3637,
267,
327,
8139,
26,
1455,
921,
22899,
14,
271,
15,
2078,
49,
14,
1360,
3,
26460,
13,
30977,
13,
84,
13,
1589,
13,
9118,
13,
1361,
13,
1422,
13,
264,
908,
13,
1662,
13,
1652,
13,
1199,
267,
327,
880,
8437,
370,
4692,
12,
2198,
465,
4692,
334,
2168,
8139,
9,
2066,
8437,
267,
327,
465,
4692,
334,
9118,
870,
9,
267,
3819,
63,
889,
63,
8506,
275,
7559,
14,
13521,
8,
288,
7559,
14,
14028,
8,
1047,
12,
2644,
534,
1624,
13,
24,
659,
288,
1798,
29,
9464,
14,
4317,
2842,
8,
2991,
534,
1624,
13,
24,
297,
2813,
63,
2500,
63,
505,
29,
549,
430,
267,
372,
7559,
14,
14028,
8,
288,
3819,
63,
889,
63,
8506,
12,
2644,
534,
2975,
297,
7268,
63,
1361,
29,
549,
9,
339,
347,
3350,
63,
1047,
63,
2792,
8,
277,
12,
2467,
12,
1747,
12,
2455,
63,
344,
12,
3420,
63,
8006,
12,
8343,
12,
1067,
29,
403,
304,
267,
327,
314,
1738,
402,
314,
3819,
3420,
9296,
1133,
5965,
506,
8717,
465,
652,
1159,
267,
327,
440,
7710,
14783,
6337,
12,
1454,
314,
1564,
5651,
21797,
365,
14783,
14,
398,
359,
1345,
61,
275,
291,
14,
4570,
8,
1556,
12,
1747,
12,
359,
1345,
63,
344,
467,
1067,
29,
1100,
9,
267,
3819,
275,
7559,
14,
13521,
8,
1345,
14,
1047,
14,
2143,
360,
1624,
13,
24,
1333,
267,
327,
9265,
664,
314,
8343,
1738,
267,
340,
440,
3420,
63,
8006,
26,
288,
1738,
275,
3819,
267,
587,
26,
288,
327,
4868,
2337,
1159,
1454,
1373,
1336,
288,
359,
1231,
61,
275,
3819,
14,
8006,
8,
2792,
63,
8006,
9,
398,
1738,
14,
505,
275,
8343,
14,
505,
267,
1738,
14,
1521,
275,
8343,
14,
1521,
267,
327,
3350,
1006,
4978,
267,
2150,
1738,
5873,
267,
367,
1982,
315,
8343,
26,
288,
1738,
14,
740,
8,
1574,
14,
8293,
8,
1739,
430,
398,
372,
3819,
339,
347,
370,
63,
698,
63,
1121,
8,
277,
12,
2467,
12,
1747,
12,
579,
12,
1067,
29,
403,
304,
267,
327,
2457,
734,
3404,
13,
11697,
11788,
315,
314,
2213,
267,
3004,
275,
1211,
1332,
75,
12,
373,
9,
367,
1022,
12,
373,
315,
579,
14,
1744,
342,
2079,
340,
440,
1022,
14,
2460,
360,
576,
13,
13361,
13,
1333,
267,
3004,
459,
84,
13,
698,
418,
275,
579,
14,
362,
360,
576,
13,
13361,
13,
5599,
358,
398,
734,
275,
3517,
14,
1360,
63,
2087,
14,
1875,
2108,
8,
352,
14,
1450,
12,
14399,
29,
2987,
9,
267,
734,
14,
1521,
275,
579,
14,
1521,
267,
372,
734,
339,
347,
3354,
8,
277,
12,
2467,
12,
1747,
12,
522,
63,
344,
12,
574,
12,
14462,
29,
403,
12,
1067,
29,
403,
304,
267,
408,
6162,
282,
2455,
3420,
14,
710,
2455,
3420,
1443,
6441,
1504,
370,
2218,
398,
520,
635,
620,
1402,
26,
267,
520,
635,
1109,
522,
63,
344,
26,
267,
520,
635,
620,
14462,
26,
1686,
14462,
370,
314,
1947,
370,
3350,
267,
408,
267,
522,
63,
344,
275,
1109,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
pavlova-marina/QGIS
|
python/plugins/processing/algs/qgis/Delaunay.py
|
8
|
4281
|
# -*- coding: utf-8 -*-
"""
***************************************************************************
Delaunay.py
---------------------
Date : August 2012
Copyright : (C) 2012 by Victor Olaya
Email : volayaf at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************
"""
__author__ = 'Victor Olaya'
__date__ = 'August 2012'
__copyright__ = '(C) 2012, Victor Olaya'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'
from sets import Set
from PyQt4.QtCore import QVariant
from qgis.core import QGis, QgsField, QgsFeatureRequest, QgsFeature, QgsGeometry, QgsPoint
from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
from processing.tools import dataobjects, vector
from processing.core.parameters import ParameterVector
from processing.core.outputs import OutputVector
import voronoi
class Delaunay(GeoAlgorithm):
INPUT = 'INPUT'
OUTPUT = 'OUTPUT'
def defineCharacteristics(self):
self.name = 'Delaunay triangulation'
self.group = 'Vector geometry tools'
self.addParameter(ParameterVector(self.INPUT,
self.tr('Input layer'), [ParameterVector.VECTOR_TYPE_POINT]))
self.addOutput(OutputVector(self.OUTPUT,
self.tr('Delaunay triangulation')))
def processAlgorithm(self, progress):
layer = dataobjects.getObjectFromUri(
self.getParameterValue(self.INPUT))
fields = [QgsField('POINTA', QVariant.Double, '', 24, 15),
QgsField('POINTB', QVariant.Double, '', 24, 15),
QgsField('POINTC', QVariant.Double, '', 24, 15)]
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(fields,
QGis.WKBPolygon, layer.crs())
pts = []
ptDict = {}
ptNdx = -1
c = voronoi.Context()
features = vector.features(layer)
for inFeat in features:
geom = QgsGeometry(inFeat.geometry())
point = geom.asPoint()
x = point.x()
y = point.y()
pts.append((x, y))
ptNdx += 1
ptDict[ptNdx] = inFeat.id()
if len(pts) < 3:
raise GeoAlgorithmExecutionException(
self.tr('Input file should contain at least 3 points. Choose '
'another file and try again.'))
uniqueSet = Set(item for item in pts)
ids = [pts.index(item) for item in uniqueSet]
sl = voronoi.SiteList([voronoi.Site(*i) for i in uniqueSet])
c.triangulate = True
voronoi.voronoi(sl, c)
triangles = c.triangles
feat = QgsFeature()
current = 0
total = 100.0 / float(len(triangles))
for triangle in triangles:
indicies = list(triangle)
indicies.append(indicies[0])
polygon = []
attrs = []
step = 0
for index in indicies:
request = QgsFeatureRequest().setFilterFid(ptDict[ids[index]])
inFeat = layer.getFeatures(request).next()
geom = QgsGeometry(inFeat.geometry())
point = QgsPoint(geom.asPoint())
polygon.append(point)
if step <= 3:
attrs.append(ids[index])
step += 1
feat.setAttributes(attrs)
geometry = QgsGeometry().fromPolygon([polygon])
feat.setGeometry(geometry)
writer.addFeature(feat)
current += 1
progress.setPercentage(int(current * total))
del writer
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
199,
17623,
272,
18464,
65,
324,
1187,
14,
647,
272,
10652,
9858,
272,
6148,
463,
520,
25298,
833,
6029,
272,
1898,
3322,
520,
334,
35,
9,
6029,
701,
6561,
630,
593,
817,
65,
272,
11426,
4483,
520,
5236,
1187,
2756,
737,
29712,
6308,
2414,
199,
17623,
199,
10,
17997,
627,
199,
10,
257,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
221,
627,
199,
10,
257,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
221,
627,
199,
10,
257,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
258,
627,
199,
10,
257,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
15530,
627,
199,
10,
17997,
627,
199,
17623,
199,
624,
199,
199,
363,
2502,
363,
275,
283,
2201,
630,
593,
817,
65,
7,
199,
363,
602,
363,
275,
283,
21640,
833,
6029,
7,
199,
363,
7307,
363,
275,
8189,
35,
9,
6029,
12,
6561,
630,
593,
817,
65,
7,
199,
199,
3,
961,
911,
664,
8717,
543,
282,
6135,
12002,
17,
1380,
1265,
886,
282,
6135,
6359,
199,
199,
363,
5792,
363,
275,
4505,
3484,
2689,
40,
12913,
199,
199,
504,
5951,
492,
2494,
199,
504,
14084,
20,
14,
10901,
492,
27875,
199,
504,
15640,
14,
1018,
492,
1413,
39,
374,
12,
4888,
792,
12,
26833,
2017,
12,
26833,
12,
4888,
6831,
12,
4888,
3428,
199,
504,
6661,
14,
1018,
14,
10748,
11570,
492,
8875,
11570,
199,
504,
6661,
14,
1018,
14,
10748,
11570,
11310,
1726,
492,
8875,
11570,
11310,
1726,
199,
504,
6661,
14,
2537,
492,
666,
1462,
12,
5477,
199,
504,
6661,
14,
1018,
14,
3214,
492,
12009,
3646,
199,
504,
6661,
14,
1018,
14,
4467,
492,
7242,
3646,
199,
646,
373,
269,
265,
16142,
421,
199,
533,
18464,
65,
324,
1187,
8,
10748,
11570,
304,
339,
21955,
275,
283,
7321,
7,
272,
18746,
275,
283,
8414,
7,
339,
347,
5627,
1610,
29867,
8,
277,
304,
267,
291,
14,
354,
275,
283,
6994,
65,
324,
1187,
3229,
621,
5332,
7,
267,
291,
14,
923,
275,
283,
3646,
3400,
7249,
7,
398,
291,
14,
26895,
8,
4720,
3646,
8,
277,
14,
7321,
12,
288,
291,
14,
454,
360,
3205,
4045,
659,
359,
4720,
3646,
14,
2524,
1028,
726,
63,
2711,
63,
7217,
2459,
398,
291,
14,
525,
2959,
8,
2959,
3646,
8,
277,
14,
8414,
12,
288,
291,
14,
454,
360,
6994,
65,
324,
1187,
3229,
621,
5332,
7058,
339,
347,
2112,
11570,
8,
277,
12,
6696,
304,
267,
4045,
275,
666,
1462,
14,
362,
1692,
2532,
14014,
8,
288,
291,
14,
362,
24637,
8,
277,
14,
7321,
430,
398,
1504,
275,
359,
7350,
792,
360,
7217,
33,
297,
27875,
14,
7281,
12,
3260,
5504,
12,
4114,
395,
2116,
4888,
792,
360,
7217,
34,
297,
27875,
14,
7281,
12,
3260,
5504,
12,
4114,
395,
2116,
4888,
792,
360,
7217,
35,
297,
27875,
14,
7281,
12,
3260,
5504,
12,
4114,
1874,
398,
7060,
275,
291,
14,
362,
2959,
2532,
985,
8,
277,
14,
8414,
680,
362,
3646,
6261,
8,
955,
12,
355,
1413,
39,
374,
14,
28328,
12367,
12,
4045,
14,
19034,
1012,
398,
21286,
275,
942,
267,
10063,
2141,
275,
1052,
267,
10063,
46,
8373,
275,
446,
17,
267,
286,
275,
373,
269,
265,
16142,
14,
2998,
342,
267,
4534,
275,
5477,
14,
3179,
8,
1897,
9,
267,
367,
315,
24927,
315,
4534,
26,
288,
9671,
275,
4888,
6831,
8,
262,
24927,
14,
7660,
1012,
288,
2376,
275,
9671,
14,
305,
3428,
342,
288,
671,
275,
2376,
14,
88,
342,
288,
612,
275,
2376,
14,
89,
342,
288,
21286,
14,
740,
1332,
88,
12,
612,
430,
288,
10063,
46,
8373,
847,
413,
288,
10063,
2141,
59,
541,
46,
8373,
61,
275,
315,
24927,
14,
344,
342,
398,
340,
822,
8,
8382,
9,
665,
650,
26,
288,
746,
8875,
11570,
11310,
1726,
8,
355,
291,
14,
454,
360,
3205,
570,
1077,
1395,
737,
5210,
650,
4501,
14,
29826,
283,
717,
283,
13565,
570,
436,
862,
4020,
12459,
398,
3747,
1084,
275,
2494,
8,
1053,
367,
1242,
315,
21286,
9,
267,
2762,
275,
359,
8382,
14,
1080,
8,
1053,
9,
367,
1242,
315,
3747,
1084,
61,
267,
5340,
275,
373,
269,
265,
16142,
14,
8972,
1296,
779,
14419,
265,
16142,
14,
8972,
2031,
73,
9,
367,
284,
315,
3747,
1084,
566,
267,
286,
14,
599,
621,
5434,
275,
715,
267,
373,
269,
265,
16142,
14,
14419,
265,
16142,
8,
2482,
12,
286,
9,
267,
3229,
13162,
275,
286,
14,
599,
13162,
267,
13953,
275,
26833,
342,
398,
1453,
275,
378,
267,
3141,
275,
2948,
14,
16,
1182,
2069,
8,
552,
8,
599,
13162,
430,
398,
367,
26268,
315,
3229,
13162,
26,
288,
2539,
2578,
275,
769,
8,
21584,
9,
288,
2539,
2578,
14,
740,
8,
3558,
2578,
59,
16,
566,
288,
17248,
275,
942,
288,
3290,
275,
942,
288,
3650,
275,
378,
288,
367,
1478,
315,
2539,
2578,
26,
355,
1056,
275,
26833,
2017,
1252,
409,
4131,
38,
344,
8,
541,
2141,
59,
1580,
59,
1080,
3934,
355,
315,
24927,
275,
4045,
14,
362,
10807,
8,
1069,
680,
2184,
342,
355,
9671,
275,
4888,
6831,
8,
262,
24927,
14,
7660,
1012,
355,
2376,
275,
4888,
3428,
8,
6481,
14,
305,
3428,
1012,
355,
17248,
14,
740,
8,
1403,
9,
355,
340,
3650,
2695,
650,
26,
490,
3290,
14,
740,
8,
1580,
59,
1080,
566,
355,
3650,
847,
413,
288,
13953,
14,
31674,
8,
3288,
9,
288,
3400,
275,
4888,
6831,
1252,
504,
12367,
779,
16295,
566,
288,
13953,
14,
25559,
8,
7660,
9,
288,
7060,
14,
525,
5968,
8,
11873,
9,
288,
1453,
847,
413,
288,
6696,
14,
409,
17931,
474,
8,
442,
8,
1818,
627,
3141,
430,
398,
2150,
7060,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
199,
17623,
272,
18464,
65,
324,
1187,
14,
647,
272,
10652,
9858,
272,
6148,
463,
520,
25298,
833,
6029,
272,
1898,
3322,
520,
334,
35,
9,
6029,
701,
6561,
630,
593,
817,
65,
272,
11426,
4483,
520,
5236,
1187,
2756,
737,
29712,
6308,
2414,
199,
17623,
199,
10,
17997,
627,
199,
10,
257,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
221,
627,
199,
10,
257,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
221,
627,
199,
10,
257,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
258,
627,
199,
10,
257,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
15530,
627,
199,
10,
17997,
627,
199,
17623,
199,
624,
199,
199,
363,
2502,
363,
275,
283,
2201,
630,
593,
817,
65,
7,
199,
363,
602,
363,
275,
283,
21640,
833,
6029,
7,
199,
363,
7307,
363,
275,
8189,
35,
9,
6029,
12,
6561,
630,
593,
817,
65,
7,
199,
199,
3,
961,
911,
664,
8717,
543,
282,
6135,
12002,
17,
1380,
1265,
886,
282,
6135,
6359,
199,
199,
363,
5792,
363,
275,
4505,
3484,
2689,
40,
12913,
199,
199,
504,
5951,
492,
2494,
199,
504,
14084,
20,
14,
10901,
492,
27875,
199,
504,
15640,
14,
1018,
492,
1413,
39,
374,
12,
4888,
792,
12,
26833,
2017,
12,
26833,
12,
4888,
6831,
12,
4888,
3428,
199,
504,
6661,
14,
1018,
14,
10748,
11570,
492,
8875,
11570,
199,
504,
6661,
14,
1018,
14,
10748,
11570,
11310,
1726,
492,
8875,
11570,
11310,
1726,
199,
504,
6661,
14,
2537,
492,
666,
1462,
12,
5477,
199,
504,
6661,
14,
1018,
14,
3214,
492,
12009,
3646,
199,
504,
6661,
14,
1018,
14,
4467,
492,
7242,
3646,
199,
646,
373,
269,
265,
16142,
421,
199,
533,
18464,
65,
324,
1187,
8,
10748,
11570,
304,
339,
21955,
275,
283,
7321,
7,
272,
18746,
275,
283,
8414,
7,
339,
347,
5627,
1610,
29867,
8,
277,
304,
267,
291,
14,
354,
275,
283,
6994,
65,
324,
1187,
3229,
621,
5332,
7,
267,
291,
14,
923,
275,
283,
3646,
3400,
7249,
7,
398,
291,
14,
26895,
8,
4720,
3646,
8,
277,
14,
7321,
12,
288,
291,
14,
454,
360,
3205,
4045,
659,
359,
4720,
3646,
14,
2524,
1028,
726,
63,
2711,
63,
7217,
2459,
398,
291,
14,
525,
2959,
8,
2959,
3646,
8,
277,
14,
8414,
12,
288,
291,
14,
454,
360,
6994,
65,
324,
1187,
3229,
621,
5332,
7058,
339,
347,
2112,
11570,
8,
277,
12,
6696,
304,
267,
4045,
275,
666,
1462,
14,
362,
1692,
2532,
14014,
8,
288,
291,
14,
362,
24637,
8,
277,
14,
7321,
430,
398,
1504,
275,
359,
7350,
792,
360,
7217,
33,
297,
27875,
14,
7281,
12,
3260,
5504,
12,
4114,
395,
2116,
4888,
792,
360,
7217,
34,
297,
27875,
14,
7281,
12,
3260,
5504,
12,
4114,
395,
2116,
4888,
792,
360,
7217,
35,
297,
27875,
14,
7281,
12,
3260,
5504,
12,
4114,
1874,
398,
7060,
275,
291,
14,
362,
2959,
2532,
985,
8,
277,
14,
8414,
680,
362,
3646,
6261,
8,
955,
12,
355,
1413,
39,
374,
14,
28328,
12367,
12,
4045,
14,
19034,
1012,
398,
21286,
275,
942,
267,
10063,
2141,
275,
1052,
267,
10063,
46,
8373,
275,
446,
17,
267,
286,
275,
373,
269,
265,
16142,
14,
2998,
342,
267,
4534,
275,
5477,
14,
3179,
8,
1897,
9,
267,
367,
315,
24927,
315,
4534,
26,
288,
9671,
275,
4888,
6831,
8,
262,
24927,
14,
7660,
1012,
288,
2376,
275,
9671,
14,
305,
3428,
342,
288,
671,
275,
2376,
14,
88,
342,
288,
612,
275,
2376,
14,
89,
342,
288,
21286,
14,
740,
1332,
88,
12,
612,
430,
288,
10063,
46,
8373,
847,
413,
288,
10063,
2141,
59,
541,
46,
8373,
61,
275,
315,
24927,
14,
344,
342,
398,
340,
822,
8,
8382,
9,
665,
650,
26,
288,
746,
8875,
11570,
11310,
1726,
8,
355,
291,
14,
454,
360,
3205,
570,
1077,
1395,
737,
5210,
650,
4501,
14,
29826,
283,
717,
283,
13565,
570,
436,
862,
4020,
12459,
398,
3747,
1084,
275,
2494,
8,
1053,
367,
1242,
315,
21286,
9,
267,
2762,
275,
359,
8382,
14,
1080,
8,
1053,
9,
367,
1242,
315,
3747,
1084,
61,
267,
5340,
275,
373,
269,
265,
16142,
14,
8972,
1296,
779,
14419,
265,
16142,
14,
8972,
2031,
73,
9,
367,
284,
315,
3747,
1084,
566,
267,
286,
14,
599,
621,
5434,
275,
715,
267,
373,
269,
265,
16142,
14,
14419,
265,
16142,
8,
2482,
12,
286,
9,
267,
3229,
13162,
275,
286,
14,
599,
13162,
267,
13953,
275,
26833,
342,
398,
1453,
275,
378,
267,
3141,
275,
2948,
14,
16,
1182,
2069,
8,
552,
8,
599,
13162,
430,
398,
367,
26268,
315,
3229,
13162,
26,
288,
2539,
2578,
275,
769,
8,
21584,
9,
288,
2539,
2578,
14,
740,
8,
3558,
2578,
59,
16,
566,
288,
17248,
275,
942,
288,
3290,
275,
942,
288,
3650,
275,
378,
288,
367,
1478,
315,
2539,
2578,
26,
355,
1056,
275,
26833,
2017,
1252,
409,
4131,
38,
344,
8,
541,
2141,
59,
1580,
59,
1080,
3934,
355,
315,
24927,
275,
4045,
14,
362,
10807,
8,
1069,
680,
2184,
342,
355,
9671,
275,
4888,
6831,
8,
262,
24927,
14,
7660,
1012,
355,
2376,
275,
4888,
3428,
8,
6481,
14,
305,
3428,
1012,
355,
17248,
14,
740,
8,
1403,
9,
355,
340,
3650,
2695,
650,
26,
490,
3290,
14,
740,
8,
1580,
59,
1080,
566,
355,
3650,
847,
413,
288,
13953,
14,
31674,
8,
3288,
9,
288,
3400,
275,
4888,
6831,
1252,
504,
12367,
779,
16295,
566,
288,
13953,
14,
25559,
8,
7660,
9,
288,
7060,
14,
525,
5968,
8,
11873,
9,
288,
1453,
847,
413,
288,
6696,
14,
409,
17931,
474,
8,
442,
8,
1818,
627,
3141,
430,
398,
2150,
7060,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
chippey/gaffer
|
python/GafferTest/UndoTest.py
|
1
|
5828
|
##########################################################################
#
# Copyright (c) 2011-2012, John Haddon. All rights reserved.
# Copyright (c) 2011-2013, Image Engine Design Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above
# copyright notice, this list of conditions and the following
# disclaimer.
#
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided with
# the distribution.
#
# * Neither the name of John Haddon nor the names of
# any other contributors to this software may be used to endorse or
# promote products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
##########################################################################
from __future__ import with_statement
import unittest
import IECore
import Gaffer
import GafferTest
class UndoTest( GafferTest.TestCase ) :
def testSetName( self ) :
s = Gaffer.ScriptNode()
self.assertEqual( s.undoAvailable(), False )
self.assertEqual( s.redoAvailable(), False )
self.assertRaises( Exception, s.undo )
n = Gaffer.Node()
s["a"] = n
self.assertEqual( n.getName(), "a" )
n.setName( "b" )
self.assertEqual( n.getName(), "b" )
self.assertEqual( s.undoAvailable(), False )
self.assertEqual( s.redoAvailable(), False )
self.assertRaises( Exception, s.undo )
with Gaffer.UndoContext( s ) :
n.setName( "c" )
self.assertEqual( s.undoAvailable(), True )
self.assertEqual( s.redoAvailable(), False )
s.undo()
self.assertEqual( s.undoAvailable(), False )
self.assertEqual( s.redoAvailable(), True )
self.assertEqual( n.getName(), "b" )
s.redo()
self.assertEqual( s.undoAvailable(), True )
self.assertEqual( s.redoAvailable(), False )
self.assertEqual( n.getName(), "c" )
self.assertRaises( Exception, s.redo )
def testSetInput( self ) :
s = Gaffer.ScriptNode()
n1 = GafferTest.AddNode()
n2 = GafferTest.AddNode()
s["n1"] = n1
s["n2"] = n2
with Gaffer.UndoContext( s ) :
n1["op1"].setInput( n2["sum"] )
self.assert_( n1["op1"].getInput().isSame( n2["sum"] ) )
s.undo()
self.assertEqual( n1["op1"].getInput(), None )
s.redo()
self.assert_( n1["op1"].getInput().isSame( n2["sum"] ) )
def testChildren( self ) :
s = Gaffer.ScriptNode()
n = Gaffer.Node()
self.assertEqual( n.parent(), None )
with Gaffer.UndoContext( s ) :
s["n"] = n
self.assert_( n.parent().isSame( s ) )
s.undo()
self.assertEqual( n.parent(), None )
s.redo()
self.assert_( n.parent().isSame( s ) )
def testDelete( self ) :
s = Gaffer.ScriptNode()
n1 = GafferTest.AddNode()
n2 = GafferTest.AddNode()
n3 = GafferTest.AddNode()
s.addChild( n1 )
s.addChild( n2 )
s.addChild( n3 )
n2["op1"].setInput( n1["sum"] )
n2["op2"].setInput( n1["sum"] )
n3["op1"].setInput( n2["sum"] )
n3["op2"].setInput( n2["sum"] )
self.assert_( n2["op1"].getInput().isSame( n1["sum"] ) )
self.assert_( n2["op2"].getInput().isSame( n1["sum"] ) )
self.assert_( n3["op1"].getInput().isSame( n2["sum"] ) )
self.assert_( n3["op2"].getInput().isSame( n2["sum"] ) )
with Gaffer.UndoContext( s ) :
s.deleteNodes( filter = Gaffer.StandardSet( [ n2 ] ) )
self.assertEqual( n2["op1"].getInput(), None )
self.assertEqual( n2["op2"].getInput(), None )
self.assert_( n3["op1"].getInput().isSame( n1["sum"] ) )
self.assert_( n3["op2"].getInput().isSame( n1["sum"] ) )
s.undo()
self.assert_( n2["op1"].getInput().isSame( n1["sum"] ) )
self.assert_( n2["op2"].getInput().isSame( n1["sum"] ) )
self.assert_( n3["op1"].getInput().isSame( n2["sum"] ) )
self.assert_( n3["op2"].getInput().isSame( n2["sum"] ) )
with Gaffer.UndoContext( s ) :
s.deleteNodes( filter = Gaffer.StandardSet( [ n2 ] ), reconnect = False )
self.assertEqual( n2["op1"].getInput(), None )
self.assertEqual( n2["op2"].getInput(), None )
self.assertEqual( n3["op1"].getInput(), None )
self.assertEqual( n3["op2"].getInput(), None )
s.undo()
self.assert_( n2["op1"].getInput().isSame( n1["sum"] ) )
self.assert_( n2["op2"].getInput().isSame( n1["sum"] ) )
self.assert_( n3["op1"].getInput().isSame( n2["sum"] ) )
self.assert_( n3["op2"].getInput().isSame( n2["sum"] ) )
def testDisable( self ) :
s = Gaffer.ScriptNode()
s["n"] = GafferTest.AddNode()
with Gaffer.UndoContext( s, Gaffer.UndoContext.State.Disabled ) :
s["n"]["op1"].setValue( 10 )
self.assertFalse( s.undoAvailable() )
with Gaffer.UndoContext( s, Gaffer.UndoContext.State.Enabled ) :
with Gaffer.UndoContext( s, Gaffer.UndoContext.State.Disabled ) :
s["n"]["op1"].setValue( 20 )
self.assertFalse( s.undoAvailable() )
if __name__ == "__main__":
unittest.main()
|
bsd-3-clause
|
[
26863,
199,
3,
199,
3,
221,
1898,
334,
67,
9,
7760,
13,
7409,
12,
17815,
869,
9291,
14,
2900,
4481,
4644,
14,
199,
3,
221,
1898,
334,
67,
9,
7760,
13,
6965,
12,
6047,
12580,
29410,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
221,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
221,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
221,
7647,
26,
199,
3,
199,
3,
420,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
199,
3,
263,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
199,
3,
263,
6450,
14,
199,
3,
199,
3,
420,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
263,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
199,
3,
263,
6450,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
199,
3,
263,
314,
4084,
14,
199,
3,
199,
3,
420,
627,
11443,
314,
536,
402,
17815,
869,
9291,
6590,
314,
1561,
402,
199,
3,
263,
1263,
1163,
8417,
370,
642,
2032,
1443,
506,
1202,
370,
10692,
503,
199,
3,
263,
10016,
7585,
7131,
687,
642,
2032,
1928,
2488,
6791,
199,
3,
263,
5313,
4983,
14,
199,
3,
199,
3,
221,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
298,
1179,
199,
3,
221,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
199,
3,
221,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
199,
3,
221,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
11489,
1549,
199,
3,
221,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
8820,
12,
199,
3,
221,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
199,
3,
221,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
199,
3,
221,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
1634,
199,
3,
221,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
334,
6446,
199,
3,
221,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
199,
3,
221,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
3,
199,
26863,
199,
199,
504,
636,
2443,
363,
492,
543,
63,
6242,
199,
199,
646,
2882,
199,
199,
646,
14707,
199,
646,
16600,
199,
646,
16600,
774,
199,
199,
533,
738,
21175,
774,
8,
16600,
774,
14,
1746,
776,
520,
421,
198,
318,
511,
1084,
985,
8,
291,
776,
520,
2742,
198,
83,
275,
16600,
14,
5229,
1716,
342,
507,
198,
277,
14,
629,
8,
308,
14,
11833,
11464,
1062,
756,
776,
507,
198,
277,
14,
629,
8,
308,
14,
30938,
11464,
1062,
756,
776,
507,
198,
277,
14,
1855,
8,
2186,
12,
308,
14,
11833,
776,
2742,
198,
78,
275,
16600,
14,
1716,
342,
2742,
198,
83,
905,
65,
937,
275,
302,
507,
198,
277,
14,
629,
8,
302,
14,
16405,
1062,
298,
65,
2,
776,
2742,
198,
78,
14,
18347,
8,
298,
66,
2,
776,
507,
198,
277,
14,
629,
8,
302,
14,
16405,
1062,
298,
66,
2,
776,
507,
198,
277,
14,
629,
8,
308,
14,
11833,
11464,
1062,
756,
776,
507,
198,
277,
14,
629,
8,
308,
14,
30938,
11464,
1062,
756,
776,
507,
198,
277,
14,
1855,
8,
2186,
12,
308,
14,
11833,
776,
2742,
198,
1045,
16600,
14,
29832,
2998,
8,
308,
776,
520,
686,
198,
78,
14,
18347,
8,
298,
67,
2,
776,
2742,
198,
277,
14,
629,
8,
308,
14,
11833,
11464,
1062,
715,
776,
507,
198,
277,
14,
629,
8,
308,
14,
30938,
11464,
1062,
756,
776,
507,
198,
83,
14,
11833,
342,
507,
198,
277,
14,
629,
8,
308,
14,
11833,
11464,
1062,
756,
776,
507,
198,
277,
14,
629,
8,
308,
14,
30938,
11464,
1062,
715,
776,
507,
198,
277,
14,
629,
8,
302,
14,
16405,
1062,
298,
66,
2,
776,
2742,
198,
83,
14,
30938,
342,
507,
198,
277,
14,
629,
8,
308,
14,
11833,
11464,
1062,
715,
776,
507,
198,
277,
14,
629,
8,
308,
14,
30938,
11464,
1062,
756,
776,
507,
198,
277,
14,
629,
8,
302,
14,
16405,
1062,
298,
67,
2,
776,
507,
198,
277,
14,
1855,
8,
2186,
12,
308,
14,
30938,
776,
421,
198,
318,
511,
24029,
8,
291,
776,
520,
2742,
198,
83,
275,
16600,
14,
5229,
1716,
342,
2742,
198,
78,
17,
275,
16600,
774,
14,
1123,
1716,
342,
507,
198,
78,
18,
275,
16600,
774,
14,
1123,
1716,
342,
2742,
198,
83,
905,
78,
17,
937,
275,
302,
17,
507,
198,
83,
905,
78,
18,
937,
275,
302,
18,
2742,
198,
1045,
16600,
14,
29832,
2998,
8,
308,
776,
520,
686,
198,
78,
17,
905,
411,
17,
4140,
409,
3205,
8,
302,
18,
905,
1838,
937,
776,
2742,
198,
277,
14,
479,
2531,
302,
17,
905,
411,
17,
4140,
362,
3205,
1252,
374,
8479,
8,
302,
18,
905,
1838,
937,
776,
776,
2742,
198,
83,
14,
11833,
342,
507,
198,
277,
14,
629,
8,
302,
17,
905,
411,
17,
4140,
362,
3205,
1062,
488,
776,
2742,
198,
83,
14,
30938,
342,
507,
198,
277,
14,
479,
2531,
302,
17,
905,
411,
17,
4140,
362,
3205,
1252,
374,
8479,
8,
302,
18,
905,
1838,
937,
776,
776,
421,
198,
318,
511,
7139,
8,
291,
776,
520,
2742,
198,
83,
275,
16600,
14,
5229,
1716,
342,
507,
198,
78,
275,
16600,
14,
1716,
342,
2742,
198,
277,
14,
629,
8,
302,
14,
1708,
1062,
488,
776,
2742,
198,
1045,
16600,
14,
29832,
2998,
8,
308,
776,
520,
686,
198,
83,
905,
78,
937,
275,
302,
507,
198,
277,
14,
479,
2531,
302,
14,
1708,
1252,
374,
8479,
8,
308,
776,
776,
507,
198,
83,
14,
11833,
342,
507,
198,
277,
14,
629,
8,
302,
14,
1708,
1062,
488,
776,
507,
198,
83,
14,
30938,
342,
507,
198,
277,
14,
479,
2531,
302,
14,
1708,
1252,
374,
8479,
8,
308,
776,
776,
421,
198,
318,
511,
5392,
8,
291,
776,
520,
2742,
198,
83,
275,
16600,
14,
5229,
1716,
342,
507
] |
[
199,
3,
199,
3,
221,
1898,
334,
67,
9,
7760,
13,
7409,
12,
17815,
869,
9291,
14,
2900,
4481,
4644,
14,
199,
3,
221,
1898,
334,
67,
9,
7760,
13,
6965,
12,
6047,
12580,
29410,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
221,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
221,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
221,
7647,
26,
199,
3,
199,
3,
420,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
199,
3,
263,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
199,
3,
263,
6450,
14,
199,
3,
199,
3,
420,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
263,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
199,
3,
263,
6450,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
199,
3,
263,
314,
4084,
14,
199,
3,
199,
3,
420,
627,
11443,
314,
536,
402,
17815,
869,
9291,
6590,
314,
1561,
402,
199,
3,
263,
1263,
1163,
8417,
370,
642,
2032,
1443,
506,
1202,
370,
10692,
503,
199,
3,
263,
10016,
7585,
7131,
687,
642,
2032,
1928,
2488,
6791,
199,
3,
263,
5313,
4983,
14,
199,
3,
199,
3,
221,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
298,
1179,
199,
3,
221,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
199,
3,
221,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
199,
3,
221,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
11489,
1549,
199,
3,
221,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
8820,
12,
199,
3,
221,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
199,
3,
221,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
199,
3,
221,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
1634,
199,
3,
221,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
334,
6446,
199,
3,
221,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
199,
3,
221,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
3,
199,
26863,
199,
199,
504,
636,
2443,
363,
492,
543,
63,
6242,
199,
199,
646,
2882,
199,
199,
646,
14707,
199,
646,
16600,
199,
646,
16600,
774,
199,
199,
533,
738,
21175,
774,
8,
16600,
774,
14,
1746,
776,
520,
421,
198,
318,
511,
1084,
985,
8,
291,
776,
520,
2742,
198,
83,
275,
16600,
14,
5229,
1716,
342,
507,
198,
277,
14,
629,
8,
308,
14,
11833,
11464,
1062,
756,
776,
507,
198,
277,
14,
629,
8,
308,
14,
30938,
11464,
1062,
756,
776,
507,
198,
277,
14,
1855,
8,
2186,
12,
308,
14,
11833,
776,
2742,
198,
78,
275,
16600,
14,
1716,
342,
2742,
198,
83,
905,
65,
937,
275,
302,
507,
198,
277,
14,
629,
8,
302,
14,
16405,
1062,
298,
65,
2,
776,
2742,
198,
78,
14,
18347,
8,
298,
66,
2,
776,
507,
198,
277,
14,
629,
8,
302,
14,
16405,
1062,
298,
66,
2,
776,
507,
198,
277,
14,
629,
8,
308,
14,
11833,
11464,
1062,
756,
776,
507,
198,
277,
14,
629,
8,
308,
14,
30938,
11464,
1062,
756,
776,
507,
198,
277,
14,
1855,
8,
2186,
12,
308,
14,
11833,
776,
2742,
198,
1045,
16600,
14,
29832,
2998,
8,
308,
776,
520,
686,
198,
78,
14,
18347,
8,
298,
67,
2,
776,
2742,
198,
277,
14,
629,
8,
308,
14,
11833,
11464,
1062,
715,
776,
507,
198,
277,
14,
629,
8,
308,
14,
30938,
11464,
1062,
756,
776,
507,
198,
83,
14,
11833,
342,
507,
198,
277,
14,
629,
8,
308,
14,
11833,
11464,
1062,
756,
776,
507,
198,
277,
14,
629,
8,
308,
14,
30938,
11464,
1062,
715,
776,
507,
198,
277,
14,
629,
8,
302,
14,
16405,
1062,
298,
66,
2,
776,
2742,
198,
83,
14,
30938,
342,
507,
198,
277,
14,
629,
8,
308,
14,
11833,
11464,
1062,
715,
776,
507,
198,
277,
14,
629,
8,
308,
14,
30938,
11464,
1062,
756,
776,
507,
198,
277,
14,
629,
8,
302,
14,
16405,
1062,
298,
67,
2,
776,
507,
198,
277,
14,
1855,
8,
2186,
12,
308,
14,
30938,
776,
421,
198,
318,
511,
24029,
8,
291,
776,
520,
2742,
198,
83,
275,
16600,
14,
5229,
1716,
342,
2742,
198,
78,
17,
275,
16600,
774,
14,
1123,
1716,
342,
507,
198,
78,
18,
275,
16600,
774,
14,
1123,
1716,
342,
2742,
198,
83,
905,
78,
17,
937,
275,
302,
17,
507,
198,
83,
905,
78,
18,
937,
275,
302,
18,
2742,
198,
1045,
16600,
14,
29832,
2998,
8,
308,
776,
520,
686,
198,
78,
17,
905,
411,
17,
4140,
409,
3205,
8,
302,
18,
905,
1838,
937,
776,
2742,
198,
277,
14,
479,
2531,
302,
17,
905,
411,
17,
4140,
362,
3205,
1252,
374,
8479,
8,
302,
18,
905,
1838,
937,
776,
776,
2742,
198,
83,
14,
11833,
342,
507,
198,
277,
14,
629,
8,
302,
17,
905,
411,
17,
4140,
362,
3205,
1062,
488,
776,
2742,
198,
83,
14,
30938,
342,
507,
198,
277,
14,
479,
2531,
302,
17,
905,
411,
17,
4140,
362,
3205,
1252,
374,
8479,
8,
302,
18,
905,
1838,
937,
776,
776,
421,
198,
318,
511,
7139,
8,
291,
776,
520,
2742,
198,
83,
275,
16600,
14,
5229,
1716,
342,
507,
198,
78,
275,
16600,
14,
1716,
342,
2742,
198,
277,
14,
629,
8,
302,
14,
1708,
1062,
488,
776,
2742,
198,
1045,
16600,
14,
29832,
2998,
8,
308,
776,
520,
686,
198,
83,
905,
78,
937,
275,
302,
507,
198,
277,
14,
479,
2531,
302,
14,
1708,
1252,
374,
8479,
8,
308,
776,
776,
507,
198,
83,
14,
11833,
342,
507,
198,
277,
14,
629,
8,
302,
14,
1708,
1062,
488,
776,
507,
198,
83,
14,
30938,
342,
507,
198,
277,
14,
479,
2531,
302,
14,
1708,
1252,
374,
8479,
8,
308,
776,
776,
421,
198,
318,
511,
5392,
8,
291,
776,
520,
2742,
198,
83,
275,
16600,
14,
5229,
1716,
342,
507,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
simonwydooghe/ansible
|
lib/ansible/plugins/terminal/dellos10.py
|
125
|
2767
|
#
# (c) 2016 Red Hat Inc.
#
# This file is part of Ansible
#
# Copyright (c) 2017 Dell Inc.
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
#
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import re
import json
from ansible.module_utils._text import to_text, to_bytes
from ansible.plugins.terminal import TerminalBase
from ansible.errors import AnsibleConnectionFailure
class TerminalModule(TerminalBase):
terminal_stdout_re = [
re.compile(br"[\r\n]?[\w+\-\.:\/\[\]]+(?:\([^\)]+\)){,3}(?:#) ?$"),
re.compile(br"\[\w+\@[\w\-\.]+(?: [^\]])\] ?[>#\$] ?$")
]
terminal_stderr_re = [
re.compile(br"% ?Error"),
re.compile(br"% ?Bad secret"),
re.compile(br"Syntax error:"),
re.compile(br"invalid input", re.I),
re.compile(br"(?:incomplete|ambiguous) command", re.I),
re.compile(br"connection timed out", re.I),
re.compile(br"[^\r\n]+ not found", re.I),
re.compile(br"'[^']' +returned error code: ?\d+"),
]
def on_open_shell(self):
try:
self._exec_cli_command(b'terminal length 0')
except AnsibleConnectionFailure:
raise AnsibleConnectionFailure('unable to set terminal parameters')
def on_become(self, passwd=None):
if self._get_prompt().endswith(b'#'):
return
cmd = {u'command': u'enable'}
if passwd:
cmd[u'prompt'] = to_text(r"[\r\n]?password: $", errors='surrogate_or_strict')
cmd[u'answer'] = passwd
try:
self._exec_cli_command(to_bytes(json.dumps(cmd), errors='surrogate_or_strict'))
except AnsibleConnectionFailure:
raise AnsibleConnectionFailure('unable to elevate privilege to enable mode')
def on_unbecome(self):
prompt = self._get_prompt()
if prompt is None:
# if prompt is None most likely the terminal is hung up at a prompt
return
if prompt.strip().endswith(b')#'):
self._exec_cli_command(b'end')
self._exec_cli_command(b'disable')
elif prompt.endswith(b'#'):
self._exec_cli_command(b'disable')
|
gpl-3.0
|
[
3,
199,
3,
334,
67,
9,
7800,
9572,
13002,
3277,
14,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
1898,
334,
67,
9,
9708,
577,
1697,
3277,
14,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
646,
295,
199,
646,
2022,
199,
199,
504,
3242,
14,
578,
63,
1208,
423,
505,
492,
370,
63,
505,
12,
370,
63,
2394,
199,
504,
3242,
14,
5265,
14,
12010,
492,
20429,
279,
1563,
199,
504,
3242,
14,
2550,
492,
2622,
3225,
6782,
421,
199,
533,
20429,
279,
2377,
8,
22015,
1563,
304,
339,
11167,
63,
2703,
63,
264,
275,
359,
267,
295,
14,
2014,
8,
3289,
29354,
82,
60,
78,
11843,
7023,
87,
7896,
2696,
14,
3427,
6307,
7023,
2677,
11,
15840,
21690,
1874,
7896,
430,
91,
12,
19,
93,
5169,
3,
9,
5805,
4,
1288,
267,
295,
14,
2014,
8,
3289,
3212,
7023,
87,
7896,
32,
7023,
87,
60,
2696,
32455,
5169,
359,
12773,
3934,
32174,
5805,
59,
30,
20262,
4,
61,
5805,
22550,
272,
1622,
339,
11167,
63,
3083,
63,
264,
275,
359,
267,
295,
14,
2014,
8,
3289,
6808,
5805,
547,
1288,
267,
295,
14,
2014,
8,
3289,
6808,
5805,
5725,
7565,
1288,
267,
295,
14,
2014,
8,
3289,
2,
16626,
1125,
26,
1288,
267,
295,
14,
2014,
8,
3289,
2,
3197,
1324,
401,
295,
14,
41,
395,
267,
295,
14,
2014,
8,
3289,
2,
5169,
24575,
92,
26465,
9,
1414,
401,
295,
14,
41,
395,
267,
295,
14,
2014,
8,
3289,
2,
2105,
18590,
734,
401,
295,
14,
41,
395,
267,
295,
14,
2014,
8,
3289,
2,
16045,
82,
60,
78,
2807,
440,
1911,
401,
295,
14,
41,
395,
267,
295,
14,
2014,
8,
3289,
2,
16122,
418,
7,
435,
19065,
1125,
1233,
26,
5805,
60,
68,
11,
1288,
272,
1622,
339,
347,
641,
63,
1490,
63,
5641,
8,
277,
304,
267,
862,
26,
288,
291,
423,
1628,
63,
2764,
63,
1531,
8,
66,
1133,
281,
827,
279,
2582,
378,
358,
267,
871,
2622,
3225,
6782,
26,
288,
746,
2622,
3225,
6782,
360,
17200,
370,
663,
11167,
2633,
358,
339,
347,
641,
63,
13970,
8,
277,
12,
15081,
29,
403,
304,
267,
340,
291,
423,
362,
63,
7650,
1252,
4130,
8,
66,
11525,
735,
288,
372,
398,
2088,
275,
469,
85,
7,
1531,
356,
399,
7,
4296,
936,
267,
340,
15081,
26,
288,
2088,
59,
85,
7,
7650,
418,
275,
370,
63,
505,
8,
82,
29354,
82,
60,
78,
11843,
2060,
26,
2672,
401,
2552,
534,
16380,
63,
269,
63,
4768,
358,
288,
2088,
59,
85,
7,
5934,
418,
275,
15081,
398,
862,
26,
288,
291,
423,
1628,
63,
2764,
63,
1531,
8,
475,
63,
2394,
8,
1001,
14,
4180,
8,
1760,
395,
2552,
534,
16380,
63,
269,
63,
4768,
1333,
267,
871,
2622,
3225,
6782,
26,
288,
746,
2622,
3225,
6782,
360,
17200,
370,
12993,
2409,
1979,
17228,
370,
4756,
818,
358,
339,
347,
641,
63,
324,
13970,
8,
277,
304,
267,
8457,
275,
291,
423,
362,
63,
7650,
342,
267,
340,
8457,
365,
488,
26,
288,
327,
340,
8457,
365,
488,
4750,
12060,
314,
11167,
365,
394,
10335,
1536,
737,
282,
8457,
288,
372,
398,
340,
8457,
14,
1913,
1252,
4130,
8,
66,
358,
3,
735,
288,
291,
423,
1628,
63,
2764,
63,
1531,
8,
66,
7,
500,
358,
288,
291,
423,
1628,
63,
2764,
63,
1531,
8,
66,
5121,
374,
461,
358,
398,
916,
8457,
14,
4130,
8,
66,
11525,
735,
288,
291,
423,
1628,
63,
2764,
63,
1531,
8,
66,
5121,
374,
461,
358,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
3,
334,
67,
9,
7800,
9572,
13002,
3277,
14,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
1898,
334,
67,
9,
9708,
577,
1697,
3277,
14,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
646,
295,
199,
646,
2022,
199,
199,
504,
3242,
14,
578,
63,
1208,
423,
505,
492,
370,
63,
505,
12,
370,
63,
2394,
199,
504,
3242,
14,
5265,
14,
12010,
492,
20429,
279,
1563,
199,
504,
3242,
14,
2550,
492,
2622,
3225,
6782,
421,
199,
533,
20429,
279,
2377,
8,
22015,
1563,
304,
339,
11167,
63,
2703,
63,
264,
275,
359,
267,
295,
14,
2014,
8,
3289,
29354,
82,
60,
78,
11843,
7023,
87,
7896,
2696,
14,
3427,
6307,
7023,
2677,
11,
15840,
21690,
1874,
7896,
430,
91,
12,
19,
93,
5169,
3,
9,
5805,
4,
1288,
267,
295,
14,
2014,
8,
3289,
3212,
7023,
87,
7896,
32,
7023,
87,
60,
2696,
32455,
5169,
359,
12773,
3934,
32174,
5805,
59,
30,
20262,
4,
61,
5805,
22550,
272,
1622,
339,
11167,
63,
3083,
63,
264,
275,
359,
267,
295,
14,
2014,
8,
3289,
6808,
5805,
547,
1288,
267,
295,
14,
2014,
8,
3289,
6808,
5805,
5725,
7565,
1288,
267,
295,
14,
2014,
8,
3289,
2,
16626,
1125,
26,
1288,
267,
295,
14,
2014,
8,
3289,
2,
3197,
1324,
401,
295,
14,
41,
395,
267,
295,
14,
2014,
8,
3289,
2,
5169,
24575,
92,
26465,
9,
1414,
401,
295,
14,
41,
395,
267,
295,
14,
2014,
8,
3289,
2,
2105,
18590,
734,
401,
295,
14,
41,
395,
267,
295,
14,
2014,
8,
3289,
2,
16045,
82,
60,
78,
2807,
440,
1911,
401,
295,
14,
41,
395,
267,
295,
14,
2014,
8,
3289,
2,
16122,
418,
7,
435,
19065,
1125,
1233,
26,
5805,
60,
68,
11,
1288,
272,
1622,
339,
347,
641,
63,
1490,
63,
5641,
8,
277,
304,
267,
862,
26,
288,
291,
423,
1628,
63,
2764,
63,
1531,
8,
66,
1133,
281,
827,
279,
2582,
378,
358,
267,
871,
2622,
3225,
6782,
26,
288,
746,
2622,
3225,
6782,
360,
17200,
370,
663,
11167,
2633,
358,
339,
347,
641,
63,
13970,
8,
277,
12,
15081,
29,
403,
304,
267,
340,
291,
423,
362,
63,
7650,
1252,
4130,
8,
66,
11525,
735,
288,
372,
398,
2088,
275,
469,
85,
7,
1531,
356,
399,
7,
4296,
936,
267,
340,
15081,
26,
288,
2088,
59,
85,
7,
7650,
418,
275,
370,
63,
505,
8,
82,
29354,
82,
60,
78,
11843,
2060,
26,
2672,
401,
2552,
534,
16380,
63,
269,
63,
4768,
358,
288,
2088,
59,
85,
7,
5934,
418,
275,
15081,
398,
862,
26,
288,
291,
423,
1628,
63,
2764,
63,
1531,
8,
475,
63,
2394,
8,
1001,
14,
4180,
8,
1760,
395,
2552,
534,
16380,
63,
269,
63,
4768,
1333,
267,
871,
2622,
3225,
6782,
26,
288,
746,
2622,
3225,
6782,
360,
17200,
370,
12993,
2409,
1979,
17228,
370,
4756,
818,
358,
339,
347,
641,
63,
324,
13970,
8,
277,
304,
267,
8457,
275,
291,
423,
362,
63,
7650,
342,
267,
340,
8457,
365,
488,
26,
288,
327,
340,
8457,
365,
488,
4750,
12060,
314,
11167,
365,
394,
10335,
1536,
737,
282,
8457,
288,
372,
398,
340,
8457,
14,
1913,
1252,
4130,
8,
66,
358,
3,
735,
288,
291,
423,
1628,
63,
2764,
63,
1531,
8,
66,
7,
500,
358,
288,
291,
423,
1628,
63,
2764,
63,
1531,
8,
66,
5121,
374,
461,
358,
398,
916,
8457,
14,
4130,
8,
66,
11525,
735,
288,
291,
423,
1628,
63,
2764,
63,
1531,
8,
66,
5121,
374,
461,
358,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
bjmorgan/vasppy
|
docs/source/conf.py
|
1
|
5544
|
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# vasppy documentation build configuration file, created by
# sphinx-quickstart on Tue Mar 6 13:36:30 2018.
#
# This file is execfile()d with the current directory set to its
# containing dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file.
#
# All configuration values have a default; values that are commented out
# serve to show the default.
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import os
import sys
sys.path.insert(0, os.path.abspath('../../'))
# -- General configuration ------------------------------------------------
# If your documentation needs a minimal Sphinx version, state it here.
#
# needs_sphinx = '1.0'
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = ['sphinx.ext.autodoc',
'sphinx.ext.coverage',
'sphinx.ext.mathjax',
'sphinx.ext.viewcode',
'sphinx.ext.githubpages',
'sphinx.ext.napoleon',
'nbsphinx']
autoclass_content = 'both'
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'
# The master toctree document.
master_doc = 'index'
# General information about the project.
project = 'vasppy'
copyright = '2018, Benjamin J. Morgan'
author = 'Benjamin J. Morgan'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = '0.4'
# The full version, including alpha/beta/rc tags.
release = '0.4'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This patterns also effect to html_static_path and html_extra_path
exclude_patterns = ['_build', '**.ipynb_checkpoints']
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
add_module_names = False
# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = False
# -- Options for HTML output ----------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'sphinx_rtd_theme'
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#
# html_theme_options = {}
nbsphinx_prompt_width = 0
# NbSphinx configuration
nbsphinx_execute = 'never'
nbsphinx_codecell_lexer = 'python3'
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
# Custom sidebar templates, must be a dictionary that maps document names
# to template names.
#
# This is required for the alabaster theme
# refs: http://alabaster.readthedocs.io/en/latest/installation.html#sidebars
html_sidebars = {
'**': [
'relations.html', # needs 'show_related': True theme option to display
'searchbox.html',
]
}
# -- Options for HTMLHelp output ------------------------------------------
# Output file base name for HTML help builder.
htmlhelp_basename = 'vasppydoc'
# -- Options for LaTeX output ---------------------------------------------
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',
# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
}
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'vasppy.tex', 'vasppy Documentation',
'Benjamin J. Morgan', 'manual'),
]
# -- Options for manual page output ---------------------------------------
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'vasppy', 'vasppy Documentation',
[author], 1)
]
# -- Options for Texinfo output -------------------------------------------
# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'vasppy', 'vasppy Documentation',
author, 'vasppy', 'One line description of project.',
'Miscellaneous'),
]
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
19,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
373,
20222,
647,
3794,
1900,
2897,
570,
12,
2737,
701,
199,
3,
15882,
13,
28957,
641,
377,
310,
16794,
221,
1227,
4944,
26,
1344,
26,
1216,
14894,
14,
199,
3,
199,
3,
961,
570,
365,
22711,
342,
68,
543,
314,
1453,
2082,
663,
370,
2399,
199,
3,
3035,
2935,
14,
199,
3,
199,
3,
3390,
626,
440,
1006,
3962,
2897,
1338,
787,
3451,
315,
642,
199,
3,
18392,
570,
14,
199,
3,
199,
3,
2900,
2897,
1338,
1172,
282,
849,
27,
1338,
626,
787,
21804,
734,
199,
3,
14062,
370,
2498,
314,
849,
14,
199,
199,
3,
982,
5478,
334,
269,
4621,
370,
2213,
543,
29973,
9,
787,
315,
4573,
2082,
12,
199,
3,
1050,
3520,
6602,
370,
984,
14,
515,
2348,
14,
982,
314,
2082,
365,
3847,
370,
314,
199,
3,
3794,
1738,
12,
675,
747,
14,
515,
14,
4832,
370,
1852,
652,
3679,
12,
2839,
9164,
2348,
14,
199,
3,
199,
646,
747,
199,
646,
984,
199,
1274,
14,
515,
14,
3176,
8,
16,
12,
747,
14,
515,
14,
4832,
360,
9707,
1333,
421,
199,
3,
1553,
1696,
2897,
9527,
199,
199,
3,
982,
2195,
3794,
4839,
282,
13460,
10229,
1015,
12,
1174,
652,
2348,
14,
199,
3,
199,
3,
4839,
63,
8008,
275,
283,
17,
14,
16,
7,
199,
199,
3,
2654,
1263,
10229,
3329,
859,
1561,
2348,
12,
465,
3326,
14,
9322,
883,
506,
199,
3,
5478,
17262,
543,
10229,
334,
4579,
283,
8008,
14,
832,
24915,
503,
2195,
3537,
199,
3,
7869,
14,
199,
5359,
275,
788,
8008,
14,
832,
14,
28056,
297,
272,
283,
8008,
14,
832,
14,
10828,
297,
272,
283,
8008,
14,
832,
14,
3442,
15863,
297,
272,
283,
8008,
14,
832,
14,
1345,
600,
297,
272,
283,
8008,
14,
832,
14,
5031,
5856,
297,
272,
283,
8008,
14,
832,
14,
2542,
16721,
265,
297,
272,
283,
4994,
8008,
418,
199,
199,
2495,
533,
63,
1317,
275,
283,
10727,
7,
199,
199,
3,
2654,
1263,
3792,
626,
1395,
7009,
2348,
12,
3847,
370,
642,
2082,
14,
199,
5876,
63,
515,
275,
4044,
5876,
418,
199,
199,
3,
710,
4739,
8,
397,
9,
402,
1350,
6203,
14,
199,
3,
2047,
883,
4165,
3663,
4739,
465,
282,
769,
402,
1059,
26,
199,
3,
199,
3,
1350,
63,
4511,
275,
18953,
8332,
297,
1987,
1064,
418,
199,
1365,
63,
4511,
275,
1987,
8332,
7,
199,
199,
3,
710,
5288,
28310,
2213,
14,
199,
4133,
63,
1301,
275,
283,
1080,
7,
199,
199,
3,
1696,
2556,
3595,
314,
2199,
14,
199,
1715,
275,
283,
4755,
80,
647,
7,
199,
7307,
275,
283,
12682,
12,
26844,
16997,
262,
1603,
14,
603,
19916,
7,
199,
2502,
275,
283,
31231,
16997,
262,
1603,
14,
603,
19916,
7,
199,
199,
3,
710,
1015,
2256,
367,
314,
2199,
1265,
3984,
29904,
12,
17795,
465,
8343,
367,
199,
3,
1204,
1023,
92,
436,
1204,
3221,
18712,
2597,
1202,
315,
7750,
1163,
9825,
23088,
314,
199,
3,
6137,
8247,
14,
199,
3,
199,
3,
710,
3974,
1323,
14,
57,
1015,
14,
199,
1023,
275,
283,
16,
14,
20,
7,
199,
3,
710,
2615,
1015,
12,
5893,
5131,
15,
5683,
15,
1195,
3762,
14,
199,
3221,
275,
283,
16,
14,
20,
7,
199,
199,
3,
710,
2637,
367,
1564,
18392,
701,
10229,
14,
21751,
370,
3794,
199,
3,
367,
282,
769,
402,
3748,
10815,
14,
199,
3,
199,
3,
961,
365,
2597,
1202,
340,
1265,
886,
1564,
7761,
4799,
9796,
6230,
18238,
14,
199,
3,
24612,
1265,
663,
298,
3671,
2,
687,
314,
1414,
1004,
367,
3520,
5560,
14,
199,
3671,
275,
488,
199,
199,
3,
3820,
402,
7970,
12,
3847,
370,
1350,
2082,
12,
626,
1336,
1584,
436,
199,
3,
6602,
370,
3686,
1380,
10023,
367,
1350,
1584,
14,
199,
3,
961,
7970,
2597,
7763,
370,
3517,
63,
1986,
63,
515,
436,
3517,
63,
2911,
63,
515,
199,
5473,
63,
7435,
275,
4044,
1506,
297,
23940,
14,
73,
647,
4994,
63,
32475,
418,
199,
199,
3,
710,
536,
402,
314,
14493,
334,
7093,
22437,
9,
3449,
370,
675,
14,
199,
12173,
63,
2487,
275,
283,
8008,
7,
199,
199,
3,
982,
2549,
12,
314,
1453,
859,
536,
911,
506,
20247,
370,
1006,
1369,
199,
3,
4137,
16194,
334,
10180,
465,
2508,
805,
32469,
199,
525,
63,
578,
63,
1247,
275,
756,
199,
199,
3,
982,
2549,
12,
658,
11396,
64,
436,
658,
11396,
1296,
64,
7389,
1072,
12,
587,
2985,
7389,
6548,
14,
199,
11396,
63,
2613,
63,
5766,
736,
275,
756,
421,
199,
3,
1553,
8394,
367,
4163,
1072,
11016,
10965,
199,
199,
3,
710,
8879,
370,
675,
367,
4163,
436,
4163,
15456,
6497,
14,
221,
1666,
314,
3794,
367,
199,
3,
282,
769,
402,
6762,
17915,
14,
199,
3,
199,
1360,
63,
7915,
275,
283,
8008,
63,
29048,
63,
7915,
7,
199,
199,
3,
23978,
1511,
787,
8879,
13,
6100,
436,
17551,
314,
3648,
436,
23109,
402,
282,
8879,
199,
3,
9848,
14,
221,
2104,
282,
769,
402,
1511,
2808,
367,
1924,
8879,
12,
1937,
314,
199,
3,
3794,
14,
199,
3,
199,
3,
3517,
63,
7915,
63,
1419,
275,
1052,
199,
199,
4994,
8008,
63,
7650,
63,
2063,
275,
378,
199,
199,
3,
653,
66,
51,
7807,
2897,
199,
4994,
8008,
63,
2526,
275,
283,
18178,
7,
199,
4994,
8008,
63,
600,
3890,
63,
11729,
275,
283,
1548,
19,
7,
199,
199,
3,
2654,
1263,
3792,
626,
1395,
3537,
2955,
1584,
334,
10180,
465,
3449,
24405,
9,
2348,
12,
199,
3,
3847,
370,
642,
2082,
14,
9322,
787,
8876,
2410,
314,
6762,
2955,
1584,
12,
199,
3,
880,
282,
570,
4310,
298,
885,
14,
3919,
2,
911,
8970,
314,
6762,
298,
885,
14,
3919,
1674,
199,
1360,
63,
1986,
63,
515,
275,
4044,
1986,
418,
199,
199,
3,
8388,
18437,
7009,
12,
1471,
506,
282,
2600,
626,
9033,
2213,
1561,
199,
3,
370,
1978,
1561,
14,
199,
3,
199,
3,
961,
365,
1415,
367,
314,
741,
371,
2311,
8879,
199,
3,
15749,
26,
1455,
921,
279,
371,
2311,
14,
25085,
14,
2308,
15,
287,
15,
7410,
15,
23048,
14,
1360,
3,
29627,
199
] |
[
2647,
15,
1393,
15,
1813,
2366,
19,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
373,
20222,
647,
3794,
1900,
2897,
570,
12,
2737,
701,
199,
3,
15882,
13,
28957,
641,
377,
310,
16794,
221,
1227,
4944,
26,
1344,
26,
1216,
14894,
14,
199,
3,
199,
3,
961,
570,
365,
22711,
342,
68,
543,
314,
1453,
2082,
663,
370,
2399,
199,
3,
3035,
2935,
14,
199,
3,
199,
3,
3390,
626,
440,
1006,
3962,
2897,
1338,
787,
3451,
315,
642,
199,
3,
18392,
570,
14,
199,
3,
199,
3,
2900,
2897,
1338,
1172,
282,
849,
27,
1338,
626,
787,
21804,
734,
199,
3,
14062,
370,
2498,
314,
849,
14,
199,
199,
3,
982,
5478,
334,
269,
4621,
370,
2213,
543,
29973,
9,
787,
315,
4573,
2082,
12,
199,
3,
1050,
3520,
6602,
370,
984,
14,
515,
2348,
14,
982,
314,
2082,
365,
3847,
370,
314,
199,
3,
3794,
1738,
12,
675,
747,
14,
515,
14,
4832,
370,
1852,
652,
3679,
12,
2839,
9164,
2348,
14,
199,
3,
199,
646,
747,
199,
646,
984,
199,
1274,
14,
515,
14,
3176,
8,
16,
12,
747,
14,
515,
14,
4832,
360,
9707,
1333,
421,
199,
3,
1553,
1696,
2897,
9527,
199,
199,
3,
982,
2195,
3794,
4839,
282,
13460,
10229,
1015,
12,
1174,
652,
2348,
14,
199,
3,
199,
3,
4839,
63,
8008,
275,
283,
17,
14,
16,
7,
199,
199,
3,
2654,
1263,
10229,
3329,
859,
1561,
2348,
12,
465,
3326,
14,
9322,
883,
506,
199,
3,
5478,
17262,
543,
10229,
334,
4579,
283,
8008,
14,
832,
24915,
503,
2195,
3537,
199,
3,
7869,
14,
199,
5359,
275,
788,
8008,
14,
832,
14,
28056,
297,
272,
283,
8008,
14,
832,
14,
10828,
297,
272,
283,
8008,
14,
832,
14,
3442,
15863,
297,
272,
283,
8008,
14,
832,
14,
1345,
600,
297,
272,
283,
8008,
14,
832,
14,
5031,
5856,
297,
272,
283,
8008,
14,
832,
14,
2542,
16721,
265,
297,
272,
283,
4994,
8008,
418,
199,
199,
2495,
533,
63,
1317,
275,
283,
10727,
7,
199,
199,
3,
2654,
1263,
3792,
626,
1395,
7009,
2348,
12,
3847,
370,
642,
2082,
14,
199,
5876,
63,
515,
275,
4044,
5876,
418,
199,
199,
3,
710,
4739,
8,
397,
9,
402,
1350,
6203,
14,
199,
3,
2047,
883,
4165,
3663,
4739,
465,
282,
769,
402,
1059,
26,
199,
3,
199,
3,
1350,
63,
4511,
275,
18953,
8332,
297,
1987,
1064,
418,
199,
1365,
63,
4511,
275,
1987,
8332,
7,
199,
199,
3,
710,
5288,
28310,
2213,
14,
199,
4133,
63,
1301,
275,
283,
1080,
7,
199,
199,
3,
1696,
2556,
3595,
314,
2199,
14,
199,
1715,
275,
283,
4755,
80,
647,
7,
199,
7307,
275,
283,
12682,
12,
26844,
16997,
262,
1603,
14,
603,
19916,
7,
199,
2502,
275,
283,
31231,
16997,
262,
1603,
14,
603,
19916,
7,
199,
199,
3,
710,
1015,
2256,
367,
314,
2199,
1265,
3984,
29904,
12,
17795,
465,
8343,
367,
199,
3,
1204,
1023,
92,
436,
1204,
3221,
18712,
2597,
1202,
315,
7750,
1163,
9825,
23088,
314,
199,
3,
6137,
8247,
14,
199,
3,
199,
3,
710,
3974,
1323,
14,
57,
1015,
14,
199,
1023,
275,
283,
16,
14,
20,
7,
199,
3,
710,
2615,
1015,
12,
5893,
5131,
15,
5683,
15,
1195,
3762,
14,
199,
3221,
275,
283,
16,
14,
20,
7,
199,
199,
3,
710,
2637,
367,
1564,
18392,
701,
10229,
14,
21751,
370,
3794,
199,
3,
367,
282,
769,
402,
3748,
10815,
14,
199,
3,
199,
3,
961,
365,
2597,
1202,
340,
1265,
886,
1564,
7761,
4799,
9796,
6230,
18238,
14,
199,
3,
24612,
1265,
663,
298,
3671,
2,
687,
314,
1414,
1004,
367,
3520,
5560,
14,
199,
3671,
275,
488,
199,
199,
3,
3820,
402,
7970,
12,
3847,
370,
1350,
2082,
12,
626,
1336,
1584,
436,
199,
3,
6602,
370,
3686,
1380,
10023,
367,
1350,
1584,
14,
199,
3,
961,
7970,
2597,
7763,
370,
3517,
63,
1986,
63,
515,
436,
3517,
63,
2911,
63,
515,
199,
5473,
63,
7435,
275,
4044,
1506,
297,
23940,
14,
73,
647,
4994,
63,
32475,
418,
199,
199,
3,
710,
536,
402,
314,
14493,
334,
7093,
22437,
9,
3449,
370,
675,
14,
199,
12173,
63,
2487,
275,
283,
8008,
7,
199,
199,
3,
982,
2549,
12,
314,
1453,
859,
536,
911,
506,
20247,
370,
1006,
1369,
199,
3,
4137,
16194,
334,
10180,
465,
2508,
805,
32469,
199,
525,
63,
578,
63,
1247,
275,
756,
199,
199,
3,
982,
2549,
12,
658,
11396,
64,
436,
658,
11396,
1296,
64,
7389,
1072,
12,
587,
2985,
7389,
6548,
14,
199,
11396,
63,
2613,
63,
5766,
736,
275,
756,
421,
199,
3,
1553,
8394,
367,
4163,
1072,
11016,
10965,
199,
199,
3,
710,
8879,
370,
675,
367,
4163,
436,
4163,
15456,
6497,
14,
221,
1666,
314,
3794,
367,
199,
3,
282,
769,
402,
6762,
17915,
14,
199,
3,
199,
1360,
63,
7915,
275,
283,
8008,
63,
29048,
63,
7915,
7,
199,
199,
3,
23978,
1511,
787,
8879,
13,
6100,
436,
17551,
314,
3648,
436,
23109,
402,
282,
8879,
199,
3,
9848,
14,
221,
2104,
282,
769,
402,
1511,
2808,
367,
1924,
8879,
12,
1937,
314,
199,
3,
3794,
14,
199,
3,
199,
3,
3517,
63,
7915,
63,
1419,
275,
1052,
199,
199,
4994,
8008,
63,
7650,
63,
2063,
275,
378,
199,
199,
3,
653,
66,
51,
7807,
2897,
199,
4994,
8008,
63,
2526,
275,
283,
18178,
7,
199,
4994,
8008,
63,
600,
3890,
63,
11729,
275,
283,
1548,
19,
7,
199,
199,
3,
2654,
1263,
3792,
626,
1395,
3537,
2955,
1584,
334,
10180,
465,
3449,
24405,
9,
2348,
12,
199,
3,
3847,
370,
642,
2082,
14,
9322,
787,
8876,
2410,
314,
6762,
2955,
1584,
12,
199,
3,
880,
282,
570,
4310,
298,
885,
14,
3919,
2,
911,
8970,
314,
6762,
298,
885,
14,
3919,
1674,
199,
1360,
63,
1986,
63,
515,
275,
4044,
1986,
418,
199,
199,
3,
8388,
18437,
7009,
12,
1471,
506,
282,
2600,
626,
9033,
2213,
1561,
199,
3,
370,
1978,
1561,
14,
199,
3,
199,
3,
961,
365,
1415,
367,
314,
741,
371,
2311,
8879,
199,
3,
15749,
26,
1455,
921,
279,
371,
2311,
14,
25085,
14,
2308,
15,
287,
15,
7410,
15,
23048,
14,
1360,
3,
29627,
199,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
michaelBenin/django-oscar
|
tests/unit/offer/results_tests.py
|
62
|
1039
|
from decimal import Decimal as D
from django.test import TestCase
from oscar.apps.offer import models, results
class TestOfferApplicationsObject(TestCase):
def setUp(self):
self.applications = results.OfferApplications()
self.offer = models.ConditionalOffer()
def test_is_countable(self):
self.assertEqual(0, len(self.applications))
def test_can_filter_shipping_discounts(self):
result = models.ShippingDiscount()
self.applications.add(self.offer, result)
self.assertEqual(1, len(self.applications.shipping_discounts))
def test_can_filter_offer_discounts(self):
result = models.BasketDiscount(D('2.00'))
self.applications.add(self.offer, result)
self.assertEqual(1, len(self.applications.offer_discounts))
def test_can_filter_post_order_actions(self):
result = models.PostOrderAction("Something will happen")
self.applications.add(self.offer, result)
self.assertEqual(1, len(self.applications.post_order_actions))
|
bsd-3-clause
|
[
504,
6107,
492,
6345,
465,
577,
199,
199,
504,
1639,
14,
396,
492,
7640,
199,
199,
504,
312,
22707,
14,
5181,
14,
12786,
492,
1709,
12,
2058,
421,
199,
533,
1379,
22154,
31907,
1692,
8,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
15853,
275,
2058,
14,
22154,
31907,
342,
267,
291,
14,
12786,
275,
1709,
14,
21321,
22154,
342,
339,
347,
511,
63,
374,
63,
835,
461,
8,
277,
304,
267,
291,
14,
629,
8,
16,
12,
822,
8,
277,
14,
15853,
430,
339,
347,
511,
63,
2425,
63,
1541,
63,
17801,
63,
2297,
6851,
8,
277,
304,
267,
754,
275,
1709,
14,
30707,
4073,
2825,
835,
342,
267,
291,
14,
15853,
14,
525,
8,
277,
14,
12786,
12,
754,
9,
267,
291,
14,
629,
8,
17,
12,
822,
8,
277,
14,
15853,
14,
17801,
63,
2297,
6851,
430,
339,
347,
511,
63,
2425,
63,
1541,
63,
12786,
63,
2297,
6851,
8,
277,
304,
267,
754,
275,
1709,
14,
34,
12351,
2825,
835,
8,
36,
360,
18,
14,
383,
1333,
267,
291,
14,
15853,
14,
525,
8,
277,
14,
12786,
12,
754,
9,
267,
291,
14,
629,
8,
17,
12,
822,
8,
277,
14,
15853,
14,
12786,
63,
2297,
6851,
430,
339,
347,
511,
63,
2425,
63,
1541,
63,
1932,
63,
1648,
63,
3723,
8,
277,
304,
267,
754,
275,
1709,
14,
6564,
4738,
3310,
480,
20641,
911,
5992,
531,
267,
291,
14,
15853,
14,
525,
8,
277,
14,
12786,
12,
754,
9,
267,
291,
14,
629,
8,
17,
12,
822,
8,
277,
14,
15853,
14,
1932,
63,
1648,
63,
3723,
430,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
6107,
492,
6345,
465,
577,
199,
199,
504,
1639,
14,
396,
492,
7640,
199,
199,
504,
312,
22707,
14,
5181,
14,
12786,
492,
1709,
12,
2058,
421,
199,
533,
1379,
22154,
31907,
1692,
8,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
15853,
275,
2058,
14,
22154,
31907,
342,
267,
291,
14,
12786,
275,
1709,
14,
21321,
22154,
342,
339,
347,
511,
63,
374,
63,
835,
461,
8,
277,
304,
267,
291,
14,
629,
8,
16,
12,
822,
8,
277,
14,
15853,
430,
339,
347,
511,
63,
2425,
63,
1541,
63,
17801,
63,
2297,
6851,
8,
277,
304,
267,
754,
275,
1709,
14,
30707,
4073,
2825,
835,
342,
267,
291,
14,
15853,
14,
525,
8,
277,
14,
12786,
12,
754,
9,
267,
291,
14,
629,
8,
17,
12,
822,
8,
277,
14,
15853,
14,
17801,
63,
2297,
6851,
430,
339,
347,
511,
63,
2425,
63,
1541,
63,
12786,
63,
2297,
6851,
8,
277,
304,
267,
754,
275,
1709,
14,
34,
12351,
2825,
835,
8,
36,
360,
18,
14,
383,
1333,
267,
291,
14,
15853,
14,
525,
8,
277,
14,
12786,
12,
754,
9,
267,
291,
14,
629,
8,
17,
12,
822,
8,
277,
14,
15853,
14,
12786,
63,
2297,
6851,
430,
339,
347,
511,
63,
2425,
63,
1541,
63,
1932,
63,
1648,
63,
3723,
8,
277,
304,
267,
754,
275,
1709,
14,
6564,
4738,
3310,
480,
20641,
911,
5992,
531,
267,
291,
14,
15853,
14,
525,
8,
277,
14,
12786,
12,
754,
9,
267,
291,
14,
629,
8,
17,
12,
822,
8,
277,
14,
15853,
14,
1932,
63,
1648,
63,
3723,
430,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
blackbliss/callme
|
flask/lib/python2.7/site-packages/sqlalchemy/util/topological.py
|
79
|
2656
|
# util/topological.py
# Copyright (C) 2005-2014 the SQLAlchemy authors and contributors <see AUTHORS file>
#
# This module is part of SQLAlchemy and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
"""Topological sorting algorithms."""
from ..exc import CircularDependencyError
from .. import util
__all__ = ['sort', 'sort_as_subsets', 'find_cycles']
def sort_as_subsets(tuples, allitems):
edges = util.defaultdict(set)
for parent, child in tuples:
edges[child].add(parent)
todo = set(allitems)
while todo:
output = set()
for node in list(todo):
if not todo.intersection(edges[node]):
output.add(node)
if not output:
raise CircularDependencyError(
"Circular dependency detected.",
find_cycles(tuples, allitems),
_gen_edges(edges)
)
todo.difference_update(output)
yield output
def sort(tuples, allitems):
"""sort the given list of items by dependency.
'tuples' is a list of tuples representing a partial ordering.
"""
for set_ in sort_as_subsets(tuples, allitems):
for s in set_:
yield s
def find_cycles(tuples, allitems):
# adapted from:
# http://neopythonic.blogspot.com/2009/01/detecting-cycles-in-directed-graph.html
edges = util.defaultdict(set)
for parent, child in tuples:
edges[parent].add(child)
nodes_to_test = set(edges)
output = set()
# we'd like to find all nodes that are
# involved in cycles, so we do the full
# pass through the whole thing for each
# node in the original list.
# we can go just through parent edge nodes.
# if a node is only a child and never a parent,
# by definition it can't be part of a cycle. same
# if it's not in the edges at all.
for node in nodes_to_test:
stack = [node]
todo = nodes_to_test.difference(stack)
while stack:
top = stack[-1]
for node in edges[top]:
if node in stack:
cyc = stack[stack.index(node):]
todo.difference_update(cyc)
output.update(cyc)
if node in todo:
stack.append(node)
todo.remove(node)
break
else:
node = stack.pop()
return output
def _gen_edges(edges):
return set([
(right, left)
for left in edges
for right in edges[left]
])
|
mit
|
[
3,
4884,
15,
16851,
7954,
14,
647,
199,
3,
1898,
334,
35,
9,
11811,
13,
7280,
314,
14303,
11462,
436,
8417,
665,
3239,
10610,
570,
30,
199,
3,
199,
3,
961,
859,
365,
1777,
402,
14303,
436,
365,
14286,
1334,
199,
3,
314,
10697,
844,
26,
1455,
921,
1544,
14,
16374,
14,
1308,
15,
2383,
15,
1147,
13,
1682,
14,
8624,
199,
199,
624,
6105,
79,
7954,
13351,
18036,
1041,
199,
199,
504,
2508,
2804,
492,
445,
24998,
14403,
547,
199,
504,
2508,
492,
4884,
199,
199,
363,
452,
363,
275,
788,
3191,
297,
283,
3191,
63,
305,
63,
23060,
297,
283,
1623,
63,
23356,
418,
421,
199,
318,
4069,
63,
305,
63,
23060,
8,
11760,
12,
741,
317,
3733,
304,
339,
8207,
275,
4884,
14,
21501,
8,
409,
9,
272,
367,
1676,
12,
1982,
315,
6346,
26,
267,
8207,
59,
1739,
1055,
525,
8,
1708,
9,
339,
11386,
275,
663,
8,
279,
317,
3733,
9,
339,
1830,
11386,
26,
267,
1072,
275,
663,
342,
267,
367,
1031,
315,
769,
8,
11396,
304,
288,
340,
440,
11386,
14,
12569,
8,
6929,
59,
932,
4682,
355,
1072,
14,
525,
8,
932,
9,
398,
340,
440,
1072,
26,
288,
746,
445,
24998,
14403,
547,
8,
490,
298,
35,
24998,
5936,
10501,
4765,
490,
2342,
63,
23356,
8,
11760,
12,
741,
317,
3733,
395,
490,
485,
2268,
63,
6929,
8,
6929,
9,
355,
776,
398,
11386,
14,
9196,
63,
873,
8,
1199,
9,
267,
1995,
1072,
421,
199,
318,
4069,
8,
11760,
12,
741,
317,
3733,
304,
272,
408,
3191,
314,
1627,
769,
402,
2974,
701,
5936,
14,
339,
283,
11760,
7,
365,
282,
769,
402,
6346,
6144,
282,
7417,
7794,
14,
272,
408,
339,
367,
663,
63,
315,
4069,
63,
305,
63,
23060,
8,
11760,
12,
741,
317,
3733,
304,
267,
367,
308,
315,
663,
10388,
288,
1995,
308,
421,
199,
318,
2342,
63,
23356,
8,
11760,
12,
741,
317,
3733,
304,
272,
327,
26266,
687,
26,
272,
327,
1455,
921,
685,
927,
898,
530,
14,
66,
7270,
14173,
14,
957,
15,
8664,
15,
614,
15,
13552,
316,
13,
23356,
13,
262,
13,
12080,
13,
2180,
14,
1360,
339,
8207,
275,
4884,
14,
21501,
8,
409,
9,
272,
367,
1676,
12,
1982,
315,
6346,
26,
267,
8207,
59,
1708,
1055,
525,
8,
1739,
9,
272,
3380,
63,
475,
63,
396,
275,
663,
8,
6929,
9,
339,
1072,
275,
663,
342,
339,
327,
781,
5121,
2839,
370,
2342,
1006,
3380,
626,
787,
272,
327,
28244,
315,
19001,
12,
880,
781,
886,
314,
2615,
272,
327,
986,
4012,
314,
8852,
8377,
367,
1924,
272,
327,
1031,
315,
314,
3379,
769,
14,
339,
327,
781,
883,
2621,
2951,
4012,
1676,
6275,
3380,
14,
272,
327,
340,
282,
1031,
365,
1454,
282,
1982,
436,
7078,
282,
1676,
12,
272,
327,
701,
5492,
652,
883,
1133,
506,
1777,
402,
282,
8643,
14,
221,
2011,
272,
327,
340,
652,
1159,
440,
315,
314,
8207,
737,
1006,
14,
272,
367,
1031,
315,
3380,
63,
475,
63,
396,
26,
267,
3464,
275,
359,
932,
61,
267,
11386,
275,
3380,
63,
475,
63,
396,
14,
9196,
8,
2340,
9,
267,
1830,
3464,
26,
288,
2746,
275,
3464,
1988,
17,
61,
288,
367,
1031,
315,
8207,
59,
2119,
2189,
355,
340,
1031,
315,
3464,
26,
490,
6325,
67,
275,
3464,
59,
2340,
14,
1080,
8,
932,
15405,
490,
11386,
14,
9196,
63,
873,
8,
1480,
67,
9,
490,
1072,
14,
873,
8,
1480,
67,
9,
2234,
340,
1031,
315,
11386,
26,
490,
3464,
14,
740,
8,
932,
9,
490,
11386,
14,
2168,
8,
932,
9,
490,
2059,
288,
587,
26,
355,
1031,
275,
3464,
14,
1935,
342,
272,
372,
1072,
421,
199,
318,
485,
2268,
63,
6929,
8,
6929,
304,
272,
372,
663,
779,
490,
334,
1019,
12,
3602,
9,
490,
367,
3602,
315,
8207,
490,
367,
2451,
315,
8207,
59,
3039,
61,
355,
4794,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
4884,
15,
16851,
7954,
14,
647,
199,
3,
1898,
334,
35,
9,
11811,
13,
7280,
314,
14303,
11462,
436,
8417,
665,
3239,
10610,
570,
30,
199,
3,
199,
3,
961,
859,
365,
1777,
402,
14303,
436,
365,
14286,
1334,
199,
3,
314,
10697,
844,
26,
1455,
921,
1544,
14,
16374,
14,
1308,
15,
2383,
15,
1147,
13,
1682,
14,
8624,
199,
199,
624,
6105,
79,
7954,
13351,
18036,
1041,
199,
199,
504,
2508,
2804,
492,
445,
24998,
14403,
547,
199,
504,
2508,
492,
4884,
199,
199,
363,
452,
363,
275,
788,
3191,
297,
283,
3191,
63,
305,
63,
23060,
297,
283,
1623,
63,
23356,
418,
421,
199,
318,
4069,
63,
305,
63,
23060,
8,
11760,
12,
741,
317,
3733,
304,
339,
8207,
275,
4884,
14,
21501,
8,
409,
9,
272,
367,
1676,
12,
1982,
315,
6346,
26,
267,
8207,
59,
1739,
1055,
525,
8,
1708,
9,
339,
11386,
275,
663,
8,
279,
317,
3733,
9,
339,
1830,
11386,
26,
267,
1072,
275,
663,
342,
267,
367,
1031,
315,
769,
8,
11396,
304,
288,
340,
440,
11386,
14,
12569,
8,
6929,
59,
932,
4682,
355,
1072,
14,
525,
8,
932,
9,
398,
340,
440,
1072,
26,
288,
746,
445,
24998,
14403,
547,
8,
490,
298,
35,
24998,
5936,
10501,
4765,
490,
2342,
63,
23356,
8,
11760,
12,
741,
317,
3733,
395,
490,
485,
2268,
63,
6929,
8,
6929,
9,
355,
776,
398,
11386,
14,
9196,
63,
873,
8,
1199,
9,
267,
1995,
1072,
421,
199,
318,
4069,
8,
11760,
12,
741,
317,
3733,
304,
272,
408,
3191,
314,
1627,
769,
402,
2974,
701,
5936,
14,
339,
283,
11760,
7,
365,
282,
769,
402,
6346,
6144,
282,
7417,
7794,
14,
272,
408,
339,
367,
663,
63,
315,
4069,
63,
305,
63,
23060,
8,
11760,
12,
741,
317,
3733,
304,
267,
367,
308,
315,
663,
10388,
288,
1995,
308,
421,
199,
318,
2342,
63,
23356,
8,
11760,
12,
741,
317,
3733,
304,
272,
327,
26266,
687,
26,
272,
327,
1455,
921,
685,
927,
898,
530,
14,
66,
7270,
14173,
14,
957,
15,
8664,
15,
614,
15,
13552,
316,
13,
23356,
13,
262,
13,
12080,
13,
2180,
14,
1360,
339,
8207,
275,
4884,
14,
21501,
8,
409,
9,
272,
367,
1676,
12,
1982,
315,
6346,
26,
267,
8207,
59,
1708,
1055,
525,
8,
1739,
9,
272,
3380,
63,
475,
63,
396,
275,
663,
8,
6929,
9,
339,
1072,
275,
663,
342,
339,
327,
781,
5121,
2839,
370,
2342,
1006,
3380,
626,
787,
272,
327,
28244,
315,
19001,
12,
880,
781,
886,
314,
2615,
272,
327,
986,
4012,
314,
8852,
8377,
367,
1924,
272,
327,
1031,
315,
314,
3379,
769,
14,
339,
327,
781,
883,
2621,
2951,
4012,
1676,
6275,
3380,
14,
272,
327,
340,
282,
1031,
365,
1454,
282,
1982,
436,
7078,
282,
1676,
12,
272,
327,
701,
5492,
652,
883,
1133,
506,
1777,
402,
282,
8643,
14,
221,
2011,
272,
327,
340,
652,
1159,
440,
315,
314,
8207,
737,
1006,
14,
272,
367,
1031,
315,
3380,
63,
475,
63,
396,
26,
267,
3464,
275,
359,
932,
61,
267,
11386,
275,
3380,
63,
475,
63,
396,
14,
9196,
8,
2340,
9,
267,
1830,
3464,
26,
288,
2746,
275,
3464,
1988,
17,
61,
288,
367,
1031,
315,
8207,
59,
2119,
2189,
355,
340,
1031,
315,
3464,
26,
490,
6325,
67,
275,
3464,
59,
2340,
14,
1080,
8,
932,
15405,
490,
11386,
14,
9196,
63,
873,
8,
1480,
67,
9,
490,
1072,
14,
873,
8,
1480,
67,
9,
2234,
340,
1031,
315,
11386,
26,
490,
3464,
14,
740,
8,
932,
9,
490,
11386,
14,
2168,
8,
932,
9,
490,
2059,
288,
587,
26,
355,
1031,
275,
3464,
14,
1935,
342,
272,
372,
1072,
421,
199,
318,
485,
2268,
63,
6929,
8,
6929,
304,
272,
372,
663,
779,
490,
334,
1019,
12,
3602,
9,
490,
367,
3602,
315,
8207,
490,
367,
2451,
315,
8207,
59,
3039,
61,
355,
4794,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
therearesomewhocallmetim/omim
|
3party/Alohalytics/tests/googletest/xcode/Scripts/versiongenerate.py
|
3088
|
4536
|
#!/usr/bin/env python
#
# Copyright 2008, Google Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""A script to prepare version informtion for use the gtest Info.plist file.
This script extracts the version information from the configure.ac file and
uses it to generate a header file containing the same information. The
#defines in this header file will be included in during the generation of
the Info.plist of the framework, giving the correct value to the version
shown in the Finder.
This script makes the following assumptions (these are faults of the script,
not problems with the Autoconf):
1. The AC_INIT macro will be contained within the first 1024 characters
of configure.ac
2. The version string will be 3 integers separated by periods and will be
surrounded by squre brackets, "[" and "]" (e.g. [1.0.1]). The first
segment represents the major version, the second represents the minor
version and the third represents the fix version.
3. No ")" character exists between the opening "(" and closing ")" of
AC_INIT, including in comments and character strings.
"""
import sys
import re
# Read the command line argument (the output directory for Version.h)
if (len(sys.argv) < 3):
print "Usage: versiongenerate.py input_dir output_dir"
sys.exit(1)
else:
input_dir = sys.argv[1]
output_dir = sys.argv[2]
# Read the first 1024 characters of the configure.ac file
config_file = open("%s/configure.ac" % input_dir, 'r')
buffer_size = 1024
opening_string = config_file.read(buffer_size)
config_file.close()
# Extract the version string from the AC_INIT macro
# The following init_expression means:
# Extract three integers separated by periods and surrounded by squre
# brackets(e.g. "[1.0.1]") between "AC_INIT(" and ")". Do not be greedy
# (*? is the non-greedy flag) since that would pull in everything between
# the first "(" and the last ")" in the file.
version_expression = re.compile(r"AC_INIT\(.*?\[(\d+)\.(\d+)\.(\d+)\].*?\)",
re.DOTALL)
version_values = version_expression.search(opening_string)
major_version = version_values.group(1)
minor_version = version_values.group(2)
fix_version = version_values.group(3)
# Write the version information to a header file to be included in the
# Info.plist file.
file_data = """//
// DO NOT MODIFY THIS FILE (but you can delete it)
//
// This file is autogenerated by the versiongenerate.py script. This script
// is executed in a "Run Script" build phase when creating gtest.framework. This
// header file is not used during compilation of C-source. Rather, it simply
// defines some version strings for substitution in the Info.plist. Because of
// this, we are not not restricted to C-syntax nor are we using include guards.
//
#define GTEST_VERSIONINFO_SHORT %s.%s
#define GTEST_VERSIONINFO_LONG %s.%s.%s
""" % (major_version, minor_version, major_version, minor_version, fix_version)
version_file = open("%s/Version.h" % output_dir, 'w')
version_file.write(file_data)
version_file.close()
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
9079,
12,
4475,
3277,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
199,
3,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
4084,
14,
199,
3,
258,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
624,
33,
2884,
370,
9275,
1015,
315,
964,
296,
367,
675,
314,
9088,
10332,
14,
10265,
570,
14,
819,
961,
2884,
5536,
83,
314,
1015,
2556,
687,
314,
7908,
14,
645,
570,
436,
523,
4440,
652,
370,
3550,
282,
1406,
570,
3035,
314,
2011,
2556,
14,
710,
523,
327,
14334,
315,
642,
1406,
570,
911,
506,
5120,
315,
5309,
314,
10152,
402,
523,
314,
10332,
14,
10265,
402,
314,
10059,
12,
15131,
314,
3211,
574,
370,
314,
1015,
523,
9164,
315,
314,
481,
5755,
14,
819,
961,
2884,
7704,
314,
2569,
21546,
334,
29032,
787,
16898,
83,
402,
314,
2884,
12,
523,
440,
8826,
543,
314,
9195,
2190,
304,
272,
413,
14,
710,
6570,
63,
8727,
9559,
911,
506,
10470,
4453,
314,
1642,
6619,
4110,
2126,
402,
7908,
14,
645,
272,
499,
14,
710,
1015,
1059,
911,
506,
650,
9446,
11673,
701,
17382,
436,
911,
506,
2126,
6296,
25677,
701,
12345,
264,
21873,
12,
32607,
436,
298,
8480,
334,
69,
14,
71,
14,
359,
17,
14,
16,
14,
17,
6575,
710,
1642,
2126,
8135,
8469,
314,
12160,
1015,
12,
314,
3499,
8469,
314,
12612,
2126,
1015,
436,
314,
10919,
8469,
314,
5325,
1015,
14,
272,
650,
14,
3091,
19607,
4528,
3495,
3382,
314,
13618,
26054,
436,
11261,
19607,
402,
2126,
6570,
63,
8727,
12,
5893,
315,
6786,
436,
4528,
3326,
14,
199,
624,
199,
199,
646,
984,
199,
646,
295,
199,
199,
3,
5574,
314,
1414,
1004,
1423,
334,
1589,
1072,
2082,
367,
3394,
14,
72,
9,
199,
692,
334,
552,
8,
1274,
14,
3020,
9,
665,
650,
304,
523,
870,
298,
7692,
26,
1015,
4208,
14,
647,
1324,
63,
694,
1072,
63,
694,
2,
523,
984,
14,
2224,
8,
17,
9,
199,
2836,
26,
523,
1324,
63,
694,
275,
984,
14,
3020,
59,
17,
61,
523,
1072,
63,
694,
275,
984,
14,
3020,
59,
18,
61,
199,
199,
3,
5574,
314,
1642,
6619,
4110,
402,
314,
7908,
14,
645,
570,
199,
888,
63,
493,
275,
1551,
3647,
83,
15,
6472,
14,
645,
2,
450,
1324,
63,
694,
12,
283,
82,
358,
199,
2738,
63,
890,
275,
6619,
199,
21849,
63,
875,
275,
1101,
63,
493,
14,
739,
8,
2738,
63,
890,
9,
199,
888,
63,
493,
14,
1600,
342,
199,
199,
3,
12892,
314,
1015,
1059,
687,
314,
6570,
63,
8727,
9559,
199,
3,
257,
710,
2569,
4205,
63,
5599,
4910,
26,
199,
3,
258,
12892,
7795,
9446,
11673,
701,
17382,
436,
6296,
25677,
701,
12345,
264,
199,
3,
258,
21873,
8,
69,
14,
71,
14,
7369,
17,
14,
16,
14,
17,
12523,
3382,
298,
1348,
63,
8727,
480,
436,
6099,
1674,
4226,
440,
506,
486,
24737,
199,
3,
258,
334,
15279,
365,
314,
2222,
13,
71,
24737,
3305,
9,
3967,
626,
3955,
10299,
315,
8137,
3382,
199,
3,
258,
314,
1642,
26054,
436,
314,
2061,
19607,
315,
314,
570,
14,
199,
1023,
63,
5599,
275,
295,
14,
2014,
8,
82,
2,
1348,
63,
8727,
60,
17140,
25621,
2961,
68,
13439,
14,
2961,
68,
13439,
14,
2961,
68,
13439,
1055,
10,
8995,
4186,
1816,
295,
14,
16504,
9,
199,
1023,
63,
1459,
275,
1015,
63,
5599,
14,
1733,
8,
21849,
63,
875,
9,
199,
8452,
63,
1023,
275,
1015,
63,
1459,
14,
923,
8,
17,
9,
199,
11067,
63,
1023,
275,
1015,
63,
1459,
14,
923,
8,
18,
9,
199,
970,
63,
1023,
275,
1015,
63,
1459,
14,
923,
8,
19,
9,
199,
199,
3,
6990,
314,
1015,
2556,
370,
282,
1406,
570,
370,
506,
5120,
315,
314,
199,
3,
10332,
14,
10265,
570,
14,
199,
493,
63,
576,
275,
408,
501,
199,
501,
3506,
2845,
10362,
1914,
18114,
5749,
13024,
334,
7911,
1265,
883,
3145,
652,
9,
199,
501,
199,
501,
961,
570,
365,
18392,
701,
314,
1015,
4208,
14,
647,
2884,
14,
961,
2884,
199,
501,
365,
7934,
315,
282,
298,
2540,
14914,
2,
1900,
7669,
1380,
6425,
9088,
14,
4857,
14,
961,
199,
501,
1406,
570,
365,
440,
1202,
5309,
18653,
402,
445,
13,
1365,
14,
3898,
728,
12,
652,
9329,
199,
501,
7890,
2005,
1015,
3326,
367,
20584,
315,
314,
10332,
14,
10265,
14,
13821,
402,
199,
501,
642,
12,
781,
787,
440,
440,
15297,
370,
445
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
9079,
12,
4475,
3277,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
199,
3,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
4084,
14,
199,
3,
258,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
624,
33,
2884,
370,
9275,
1015,
315,
964,
296,
367,
675,
314,
9088,
10332,
14,
10265,
570,
14,
819,
961,
2884,
5536,
83,
314,
1015,
2556,
687,
314,
7908,
14,
645,
570,
436,
523,
4440,
652,
370,
3550,
282,
1406,
570,
3035,
314,
2011,
2556,
14,
710,
523,
327,
14334,
315,
642,
1406,
570,
911,
506,
5120,
315,
5309,
314,
10152,
402,
523,
314,
10332,
14,
10265,
402,
314,
10059,
12,
15131,
314,
3211,
574,
370,
314,
1015,
523,
9164,
315,
314,
481,
5755,
14,
819,
961,
2884,
7704,
314,
2569,
21546,
334,
29032,
787,
16898,
83,
402,
314,
2884,
12,
523,
440,
8826,
543,
314,
9195,
2190,
304,
272,
413,
14,
710,
6570,
63,
8727,
9559,
911,
506,
10470,
4453,
314,
1642,
6619,
4110,
2126,
402,
7908,
14,
645,
272,
499,
14,
710,
1015,
1059,
911,
506,
650,
9446,
11673,
701,
17382,
436,
911,
506,
2126,
6296,
25677,
701,
12345,
264,
21873,
12,
32607,
436,
298,
8480,
334,
69,
14,
71,
14,
359,
17,
14,
16,
14,
17,
6575,
710,
1642,
2126,
8135,
8469,
314,
12160,
1015,
12,
314,
3499,
8469,
314,
12612,
2126,
1015,
436,
314,
10919,
8469,
314,
5325,
1015,
14,
272,
650,
14,
3091,
19607,
4528,
3495,
3382,
314,
13618,
26054,
436,
11261,
19607,
402,
2126,
6570,
63,
8727,
12,
5893,
315,
6786,
436,
4528,
3326,
14,
199,
624,
199,
199,
646,
984,
199,
646,
295,
199,
199,
3,
5574,
314,
1414,
1004,
1423,
334,
1589,
1072,
2082,
367,
3394,
14,
72,
9,
199,
692,
334,
552,
8,
1274,
14,
3020,
9,
665,
650,
304,
523,
870,
298,
7692,
26,
1015,
4208,
14,
647,
1324,
63,
694,
1072,
63,
694,
2,
523,
984,
14,
2224,
8,
17,
9,
199,
2836,
26,
523,
1324,
63,
694,
275,
984,
14,
3020,
59,
17,
61,
523,
1072,
63,
694,
275,
984,
14,
3020,
59,
18,
61,
199,
199,
3,
5574,
314,
1642,
6619,
4110,
402,
314,
7908,
14,
645,
570,
199,
888,
63,
493,
275,
1551,
3647,
83,
15,
6472,
14,
645,
2,
450,
1324,
63,
694,
12,
283,
82,
358,
199,
2738,
63,
890,
275,
6619,
199,
21849,
63,
875,
275,
1101,
63,
493,
14,
739,
8,
2738,
63,
890,
9,
199,
888,
63,
493,
14,
1600,
342,
199,
199,
3,
12892,
314,
1015,
1059,
687,
314,
6570,
63,
8727,
9559,
199,
3,
257,
710,
2569,
4205,
63,
5599,
4910,
26,
199,
3,
258,
12892,
7795,
9446,
11673,
701,
17382,
436,
6296,
25677,
701,
12345,
264,
199,
3,
258,
21873,
8,
69,
14,
71,
14,
7369,
17,
14,
16,
14,
17,
12523,
3382,
298,
1348,
63,
8727,
480,
436,
6099,
1674,
4226,
440,
506,
486,
24737,
199,
3,
258,
334,
15279,
365,
314,
2222,
13,
71,
24737,
3305,
9,
3967,
626,
3955,
10299,
315,
8137,
3382,
199,
3,
258,
314,
1642,
26054,
436,
314,
2061,
19607,
315,
314,
570,
14,
199,
1023,
63,
5599,
275,
295,
14,
2014,
8,
82,
2,
1348,
63,
8727,
60,
17140,
25621,
2961,
68,
13439,
14,
2961,
68,
13439,
14,
2961,
68,
13439,
1055,
10,
8995,
4186,
1816,
295,
14,
16504,
9,
199,
1023,
63,
1459,
275,
1015,
63,
5599,
14,
1733,
8,
21849,
63,
875,
9,
199,
8452,
63,
1023,
275,
1015,
63,
1459,
14,
923,
8,
17,
9,
199,
11067,
63,
1023,
275,
1015,
63,
1459,
14,
923,
8,
18,
9,
199,
970,
63,
1023,
275,
1015,
63,
1459,
14,
923,
8,
19,
9,
199,
199,
3,
6990,
314,
1015,
2556,
370,
282,
1406,
570,
370,
506,
5120,
315,
314,
199,
3,
10332,
14,
10265,
570,
14,
199,
493,
63,
576,
275,
408,
501,
199,
501,
3506,
2845,
10362,
1914,
18114,
5749,
13024,
334,
7911,
1265,
883,
3145,
652,
9,
199,
501,
199,
501,
961,
570,
365,
18392,
701,
314,
1015,
4208,
14,
647,
2884,
14,
961,
2884,
199,
501,
365,
7934,
315,
282,
298,
2540,
14914,
2,
1900,
7669,
1380,
6425,
9088,
14,
4857,
14,
961,
199,
501,
1406,
570,
365,
440,
1202,
5309,
18653,
402,
445,
13,
1365,
14,
3898,
728,
12,
652,
9329,
199,
501,
7890,
2005,
1015,
3326,
367,
20584,
315,
314,
10332,
14,
10265,
14,
13821,
402,
199,
501,
642,
12,
781,
787,
440,
440,
15297,
370,
445,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
farazaftab/sjhschool
|
node_modules/node-gyp/gyp/pylib/gyp/__init__.py
|
1524
|
22178
|
#!/usr/bin/env python
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import copy
import gyp.input
import optparse
import os.path
import re
import shlex
import sys
import traceback
from gyp.common import GypError
# Default debug modes for GYP
debug = {}
# List of "official" debug modes, but you can use anything you like.
DEBUG_GENERAL = 'general'
DEBUG_VARIABLES = 'variables'
DEBUG_INCLUDES = 'includes'
def DebugOutput(mode, message, *args):
if 'all' in gyp.debug or mode in gyp.debug:
ctx = ('unknown', 0, 'unknown')
try:
f = traceback.extract_stack(limit=2)
if f:
ctx = f[0][:3]
except:
pass
if args:
message %= args
print '%s:%s:%d:%s %s' % (mode.upper(), os.path.basename(ctx[0]),
ctx[1], ctx[2], message)
def FindBuildFiles():
extension = '.gyp'
files = os.listdir(os.getcwd())
build_files = []
for file in files:
if file.endswith(extension):
build_files.append(file)
return build_files
def Load(build_files, format, default_variables={},
includes=[], depth='.', params=None, check=False,
circular_check=True, duplicate_basename_check=True):
"""
Loads one or more specified build files.
default_variables and includes will be copied before use.
Returns the generator for the specified format and the
data returned by loading the specified build files.
"""
if params is None:
params = {}
if '-' in format:
format, params['flavor'] = format.split('-', 1)
default_variables = copy.copy(default_variables)
# Default variables provided by this program and its modules should be
# named WITH_CAPITAL_LETTERS to provide a distinct "best practice" namespace,
# avoiding collisions with user and automatic variables.
default_variables['GENERATOR'] = format
default_variables['GENERATOR_FLAVOR'] = params.get('flavor', '')
# Format can be a custom python file, or by default the name of a module
# within gyp.generator.
if format.endswith('.py'):
generator_name = os.path.splitext(format)[0]
path, generator_name = os.path.split(generator_name)
# Make sure the path to the custom generator is in sys.path
# Don't worry about removing it once we are done. Keeping the path
# to each generator that is used in sys.path is likely harmless and
# arguably a good idea.
path = os.path.abspath(path)
if path not in sys.path:
sys.path.insert(0, path)
else:
generator_name = 'gyp.generator.' + format
# These parameters are passed in order (as opposed to by key)
# because ActivePython cannot handle key parameters to __import__.
generator = __import__(generator_name, globals(), locals(), generator_name)
for (key, val) in generator.generator_default_variables.items():
default_variables.setdefault(key, val)
# Give the generator the opportunity to set additional variables based on
# the params it will receive in the output phase.
if getattr(generator, 'CalculateVariables', None):
generator.CalculateVariables(default_variables, params)
# Give the generator the opportunity to set generator_input_info based on
# the params it will receive in the output phase.
if getattr(generator, 'CalculateGeneratorInputInfo', None):
generator.CalculateGeneratorInputInfo(params)
# Fetch the generator specific info that gets fed to input, we use getattr
# so we can default things and the generators only have to provide what
# they need.
generator_input_info = {
'non_configuration_keys':
getattr(generator, 'generator_additional_non_configuration_keys', []),
'path_sections':
getattr(generator, 'generator_additional_path_sections', []),
'extra_sources_for_rules':
getattr(generator, 'generator_extra_sources_for_rules', []),
'generator_supports_multiple_toolsets':
getattr(generator, 'generator_supports_multiple_toolsets', False),
'generator_wants_static_library_dependencies_adjusted':
getattr(generator,
'generator_wants_static_library_dependencies_adjusted', True),
'generator_wants_sorted_dependencies':
getattr(generator, 'generator_wants_sorted_dependencies', False),
'generator_filelist_paths':
getattr(generator, 'generator_filelist_paths', None),
}
# Process the input specific to this generator.
result = gyp.input.Load(build_files, default_variables, includes[:],
depth, generator_input_info, check, circular_check,
duplicate_basename_check,
params['parallel'], params['root_targets'])
return [generator] + result
def NameValueListToDict(name_value_list):
"""
Takes an array of strings of the form 'NAME=VALUE' and creates a dictionary
of the pairs. If a string is simply NAME, then the value in the dictionary
is set to True. If VALUE can be converted to an integer, it is.
"""
result = { }
for item in name_value_list:
tokens = item.split('=', 1)
if len(tokens) == 2:
# If we can make it an int, use that, otherwise, use the string.
try:
token_value = int(tokens[1])
except ValueError:
token_value = tokens[1]
# Set the variable to the supplied value.
result[tokens[0]] = token_value
else:
# No value supplied, treat it as a boolean and set it.
result[tokens[0]] = True
return result
def ShlexEnv(env_name):
flags = os.environ.get(env_name, [])
if flags:
flags = shlex.split(flags)
return flags
def FormatOpt(opt, value):
if opt.startswith('--'):
return '%s=%s' % (opt, value)
return opt + value
def RegenerateAppendFlag(flag, values, predicate, env_name, options):
"""Regenerate a list of command line flags, for an option of action='append'.
The |env_name|, if given, is checked in the environment and used to generate
an initial list of options, then the options that were specified on the
command line (given in |values|) are appended. This matches the handling of
environment variables and command line flags where command line flags override
the environment, while not requiring the environment to be set when the flags
are used again.
"""
flags = []
if options.use_environment and env_name:
for flag_value in ShlexEnv(env_name):
value = FormatOpt(flag, predicate(flag_value))
if value in flags:
flags.remove(value)
flags.append(value)
if values:
for flag_value in values:
flags.append(FormatOpt(flag, predicate(flag_value)))
return flags
def RegenerateFlags(options):
"""Given a parsed options object, and taking the environment variables into
account, returns a list of flags that should regenerate an equivalent options
object (even in the absence of the environment variables.)
Any path options will be normalized relative to depth.
The format flag is not included, as it is assumed the calling generator will
set that as appropriate.
"""
def FixPath(path):
path = gyp.common.FixIfRelativePath(path, options.depth)
if not path:
return os.path.curdir
return path
def Noop(value):
return value
# We always want to ignore the environment when regenerating, to avoid
# duplicate or changed flags in the environment at the time of regeneration.
flags = ['--ignore-environment']
for name, metadata in options._regeneration_metadata.iteritems():
opt = metadata['opt']
value = getattr(options, name)
value_predicate = metadata['type'] == 'path' and FixPath or Noop
action = metadata['action']
env_name = metadata['env_name']
if action == 'append':
flags.extend(RegenerateAppendFlag(opt, value, value_predicate,
env_name, options))
elif action in ('store', None): # None is a synonym for 'store'.
if value:
flags.append(FormatOpt(opt, value_predicate(value)))
elif options.use_environment and env_name and os.environ.get(env_name):
flags.append(FormatOpt(opt, value_predicate(os.environ.get(env_name))))
elif action in ('store_true', 'store_false'):
if ((action == 'store_true' and value) or
(action == 'store_false' and not value)):
flags.append(opt)
elif options.use_environment and env_name:
print >>sys.stderr, ('Warning: environment regeneration unimplemented '
'for %s flag %r env_name %r' % (action, opt,
env_name))
else:
print >>sys.stderr, ('Warning: regeneration unimplemented for action %r '
'flag %r' % (action, opt))
return flags
class RegeneratableOptionParser(optparse.OptionParser):
def __init__(self):
self.__regeneratable_options = {}
optparse.OptionParser.__init__(self)
def add_option(self, *args, **kw):
"""Add an option to the parser.
This accepts the same arguments as OptionParser.add_option, plus the
following:
regenerate: can be set to False to prevent this option from being included
in regeneration.
env_name: name of environment variable that additional values for this
option come from.
type: adds type='path', to tell the regenerator that the values of
this option need to be made relative to options.depth
"""
env_name = kw.pop('env_name', None)
if 'dest' in kw and kw.pop('regenerate', True):
dest = kw['dest']
# The path type is needed for regenerating, for optparse we can just treat
# it as a string.
type = kw.get('type')
if type == 'path':
kw['type'] = 'string'
self.__regeneratable_options[dest] = {
'action': kw.get('action'),
'type': type,
'env_name': env_name,
'opt': args[0],
}
optparse.OptionParser.add_option(self, *args, **kw)
def parse_args(self, *args):
values, args = optparse.OptionParser.parse_args(self, *args)
values._regeneration_metadata = self.__regeneratable_options
return values, args
def gyp_main(args):
my_name = os.path.basename(sys.argv[0])
parser = RegeneratableOptionParser()
usage = 'usage: %s [options ...] [build_file ...]'
parser.set_usage(usage.replace('%s', '%prog'))
parser.add_option('--build', dest='configs', action='append',
help='configuration for build after project generation')
parser.add_option('--check', dest='check', action='store_true',
help='check format of gyp files')
parser.add_option('--config-dir', dest='config_dir', action='store',
env_name='GYP_CONFIG_DIR', default=None,
help='The location for configuration files like '
'include.gypi.')
parser.add_option('-d', '--debug', dest='debug', metavar='DEBUGMODE',
action='append', default=[], help='turn on a debugging '
'mode for debugging GYP. Supported modes are "variables", '
'"includes" and "general" or "all" for all of them.')
parser.add_option('-D', dest='defines', action='append', metavar='VAR=VAL',
env_name='GYP_DEFINES',
help='sets variable VAR to value VAL')
parser.add_option('--depth', dest='depth', metavar='PATH', type='path',
help='set DEPTH gyp variable to a relative path to PATH')
parser.add_option('-f', '--format', dest='formats', action='append',
env_name='GYP_GENERATORS', regenerate=False,
help='output formats to generate')
parser.add_option('-G', dest='generator_flags', action='append', default=[],
metavar='FLAG=VAL', env_name='GYP_GENERATOR_FLAGS',
help='sets generator flag FLAG to VAL')
parser.add_option('--generator-output', dest='generator_output',
action='store', default=None, metavar='DIR', type='path',
env_name='GYP_GENERATOR_OUTPUT',
help='puts generated build files under DIR')
parser.add_option('--ignore-environment', dest='use_environment',
action='store_false', default=True, regenerate=False,
help='do not read options from environment variables')
parser.add_option('-I', '--include', dest='includes', action='append',
metavar='INCLUDE', type='path',
help='files to include in all loaded .gyp files')
# --no-circular-check disables the check for circular relationships between
# .gyp files. These relationships should not exist, but they've only been
# observed to be harmful with the Xcode generator. Chromium's .gyp files
# currently have some circular relationships on non-Mac platforms, so this
# option allows the strict behavior to be used on Macs and the lenient
# behavior to be used elsewhere.
# TODO(mark): Remove this option when http://crbug.com/35878 is fixed.
parser.add_option('--no-circular-check', dest='circular_check',
action='store_false', default=True, regenerate=False,
help="don't check for circular relationships between files")
# --no-duplicate-basename-check disables the check for duplicate basenames
# in a static_library/shared_library project. Visual C++ 2008 generator
# doesn't support this configuration. Libtool on Mac also generates warnings
# when duplicate basenames are passed into Make generator on Mac.
# TODO(yukawa): Remove this option when these legacy generators are
# deprecated.
parser.add_option('--no-duplicate-basename-check',
dest='duplicate_basename_check', action='store_false',
default=True, regenerate=False,
help="don't check for duplicate basenames")
parser.add_option('--no-parallel', action='store_true', default=False,
help='Disable multiprocessing')
parser.add_option('-S', '--suffix', dest='suffix', default='',
help='suffix to add to generated files')
parser.add_option('--toplevel-dir', dest='toplevel_dir', action='store',
default=None, metavar='DIR', type='path',
help='directory to use as the root of the source tree')
parser.add_option('-R', '--root-target', dest='root_targets',
action='append', metavar='TARGET',
help='include only TARGET and its deep dependencies')
options, build_files_arg = parser.parse_args(args)
build_files = build_files_arg
# Set up the configuration directory (defaults to ~/.gyp)
if not options.config_dir:
home = None
home_dot_gyp = None
if options.use_environment:
home_dot_gyp = os.environ.get('GYP_CONFIG_DIR', None)
if home_dot_gyp:
home_dot_gyp = os.path.expanduser(home_dot_gyp)
if not home_dot_gyp:
home_vars = ['HOME']
if sys.platform in ('cygwin', 'win32'):
home_vars.append('USERPROFILE')
for home_var in home_vars:
home = os.getenv(home_var)
if home != None:
home_dot_gyp = os.path.join(home, '.gyp')
if not os.path.exists(home_dot_gyp):
home_dot_gyp = None
else:
break
else:
home_dot_gyp = os.path.expanduser(options.config_dir)
if home_dot_gyp and not os.path.exists(home_dot_gyp):
home_dot_gyp = None
if not options.formats:
# If no format was given on the command line, then check the env variable.
generate_formats = []
if options.use_environment:
generate_formats = os.environ.get('GYP_GENERATORS', [])
if generate_formats:
generate_formats = re.split(r'[\s,]', generate_formats)
if generate_formats:
options.formats = generate_formats
else:
# Nothing in the variable, default based on platform.
if sys.platform == 'darwin':
options.formats = ['xcode']
elif sys.platform in ('win32', 'cygwin'):
options.formats = ['msvs']
else:
options.formats = ['make']
if not options.generator_output and options.use_environment:
g_o = os.environ.get('GYP_GENERATOR_OUTPUT')
if g_o:
options.generator_output = g_o
options.parallel = not options.no_parallel
for mode in options.debug:
gyp.debug[mode] = 1
# Do an extra check to avoid work when we're not debugging.
if DEBUG_GENERAL in gyp.debug:
DebugOutput(DEBUG_GENERAL, 'running with these options:')
for option, value in sorted(options.__dict__.items()):
if option[0] == '_':
continue
if isinstance(value, basestring):
DebugOutput(DEBUG_GENERAL, " %s: '%s'", option, value)
else:
DebugOutput(DEBUG_GENERAL, " %s: %s", option, value)
if not build_files:
build_files = FindBuildFiles()
if not build_files:
raise GypError((usage + '\n\n%s: error: no build_file') %
(my_name, my_name))
# TODO(mark): Chromium-specific hack!
# For Chromium, the gyp "depth" variable should always be a relative path
# to Chromium's top-level "src" directory. If no depth variable was set
# on the command line, try to find a "src" directory by looking at the
# absolute path to each build file's directory. The first "src" component
# found will be treated as though it were the path used for --depth.
if not options.depth:
for build_file in build_files:
build_file_dir = os.path.abspath(os.path.dirname(build_file))
build_file_dir_components = build_file_dir.split(os.path.sep)
components_len = len(build_file_dir_components)
for index in xrange(components_len - 1, -1, -1):
if build_file_dir_components[index] == 'src':
options.depth = os.path.sep.join(build_file_dir_components)
break
del build_file_dir_components[index]
# If the inner loop found something, break without advancing to another
# build file.
if options.depth:
break
if not options.depth:
raise GypError('Could not automatically locate src directory. This is'
'a temporary Chromium feature that will be removed. Use'
'--depth as a workaround.')
# If toplevel-dir is not set, we assume that depth is the root of our source
# tree.
if not options.toplevel_dir:
options.toplevel_dir = options.depth
# -D on the command line sets variable defaults - D isn't just for define,
# it's for default. Perhaps there should be a way to force (-F?) a
# variable's value so that it can't be overridden by anything else.
cmdline_default_variables = {}
defines = []
if options.use_environment:
defines += ShlexEnv('GYP_DEFINES')
if options.defines:
defines += options.defines
cmdline_default_variables = NameValueListToDict(defines)
if DEBUG_GENERAL in gyp.debug:
DebugOutput(DEBUG_GENERAL,
"cmdline_default_variables: %s", cmdline_default_variables)
# Set up includes.
includes = []
# If ~/.gyp/include.gypi exists, it'll be forcibly included into every
# .gyp file that's loaded, before anything else is included.
if home_dot_gyp != None:
default_include = os.path.join(home_dot_gyp, 'include.gypi')
if os.path.exists(default_include):
print 'Using overrides found in ' + default_include
includes.append(default_include)
# Command-line --include files come after the default include.
if options.includes:
includes.extend(options.includes)
# Generator flags should be prefixed with the target generator since they
# are global across all generator runs.
gen_flags = []
if options.use_environment:
gen_flags += ShlexEnv('GYP_GENERATOR_FLAGS')
if options.generator_flags:
gen_flags += options.generator_flags
generator_flags = NameValueListToDict(gen_flags)
if DEBUG_GENERAL in gyp.debug.keys():
DebugOutput(DEBUG_GENERAL, "generator_flags: %s", generator_flags)
# Generate all requested formats (use a set in case we got one format request
# twice)
for format in set(options.formats):
params = {'options': options,
'build_files': build_files,
'generator_flags': generator_flags,
'cwd': os.getcwd(),
'build_files_arg': build_files_arg,
'gyp_binary': sys.argv[0],
'home_dot_gyp': home_dot_gyp,
'parallel': options.parallel,
'root_targets': options.root_targets,
'target_arch': cmdline_default_variables.get('target_arch', '')}
# Start with the default variables from the command line.
[generator, flat_list, targets, data] = Load(
build_files, format, cmdline_default_variables, includes, options.depth,
params, options.check, options.circular_check,
options.duplicate_basename_check)
# TODO(mark): Pass |data| for now because the generator needs a list of
# build files that came in. In the future, maybe it should just accept
# a list, and not the whole data dict.
# NOTE: flat_list is the flattened dependency graph specifying the order
# that targets may be built. Build systems that operate serially or that
# need to have dependencies defined before dependents reference them should
# generate targets in the order specified in flat_list.
generator.GenerateOutput(flat_list, targets, data, params)
if options.configs:
valid_configs = targets[flat_list[0]]['configurations'].keys()
for conf in options.configs:
if conf not in valid_configs:
raise GypError('Invalid config specified via --build: %s' % conf)
generator.PerformBuild(data, options.configs, params)
# Done
return 0
def main(args):
try:
return gyp_main(args)
except GypError, e:
sys.stderr.write("gyp: %s\n" % e)
return 1
# NOTE: setuptools generated console_scripts calls function with no arguments
def script_main():
return main(sys.argv[1:])
if __name__ == '__main__':
sys.exit(script_main())
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
1898,
334,
67,
9,
6029,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
646,
1331,
199,
646,
4902,
14,
1210,
199,
646,
8691,
199,
646,
747,
14,
515,
199,
646,
295,
199,
646,
16701,
199,
646,
984,
199,
646,
5190,
199,
504,
4902,
14,
2330,
492,
18151,
199,
199,
3,
3758,
3105,
12404,
367,
25686,
199,
1757,
275,
1052,
199,
199,
3,
3820,
402,
298,
29260,
2,
3105,
12404,
12,
1325,
1265,
883,
675,
7003,
1265,
2839,
14,
199,
5287,
63,
31548,
275,
283,
10706,
7,
199,
5287,
63,
21161,
275,
283,
3669,
7,
199,
5287,
63,
568,
29992,
275,
283,
9441,
7,
421,
199,
318,
14245,
2959,
8,
632,
12,
1245,
12,
627,
589,
304,
523,
340,
283,
452,
7,
315,
4902,
14,
1757,
503,
818,
315,
4902,
14,
1757,
26,
272,
4027,
275,
661,
5187,
297,
378,
12,
283,
5187,
358,
272,
862,
26,
489,
289,
275,
5190,
14,
5005,
63,
2340,
8,
3097,
29,
18,
9,
489,
340,
289,
26,
267,
4027,
275,
289,
59,
16,
19663,
19,
61,
272,
871,
26,
489,
986,
272,
340,
1249,
26,
489,
1245,
450,
29,
1249,
272,
870,
1543,
83,
2689,
83,
2689,
68,
2689,
83,
450,
83,
7,
450,
334,
632,
14,
4142,
1062,
747,
14,
515,
14,
4846,
8,
3799,
59,
16,
2522,
2892,
4027,
59,
17,
467,
4027,
59,
18,
467,
1245,
9,
199,
199,
318,
6668,
3425,
5535,
837,
523,
3329,
275,
1987,
6179,
7,
523,
1584,
275,
747,
14,
7374,
8,
736,
14,
9458,
1012,
523,
1900,
63,
1725,
275,
942,
523,
367,
570,
315,
1584,
26,
272,
340,
570,
14,
4130,
8,
3435,
304,
489,
1900,
63,
1725,
14,
740,
8,
493,
9,
523,
372,
1900,
63,
1725,
421,
199,
318,
7190,
8,
1506,
63,
1725,
12,
1475,
12,
849,
63,
3669,
10324,
268,
6952,
6034,
5818,
534,
3130,
1862,
29,
403,
12,
1104,
29,
797,
12,
268,
15032,
63,
1074,
29,
549,
12,
9250,
63,
4846,
63,
1074,
29,
549,
304,
523,
408,
523,
30367,
1373,
503,
1655,
2013,
1900,
1584,
14,
523,
849,
63,
3669,
436,
6952,
911,
506,
8876,
2544,
675,
14,
523,
1803,
314,
4306,
367,
314,
2013,
1475,
436,
314,
523,
666,
2138,
701,
8697,
314,
2013,
1900,
1584,
14,
523,
408,
523,
340,
1862,
365,
488,
26,
272,
1862,
275,
1052,
819,
340,
10791,
315,
1475,
26,
272,
1475,
12,
1862,
459,
6081,
418,
275,
1475,
14,
1294,
13858,
413,
9,
819,
849,
63,
3669,
275,
1331,
14,
1574,
8,
885,
63,
3669,
9,
819,
327,
3758,
2860,
2741,
701,
642,
2240,
436,
2399,
4621,
1077,
506,
523,
327,
4310,
1663,
63,
35,
2669,
63,
44,
1573,
51,
370,
5647,
282,
15392,
298,
7010,
24471,
2,
3231,
12,
523,
327,
5126,
316,
30063,
543,
922,
436,
4834,
2860,
14,
523,
849,
63,
3669,
459,
12795,
6467,
418,
275,
1475,
523,
849,
63,
3669,
459,
12795,
6467,
63,
3143,
6087,
726,
418,
275,
1862,
14,
362,
360,
6081,
297,
4074,
819,
327,
9701,
883,
506,
282,
3537,
2366,
570,
12,
503,
701,
849,
314,
536,
402,
282,
859,
523,
327,
4453,
4902,
14,
4679,
14,
523,
340,
1475,
14,
4130,
5175,
647,
735,
272,
4306,
63,
354,
275,
747,
14,
515,
14,
7973,
8,
908,
2788,
16,
61,
272,
931,
12,
4306,
63,
354,
275,
747,
14,
515,
14,
1294,
8,
4679,
63,
354,
9,
339,
327,
4155,
3238,
314,
931,
370,
314,
3537,
4306,
365,
315,
984,
14,
515,
272,
327,
7529,
1133,
30944,
3595,
12881,
652,
5403,
781,
787,
4224,
14,
221,
1804,
1024,
4073,
314,
931,
272,
327,
370,
1924,
4306,
626,
365,
1202,
315,
984,
14,
515,
365,
12060,
394,
5362,
2003,
436,
272,
327,
1680,
85,
6665,
282,
6954,
16819,
14,
272,
931,
275,
747,
14,
515,
14,
4832,
8,
515,
9,
272,
340,
931,
440,
315,
984,
14,
515,
26,
489,
984,
14,
515,
14,
3176,
8,
16,
12,
931,
9,
523,
587,
26,
272,
4306,
63,
354,
275,
283,
6179,
14,
4679,
3530,
435,
1475,
819,
327,
5723,
2633,
787,
3032,
315,
1865,
334,
305,
25068,
370,
701,
790,
9,
523,
327,
2952,
23241,
4718,
3913,
2429,
790,
2633,
370,
636,
646,
4343,
523,
4306,
275,
636,
646,
721,
4679,
63,
354,
12,
7992,
1062,
9480,
1062,
4306,
63,
354,
9,
523,
367,
334,
498,
12,
1139,
9,
315,
4306,
14,
4679,
63,
885,
63,
3669,
14,
1744,
837,
272,
849,
63,
3669,
14,
5486,
8,
498,
12,
1139,
9,
819,
327,
25495,
314,
4306,
314,
30914,
370,
663,
4722,
2860,
4079,
641,
523,
327,
314,
1862,
652,
911,
9128,
315,
314,
1072,
7669,
14,
523,
340,
2519,
8,
4679,
12,
283,
14860,
11458,
297,
488,
304,
272,
4306,
14,
14860,
11458,
8,
885,
63,
3669,
12,
1862,
9,
819,
327,
25495,
314,
4306,
314,
30914,
370,
663,
4306,
63,
1210,
63,
815,
4079,
641,
523,
327,
314,
1862,
652,
911,
9128,
315,
314,
1072,
7669,
14,
523,
340,
2519,
8,
4679,
12,
283,
14860,
7599,
3205,
2354,
297,
488,
304,
272,
4306,
14,
14860,
7599,
3205,
2354,
8,
1162,
9,
819,
327,
16347,
314,
4306,
2488,
2256,
626,
7545,
23036,
370,
1324,
12,
781,
675,
2519,
523,
327,
880,
781,
883,
849,
7645,
436,
314,
16952,
1454,
1172,
370,
5647,
4052,
523,
327,
2985,
1929,
14,
523,
4306,
63,
1210,
63,
815,
275,
469,
272,
283,
2865,
63,
4758,
63,
1612,
356,
267,
2519,
8,
4679,
12,
283,
4679,
63,
8460,
63,
2865,
63,
4758,
63,
1612,
297,
14431,
272,
283,
515,
63,
7786,
356,
267,
2519,
8,
4679,
12,
283,
4679,
63,
8460,
63,
515,
63,
7786,
297,
14431,
272,
283,
2911,
63,
4553,
63,
509,
63,
4423,
356,
267,
2519,
8,
4679,
12,
283,
4679,
63,
2911,
63,
4553,
63,
509,
63,
4423,
297,
14431,
272,
283,
4679,
63,
9823,
63,
6048,
63,
30116,
356,
267,
2519,
8,
4679,
12,
283,
4679,
63,
9823,
63,
6048,
63,
30116,
297,
756,
395,
272,
283,
4679,
63,
28789
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
1898,
334,
67,
9,
6029,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
646,
1331,
199,
646,
4902,
14,
1210,
199,
646,
8691,
199,
646,
747,
14,
515,
199,
646,
295,
199,
646,
16701,
199,
646,
984,
199,
646,
5190,
199,
504,
4902,
14,
2330,
492,
18151,
199,
199,
3,
3758,
3105,
12404,
367,
25686,
199,
1757,
275,
1052,
199,
199,
3,
3820,
402,
298,
29260,
2,
3105,
12404,
12,
1325,
1265,
883,
675,
7003,
1265,
2839,
14,
199,
5287,
63,
31548,
275,
283,
10706,
7,
199,
5287,
63,
21161,
275,
283,
3669,
7,
199,
5287,
63,
568,
29992,
275,
283,
9441,
7,
421,
199,
318,
14245,
2959,
8,
632,
12,
1245,
12,
627,
589,
304,
523,
340,
283,
452,
7,
315,
4902,
14,
1757,
503,
818,
315,
4902,
14,
1757,
26,
272,
4027,
275,
661,
5187,
297,
378,
12,
283,
5187,
358,
272,
862,
26,
489,
289,
275,
5190,
14,
5005,
63,
2340,
8,
3097,
29,
18,
9,
489,
340,
289,
26,
267,
4027,
275,
289,
59,
16,
19663,
19,
61,
272,
871,
26,
489,
986,
272,
340,
1249,
26,
489,
1245,
450,
29,
1249,
272,
870,
1543,
83,
2689,
83,
2689,
68,
2689,
83,
450,
83,
7,
450,
334,
632,
14,
4142,
1062,
747,
14,
515,
14,
4846,
8,
3799,
59,
16,
2522,
2892,
4027,
59,
17,
467,
4027,
59,
18,
467,
1245,
9,
199,
199,
318,
6668,
3425,
5535,
837,
523,
3329,
275,
1987,
6179,
7,
523,
1584,
275,
747,
14,
7374,
8,
736,
14,
9458,
1012,
523,
1900,
63,
1725,
275,
942,
523,
367,
570,
315,
1584,
26,
272,
340,
570,
14,
4130,
8,
3435,
304,
489,
1900,
63,
1725,
14,
740,
8,
493,
9,
523,
372,
1900,
63,
1725,
421,
199,
318,
7190,
8,
1506,
63,
1725,
12,
1475,
12,
849,
63,
3669,
10324,
268,
6952,
6034,
5818,
534,
3130,
1862,
29,
403,
12,
1104,
29,
797,
12,
268,
15032,
63,
1074,
29,
549,
12,
9250,
63,
4846,
63,
1074,
29,
549,
304,
523,
408,
523,
30367,
1373,
503,
1655,
2013,
1900,
1584,
14,
523,
849,
63,
3669,
436,
6952,
911,
506,
8876,
2544,
675,
14,
523,
1803,
314,
4306,
367,
314,
2013,
1475,
436,
314,
523,
666,
2138,
701,
8697,
314,
2013,
1900,
1584,
14,
523,
408,
523,
340,
1862,
365,
488,
26,
272,
1862,
275,
1052,
819,
340,
10791,
315,
1475,
26,
272,
1475,
12,
1862,
459,
6081,
418,
275,
1475,
14,
1294,
13858,
413,
9,
819,
849,
63,
3669,
275,
1331,
14,
1574,
8,
885,
63,
3669,
9,
819,
327,
3758,
2860,
2741,
701,
642,
2240,
436,
2399,
4621,
1077,
506,
523,
327,
4310,
1663,
63,
35,
2669,
63,
44,
1573,
51,
370,
5647,
282,
15392,
298,
7010,
24471,
2,
3231,
12,
523,
327,
5126,
316,
30063,
543,
922,
436,
4834,
2860,
14,
523,
849,
63,
3669,
459,
12795,
6467,
418,
275,
1475,
523,
849,
63,
3669,
459,
12795,
6467,
63,
3143,
6087,
726,
418,
275,
1862,
14,
362,
360,
6081,
297,
4074,
819,
327,
9701,
883,
506,
282,
3537,
2366,
570,
12,
503,
701,
849,
314,
536,
402,
282,
859,
523,
327,
4453,
4902,
14,
4679,
14,
523,
340,
1475,
14,
4130,
5175,
647,
735,
272,
4306,
63,
354,
275,
747,
14,
515,
14,
7973,
8,
908,
2788,
16,
61,
272,
931,
12,
4306,
63,
354,
275,
747,
14,
515,
14,
1294,
8,
4679,
63,
354,
9,
339,
327,
4155,
3238,
314,
931,
370,
314,
3537,
4306,
365,
315,
984,
14,
515,
272,
327,
7529,
1133,
30944,
3595,
12881,
652,
5403,
781,
787,
4224,
14,
221,
1804,
1024,
4073,
314,
931,
272,
327,
370,
1924,
4306,
626,
365,
1202,
315,
984,
14,
515,
365,
12060,
394,
5362,
2003,
436,
272,
327,
1680,
85,
6665,
282,
6954,
16819,
14,
272,
931,
275,
747,
14,
515,
14,
4832,
8,
515,
9,
272,
340,
931,
440,
315,
984,
14,
515,
26,
489,
984,
14,
515,
14,
3176,
8,
16,
12,
931,
9,
523,
587,
26,
272,
4306,
63,
354,
275,
283,
6179,
14,
4679,
3530,
435,
1475,
819,
327,
5723,
2633,
787,
3032,
315,
1865,
334,
305,
25068,
370,
701,
790,
9,
523,
327,
2952,
23241,
4718,
3913,
2429,
790,
2633,
370,
636,
646,
4343,
523,
4306,
275,
636,
646,
721,
4679,
63,
354,
12,
7992,
1062,
9480,
1062,
4306,
63,
354,
9,
523,
367,
334,
498,
12,
1139,
9,
315,
4306,
14,
4679,
63,
885,
63,
3669,
14,
1744,
837,
272,
849,
63,
3669,
14,
5486,
8,
498,
12,
1139,
9,
819,
327,
25495,
314,
4306,
314,
30914,
370,
663,
4722,
2860,
4079,
641,
523,
327,
314,
1862,
652,
911,
9128,
315,
314,
1072,
7669,
14,
523,
340,
2519,
8,
4679,
12,
283,
14860,
11458,
297,
488,
304,
272,
4306,
14,
14860,
11458,
8,
885,
63,
3669,
12,
1862,
9,
819,
327,
25495,
314,
4306,
314,
30914,
370,
663,
4306,
63,
1210,
63,
815,
4079,
641,
523,
327,
314,
1862,
652,
911,
9128,
315,
314,
1072,
7669,
14,
523,
340,
2519,
8,
4679,
12,
283,
14860,
7599,
3205,
2354,
297,
488,
304,
272,
4306,
14,
14860,
7599,
3205,
2354,
8,
1162,
9,
819,
327,
16347,
314,
4306,
2488,
2256,
626,
7545,
23036,
370,
1324,
12,
781,
675,
2519,
523,
327,
880,
781,
883,
849,
7645,
436,
314,
16952,
1454,
1172,
370,
5647,
4052,
523,
327,
2985,
1929,
14,
523,
4306,
63,
1210,
63,
815,
275,
469,
272,
283,
2865,
63,
4758,
63,
1612,
356,
267,
2519,
8,
4679,
12,
283,
4679,
63,
8460,
63,
2865,
63,
4758,
63,
1612,
297,
14431,
272,
283,
515,
63,
7786,
356,
267,
2519,
8,
4679,
12,
283,
4679,
63,
8460,
63,
515,
63,
7786,
297,
14431,
272,
283,
2911,
63,
4553,
63,
509,
63,
4423,
356,
267,
2519,
8,
4679,
12,
283,
4679,
63,
2911,
63,
4553,
63,
509,
63,
4423,
297,
14431,
272,
283,
4679,
63,
9823,
63,
6048,
63,
30116,
356,
267,
2519,
8,
4679,
12,
283,
4679,
63,
9823,
63,
6048,
63,
30116,
297,
756,
395,
272,
283,
4679,
63,
28789,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
mydongistiny/android_external_skia
|
gm/rebaseline_server/column.py
|
67
|
2679
|
#!/usr/bin/python
"""
Copyright 2014 Google Inc.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
ColumnHeaderFactory class (see class docstring for details)
"""
# Keys used within dictionary representation of each column header.
# NOTE: Keep these in sync with static/constants.js
KEY__EXTRACOLUMNHEADERS__HEADER_TEXT = 'headerText'
KEY__EXTRACOLUMNHEADERS__HEADER_URL = 'headerUrl'
KEY__EXTRACOLUMNHEADERS__IS_FILTERABLE = 'isFilterable'
KEY__EXTRACOLUMNHEADERS__IS_SORTABLE = 'isSortable'
KEY__EXTRACOLUMNHEADERS__VALUES_AND_COUNTS = 'valuesAndCounts'
class ColumnHeaderFactory(object):
"""Factory which assembles the header for a single column of data."""
def __init__(self, header_text, header_url=None,
is_filterable=True, is_sortable=True,
include_values_and_counts=True):
"""
Args:
header_text: string; text the client should display within column header.
header_url: string; target URL if user clicks on column header.
If None, nothing to click on.
is_filterable: boolean; whether client should allow filtering on this
column.
is_sortable: boolean; whether client should allow sorting on this column.
include_values_and_counts: boolean; whether the set of values found
within this column, and their counts, should be available for the
client to display.
"""
self._header_text = header_text
self._header_url = header_url
self._is_filterable = is_filterable
self._is_sortable = is_sortable
self._include_values_and_counts = include_values_and_counts
def create_as_dict(self, values_and_counts_dict=None):
"""Creates the header for this column, in dictionary form.
Creates the header for this column in dictionary form, as needed when
constructing the JSON representation. Uses the KEY__EXTRACOLUMNHEADERS__*
constants as keys.
Args:
values_and_counts_dict: dictionary mapping each possible column value
to its count (how many entries in the column have this value), or
None if this information is not available.
"""
asdict = {
KEY__EXTRACOLUMNHEADERS__HEADER_TEXT: self._header_text,
KEY__EXTRACOLUMNHEADERS__IS_FILTERABLE: self._is_filterable,
KEY__EXTRACOLUMNHEADERS__IS_SORTABLE: self._is_sortable,
}
if self._header_url:
asdict[KEY__EXTRACOLUMNHEADERS__HEADER_URL] = self._header_url
if self._include_values_and_counts and values_and_counts_dict:
asdict[KEY__EXTRACOLUMNHEADERS__VALUES_AND_COUNTS] = sorted(
values_and_counts_dict.items())
return asdict
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
199,
624,
199,
7384,
6927,
4475,
3277,
14,
199,
199,
6119,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
4214,
315,
314,
5113,
570,
14,
199,
199,
4547,
2567,
2927,
1021,
334,
3239,
1021,
9214,
367,
2436,
9,
199,
624,
199,
199,
3,
17276,
1202,
4453,
2600,
6025,
402,
1924,
2763,
1406,
14,
199,
3,
6944,
26,
14797,
3520,
315,
7604,
543,
2955,
15,
5559,
14,
3596,
199,
3078,
363,
1438,
1766,
1348,
2228,
2639,
46,
21178,
363,
7311,
63,
3876,
275,
283,
1291,
1872,
7,
199,
3078,
363,
1438,
1766,
1348,
2228,
2639,
46,
21178,
363,
7311,
63,
2632,
275,
283,
1291,
6417,
7,
199,
3078,
363,
1438,
1766,
1348,
2228,
2639,
46,
21178,
363,
1311,
63,
9905,
2617,
275,
283,
374,
13079,
13048,
7,
199,
3078,
363,
1438,
1766,
1348,
2228,
2639,
46,
21178,
363,
1311,
63,
23447,
2617,
275,
283,
374,
14376,
461,
7,
199,
3078,
363,
1438,
1766,
1348,
2228,
2639,
46,
21178,
363,
15514,
63,
3649,
63,
8760,
51,
275,
283,
1459,
3325,
23209,
7,
421,
199,
533,
4996,
2567,
2927,
8,
785,
304,
523,
408,
2927,
1314,
22931,
83,
314,
1406,
367,
282,
2849,
2763,
402,
666,
1041,
819,
347,
636,
826,
721,
277,
12,
1406,
63,
505,
12,
1406,
63,
633,
29,
403,
12,
2049,
365,
63,
1289,
13048,
29,
549,
12,
365,
63,
3191,
461,
29,
549,
12,
2049,
2387,
63,
1459,
63,
460,
63,
6851,
29,
549,
304,
272,
408,
272,
3033,
26,
489,
1406,
63,
505,
26,
1059,
27,
1318,
314,
1890,
1077,
2929,
4453,
2763,
1406,
14,
489,
1406,
63,
633,
26,
1059,
27,
1347,
2851,
340,
922,
5053,
5618,
641,
2763,
1406,
14,
881,
982,
488,
12,
6548,
370,
8968,
641,
14,
489,
365,
63,
1289,
13048,
26,
5046,
27,
3775,
1890,
1077,
2040,
14545,
641,
642,
881,
2763,
14,
489,
365,
63,
3191,
461,
26,
5046,
27,
3775,
1890,
1077,
2040,
13351,
641,
642,
2763,
14,
489,
2387,
63,
1459,
63,
460,
63,
6851,
26,
5046,
27,
3775,
314,
663,
402,
1338,
1911,
881,
4453,
642,
2763,
12,
436,
3932,
8242,
12,
1077,
506,
2808,
367,
314,
881,
1890,
370,
2929,
14,
272,
408,
272,
291,
423,
1291,
63,
505,
275,
1406,
63,
505,
272,
291,
423,
1291,
63,
633,
275,
1406,
63,
633,
272,
291,
423,
374,
63,
1289,
13048,
275,
365,
63,
1289,
13048,
272,
291,
423,
374,
63,
3191,
461,
275,
365,
63,
3191,
461,
272,
291,
423,
2613,
63,
1459,
63,
460,
63,
6851,
275,
2387,
63,
1459,
63,
460,
63,
6851,
819,
347,
1218,
63,
305,
63,
807,
8,
277,
12,
1338,
63,
460,
63,
6851,
63,
807,
29,
403,
304,
272,
408,
10607,
314,
1406,
367,
642,
2763,
12,
315,
2600,
1824,
14,
339,
10560,
314,
1406,
367,
642,
2763,
315,
2600,
1824,
12,
465,
4346,
1380,
272,
22048,
314,
4840,
6025,
14,
221,
14911,
314,
9301,
363,
1438,
1766,
1348,
2228,
2639,
46,
21178,
363,
10,
272,
5262,
465,
2883,
14,
339,
3033,
26,
489,
1338,
63,
460,
63,
6851,
63,
807,
26,
2600,
4412,
1924,
3962,
2763,
574,
881,
370,
2399,
2338,
334,
1917,
5002,
4811,
315,
314,
2763,
1172,
642,
574,
395,
503,
881,
488,
340,
642,
2556,
365,
440,
2808,
14,
272,
408,
272,
465,
807,
275,
469,
267,
9301,
363,
1438,
1766,
1348,
2228,
2639,
46,
21178,
363,
7311,
63,
3876,
26,
291,
423,
1291,
63,
505,
12,
267,
9301,
363,
1438,
1766,
1348,
2228,
2639,
46,
21178,
363,
1311,
63,
9905,
2617,
26,
291,
423,
374,
63,
1289,
13048,
12,
267,
9301,
363,
1438,
1766,
1348,
2228,
2639,
46,
21178,
363,
1311,
63,
23447,
2617,
26,
291,
423,
374,
63,
3191,
461,
12,
272,
789,
272,
340,
291,
423,
1291,
63,
633,
26,
489,
465,
807,
59,
3078,
363,
1438,
1766,
1348,
2228,
2639,
46,
21178,
363,
7311,
63,
2632,
61,
275,
291,
423,
1291,
63,
633,
272,
340,
291,
423,
2613,
63,
1459,
63,
460,
63,
6851,
436,
1338,
63,
460,
63,
6851,
63,
807,
26,
489,
465,
807,
59,
3078,
363,
1438,
1766,
1348,
2228,
2639,
46,
21178,
363,
15514,
63,
3649,
63,
8760,
51,
61,
275,
3355,
8,
881,
1338,
63,
460,
63,
6851,
63,
807,
14,
1744,
1012,
272,
372,
465,
807,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1548,
199,
199,
624,
199,
7384,
6927,
4475,
3277,
14,
199,
199,
6119,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
4214,
315,
314,
5113,
570,
14,
199,
199,
4547,
2567,
2927,
1021,
334,
3239,
1021,
9214,
367,
2436,
9,
199,
624,
199,
199,
3,
17276,
1202,
4453,
2600,
6025,
402,
1924,
2763,
1406,
14,
199,
3,
6944,
26,
14797,
3520,
315,
7604,
543,
2955,
15,
5559,
14,
3596,
199,
3078,
363,
1438,
1766,
1348,
2228,
2639,
46,
21178,
363,
7311,
63,
3876,
275,
283,
1291,
1872,
7,
199,
3078,
363,
1438,
1766,
1348,
2228,
2639,
46,
21178,
363,
7311,
63,
2632,
275,
283,
1291,
6417,
7,
199,
3078,
363,
1438,
1766,
1348,
2228,
2639,
46,
21178,
363,
1311,
63,
9905,
2617,
275,
283,
374,
13079,
13048,
7,
199,
3078,
363,
1438,
1766,
1348,
2228,
2639,
46,
21178,
363,
1311,
63,
23447,
2617,
275,
283,
374,
14376,
461,
7,
199,
3078,
363,
1438,
1766,
1348,
2228,
2639,
46,
21178,
363,
15514,
63,
3649,
63,
8760,
51,
275,
283,
1459,
3325,
23209,
7,
421,
199,
533,
4996,
2567,
2927,
8,
785,
304,
523,
408,
2927,
1314,
22931,
83,
314,
1406,
367,
282,
2849,
2763,
402,
666,
1041,
819,
347,
636,
826,
721,
277,
12,
1406,
63,
505,
12,
1406,
63,
633,
29,
403,
12,
2049,
365,
63,
1289,
13048,
29,
549,
12,
365,
63,
3191,
461,
29,
549,
12,
2049,
2387,
63,
1459,
63,
460,
63,
6851,
29,
549,
304,
272,
408,
272,
3033,
26,
489,
1406,
63,
505,
26,
1059,
27,
1318,
314,
1890,
1077,
2929,
4453,
2763,
1406,
14,
489,
1406,
63,
633,
26,
1059,
27,
1347,
2851,
340,
922,
5053,
5618,
641,
2763,
1406,
14,
881,
982,
488,
12,
6548,
370,
8968,
641,
14,
489,
365,
63,
1289,
13048,
26,
5046,
27,
3775,
1890,
1077,
2040,
14545,
641,
642,
881,
2763,
14,
489,
365,
63,
3191,
461,
26,
5046,
27,
3775,
1890,
1077,
2040,
13351,
641,
642,
2763,
14,
489,
2387,
63,
1459,
63,
460,
63,
6851,
26,
5046,
27,
3775,
314,
663,
402,
1338,
1911,
881,
4453,
642,
2763,
12,
436,
3932,
8242,
12,
1077,
506,
2808,
367,
314,
881,
1890,
370,
2929,
14,
272,
408,
272,
291,
423,
1291,
63,
505,
275,
1406,
63,
505,
272,
291,
423,
1291,
63,
633,
275,
1406,
63,
633,
272,
291,
423,
374,
63,
1289,
13048,
275,
365,
63,
1289,
13048,
272,
291,
423,
374,
63,
3191,
461,
275,
365,
63,
3191,
461,
272,
291,
423,
2613,
63,
1459,
63,
460,
63,
6851,
275,
2387,
63,
1459,
63,
460,
63,
6851,
819,
347,
1218,
63,
305,
63,
807,
8,
277,
12,
1338,
63,
460,
63,
6851,
63,
807,
29,
403,
304,
272,
408,
10607,
314,
1406,
367,
642,
2763,
12,
315,
2600,
1824,
14,
339,
10560,
314,
1406,
367,
642,
2763,
315,
2600,
1824,
12,
465,
4346,
1380,
272,
22048,
314,
4840,
6025,
14,
221,
14911,
314,
9301,
363,
1438,
1766,
1348,
2228,
2639,
46,
21178,
363,
10,
272,
5262,
465,
2883,
14,
339,
3033,
26,
489,
1338,
63,
460,
63,
6851,
63,
807,
26,
2600,
4412,
1924,
3962,
2763,
574,
881,
370,
2399,
2338,
334,
1917,
5002,
4811,
315,
314,
2763,
1172,
642,
574,
395,
503,
881,
488,
340,
642,
2556,
365,
440,
2808,
14,
272,
408,
272,
465,
807,
275,
469,
267,
9301,
363,
1438,
1766,
1348,
2228,
2639,
46,
21178,
363,
7311,
63,
3876,
26,
291,
423,
1291,
63,
505,
12,
267,
9301,
363,
1438,
1766,
1348,
2228,
2639,
46,
21178,
363,
1311,
63,
9905,
2617,
26,
291,
423,
374,
63,
1289,
13048,
12,
267,
9301,
363,
1438,
1766,
1348,
2228,
2639,
46,
21178,
363,
1311,
63,
23447,
2617,
26,
291,
423,
374,
63,
3191,
461,
12,
272,
789,
272,
340,
291,
423,
1291,
63,
633,
26,
489,
465,
807,
59,
3078,
363,
1438,
1766,
1348,
2228,
2639,
46,
21178,
363,
7311,
63,
2632,
61,
275,
291,
423,
1291,
63,
633,
272,
340,
291,
423,
2613,
63,
1459,
63,
460,
63,
6851,
436,
1338,
63,
460,
63,
6851,
63,
807,
26,
489,
465,
807,
59,
3078,
363,
1438,
1766,
1348,
2228,
2639,
46,
21178,
363,
15514,
63,
3649,
63,
8760,
51,
61,
275,
3355,
8,
881,
1338,
63,
460,
63,
6851,
63,
807,
14,
1744,
1012,
272,
372,
465,
807,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
intel-hadoop/Big-Data-Benchmark-for-Big-Bench
|
engines/hive/queries/q08/q08_filter_sales_with_reviews_viewed_before.py
|
1
|
3144
|
#"INTEL CONFIDENTIAL"
#Copyright 2016 Intel Corporation All Rights Reserved.
#
#The source code contained or described herein and all documents related to the source code ("Material") are owned by Intel Corporation or its suppliers or licensors. Title to the Material remains with Intel Corporation or its suppliers and licensors. The Material contains trade secrets and proprietary and confidential information of Intel or its suppliers and licensors. The Material is protected by worldwide copyright and trade secret laws and treaty provisions. No part of the Material may be used, copied, reproduced, modified, published, uploaded, posted, transmitted, distributed, or disclosed in any way without Intel's prior express written permission.
#
#No license under any patent, copyright, trade secret or other intellectual property right is granted to or conferred upon you by disclosure or delivery of the Materials, either expressly, by implication, inducement, estoppel or otherwise. Any license under such intellectual property rights must be express and approved by Intel in writing.
import sys
import logging
import traceback
import os
import time
from time import strftime
web_page_type_filter=sys.argv[1]
seconds_before_sale_filter = long(sys.argv[2])
if __name__ == "__main__":
line = ''
try:
current_key = ''
last_review_date=-1
#sales_sk should be distinct
last_sales_sk = ''
#expects input to be partitioned by uid and sorted by date_sk (and timestamp) ascending
for line in sys.stdin:
# lustered by wcs_user_sk and by wcs_user_sk, tstamp_inSec_str, wcs_sales_sk, wp_type ascending in this order => ensured by hive
wcs_user_sk, tstamp_inSec_str, wcs_sales_sk, wp_type = line.strip().split("\t")
#reset on partition change
if current_key != wcs_user_sk :
current_key = wcs_user_sk
last_review_date = -1
last_sales_sk = ''
tstamp_inSec = long(tstamp_inSec_str)
#found review before purchase, save last review date
if wp_type == web_page_type_filter:
last_review_date = tstamp_inSec
continue
#if we encounter a sold item ( wcs_sales_sk.isdigit() => valid non null value) and a user looked at a review within 'seconds_before_sale_filter' => print found sales_sk backt to hive
#if last_review_date > 0 and (tstamp_inSec - last_review_date) <= seconds_before_sale_filter and wcs_sales_sk.isdigit() : #version with duplicate sales_sk's
if last_review_date > 0 and (tstamp_inSec - last_review_date) <= seconds_before_sale_filter and wcs_sales_sk.isdigit() and last_sales_sk != wcs_sales_sk : #version reduced duplicate sales_sk's
last_sales_sk = wcs_sales_sk
print wcs_sales_sk
except:
## should only happen if input format is not correct, like 4 instead of 5 tab separated values
logging.basicConfig(level=logging.DEBUG, filename=strftime("/tmp/bigbench_q8_reducer_%Y%m%d-%H%M%S.log"))
logging.info('web_page_type_filter: ' + web_page_type_filter )
logging.info('seconds_before_sale_filter: ' + seconds_before_sale_filter )
logging.info("line from hive: \"" + line + "\"")
logging.exception("Oops:")
raise
sys.exit(1)
|
apache-2.0
|
[
23662,
28859,
6392,
7466,
4938,
2,
199,
3,
7384,
7800,
20619,
11098,
2900,
5924,
5702,
14,
221,
199,
3,
199,
3,
1918,
1350,
1233,
10470,
503,
11736,
2348,
262,
436,
1006,
8247,
4048,
370,
314,
1350,
1233,
1689,
15787,
531,
787,
23191,
701,
20619,
11098,
503,
2399,
4973,
14035,
503,
23854,
17564,
14,
16881,
370,
314,
26570,
25803,
543,
20619,
11098,
503,
2399,
4973,
14035,
436,
23854,
17564,
14,
710,
26570,
3509,
21032,
25563,
436,
557,
1359,
386,
695,
436,
406,
329,
3256,
2556,
402,
20619,
503,
2399,
4973,
14035,
436,
23854,
17564,
14,
710,
26570,
365,
17819,
701,
6701,
13062,
4248,
436,
21032,
7565,
1127,
3569,
436,
14312,
89,
1727,
1356,
14,
3091,
1777,
402,
314,
26570,
1443,
506,
1202,
12,
8876,
12,
9172,
68,
12,
6042,
12,
3267,
12,
14238,
12,
22752,
12,
29818,
12,
1854,
12,
503,
4339,
320,
939,
315,
1263,
4340,
1928,
20619,
1159,
6791,
4056,
5313,
4983,
14,
199,
3,
199,
3,
1944,
4190,
1334,
1263,
299,
323,
343,
12,
4248,
12,
21032,
7565,
503,
1163,
27925,
1264,
1061,
3324,
2451,
365,
10009,
370,
503,
406,
5057,
12188,
1265,
701,
4339,
320,
3253,
503,
18719,
402,
314,
26570,
83,
12,
1902,
4056,
590,
12,
701,
1742,
1863,
12,
315,
3402,
434,
12,
325,
2379,
28478,
503,
4257,
14,
6184,
4190,
1334,
4066,
27925,
1264,
1061,
3324,
4481,
1471,
506,
4056,
436,
30055,
701,
20619,
315,
3575,
14,
199,
199,
646,
984,
199,
646,
2050,
199,
646,
5190,
199,
646,
747,
199,
646,
900,
199,
504,
900,
492,
14053,
199,
199,
2520,
63,
1606,
63,
466,
63,
1541,
29,
1274,
14,
3020,
59,
17,
61,
221,
199,
4515,
63,
5182,
63,
8515,
63,
1541,
275,
1846,
8,
1274,
14,
3020,
59,
18,
566,
8299,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
199,
198,
604,
275,
2125,
199,
198,
893,
26,
507,
198,
1818,
63,
498,
275,
2125,
507,
198,
2019,
63,
8578,
63,
602,
4022,
17,
507,
198,
3,
16175,
63,
1339,
1077,
506,
15392,
507,
198,
2019,
63,
16175,
63,
1339,
275,
2125,
507,
198,
3,
4921,
83,
1324,
370,
506,
27105,
701,
1747,
436,
3355,
701,
1434,
63,
1339,
334,
460,
4913,
9,
24525,
6319,
507,
198,
509,
1004,
315,
984,
14,
6626,
26,
686,
198,
3,
634,
527,
3014,
701,
336,
1259,
63,
751,
63,
1339,
436,
701,
336,
1259,
63,
751,
63,
1339,
12,
307,
2359,
63,
262,
4933,
63,
495,
12,
336,
1259,
63,
16175,
63,
1339,
12,
19997,
63,
466,
24525,
315,
642,
1865,
9265,
12889,
3297,
701,
29134,
686,
198,
30394,
63,
751,
63,
1339,
12,
307,
2359,
63,
262,
4933,
63,
495,
12,
336,
1259,
63,
16175,
63,
1339,
12,
19997,
63,
466,
275,
1004,
14,
1913,
1252,
1294,
4582,
84,
531,
6319,
198,
3,
3958,
641,
6484,
1570,
20866,
198,
692,
1453,
63,
498,
1137,
336,
1259,
63,
751,
63,
1339,
520,
1585,
198,
1818,
63,
498,
275,
336,
1259,
63,
751,
63,
1339,
1585,
198,
2019,
63,
8578,
63,
602,
275,
446,
17,
1585,
198,
2019,
63,
16175,
63,
1339,
275,
2125,
1871,
686,
198,
84,
2359,
63,
262,
4933,
275,
1846,
8,
84,
2359,
63,
262,
4933,
63,
495,
9,
1871,
686,
198,
3,
4214,
11248,
2544,
15932,
12,
3354,
2061,
11248,
1434,
686,
198,
692,
19997,
63,
466,
508,
3330,
63,
1606,
63,
466,
63,
1541,
26,
1585,
198,
2019,
63,
8578,
63,
602,
275,
307,
2359,
63,
262,
4933,
1585,
198,
6958,
1871,
686,
198,
3,
692,
781,
655,
5337,
282,
308,
1753,
1242,
334,
336,
1259,
63,
16175,
63,
1339,
14,
13896,
342,
9265,
1686,
2222,
2973,
574,
9,
436,
282,
922,
21182,
737,
282,
11248,
4453,
283,
4515,
63,
5182,
63,
8515,
63,
1541,
7,
9265,
870,
1911,
21702,
63,
1339,
1771,
84,
370,
29134,
686,
198,
3,
692,
2061,
63,
8578,
63,
602,
690,
378,
221,
436,
334,
84,
2359,
63,
262,
4933,
446,
2061,
63,
8578,
63,
602,
9,
2695,
4696,
63,
5182,
63,
8515,
63,
1541,
436,
336,
1259,
63,
16175,
63,
1339,
14,
13896,
342,
221,
520,
257,
327,
1023,
543,
9250,
21702,
63,
1339,
1159,
686,
198,
692,
2061,
63,
8578,
63,
602,
690,
378,
221,
436,
334,
84,
2359,
63,
262,
4933,
446,
2061,
63,
8578,
63,
602,
9,
2695,
4696,
63,
5182,
63,
8515,
63,
1541,
436,
336,
1259,
63,
16175,
63,
1339,
14,
13896,
342,
436,
2061,
63,
16175,
63,
1339,
1137,
336,
1259,
63,
16175,
63,
1339,
520,
327,
1023,
14953,
9250,
21702,
63,
1339,
1159,
1585,
198,
2019,
63,
16175,
63,
1339,
275,
336,
1259,
63,
16175,
63,
1339,
1585,
198,
1361,
336,
1259,
63,
16175,
63,
1339,
421,
198,
2590,
26,
507,
198,
309,
1077,
1454,
5992,
340,
1324,
1475,
365,
440,
3211,
12,
2839,
841,
3140,
402,
959,
5174,
11673,
1338,
507,
198,
4806,
14,
19602,
8,
1896,
29,
4806,
14,
5287,
12,
1788,
29,
6205,
4769,
2791,
15,
5076,
16571,
63,
81,
24,
63,
581,
947,
281,
4970,
57,
5,
77,
5,
68,
3295,
40,
5,
45,
5,
51,
14,
793,
2237,
507,
198,
4806,
14,
815,
360,
2520,
63,
1606,
63,
466,
63,
1541,
26,
283,
435,
3330,
63,
1606,
63,
466,
63,
1541,
776,
507,
198,
4806,
14,
815,
360,
4515,
63,
5182,
63,
8515,
63,
1541,
26,
283,
435,
4696,
63,
5182,
63,
8515,
63,
1541,
776,
507,
198,
4806,
14,
815,
480,
604,
687,
29134,
26,
19669,
435,
1004,
435,
1867,
7230,
507,
198,
4806,
14,
1971,
480,
47,
1483,
9107,
507,
198,
3730,
507,
198,
1274,
14,
2224,
8,
17,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
28859,
6392,
7466,
4938,
2,
199,
3,
7384,
7800,
20619,
11098,
2900,
5924,
5702,
14,
221,
199,
3,
199,
3,
1918,
1350,
1233,
10470,
503,
11736,
2348,
262,
436,
1006,
8247,
4048,
370,
314,
1350,
1233,
1689,
15787,
531,
787,
23191,
701,
20619,
11098,
503,
2399,
4973,
14035,
503,
23854,
17564,
14,
16881,
370,
314,
26570,
25803,
543,
20619,
11098,
503,
2399,
4973,
14035,
436,
23854,
17564,
14,
710,
26570,
3509,
21032,
25563,
436,
557,
1359,
386,
695,
436,
406,
329,
3256,
2556,
402,
20619,
503,
2399,
4973,
14035,
436,
23854,
17564,
14,
710,
26570,
365,
17819,
701,
6701,
13062,
4248,
436,
21032,
7565,
1127,
3569,
436,
14312,
89,
1727,
1356,
14,
3091,
1777,
402,
314,
26570,
1443,
506,
1202,
12,
8876,
12,
9172,
68,
12,
6042,
12,
3267,
12,
14238,
12,
22752,
12,
29818,
12,
1854,
12,
503,
4339,
320,
939,
315,
1263,
4340,
1928,
20619,
1159,
6791,
4056,
5313,
4983,
14,
199,
3,
199,
3,
1944,
4190,
1334,
1263,
299,
323,
343,
12,
4248,
12,
21032,
7565,
503,
1163,
27925,
1264,
1061,
3324,
2451,
365,
10009,
370,
503,
406,
5057,
12188,
1265,
701,
4339,
320,
3253,
503,
18719,
402,
314,
26570,
83,
12,
1902,
4056,
590,
12,
701,
1742,
1863,
12,
315,
3402,
434,
12,
325,
2379,
28478,
503,
4257,
14,
6184,
4190,
1334,
4066,
27925,
1264,
1061,
3324,
4481,
1471,
506,
4056,
436,
30055,
701,
20619,
315,
3575,
14,
199,
199,
646,
984,
199,
646,
2050,
199,
646,
5190,
199,
646,
747,
199,
646,
900,
199,
504,
900,
492,
14053,
199,
199,
2520,
63,
1606,
63,
466,
63,
1541,
29,
1274,
14,
3020,
59,
17,
61,
221,
199,
4515,
63,
5182,
63,
8515,
63,
1541,
275,
1846,
8,
1274,
14,
3020,
59,
18,
566,
8299,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
199,
198,
604,
275,
2125,
199,
198,
893,
26,
507,
198,
1818,
63,
498,
275,
2125,
507,
198,
2019,
63,
8578,
63,
602,
4022,
17,
507,
198,
3,
16175,
63,
1339,
1077,
506,
15392,
507,
198,
2019,
63,
16175,
63,
1339,
275,
2125,
507,
198,
3,
4921,
83,
1324,
370,
506,
27105,
701,
1747,
436,
3355,
701,
1434,
63,
1339,
334,
460,
4913,
9,
24525,
6319,
507,
198,
509,
1004,
315,
984,
14,
6626,
26,
686,
198,
3,
634,
527,
3014,
701,
336,
1259,
63,
751,
63,
1339,
436,
701,
336,
1259,
63,
751,
63,
1339,
12,
307,
2359,
63,
262,
4933,
63,
495,
12,
336,
1259,
63,
16175,
63,
1339,
12,
19997,
63,
466,
24525,
315,
642,
1865,
9265,
12889,
3297,
701,
29134,
686,
198,
30394,
63,
751,
63,
1339,
12,
307,
2359,
63,
262,
4933,
63,
495,
12,
336,
1259,
63,
16175,
63,
1339,
12,
19997,
63,
466,
275,
1004,
14,
1913,
1252,
1294,
4582,
84,
531,
6319,
198,
3,
3958,
641,
6484,
1570,
20866,
198,
692,
1453,
63,
498,
1137,
336,
1259,
63,
751,
63,
1339,
520,
1585,
198,
1818,
63,
498,
275,
336,
1259,
63,
751,
63,
1339,
1585,
198,
2019,
63,
8578,
63,
602,
275,
446,
17,
1585,
198,
2019,
63,
16175,
63,
1339,
275,
2125,
1871,
686,
198,
84,
2359,
63,
262,
4933,
275,
1846,
8,
84,
2359,
63,
262,
4933,
63,
495,
9,
1871,
686,
198,
3,
4214,
11248,
2544,
15932,
12,
3354,
2061,
11248,
1434,
686,
198,
692,
19997,
63,
466,
508,
3330,
63,
1606,
63,
466,
63,
1541,
26,
1585,
198,
2019,
63,
8578,
63,
602,
275,
307,
2359,
63,
262,
4933,
1585,
198,
6958,
1871,
686,
198,
3,
692,
781,
655,
5337,
282,
308,
1753,
1242,
334,
336,
1259,
63,
16175,
63,
1339,
14,
13896,
342,
9265,
1686,
2222,
2973,
574,
9,
436,
282,
922,
21182,
737,
282,
11248,
4453,
283,
4515,
63,
5182,
63,
8515,
63,
1541,
7,
9265,
870,
1911,
21702,
63,
1339,
1771,
84,
370,
29134,
686,
198,
3,
692,
2061,
63,
8578,
63,
602,
690,
378,
221,
436,
334,
84,
2359,
63,
262,
4933,
446,
2061,
63,
8578,
63,
602,
9,
2695,
4696,
63,
5182,
63,
8515,
63,
1541,
436,
336,
1259,
63,
16175,
63,
1339,
14,
13896,
342,
221,
520,
257,
327,
1023,
543,
9250,
21702,
63,
1339,
1159,
686,
198,
692,
2061,
63,
8578,
63,
602,
690,
378,
221,
436,
334,
84,
2359,
63,
262,
4933,
446,
2061,
63,
8578,
63,
602,
9,
2695,
4696,
63,
5182,
63,
8515,
63,
1541,
436,
336,
1259,
63,
16175,
63,
1339,
14,
13896,
342,
436,
2061,
63,
16175,
63,
1339,
1137,
336,
1259,
63,
16175,
63,
1339,
520,
327,
1023,
14953,
9250,
21702,
63,
1339,
1159,
1585,
198,
2019,
63,
16175,
63,
1339,
275,
336,
1259,
63,
16175,
63,
1339,
1585,
198,
1361,
336,
1259,
63,
16175,
63,
1339,
421,
198,
2590,
26,
507,
198,
309,
1077,
1454,
5992,
340,
1324,
1475,
365,
440,
3211,
12,
2839,
841,
3140,
402,
959,
5174,
11673,
1338,
507,
198,
4806,
14,
19602,
8,
1896,
29,
4806,
14,
5287,
12,
1788,
29,
6205,
4769,
2791,
15,
5076,
16571,
63,
81,
24,
63,
581,
947,
281,
4970,
57,
5,
77,
5,
68,
3295,
40,
5,
45,
5,
51,
14,
793,
2237,
507,
198,
4806,
14,
815,
360,
2520,
63,
1606,
63,
466,
63,
1541,
26,
283,
435,
3330,
63,
1606,
63,
466,
63,
1541,
776,
507,
198,
4806,
14,
815,
360,
4515,
63,
5182,
63,
8515,
63,
1541,
26,
283,
435,
4696,
63,
5182,
63,
8515,
63,
1541,
776,
507,
198,
4806,
14,
815,
480,
604,
687,
29134,
26,
19669,
435,
1004,
435,
1867,
7230,
507,
198,
4806,
14,
1971,
480,
47,
1483,
9107,
507,
198,
3730,
507,
198,
1274,
14,
2224,
8,
17,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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2
|
16420
|
# Copyright 2016 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Tests for Keras core layers."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import numpy as np
from tensorflow.python import keras
from tensorflow.python.eager import context
from tensorflow.python.framework import dtypes
from tensorflow.python.framework import ops
from tensorflow.python.framework import tensor_spec
from tensorflow.python.keras import keras_parameterized
from tensorflow.python.keras import testing_utils
from tensorflow.python.keras.mixed_precision.experimental import policy
from tensorflow.python.ops import array_ops
from tensorflow.python.ops import math_ops
from tensorflow.python.ops import variables
from tensorflow.python.platform import test
@keras_parameterized.run_all_keras_modes
class DropoutLayersTest(keras_parameterized.TestCase):
def test_dropout(self):
testing_utils.layer_test(
keras.layers.Dropout, kwargs={'rate': 0.5}, input_shape=(3, 2))
testing_utils.layer_test(
keras.layers.Dropout,
kwargs={'rate': 0.5,
'noise_shape': [3, 1]},
input_shape=(3, 2))
def test_dropout_supports_masking(self):
dropout = keras.layers.Dropout(0.5)
self.assertEqual(True, dropout.supports_masking)
def test_spatial_dropout_1d(self):
testing_utils.layer_test(
keras.layers.SpatialDropout1D,
kwargs={'rate': 0.5},
input_shape=(2, 3, 4))
def test_spatial_dropout_2d(self):
testing_utils.layer_test(
keras.layers.SpatialDropout2D,
kwargs={'rate': 0.5},
input_shape=(2, 3, 4, 5))
testing_utils.layer_test(
keras.layers.SpatialDropout2D,
kwargs={'rate': 0.5, 'data_format': 'channels_first'},
input_shape=(2, 3, 4, 5))
def test_spatial_dropout_3d(self):
testing_utils.layer_test(
keras.layers.SpatialDropout3D,
kwargs={'rate': 0.5},
input_shape=(2, 3, 4, 4, 5))
testing_utils.layer_test(
keras.layers.SpatialDropout3D,
kwargs={'rate': 0.5, 'data_format': 'channels_first'},
input_shape=(2, 3, 4, 4, 5))
def test_dropout_partial_noise_shape(self):
inputs = keras.Input(shape=(5, 10))
layer = keras.layers.Dropout(0.5, noise_shape=(None, 1, None))
outputs = layer(inputs)
model = keras.Model(inputs, outputs)
out = model(np.ones((20, 5, 10)), training=True)
out_np = keras.backend.get_value(out)
# Test that dropout mask is shared across second dim.
self.assertAllClose(out_np[:, 0, :], out_np[:, 1, :])
@keras_parameterized.run_all_keras_modes
class LambdaLayerTest(keras_parameterized.TestCase):
def test_lambda(self):
testing_utils.layer_test(
keras.layers.Lambda,
kwargs={'function': lambda x: x + 1},
input_shape=(3, 2))
testing_utils.layer_test(
keras.layers.Lambda,
kwargs={
'function': lambda x, a, b: x * a + b,
'arguments': {
'a': 0.6,
'b': 0.4
}
},
input_shape=(3, 2))
# test serialization with function
def f(x):
return x + 1
ld = keras.layers.Lambda(f)
config = ld.get_config()
ld = keras.layers.deserialize({
'class_name': 'Lambda',
'config': config
})
self.assertEqual(ld.function(3), 4)
# test with lambda
ld = keras.layers.Lambda(
lambda x: keras.backend.concatenate([math_ops.square(x), x]))
config = ld.get_config()
ld = keras.layers.Lambda.from_config(config)
self.assertAllEqual(self.evaluate(ld.function([3])), [9, 3])
def test_lambda_multiple_inputs(self):
ld = keras.layers.Lambda(lambda x: x[0], output_shape=lambda x: x[0])
x1 = np.ones([3, 2], np.float32)
x2 = np.ones([3, 5], np.float32)
out = ld([x1, x2])
self.assertAllEqual(out.shape, [3, 2])
def test_lambda_output_shape(self):
l = keras.layers.Lambda(lambda x: x + 1, output_shape=(1, 1))
l(keras.backend.variable(np.ones((1, 1))))
self.assertEqual((1, 1), l.get_config()['output_shape'])
def test_lambda_output_shape_function(self):
def get_output_shape(input_shape):
return 1 * input_shape
l = keras.layers.Lambda(lambda x: x + 1, output_shape=get_output_shape)
l(keras.backend.variable(np.ones((1, 1))))
self.assertEqual('lambda', l.get_config()['output_shape_type'])
def test_lambda_output_shape_autocalculate_multiple_inputs(self):
def lambda_fn(x):
return math_ops.matmul(x[0], x[1])
l = keras.layers.Lambda(lambda_fn, dtype=dtypes.float64)
output_shape = l.compute_output_shape([(10, 10), (10, 20)])
self.assertAllEqual((10, 20), output_shape)
output_signature = l.compute_output_signature([
tensor_spec.TensorSpec(dtype=dtypes.float64, shape=(10, 10)),
tensor_spec.TensorSpec(dtype=dtypes.float64, shape=(10, 20))])
self.assertAllEqual((10, 20), output_signature.shape)
self.assertAllEqual(dtypes.float64, output_signature.dtype)
def test_lambda_output_shape_list_multiple_outputs(self):
def lambda_fn(x):
return x
l = keras.layers.Lambda(lambda_fn, output_shape=[(10,), (20,)])
output_shape = l.compute_output_shape([(10, 10), (10, 20)])
self.assertAllEqual([(10, 10), (10, 20)], output_shape)
def test_lambda_output_shape_tuple_with_none(self):
def lambda_fn(x):
return x
l = keras.layers.Lambda(lambda_fn, output_shape=(None, 10))
output_shape = l.compute_output_shape((5, 10, 20))
self.assertAllEqual([5, None, 10], output_shape.as_list())
def test_lambda_output_shape_function_multiple_outputs(self):
def lambda_fn(x):
return x
def output_shape_fn(input_shape):
return input_shape
l = keras.layers.Lambda(lambda_fn, output_shape=output_shape_fn)
output_shape = l.compute_output_shape([(10, 10), (10, 20)])
self.assertAllEqual([(10, 10), (10, 20)], output_shape)
def test_lambda_output_shape_nested(self):
def lambda_fn(inputs):
return (inputs[1]['a'], {'b': inputs[0]})
l = keras.layers.Lambda(lambda_fn)
output_shape = l.compute_output_shape(((10, 20), {'a': (10, 5)}))
self.assertAllEqual(((10, 5), {'b': (10, 20)}), output_shape)
def test_lambda_config_serialization(self):
# Test serialization with output_shape and output_shape_type
layer = keras.layers.Lambda(
lambda x: x + 1,
output_shape=(1, 1),
mask=lambda i, m: m)
layer(keras.backend.variable(np.ones((1, 1))))
config = layer.get_config()
layer = keras.layers.deserialize({
'class_name': 'Lambda',
'config': config
})
self.assertAllEqual(layer.function(1), 2)
self.assertAllEqual(layer._output_shape, (1, 1))
self.assertAllEqual(layer.mask(1, True), True)
layer = keras.layers.Lambda.from_config(config)
self.assertAllEqual(layer.function(1), 2)
self.assertAllEqual(layer._output_shape, (1, 1))
self.assertAllEqual(layer.mask(1, True), True)
def test_lambda_with_variable(self):
def fn(x):
return x * variables.Variable(2., name='multiplier')
layer = keras.layers.Lambda(fn)
for _ in range(10):
layer(np.ones((10, 10), 'float32'))
self.assertLen(layer.trainable_weights, 1)
self.assertEqual(layer.trainable_weights[0].name, 'lambda/multiplier:0')
def test_lambda_with_training_arg(self):
def fn(x, training=True):
return keras.backend.in_train_phase(x, 2 * x, training=training)
layer = keras.layers.Lambda(fn)
x = keras.backend.ones(())
train_out = layer(x, training=True)
eval_out = layer(x, training=False)
self.assertEqual(keras.backend.get_value(train_out), 1.)
self.assertEqual(keras.backend.get_value(eval_out), 2.)
def test_lambda_with_mask(self):
def add_one(inputs):
return inputs + 1.0
def mask(unused_inputs, previous_mask):
return previous_mask
layer = keras.layers.Lambda(add_one, mask=mask)
x = np.ones([5, 4, 3])
x[:, -1, :] = 0
masking = keras.layers.Masking()
out = layer(masking(x))
expected_out = np.full([5, 4, 3], 2.0)
expected_out[:, -1, :] = 1.0
expected_mask = np.ones([5, 4])
expected_mask[:, -1] = 0.0
self.assertAllClose(self.evaluate(out), expected_out)
self.assertIsNotNone(out._keras_mask)
self.assertAllClose(self.evaluate(out._keras_mask), expected_mask)
class TestStatefulLambda(keras_parameterized.TestCase):
@keras_parameterized.run_all_keras_modes
@keras_parameterized.run_with_all_model_types
def test_lambda_with_variable_in_model(self):
def lambda_fn(x):
# Variable will only get created once.
v = variables.Variable(1., trainable=True)
return x * v
model = testing_utils.get_model_from_layers(
[keras.layers.Lambda(lambda_fn)], input_shape=(10,))
model.compile(
keras.optimizer_v2.gradient_descent.SGD(0.1),
'mae',
run_eagerly=testing_utils.should_run_eagerly(),
experimental_run_tf_function=testing_utils.should_run_tf_function())
x, y = np.ones((10, 10), 'float32'), 2 * np.ones((10, 10), 'float32')
model.fit(x, y, batch_size=2, epochs=2, validation_data=(x, y))
self.assertLen(model.trainable_weights, 1)
self.assertAllClose(keras.backend.get_value(model.trainable_weights[0]), 2.)
@keras_parameterized.run_all_keras_modes
class CoreLayersTest(keras_parameterized.TestCase):
def test_masking(self):
testing_utils.layer_test(
keras.layers.Masking, kwargs={}, input_shape=(3, 2, 3))
def test_keras_mask(self):
x = np.ones((10, 10))
y = keras.layers.Masking(1.)(x)
self.assertTrue(hasattr(y, '_keras_mask'))
self.assertTrue(y._keras_mask is not None)
self.assertAllClose(self.evaluate(y._keras_mask), np.zeros((10,)))
def test_compute_mask_with_positional_mask_arg(self):
class MyLayer(keras.layers.Layer):
def call(self, inputs, mask=None):
return inputs
def compute_mask(self, inputs, mask=None):
if mask is not None:
return array_ops.ones(())
else:
return array_ops.zeros(())
x, mask = array_ops.ones((1, 1)), array_ops.ones((1, 1))
layer = MyLayer()
y = layer(x, mask)
# Check that `mask` was correctly sent to `compute_mask`.
self.assertEqual(keras.backend.get_value(y._keras_mask), 1)
def test_activation(self):
# with string argument
testing_utils.layer_test(
keras.layers.Activation,
kwargs={'activation': 'relu'},
input_shape=(3, 2))
# with function argument
testing_utils.layer_test(
keras.layers.Activation,
kwargs={'activation': keras.backend.relu},
input_shape=(3, 2))
def test_reshape(self):
testing_utils.layer_test(
keras.layers.Reshape,
kwargs={'target_shape': (8, 1)},
input_shape=(3, 2, 4))
testing_utils.layer_test(
keras.layers.Reshape,
kwargs={'target_shape': (-1, 1)},
input_shape=(3, 2, 4))
testing_utils.layer_test(
keras.layers.Reshape,
kwargs={'target_shape': (1, -1)},
input_shape=(3, 2, 4))
testing_utils.layer_test(
keras.layers.Reshape,
kwargs={'target_shape': (-1, 1)},
input_shape=(None, None, 2))
def test_permute(self):
testing_utils.layer_test(
keras.layers.Permute, kwargs={'dims': (2, 1)}, input_shape=(3, 2, 4))
def test_permute_errors_on_invalid_starting_dims_index(self):
with self.assertRaisesRegexp(ValueError, r'Invalid permutation .*dims.*'):
testing_utils.layer_test(
keras.layers.Permute,
kwargs={'dims': (0, 1, 2)}, input_shape=(3, 2, 4))
def test_permute_errors_on_invalid_set_of_dims_indices(self):
with self.assertRaisesRegexp(ValueError, r'Invalid permutation .*dims.*'):
testing_utils.layer_test(
keras.layers.Permute,
kwargs={'dims': (1, 4, 2)}, input_shape=(3, 2, 4))
def test_flatten(self):
testing_utils.layer_test(
keras.layers.Flatten, kwargs={}, input_shape=(3, 2, 4))
# Test channels_first
inputs = np.random.random((10, 3, 5, 5)).astype('float32')
outputs = testing_utils.layer_test(
keras.layers.Flatten,
kwargs={'data_format': 'channels_first'},
input_data=inputs)
target_outputs = np.reshape(
np.transpose(inputs, (0, 2, 3, 1)), (-1, 5 * 5 * 3))
self.assertAllClose(outputs, target_outputs)
def test_flatten_scalar_channels(self):
testing_utils.layer_test(
keras.layers.Flatten, kwargs={}, input_shape=(3,))
# Test channels_first
inputs = np.random.random((10,)).astype('float32')
outputs = testing_utils.layer_test(
keras.layers.Flatten,
kwargs={'data_format': 'channels_first'},
input_data=inputs)
target_outputs = np.expand_dims(inputs, -1)
self.assertAllClose(outputs, target_outputs)
def test_repeat_vector(self):
testing_utils.layer_test(
keras.layers.RepeatVector, kwargs={'n': 3}, input_shape=(3, 2))
def test_dense(self):
testing_utils.layer_test(
keras.layers.Dense, kwargs={'units': 3}, input_shape=(3, 2))
testing_utils.layer_test(
keras.layers.Dense, kwargs={'units': 3}, input_shape=(3, 4, 2))
testing_utils.layer_test(
keras.layers.Dense, kwargs={'units': 3}, input_shape=(None, None, 2))
testing_utils.layer_test(
keras.layers.Dense, kwargs={'units': 3}, input_shape=(3, 4, 5, 2))
def test_dense_dtype(self):
inputs = ops.convert_to_tensor(
np.random.randint(low=0, high=7, size=(2, 2)))
layer = keras.layers.Dense(5, dtype='float32')
outputs = layer(inputs)
self.assertEqual(outputs.dtype, 'float32')
def test_dense_with_policy(self):
inputs = ops.convert_to_tensor(
np.random.randint(low=0, high=7, size=(2, 2)), dtype='float16')
layer = keras.layers.Dense(5, dtype=policy.Policy('infer_float32_vars'))
outputs = layer(inputs)
output_signature = layer.compute_output_signature(
tensor_spec.TensorSpec(dtype='float16', shape=(2, 2)))
self.assertEqual(output_signature.dtype, dtypes.float16)
self.assertEqual(output_signature.shape, (2, 5))
self.assertEqual(outputs.dtype, 'float16')
self.assertEqual(layer.kernel.dtype, 'float32')
def test_dense_regularization(self):
layer = keras.layers.Dense(
3,
kernel_regularizer=keras.regularizers.l1(0.01),
bias_regularizer='l1',
activity_regularizer='l2',
name='dense_reg')
layer(keras.backend.variable(np.ones((2, 4))))
self.assertEqual(3, len(layer.losses))
def test_dense_constraints(self):
k_constraint = keras.constraints.max_norm(0.01)
b_constraint = keras.constraints.max_norm(0.01)
layer = keras.layers.Dense(
3, kernel_constraint=k_constraint, bias_constraint=b_constraint)
layer(keras.backend.variable(np.ones((2, 4))))
self.assertEqual(layer.kernel.constraint, k_constraint)
self.assertEqual(layer.bias.constraint, b_constraint)
def test_activity_regularization(self):
layer = keras.layers.ActivityRegularization(l1=0.1)
layer(keras.backend.variable(np.ones((2, 4))))
self.assertEqual(1, len(layer.losses))
config = layer.get_config()
self.assertEqual(config.pop('l1'), 0.1)
def test_numpy_inputs(self):
if context.executing_eagerly():
layer = keras.layers.RepeatVector(2)
x = np.ones((10, 10))
self.assertAllEqual(np.ones((10, 2, 10)), layer(x))
layer = keras.layers.Concatenate()
x, y = np.ones((10, 10)), np.ones((10, 10))
self.assertAllEqual(np.ones((10, 20)), layer([x, y]))
if __name__ == '__main__':
test.main()
|
apache-2.0
|
[
3,
1898,
7800,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
2925,
367,
1804,
30037,
6170,
9393,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
2680,
465,
980,
199,
199,
504,
3228,
14,
1548,
492,
11708,
199,
504,
3228,
14,
1548,
14,
10283,
492,
1067,
199,
504,
3228,
14,
1548,
14,
4857,
492,
6674,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
4857,
492,
2345,
63,
1650,
199,
504,
3228,
14,
1548,
14,
8811,
492,
11708,
63,
25000,
199,
504,
3228,
14,
1548,
14,
8811,
492,
5343,
63,
1208,
199,
504,
3228,
14,
1548,
14,
8811,
14,
10455,
63,
6833,
14,
18924,
492,
4592,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1625,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3473,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
2860,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
421,
199,
32,
8811,
63,
25000,
14,
1065,
63,
452,
63,
8811,
63,
10433,
199,
533,
18110,
548,
16862,
774,
8,
8811,
63,
25000,
14,
1746,
304,
819,
347,
511,
63,
17953,
8,
277,
304,
272,
5343,
63,
1208,
14,
1897,
63,
396,
8,
267,
11708,
14,
4359,
14,
30662,
12,
2074,
3713,
1866,
356,
378,
14,
21,
1386,
1324,
63,
1392,
2687,
19,
12,
499,
430,
339,
5343,
63,
1208,
14,
1897,
63,
396,
8,
267,
11708,
14,
4359,
14,
30662,
12,
267,
2074,
3713,
1866,
356,
378,
14,
21,
12,
355,
283,
11838,
63,
1392,
356,
359,
19,
12,
413,
13888,
267,
1324,
63,
1392,
2687,
19,
12,
499,
430,
819,
347,
511,
63,
17953,
63,
9823,
63,
2629,
316,
8,
277,
304,
272,
19795,
275,
11708,
14,
4359,
14,
30662,
8,
16,
14,
21,
9,
272,
291,
14,
629,
8,
549,
12,
19795,
14,
9823,
63,
2629,
316,
9,
819,
347,
511,
63,
11679,
63,
17953,
63,
17,
68,
8,
277,
304,
272,
5343,
63,
1208,
14,
1897,
63,
396,
8,
267,
11708,
14,
4359,
14,
18075,
30662,
17,
36,
12,
267,
2074,
3713,
1866,
356,
378,
14,
21,
1386,
267,
1324,
63,
1392,
2687,
18,
12,
650,
12,
841,
430,
819,
347,
511,
63,
11679,
63,
17953,
63,
18,
68,
8,
277,
304,
272,
5343,
63,
1208,
14,
1897,
63,
396,
8,
267,
11708,
14,
4359,
14,
18075,
30662,
18,
36,
12,
267,
2074,
3713,
1866,
356,
378,
14,
21,
1386,
267,
1324,
63,
1392,
2687,
18,
12,
650,
12,
841,
12,
959,
430,
339,
5343,
63,
1208,
14,
1897,
63,
396,
8,
267,
11708,
14,
4359,
14,
18075,
30662,
18,
36,
12,
267,
2074,
3713,
1866,
356,
378,
14,
21,
12,
283,
576,
63,
908,
356,
283,
6324,
63,
2246,
2267,
267,
1324,
63,
1392,
2687,
18,
12,
650,
12,
841,
12,
959,
430,
819,
347,
511,
63,
11679,
63,
17953,
63,
19,
68,
8,
277,
304,
272,
5343,
63,
1208,
14,
1897,
63,
396,
8,
267,
11708,
14,
4359,
14,
18075,
30662,
19,
36,
12,
267,
2074,
3713,
1866,
356,
378,
14,
21,
1386,
267,
1324,
63,
1392,
2687,
18,
12,
650,
12,
841,
12,
841,
12,
959,
430,
339,
5343,
63,
1208,
14,
1897,
63,
396,
8,
267,
11708,
14,
4359,
14,
18075,
30662,
19,
36,
12,
267,
2074,
3713,
1866,
356,
378,
14,
21,
12,
283,
576,
63,
908,
356,
283,
6324,
63,
2246,
2267,
267,
1324,
63,
1392,
2687,
18,
12,
650,
12,
841,
12,
841,
12,
959,
430,
819,
347,
511,
63,
17953,
63,
6672,
63,
11838,
63,
1392,
8,
277,
304,
272,
4153,
275,
11708,
14,
3205,
8,
1392,
2687,
21,
12,
1616,
430,
272,
4045,
275,
11708,
14,
4359,
14,
30662,
8,
16,
14,
21,
12,
11145,
63,
1392,
2687,
403,
12,
413,
12,
488,
430,
272,
4704,
275,
4045,
8,
3711,
9,
272,
1402,
275,
11708,
14,
1685,
8,
3711,
12,
4704,
9,
272,
734,
275,
1402,
8,
1590,
14,
4548,
1332,
1165,
12,
959,
12,
1616,
1826,
6093,
29,
549,
9,
272,
734,
63,
1590,
275,
11708,
14,
4620,
14,
362,
63,
585,
8,
548,
9,
272,
327,
1379,
626,
19795,
3656,
365,
5709,
9371,
3499,
8134,
14,
272,
291,
14,
7260,
8,
548,
63,
1590,
3981,
378,
12,
26450,
734,
63,
1590,
3981,
413,
12,
520,
566,
421,
199,
32,
8811,
63,
25000,
14,
1065,
63,
452,
63,
8811,
63,
10433,
199,
533,
28650,
5003,
774,
8,
8811,
63,
25000,
14,
1746,
304,
819,
347,
511,
63,
2734,
8,
277,
304,
272,
5343,
63,
1208,
14,
1897,
63,
396,
8,
267,
11708,
14,
4359,
14,
21350,
12,
267,
2074,
3713,
1593,
356,
2400,
671,
26,
671,
435,
413,
1386,
267,
1324,
63,
1392,
2687,
19,
12,
499,
430,
339,
5343,
63,
1208,
14,
1897,
63,
396,
8,
267,
11708,
14,
4359,
14,
21350,
12,
267,
2074,
3126,
288,
283,
1593,
356,
2400,
671,
12,
282,
12,
330,
26,
671,
627,
282,
435,
330,
12,
288,
283,
4958,
356,
469,
355,
283,
65,
356,
378,
14,
22,
12,
355,
283,
66,
356,
378,
14,
20,
288,
789,
267,
1660,
267,
1324,
63,
1392,
2687,
19,
12,
499,
430,
339,
327,
511,
16953,
543,
805,
272,
347,
289,
8,
88,
304,
489,
372,
671,
435,
413,
339,
8827,
275,
11708,
14,
4359
] |
[
1898,
7800,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
2925,
367,
1804,
30037,
6170,
9393,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
2680,
465,
980,
199,
199,
504,
3228,
14,
1548,
492,
11708,
199,
504,
3228,
14,
1548,
14,
10283,
492,
1067,
199,
504,
3228,
14,
1548,
14,
4857,
492,
6674,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
4857,
492,
2345,
63,
1650,
199,
504,
3228,
14,
1548,
14,
8811,
492,
11708,
63,
25000,
199,
504,
3228,
14,
1548,
14,
8811,
492,
5343,
63,
1208,
199,
504,
3228,
14,
1548,
14,
8811,
14,
10455,
63,
6833,
14,
18924,
492,
4592,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1625,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3473,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
2860,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
421,
199,
32,
8811,
63,
25000,
14,
1065,
63,
452,
63,
8811,
63,
10433,
199,
533,
18110,
548,
16862,
774,
8,
8811,
63,
25000,
14,
1746,
304,
819,
347,
511,
63,
17953,
8,
277,
304,
272,
5343,
63,
1208,
14,
1897,
63,
396,
8,
267,
11708,
14,
4359,
14,
30662,
12,
2074,
3713,
1866,
356,
378,
14,
21,
1386,
1324,
63,
1392,
2687,
19,
12,
499,
430,
339,
5343,
63,
1208,
14,
1897,
63,
396,
8,
267,
11708,
14,
4359,
14,
30662,
12,
267,
2074,
3713,
1866,
356,
378,
14,
21,
12,
355,
283,
11838,
63,
1392,
356,
359,
19,
12,
413,
13888,
267,
1324,
63,
1392,
2687,
19,
12,
499,
430,
819,
347,
511,
63,
17953,
63,
9823,
63,
2629,
316,
8,
277,
304,
272,
19795,
275,
11708,
14,
4359,
14,
30662,
8,
16,
14,
21,
9,
272,
291,
14,
629,
8,
549,
12,
19795,
14,
9823,
63,
2629,
316,
9,
819,
347,
511,
63,
11679,
63,
17953,
63,
17,
68,
8,
277,
304,
272,
5343,
63,
1208,
14,
1897,
63,
396,
8,
267,
11708,
14,
4359,
14,
18075,
30662,
17,
36,
12,
267,
2074,
3713,
1866,
356,
378,
14,
21,
1386,
267,
1324,
63,
1392,
2687,
18,
12,
650,
12,
841,
430,
819,
347,
511,
63,
11679,
63,
17953,
63,
18,
68,
8,
277,
304,
272,
5343,
63,
1208,
14,
1897,
63,
396,
8,
267,
11708,
14,
4359,
14,
18075,
30662,
18,
36,
12,
267,
2074,
3713,
1866,
356,
378,
14,
21,
1386,
267,
1324,
63,
1392,
2687,
18,
12,
650,
12,
841,
12,
959,
430,
339,
5343,
63,
1208,
14,
1897,
63,
396,
8,
267,
11708,
14,
4359,
14,
18075,
30662,
18,
36,
12,
267,
2074,
3713,
1866,
356,
378,
14,
21,
12,
283,
576,
63,
908,
356,
283,
6324,
63,
2246,
2267,
267,
1324,
63,
1392,
2687,
18,
12,
650,
12,
841,
12,
959,
430,
819,
347,
511,
63,
11679,
63,
17953,
63,
19,
68,
8,
277,
304,
272,
5343,
63,
1208,
14,
1897,
63,
396,
8,
267,
11708,
14,
4359,
14,
18075,
30662,
19,
36,
12,
267,
2074,
3713,
1866,
356,
378,
14,
21,
1386,
267,
1324,
63,
1392,
2687,
18,
12,
650,
12,
841,
12,
841,
12,
959,
430,
339,
5343,
63,
1208,
14,
1897,
63,
396,
8,
267,
11708,
14,
4359,
14,
18075,
30662,
19,
36,
12,
267,
2074,
3713,
1866,
356,
378,
14,
21,
12,
283,
576,
63,
908,
356,
283,
6324,
63,
2246,
2267,
267,
1324,
63,
1392,
2687,
18,
12,
650,
12,
841,
12,
841,
12,
959,
430,
819,
347,
511,
63,
17953,
63,
6672,
63,
11838,
63,
1392,
8,
277,
304,
272,
4153,
275,
11708,
14,
3205,
8,
1392,
2687,
21,
12,
1616,
430,
272,
4045,
275,
11708,
14,
4359,
14,
30662,
8,
16,
14,
21,
12,
11145,
63,
1392,
2687,
403,
12,
413,
12,
488,
430,
272,
4704,
275,
4045,
8,
3711,
9,
272,
1402,
275,
11708,
14,
1685,
8,
3711,
12,
4704,
9,
272,
734,
275,
1402,
8,
1590,
14,
4548,
1332,
1165,
12,
959,
12,
1616,
1826,
6093,
29,
549,
9,
272,
734,
63,
1590,
275,
11708,
14,
4620,
14,
362,
63,
585,
8,
548,
9,
272,
327,
1379,
626,
19795,
3656,
365,
5709,
9371,
3499,
8134,
14,
272,
291,
14,
7260,
8,
548,
63,
1590,
3981,
378,
12,
26450,
734,
63,
1590,
3981,
413,
12,
520,
566,
421,
199,
32,
8811,
63,
25000,
14,
1065,
63,
452,
63,
8811,
63,
10433,
199,
533,
28650,
5003,
774,
8,
8811,
63,
25000,
14,
1746,
304,
819,
347,
511,
63,
2734,
8,
277,
304,
272,
5343,
63,
1208,
14,
1897,
63,
396,
8,
267,
11708,
14,
4359,
14,
21350,
12,
267,
2074,
3713,
1593,
356,
2400,
671,
26,
671,
435,
413,
1386,
267,
1324,
63,
1392,
2687,
19,
12,
499,
430,
339,
5343,
63,
1208,
14,
1897,
63,
396,
8,
267,
11708,
14,
4359,
14,
21350,
12,
267,
2074,
3126,
288,
283,
1593,
356,
2400,
671,
12,
282,
12,
330,
26,
671,
627,
282,
435,
330,
12,
288,
283,
4958,
356,
469,
355,
283,
65,
356,
378,
14,
22,
12,
355,
283,
66,
356,
378,
14,
20,
288,
789,
267,
1660,
267,
1324,
63,
1392,
2687,
19,
12,
499,
430,
339,
327,
511,
16953,
543,
805,
272,
347,
289,
8,
88,
304,
489,
372,
671,
435,
413,
339,
8827,
275,
11708,
14,
4359,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
goddardl/cortex
|
test/IECore/GenericImageTest.py
|
12
|
11703
|
##########################################################################
#
# Copyright (c) 2007, Image Engine Design Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# * Neither the name of Image Engine Design nor the names of any
# other contributors to this software may be used to endorse or
# promote products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
##########################################################################
import unittest
import sys, math
from IECore import *
class TestImageReadersAndWriters(unittest.TestCase):
"""
generic image reader and writer testing
"""
def testHandlers(self):
"""
test each reader and writer with grayscale (equal R,G,B channels)
image
"""
#print ''
image_handlers = ["CIN", "JPEG", "TIFF", "EXR"]
# construct the simple ImagePrimitive
width = 16
height = 16
channel = {}
channel["R"] = IECore.FloatVectorData(width * height)
for i in range(0, width*height):
channel["R"][i] = i / 255.0
channel["G"] = IECore.FloatVectorData(width * height)
for i in range(0, width*height):
channel["G"][i] = ((i + 128)%(width*height-1)) / 255.0
channel["B"] = IECore.FloatVectorData(width * height)
for i in range(0, width*height):
channel["B"][i] = ((i + 203)%(width*height-1)) / 255.0
b = IECore.Box2i(IECore.V2i(0, 0), IECore.V2i(width-1, height-1))
image = IECore.ImagePrimitive(b, b)
image["R"] = IECore.PrimitiveVariable(IECore.PrimitiveVariable.Interpolation.Vertex, channel["R"])
image["G"] = IECore.PrimitiveVariable(IECore.PrimitiveVariable.Interpolation.Vertex, channel["G"])
image["B"] = IECore.PrimitiveVariable(IECore.PrimitiveVariable.Interpolation.Vertex, channel["B"])
# test the handlers
for image_type in image_handlers:
# write the file
writer = IECore.Writer.create(image, "test/generic_image.%s" % image_type.lower())
self.assert_( writer.isInstanceOf( "ImageWriter" ) )
self.assert_( writer["object"].isInstanceOf( "ObjectParameter" ) )
self.assertEqual( writer["object"].validTypes(), [IECore.TypeId.ImagePrimitive] )
self.assert_( writer.resultParameter().isInstanceOf( "ObjectParameter" ) )
self.assertEqual( writer.resultParameter().validTypes(), [IECore.TypeId.ImagePrimitive] )
writer.write()
# read the file
reader = IECore.Reader.create("test/generic_image.%s" % image_type.lower())
self.assert_( reader.isInstanceOf( "ImageReader" ) )
self.assert_( reader.resultParameter().isInstanceOf( "ObjectParameter" ) )
self.assertEqual( reader.resultParameter().validTypes(), [IECore.TypeId.ImagePrimitive] )
read_image = reader.read()
# write back out to verify
IECore.Writer.create(read_image, "test/generic_image.blab.%s" % image_type.lower()).write()
# compare pixel values
for cn in ["R", "G", "B"]:
read_channel = read_image[cn].data
sum_of_diff = 0.0
for i in range(0, width*height):
# big epsilon for now. this should depend on the encoding. for example,
# CIN will have some big errors because we quantize down to a 10-bit log space.
# JPEG hurts on these non-photolike images
epsilon = image_type == 'CIN' and 0.005 or image_type == 'JPEG' and 0.5 or 0.000001
diff = read_channel[i] - channel[cn][i]
sum_of_diff += diff
if math.fabs(diff) > epsilon:
print '%s channel %s: difference between write and read at %d: %f (%f read vs %f generated)' % (image_type, cn, i, diff, read_channel[i], channel[cn][i])
raise Exception("bad image write or read: encoding is %s" % image_type)
if math.fabs(sum_of_diff) > (image_type == 'JPEG' and 0.2 or 0.1):
print 'sum of differences:', sum_of_diff
raise Exception("bad image write or reader: encoding is %s" % image_type)
def testWindows(self):
"""
test each reader and writer combo for windowed (axis-aligned sub-rectangle) operations
"""
#print ''
image_handlers = ["CIN", "JPEG", "TIFF", "EXR"]
# construct the simple ImagePrimitive
width = 16
height = 16
channel = IECore.FloatVectorData(width * height)
for i in range(0, width*height):
channel[i] = i / 255.0
b = IECore.Box2i(IECore.V2i(0, 0), IECore.V2i(width-1, height-1))
image = IECore.ImagePrimitive(b, b)
image["R"] = IECore.PrimitiveVariable(IECore.PrimitiveVariable.Interpolation.Vertex, channel)
image["G"] = IECore.PrimitiveVariable(IECore.PrimitiveVariable.Interpolation.Vertex, channel)
image["B"] = IECore.PrimitiveVariable(IECore.PrimitiveVariable.Interpolation.Vertex, channel)
# get smaller sub-window
sub_box = Box2iData(Box2i(V2i(0, 0), V2i(7, 7)))
# test the handlers
for image_type in image_handlers:
# write the file
IECore.Writer.create(image, "test/generic_image.window.%s" % image_type.lower()).write()
# read the file with a 1/4 area subwindow starting at origin
r = IECore.Reader.create("test/generic_image.window.%s" % image_type.lower())
r.parameters().dataWindow.setValue(sub_box)
read_image = r.read()
# write out the file
IECore.Writer.create(read_image, "test/generic_image_cut.%s" % image_type.lower()).write()
# assert proper image extents
# compare pixel values
for cn in ["R", "G", "B"]:
read_channel = read_image[cn].data
sum_of_diff = 0.0
# big epsilon for now. this should depend on the encoding. for example,
# CIN will have some big errors because we quantize down to a 10-bit log space.
epsilon = image_type == 'CIN' and 0.005 or image_type == 'JPEG' and 0.00025 or 0.000001
for y in range(0, 8):
for x in range(0, 8):
ci = 16*y + x
i = 8*y + x
diff = read_channel[i] - channel[ci]
sum_of_diff += diff
if math.fabs(diff) > epsilon:
print '%s channel %s: difference between write and read at %d: %f' % (image_type, cn, i, diff)
raise Exception("bad image write or read: encoding is %s" % image_type)
if math.fabs(sum_of_diff) > 0.1:
print 'sum of differences:', sum_of_diff
raise Exception("bad image write or reader: encoding is %s" % image_type)
def testOutsideWindows(self):
"""
test each reader and writer combo for windowed (axis-aligned sub-rectangle) operations
"""
#print ''
image_handlers = ["CIN", "JPEG", "TIFF", "EXR"]
# construct the simple ImagePrimitive
width = 16
height = 16
channel = IECore.FloatVectorData(width * height)
for i in range(0, width*height):
channel[i] = i / 255.0
b = IECore.Box2i(IECore.V2i(0, 0), IECore.V2i(width-1, height-1))
image = IECore.ImagePrimitive(b, b)
image["R"] = IECore.PrimitiveVariable(IECore.PrimitiveVariable.Interpolation.Vertex, channel)
image["G"] = IECore.PrimitiveVariable(IECore.PrimitiveVariable.Interpolation.Vertex, channel)
image["B"] = IECore.PrimitiveVariable(IECore.PrimitiveVariable.Interpolation.Vertex, channel)
# get smaller sub-window
sub_box = Box2iData(Box2i(V2i(-4, -4), V2i(21, 21)))
# test the handlers
for image_type in image_handlers:
# write the file
IECore.Writer.create(image, "test/generic_image.outside.%s" % image_type.lower()).write()
# read the file with a 1/4 area subwindow starting at origin
r = IECore.Reader.create("test/generic_image.outside.%s" % image_type.lower())
r.parameters().dataWindow.setValue(sub_box)
read_image = r.read()
# write out the file
IECore.Writer.create(read_image, "test/generic_image_outside.%s" % image_type.lower()).write()
# assert proper image extents
# ...
# compare pixel values
for cn in ["R", "G", "B"]:
read_channel = read_image[cn].data
sum_of_diff = 0.0
# big epsilon for now. this should depend on the encoding. for example,
# CIN will have some big errors because we quantize down to a 10-bit log space.
epsilon = image_type == 'CIN' and 0.005 or image_type == 'JPEG' and 0.00025 or 0.000001
for y in range(0, 26):
for x in range(0, 26):
i = 26*y + x
if y < 4 or x < 4 or y >= 4 + 16 or x >= 4 + 16:
if read_channel[i] > 0.0001:
raise Exception("non-zero channel value (%f) in outside region (x,y %d,%d) of windowed read (%s encoding)" % (read_channel[i], x, y, image_type))
else:
ci = 16*(y-4) + (x-4)
diff = read_channel[i] - channel[ci]
sum_of_diff += diff
if math.fabs(diff) > epsilon:
print '%s channel %s: difference between write and read at %d, %d: %f' % (image_type, cn, x, y, diff)
raise Exception("bad image write or read: encoding is %s" % image_type)
if math.fabs(sum_of_diff) > 0.1:
print 'sum of differences:', sum_of_diff
raise Exception("bad image write or reader: encoding is %s" % image_type)
if __name__ == "__main__":
unittest.main()
|
bsd-3-clause
|
[
26863,
199,
3,
199,
3,
221,
1898,
334,
67,
9,
10219,
12,
6047,
12580,
29410,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
221,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
221,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
221,
7647,
26,
199,
3,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
755,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
755,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
755,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
199,
3,
258,
627,
11443,
314,
536,
402,
6047,
12580,
29410,
6590,
314,
1561,
402,
1263,
199,
3,
755,
1163,
8417,
370,
642,
2032,
1443,
506,
1202,
370,
10692,
503,
199,
3,
755,
10016,
7585,
7131,
687,
642,
2032,
1928,
2488,
6791,
199,
3,
755,
5313,
4983,
14,
199,
3,
199,
3,
221,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
298,
1179,
199,
3,
221,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
199,
3,
221,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
199,
3,
221,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
11489,
1549,
199,
3,
221,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
8820,
12,
199,
3,
221,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
199,
3,
221,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
199,
3,
221,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
1634,
199,
3,
221,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
334,
6446,
199,
3,
221,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
199,
3,
221,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
3,
199,
26863,
199,
199,
646,
2882,
199,
646,
984,
12,
3473,
199,
504,
14707,
492,
627,
199,
199,
533,
1379,
3491,
5929,
83,
3325,
4966,
878,
8,
2796,
14,
1746,
304,
272,
408,
272,
7809,
1834,
7002,
436,
7060,
5343,
272,
408,
339,
347,
511,
25096,
8,
277,
304,
267,
408,
267,
511,
1924,
7002,
436,
7060,
543,
21977,
3467,
334,
1452,
820,
12,
39,
12,
34,
9245,
9,
267,
1834,
267,
408,
398,
327,
1361,
2125,
398,
1834,
63,
5586,
275,
2097,
35,
568,
401,
298,
28412,
401,
298,
13247,
1665,
401,
298,
1438,
50,
937,
398,
327,
6982,
314,
3486,
6047,
22231,
267,
3462,
275,
3193,
267,
4569,
275,
3193,
267,
3623,
275,
1052,
267,
3623,
905,
50,
937,
275,
14707,
14,
5136,
26679,
8,
2063,
627,
4569,
9,
267,
367,
284,
315,
1425,
8,
16,
12,
3462,
10,
3333,
304,
288,
3623,
905,
50,
9210,
73,
61,
275,
284,
1182,
5450,
14,
16,
398,
3623,
905,
39,
937,
275,
14707,
14,
5136,
26679,
8,
2063,
627,
4569,
9,
267,
367,
284,
315,
1425,
8,
16,
12,
3462,
10,
3333,
304,
288,
3623,
905,
39,
9210,
73,
61,
275,
3666,
73,
435,
7960,
9,
2840,
2063,
10,
3333,
13,
17,
430,
1182,
5450,
14,
16,
398,
3623,
905,
34,
937,
275,
14707,
14,
5136,
26679,
8,
2063,
627,
4569,
9,
267,
367,
284,
315,
1425,
8,
16,
12,
3462,
10,
3333,
304,
288,
3623,
905,
34,
9210,
73,
61,
275,
3666,
73,
435,
29202,
9,
2840,
2063,
10,
3333,
13,
17,
430,
1182,
5450,
14,
16,
398,
330,
275,
14707,
14,
3532,
18,
73,
8,
41,
13682,
14,
54,
18,
73,
8,
16,
12,
378,
395,
14707,
14,
54,
18,
73,
8,
2063,
13,
17,
12,
4569,
13,
17,
430,
267,
1834,
275,
14707,
14,
3491,
22231,
8,
66,
12,
330,
9,
267,
1834,
905,
50,
937,
275,
14707,
14,
22231,
2773,
8,
41,
13682,
14,
22231,
2773,
14,
32653,
14,
9787,
12,
3623,
905,
50,
3135,
267,
1834,
905,
39,
937,
275,
14707,
14,
22231,
2773,
8,
41,
13682,
14,
22231,
2773,
14,
32653,
14,
9787,
12,
3623,
905,
39,
3135,
267,
1834,
905,
34,
937,
275,
14707,
14,
22231,
2773,
8,
41,
13682,
14,
22231,
2773,
14,
32653,
14,
9787,
12,
3623,
905,
34,
3135,
398,
327,
511,
314,
8297,
267,
367,
1834,
63,
466,
315,
1834,
63,
5586,
26,
953,
327,
2218,
314,
570,
288,
7060,
275,
14707,
14,
6261,
14,
981,
8,
1569,
12,
298,
396,
15,
6767,
63,
1569,
4111,
83,
2,
450,
1834,
63,
466,
14,
2325,
1012,
288,
291,
14,
479,
2531,
7060,
14,
374,
3244,
3466,
8,
298,
3491,
6261,
2,
776,
776,
288,
291,
14,
479,
2531,
7060,
905,
785,
4140,
374,
3244,
3466,
8,
298,
1692,
4720,
2,
776,
776,
288,
291,
14,
629,
8,
7060,
905,
785,
4140,
1078,
4100,
1062,
359,
41,
13682,
14,
2568,
14,
3491,
22231,
61,
776,
288,
291,
14,
479,
2531,
7060,
14,
1099,
4720,
1252,
374,
3244,
3466,
8,
298,
1692,
4720,
2,
776,
776,
288,
291,
14,
629,
8,
7060,
14,
1099,
4720,
1252,
1078,
4100,
1062,
359,
41,
13682,
14,
2568,
14,
3491,
22231,
61,
776,
288,
7060,
14,
952,
342,
953,
327,
1586,
314,
570,
288,
7002,
275,
14707,
14,
5929,
14,
981,
480,
396,
15,
6767,
63,
1569,
4111,
83,
2,
450,
1834,
63,
466,
14,
2325,
1012,
288,
291,
14,
479,
2531,
7002,
14,
374,
3244,
3466,
8,
298,
3491,
5929,
2,
776,
776,
288,
291,
14,
479,
2531,
7002,
14,
1099,
4720,
1252,
374,
3244,
3466,
8,
298,
1692,
4720,
2,
776,
776,
288,
291,
14,
629,
8,
7002,
14,
1099,
4720,
1252,
1078,
4100,
1062,
359,
41,
13682,
14,
2568,
14,
3491,
22231,
61,
776,
288,
1586,
63,
1569,
275,
7002,
14,
739,
342,
953,
327,
2218,
1771,
734,
370,
4911,
288,
14707,
14,
6261,
14,
981,
8,
739,
63,
1569,
12,
298,
396,
15,
6767,
63,
1569,
14,
3345,
371,
4111,
83,
2,
450,
1834,
63,
466,
14,
2325
] |
[
199,
3,
199,
3,
221,
1898,
334,
67,
9,
10219,
12,
6047,
12580,
29410,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
221,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
221,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
221,
7647,
26,
199,
3,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
755,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
755,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
755,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
199,
3,
258,
627,
11443,
314,
536,
402,
6047,
12580,
29410,
6590,
314,
1561,
402,
1263,
199,
3,
755,
1163,
8417,
370,
642,
2032,
1443,
506,
1202,
370,
10692,
503,
199,
3,
755,
10016,
7585,
7131,
687,
642,
2032,
1928,
2488,
6791,
199,
3,
755,
5313,
4983,
14,
199,
3,
199,
3,
221,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
298,
1179,
199,
3,
221,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
199,
3,
221,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
199,
3,
221,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
11489,
1549,
199,
3,
221,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
8820,
12,
199,
3,
221,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
199,
3,
221,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
199,
3,
221,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
1634,
199,
3,
221,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
334,
6446,
199,
3,
221,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
199,
3,
221,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
3,
199,
26863,
199,
199,
646,
2882,
199,
646,
984,
12,
3473,
199,
504,
14707,
492,
627,
199,
199,
533,
1379,
3491,
5929,
83,
3325,
4966,
878,
8,
2796,
14,
1746,
304,
272,
408,
272,
7809,
1834,
7002,
436,
7060,
5343,
272,
408,
339,
347,
511,
25096,
8,
277,
304,
267,
408,
267,
511,
1924,
7002,
436,
7060,
543,
21977,
3467,
334,
1452,
820,
12,
39,
12,
34,
9245,
9,
267,
1834,
267,
408,
398,
327,
1361,
2125,
398,
1834,
63,
5586,
275,
2097,
35,
568,
401,
298,
28412,
401,
298,
13247,
1665,
401,
298,
1438,
50,
937,
398,
327,
6982,
314,
3486,
6047,
22231,
267,
3462,
275,
3193,
267,
4569,
275,
3193,
267,
3623,
275,
1052,
267,
3623,
905,
50,
937,
275,
14707,
14,
5136,
26679,
8,
2063,
627,
4569,
9,
267,
367,
284,
315,
1425,
8,
16,
12,
3462,
10,
3333,
304,
288,
3623,
905,
50,
9210,
73,
61,
275,
284,
1182,
5450,
14,
16,
398,
3623,
905,
39,
937,
275,
14707,
14,
5136,
26679,
8,
2063,
627,
4569,
9,
267,
367,
284,
315,
1425,
8,
16,
12,
3462,
10,
3333,
304,
288,
3623,
905,
39,
9210,
73,
61,
275,
3666,
73,
435,
7960,
9,
2840,
2063,
10,
3333,
13,
17,
430,
1182,
5450,
14,
16,
398,
3623,
905,
34,
937,
275,
14707,
14,
5136,
26679,
8,
2063,
627,
4569,
9,
267,
367,
284,
315,
1425,
8,
16,
12,
3462,
10,
3333,
304,
288,
3623,
905,
34,
9210,
73,
61,
275,
3666,
73,
435,
29202,
9,
2840,
2063,
10,
3333,
13,
17,
430,
1182,
5450,
14,
16,
398,
330,
275,
14707,
14,
3532,
18,
73,
8,
41,
13682,
14,
54,
18,
73,
8,
16,
12,
378,
395,
14707,
14,
54,
18,
73,
8,
2063,
13,
17,
12,
4569,
13,
17,
430,
267,
1834,
275,
14707,
14,
3491,
22231,
8,
66,
12,
330,
9,
267,
1834,
905,
50,
937,
275,
14707,
14,
22231,
2773,
8,
41,
13682,
14,
22231,
2773,
14,
32653,
14,
9787,
12,
3623,
905,
50,
3135,
267,
1834,
905,
39,
937,
275,
14707,
14,
22231,
2773,
8,
41,
13682,
14,
22231,
2773,
14,
32653,
14,
9787,
12,
3623,
905,
39,
3135,
267,
1834,
905,
34,
937,
275,
14707,
14,
22231,
2773,
8,
41,
13682,
14,
22231,
2773,
14,
32653,
14,
9787,
12,
3623,
905,
34,
3135,
398,
327,
511,
314,
8297,
267,
367,
1834,
63,
466,
315,
1834,
63,
5586,
26,
953,
327,
2218,
314,
570,
288,
7060,
275,
14707,
14,
6261,
14,
981,
8,
1569,
12,
298,
396,
15,
6767,
63,
1569,
4111,
83,
2,
450,
1834,
63,
466,
14,
2325,
1012,
288,
291,
14,
479,
2531,
7060,
14,
374,
3244,
3466,
8,
298,
3491,
6261,
2,
776,
776,
288,
291,
14,
479,
2531,
7060,
905,
785,
4140,
374,
3244,
3466,
8,
298,
1692,
4720,
2,
776,
776,
288,
291,
14,
629,
8,
7060,
905,
785,
4140,
1078,
4100,
1062,
359,
41,
13682,
14,
2568,
14,
3491,
22231,
61,
776,
288,
291,
14,
479,
2531,
7060,
14,
1099,
4720,
1252,
374,
3244,
3466,
8,
298,
1692,
4720,
2,
776,
776,
288,
291,
14,
629,
8,
7060,
14,
1099,
4720,
1252,
1078,
4100,
1062,
359,
41,
13682,
14,
2568,
14,
3491,
22231,
61,
776,
288,
7060,
14,
952,
342,
953,
327,
1586,
314,
570,
288,
7002,
275,
14707,
14,
5929,
14,
981,
480,
396,
15,
6767,
63,
1569,
4111,
83,
2,
450,
1834,
63,
466,
14,
2325,
1012,
288,
291,
14,
479,
2531,
7002,
14,
374,
3244,
3466,
8,
298,
3491,
5929,
2,
776,
776,
288,
291,
14,
479,
2531,
7002,
14,
1099,
4720,
1252,
374,
3244,
3466,
8,
298,
1692,
4720,
2,
776,
776,
288,
291,
14,
629,
8,
7002,
14,
1099,
4720,
1252,
1078,
4100,
1062,
359,
41,
13682,
14,
2568,
14,
3491,
22231,
61,
776,
288,
1586,
63,
1569,
275,
7002,
14,
739,
342,
953,
327,
2218,
1771,
734,
370,
4911,
288,
14707,
14,
6261,
14,
981,
8,
739,
63,
1569,
12,
298,
396,
15,
6767,
63,
1569,
14,
3345,
371,
4111,
83,
2,
450,
1834,
63,
466,
14,
2325,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
2014c2g9/c2g9
|
wsgi/static/reeborg/src/libraries/brython/Lib/difflib.py
|
737
|
82544
|
#! /usr/bin/env python3
"""
Module difflib -- helpers for computing deltas between objects.
Function get_close_matches(word, possibilities, n=3, cutoff=0.6):
Use SequenceMatcher to return list of the best "good enough" matches.
Function context_diff(a, b):
For two lists of strings, return a delta in context diff format.
Function ndiff(a, b):
Return a delta: the difference between `a` and `b` (lists of strings).
Function restore(delta, which):
Return one of the two sequences that generated an ndiff delta.
Function unified_diff(a, b):
For two lists of strings, return a delta in unified diff format.
Class SequenceMatcher:
A flexible class for comparing pairs of sequences of any type.
Class Differ:
For producing human-readable deltas from sequences of lines of text.
Class HtmlDiff:
For producing HTML side by side comparison with change highlights.
"""
__all__ = ['get_close_matches', 'ndiff', 'restore', 'SequenceMatcher',
'Differ','IS_CHARACTER_JUNK', 'IS_LINE_JUNK', 'context_diff',
'unified_diff', 'HtmlDiff', 'Match']
import warnings
import heapq
from collections import namedtuple as _namedtuple
Match = _namedtuple('Match', 'a b size')
def _calculate_ratio(matches, length):
if length:
return 2.0 * matches / length
return 1.0
class SequenceMatcher:
"""
SequenceMatcher is a flexible class for comparing pairs of sequences of
any type, so long as the sequence elements are hashable. The basic
algorithm predates, and is a little fancier than, an algorithm
published in the late 1980's by Ratcliff and Obershelp under the
hyperbolic name "gestalt pattern matching". The basic idea is to find
the longest contiguous matching subsequence that contains no "junk"
elements (R-O doesn't address junk). The same idea is then applied
recursively to the pieces of the sequences to the left and to the right
of the matching subsequence. This does not yield minimal edit
sequences, but does tend to yield matches that "look right" to people.
SequenceMatcher tries to compute a "human-friendly diff" between two
sequences. Unlike e.g. UNIX(tm) diff, the fundamental notion is the
longest *contiguous* & junk-free matching subsequence. That's what
catches peoples' eyes. The Windows(tm) windiff has another interesting
notion, pairing up elements that appear uniquely in each sequence.
That, and the method here, appear to yield more intuitive difference
reports than does diff. This method appears to be the least vulnerable
to synching up on blocks of "junk lines", though (like blank lines in
ordinary text files, or maybe "<P>" lines in HTML files). That may be
because this is the only method of the 3 that has a *concept* of
"junk" <wink>.
Example, comparing two strings, and considering blanks to be "junk":
>>> s = SequenceMatcher(lambda x: x == " ",
... "private Thread currentThread;",
... "private volatile Thread currentThread;")
>>>
.ratio() returns a float in [0, 1], measuring the "similarity" of the
sequences. As a rule of thumb, a .ratio() value over 0.6 means the
sequences are close matches:
>>> print(round(s.ratio(), 3))
0.866
>>>
If you're only interested in where the sequences match,
.get_matching_blocks() is handy:
>>> for block in s.get_matching_blocks():
... print("a[%d] and b[%d] match for %d elements" % block)
a[0] and b[0] match for 8 elements
a[8] and b[17] match for 21 elements
a[29] and b[38] match for 0 elements
Note that the last tuple returned by .get_matching_blocks() is always a
dummy, (len(a), len(b), 0), and this is the only case in which the last
tuple element (number of elements matched) is 0.
If you want to know how to change the first sequence into the second,
use .get_opcodes():
>>> for opcode in s.get_opcodes():
... print("%6s a[%d:%d] b[%d:%d]" % opcode)
equal a[0:8] b[0:8]
insert a[8:8] b[8:17]
equal a[8:29] b[17:38]
See the Differ class for a fancy human-friendly file differencer, which
uses SequenceMatcher both to compare sequences of lines, and to compare
sequences of characters within similar (near-matching) lines.
See also function get_close_matches() in this module, which shows how
simple code building on SequenceMatcher can be used to do useful work.
Timing: Basic R-O is cubic time worst case and quadratic time expected
case. SequenceMatcher is quadratic time for the worst case and has
expected-case behavior dependent in a complicated way on how many
elements the sequences have in common; best case time is linear.
Methods:
__init__(isjunk=None, a='', b='')
Construct a SequenceMatcher.
set_seqs(a, b)
Set the two sequences to be compared.
set_seq1(a)
Set the first sequence to be compared.
set_seq2(b)
Set the second sequence to be compared.
find_longest_match(alo, ahi, blo, bhi)
Find longest matching block in a[alo:ahi] and b[blo:bhi].
get_matching_blocks()
Return list of triples describing matching subsequences.
get_opcodes()
Return list of 5-tuples describing how to turn a into b.
ratio()
Return a measure of the sequences' similarity (float in [0,1]).
quick_ratio()
Return an upper bound on .ratio() relatively quickly.
real_quick_ratio()
Return an upper bound on ratio() very quickly.
"""
def __init__(self, isjunk=None, a='', b='', autojunk=True):
"""Construct a SequenceMatcher.
Optional arg isjunk is None (the default), or a one-argument
function that takes a sequence element and returns true iff the
element is junk. None is equivalent to passing "lambda x: 0", i.e.
no elements are considered to be junk. For example, pass
lambda x: x in " \\t"
if you're comparing lines as sequences of characters, and don't
want to synch up on blanks or hard tabs.
Optional arg a is the first of two sequences to be compared. By
default, an empty string. The elements of a must be hashable. See
also .set_seqs() and .set_seq1().
Optional arg b is the second of two sequences to be compared. By
default, an empty string. The elements of b must be hashable. See
also .set_seqs() and .set_seq2().
Optional arg autojunk should be set to False to disable the
"automatic junk heuristic" that treats popular elements as junk
(see module documentation for more information).
"""
# Members:
# a
# first sequence
# b
# second sequence; differences are computed as "what do
# we need to do to 'a' to change it into 'b'?"
# b2j
# for x in b, b2j[x] is a list of the indices (into b)
# at which x appears; junk and popular elements do not appear
# fullbcount
# for x in b, fullbcount[x] == the number of times x
# appears in b; only materialized if really needed (used
# only for computing quick_ratio())
# matching_blocks
# a list of (i, j, k) triples, where a[i:i+k] == b[j:j+k];
# ascending & non-overlapping in i and in j; terminated by
# a dummy (len(a), len(b), 0) sentinel
# opcodes
# a list of (tag, i1, i2, j1, j2) tuples, where tag is
# one of
# 'replace' a[i1:i2] should be replaced by b[j1:j2]
# 'delete' a[i1:i2] should be deleted
# 'insert' b[j1:j2] should be inserted
# 'equal' a[i1:i2] == b[j1:j2]
# isjunk
# a user-supplied function taking a sequence element and
# returning true iff the element is "junk" -- this has
# subtle but helpful effects on the algorithm, which I'll
# get around to writing up someday <0.9 wink>.
# DON'T USE! Only __chain_b uses this. Use "in self.bjunk".
# bjunk
# the items in b for which isjunk is True.
# bpopular
# nonjunk items in b treated as junk by the heuristic (if used).
self.isjunk = isjunk
self.a = self.b = None
self.autojunk = autojunk
self.set_seqs(a, b)
def set_seqs(self, a, b):
"""Set the two sequences to be compared.
>>> s = SequenceMatcher()
>>> s.set_seqs("abcd", "bcde")
>>> s.ratio()
0.75
"""
self.set_seq1(a)
self.set_seq2(b)
def set_seq1(self, a):
"""Set the first sequence to be compared.
The second sequence to be compared is not changed.
>>> s = SequenceMatcher(None, "abcd", "bcde")
>>> s.ratio()
0.75
>>> s.set_seq1("bcde")
>>> s.ratio()
1.0
>>>
SequenceMatcher computes and caches detailed information about the
second sequence, so if you want to compare one sequence S against
many sequences, use .set_seq2(S) once and call .set_seq1(x)
repeatedly for each of the other sequences.
See also set_seqs() and set_seq2().
"""
if a is self.a:
return
self.a = a
self.matching_blocks = self.opcodes = None
def set_seq2(self, b):
"""Set the second sequence to be compared.
The first sequence to be compared is not changed.
>>> s = SequenceMatcher(None, "abcd", "bcde")
>>> s.ratio()
0.75
>>> s.set_seq2("abcd")
>>> s.ratio()
1.0
>>>
SequenceMatcher computes and caches detailed information about the
second sequence, so if you want to compare one sequence S against
many sequences, use .set_seq2(S) once and call .set_seq1(x)
repeatedly for each of the other sequences.
See also set_seqs() and set_seq1().
"""
if b is self.b:
return
self.b = b
self.matching_blocks = self.opcodes = None
self.fullbcount = None
self.__chain_b()
# For each element x in b, set b2j[x] to a list of the indices in
# b where x appears; the indices are in increasing order; note that
# the number of times x appears in b is len(b2j[x]) ...
# when self.isjunk is defined, junk elements don't show up in this
# map at all, which stops the central find_longest_match method
# from starting any matching block at a junk element ...
# b2j also does not contain entries for "popular" elements, meaning
# elements that account for more than 1 + 1% of the total elements, and
# when the sequence is reasonably large (>= 200 elements); this can
# be viewed as an adaptive notion of semi-junk, and yields an enormous
# speedup when, e.g., comparing program files with hundreds of
# instances of "return NULL;" ...
# note that this is only called when b changes; so for cross-product
# kinds of matches, it's best to call set_seq2 once, then set_seq1
# repeatedly
def __chain_b(self):
# Because isjunk is a user-defined (not C) function, and we test
# for junk a LOT, it's important to minimize the number of calls.
# Before the tricks described here, __chain_b was by far the most
# time-consuming routine in the whole module! If anyone sees
# Jim Roskind, thank him again for profile.py -- I never would
# have guessed that.
# The first trick is to build b2j ignoring the possibility
# of junk. I.e., we don't call isjunk at all yet. Throwing
# out the junk later is much cheaper than building b2j "right"
# from the start.
b = self.b
self.b2j = b2j = {}
for i, elt in enumerate(b):
indices = b2j.setdefault(elt, [])
indices.append(i)
# Purge junk elements
self.bjunk = junk = set()
isjunk = self.isjunk
if isjunk:
for elt in b2j.keys():
if isjunk(elt):
junk.add(elt)
for elt in junk: # separate loop avoids separate list of keys
del b2j[elt]
# Purge popular elements that are not junk
self.bpopular = popular = set()
n = len(b)
if self.autojunk and n >= 200:
ntest = n // 100 + 1
for elt, idxs in b2j.items():
if len(idxs) > ntest:
popular.add(elt)
for elt in popular: # ditto; as fast for 1% deletion
del b2j[elt]
def isbjunk(self, item):
"Deprecated; use 'item in SequenceMatcher().bjunk'."
warnings.warn("'SequenceMatcher().isbjunk(item)' is deprecated;\n"
"use 'item in SMinstance.bjunk' instead.",
DeprecationWarning, 2)
return item in self.bjunk
def isbpopular(self, item):
"Deprecated; use 'item in SequenceMatcher().bpopular'."
warnings.warn("'SequenceMatcher().isbpopular(item)' is deprecated;\n"
"use 'item in SMinstance.bpopular' instead.",
DeprecationWarning, 2)
return item in self.bpopular
def find_longest_match(self, alo, ahi, blo, bhi):
"""Find longest matching block in a[alo:ahi] and b[blo:bhi].
If isjunk is not defined:
Return (i,j,k) such that a[i:i+k] is equal to b[j:j+k], where
alo <= i <= i+k <= ahi
blo <= j <= j+k <= bhi
and for all (i',j',k') meeting those conditions,
k >= k'
i <= i'
and if i == i', j <= j'
In other words, of all maximal matching blocks, return one that
starts earliest in a, and of all those maximal matching blocks that
start earliest in a, return the one that starts earliest in b.
>>> s = SequenceMatcher(None, " abcd", "abcd abcd")
>>> s.find_longest_match(0, 5, 0, 9)
Match(a=0, b=4, size=5)
If isjunk is defined, first the longest matching block is
determined as above, but with the additional restriction that no
junk element appears in the block. Then that block is extended as
far as possible by matching (only) junk elements on both sides. So
the resulting block never matches on junk except as identical junk
happens to be adjacent to an "interesting" match.
Here's the same example as before, but considering blanks to be
junk. That prevents " abcd" from matching the " abcd" at the tail
end of the second sequence directly. Instead only the "abcd" can
match, and matches the leftmost "abcd" in the second sequence:
>>> s = SequenceMatcher(lambda x: x==" ", " abcd", "abcd abcd")
>>> s.find_longest_match(0, 5, 0, 9)
Match(a=1, b=0, size=4)
If no blocks match, return (alo, blo, 0).
>>> s = SequenceMatcher(None, "ab", "c")
>>> s.find_longest_match(0, 2, 0, 1)
Match(a=0, b=0, size=0)
"""
# CAUTION: stripping common prefix or suffix would be incorrect.
# E.g.,
# ab
# acab
# Longest matching block is "ab", but if common prefix is
# stripped, it's "a" (tied with "b"). UNIX(tm) diff does so
# strip, so ends up claiming that ab is changed to acab by
# inserting "ca" in the middle. That's minimal but unintuitive:
# "it's obvious" that someone inserted "ac" at the front.
# Windiff ends up at the same place as diff, but by pairing up
# the unique 'b's and then matching the first two 'a's.
a, b, b2j, isbjunk = self.a, self.b, self.b2j, self.bjunk.__contains__
besti, bestj, bestsize = alo, blo, 0
# find longest junk-free match
# during an iteration of the loop, j2len[j] = length of longest
# junk-free match ending with a[i-1] and b[j]
j2len = {}
nothing = []
for i in range(alo, ahi):
# look at all instances of a[i] in b; note that because
# b2j has no junk keys, the loop is skipped if a[i] is junk
j2lenget = j2len.get
newj2len = {}
for j in b2j.get(a[i], nothing):
# a[i] matches b[j]
if j < blo:
continue
if j >= bhi:
break
k = newj2len[j] = j2lenget(j-1, 0) + 1
if k > bestsize:
besti, bestj, bestsize = i-k+1, j-k+1, k
j2len = newj2len
# Extend the best by non-junk elements on each end. In particular,
# "popular" non-junk elements aren't in b2j, which greatly speeds
# the inner loop above, but also means "the best" match so far
# doesn't contain any junk *or* popular non-junk elements.
while besti > alo and bestj > blo and \
not isbjunk(b[bestj-1]) and \
a[besti-1] == b[bestj-1]:
besti, bestj, bestsize = besti-1, bestj-1, bestsize+1
while besti+bestsize < ahi and bestj+bestsize < bhi and \
not isbjunk(b[bestj+bestsize]) and \
a[besti+bestsize] == b[bestj+bestsize]:
bestsize += 1
# Now that we have a wholly interesting match (albeit possibly
# empty!), we may as well suck up the matching junk on each
# side of it too. Can't think of a good reason not to, and it
# saves post-processing the (possibly considerable) expense of
# figuring out what to do with it. In the case of an empty
# interesting match, this is clearly the right thing to do,
# because no other kind of match is possible in the regions.
while besti > alo and bestj > blo and \
isbjunk(b[bestj-1]) and \
a[besti-1] == b[bestj-1]:
besti, bestj, bestsize = besti-1, bestj-1, bestsize+1
while besti+bestsize < ahi and bestj+bestsize < bhi and \
isbjunk(b[bestj+bestsize]) and \
a[besti+bestsize] == b[bestj+bestsize]:
bestsize = bestsize + 1
return Match(besti, bestj, bestsize)
def get_matching_blocks(self):
"""Return list of triples describing matching subsequences.
Each triple is of the form (i, j, n), and means that
a[i:i+n] == b[j:j+n]. The triples are monotonically increasing in
i and in j. New in Python 2.5, it's also guaranteed that if
(i, j, n) and (i', j', n') are adjacent triples in the list, and
the second is not the last triple in the list, then i+n != i' or
j+n != j'. IOW, adjacent triples never describe adjacent equal
blocks.
The last triple is a dummy, (len(a), len(b), 0), and is the only
triple with n==0.
>>> s = SequenceMatcher(None, "abxcd", "abcd")
>>> list(s.get_matching_blocks())
[Match(a=0, b=0, size=2), Match(a=3, b=2, size=2), Match(a=5, b=4, size=0)]
"""
if self.matching_blocks is not None:
return self.matching_blocks
la, lb = len(self.a), len(self.b)
# This is most naturally expressed as a recursive algorithm, but
# at least one user bumped into extreme use cases that exceeded
# the recursion limit on their box. So, now we maintain a list
# ('queue`) of blocks we still need to look at, and append partial
# results to `matching_blocks` in a loop; the matches are sorted
# at the end.
queue = [(0, la, 0, lb)]
matching_blocks = []
while queue:
alo, ahi, blo, bhi = queue.pop()
i, j, k = x = self.find_longest_match(alo, ahi, blo, bhi)
# a[alo:i] vs b[blo:j] unknown
# a[i:i+k] same as b[j:j+k]
# a[i+k:ahi] vs b[j+k:bhi] unknown
if k: # if k is 0, there was no matching block
matching_blocks.append(x)
if alo < i and blo < j:
queue.append((alo, i, blo, j))
if i+k < ahi and j+k < bhi:
queue.append((i+k, ahi, j+k, bhi))
matching_blocks.sort()
# It's possible that we have adjacent equal blocks in the
# matching_blocks list now. Starting with 2.5, this code was added
# to collapse them.
i1 = j1 = k1 = 0
non_adjacent = []
for i2, j2, k2 in matching_blocks:
# Is this block adjacent to i1, j1, k1?
if i1 + k1 == i2 and j1 + k1 == j2:
# Yes, so collapse them -- this just increases the length of
# the first block by the length of the second, and the first
# block so lengthened remains the block to compare against.
k1 += k2
else:
# Not adjacent. Remember the first block (k1==0 means it's
# the dummy we started with), and make the second block the
# new block to compare against.
if k1:
non_adjacent.append((i1, j1, k1))
i1, j1, k1 = i2, j2, k2
if k1:
non_adjacent.append((i1, j1, k1))
non_adjacent.append( (la, lb, 0) )
self.matching_blocks = non_adjacent
return map(Match._make, self.matching_blocks)
def get_opcodes(self):
"""Return list of 5-tuples describing how to turn a into b.
Each tuple is of the form (tag, i1, i2, j1, j2). The first tuple
has i1 == j1 == 0, and remaining tuples have i1 == the i2 from the
tuple preceding it, and likewise for j1 == the previous j2.
The tags are strings, with these meanings:
'replace': a[i1:i2] should be replaced by b[j1:j2]
'delete': a[i1:i2] should be deleted.
Note that j1==j2 in this case.
'insert': b[j1:j2] should be inserted at a[i1:i1].
Note that i1==i2 in this case.
'equal': a[i1:i2] == b[j1:j2]
>>> a = "qabxcd"
>>> b = "abycdf"
>>> s = SequenceMatcher(None, a, b)
>>> for tag, i1, i2, j1, j2 in s.get_opcodes():
... print(("%7s a[%d:%d] (%s) b[%d:%d] (%s)" %
... (tag, i1, i2, a[i1:i2], j1, j2, b[j1:j2])))
delete a[0:1] (q) b[0:0] ()
equal a[1:3] (ab) b[0:2] (ab)
replace a[3:4] (x) b[2:3] (y)
equal a[4:6] (cd) b[3:5] (cd)
insert a[6:6] () b[5:6] (f)
"""
if self.opcodes is not None:
return self.opcodes
i = j = 0
self.opcodes = answer = []
for ai, bj, size in self.get_matching_blocks():
# invariant: we've pumped out correct diffs to change
# a[:i] into b[:j], and the next matching block is
# a[ai:ai+size] == b[bj:bj+size]. So we need to pump
# out a diff to change a[i:ai] into b[j:bj], pump out
# the matching block, and move (i,j) beyond the match
tag = ''
if i < ai and j < bj:
tag = 'replace'
elif i < ai:
tag = 'delete'
elif j < bj:
tag = 'insert'
if tag:
answer.append( (tag, i, ai, j, bj) )
i, j = ai+size, bj+size
# the list of matching blocks is terminated by a
# sentinel with size 0
if size:
answer.append( ('equal', ai, i, bj, j) )
return answer
def get_grouped_opcodes(self, n=3):
""" Isolate change clusters by eliminating ranges with no changes.
Return a generator of groups with up to n lines of context.
Each group is in the same format as returned by get_opcodes().
>>> from pprint import pprint
>>> a = list(map(str, range(1,40)))
>>> b = a[:]
>>> b[8:8] = ['i'] # Make an insertion
>>> b[20] += 'x' # Make a replacement
>>> b[23:28] = [] # Make a deletion
>>> b[30] += 'y' # Make another replacement
>>> pprint(list(SequenceMatcher(None,a,b).get_grouped_opcodes()))
[[('equal', 5, 8, 5, 8), ('insert', 8, 8, 8, 9), ('equal', 8, 11, 9, 12)],
[('equal', 16, 19, 17, 20),
('replace', 19, 20, 20, 21),
('equal', 20, 22, 21, 23),
('delete', 22, 27, 23, 23),
('equal', 27, 30, 23, 26)],
[('equal', 31, 34, 27, 30),
('replace', 34, 35, 30, 31),
('equal', 35, 38, 31, 34)]]
"""
codes = self.get_opcodes()
if not codes:
codes = [("equal", 0, 1, 0, 1)]
# Fixup leading and trailing groups if they show no changes.
if codes[0][0] == 'equal':
tag, i1, i2, j1, j2 = codes[0]
codes[0] = tag, max(i1, i2-n), i2, max(j1, j2-n), j2
if codes[-1][0] == 'equal':
tag, i1, i2, j1, j2 = codes[-1]
codes[-1] = tag, i1, min(i2, i1+n), j1, min(j2, j1+n)
nn = n + n
group = []
for tag, i1, i2, j1, j2 in codes:
# End the current group and start a new one whenever
# there is a large range with no changes.
if tag == 'equal' and i2-i1 > nn:
group.append((tag, i1, min(i2, i1+n), j1, min(j2, j1+n)))
yield group
group = []
i1, j1 = max(i1, i2-n), max(j1, j2-n)
group.append((tag, i1, i2, j1 ,j2))
if group and not (len(group)==1 and group[0][0] == 'equal'):
yield group
def ratio(self):
"""Return a measure of the sequences' similarity (float in [0,1]).
Where T is the total number of elements in both sequences, and
M is the number of matches, this is 2.0*M / T.
Note that this is 1 if the sequences are identical, and 0 if
they have nothing in common.
.ratio() is expensive to compute if you haven't already computed
.get_matching_blocks() or .get_opcodes(), in which case you may
want to try .quick_ratio() or .real_quick_ratio() first to get an
upper bound.
>>> s = SequenceMatcher(None, "abcd", "bcde")
>>> s.ratio()
0.75
>>> s.quick_ratio()
0.75
>>> s.real_quick_ratio()
1.0
"""
matches = sum(triple[-1] for triple in self.get_matching_blocks())
return _calculate_ratio(matches, len(self.a) + len(self.b))
def quick_ratio(self):
"""Return an upper bound on ratio() relatively quickly.
This isn't defined beyond that it is an upper bound on .ratio(), and
is faster to compute.
"""
# viewing a and b as multisets, set matches to the cardinality
# of their intersection; this counts the number of matches
# without regard to order, so is clearly an upper bound
if self.fullbcount is None:
self.fullbcount = fullbcount = {}
for elt in self.b:
fullbcount[elt] = fullbcount.get(elt, 0) + 1
fullbcount = self.fullbcount
# avail[x] is the number of times x appears in 'b' less the
# number of times we've seen it in 'a' so far ... kinda
avail = {}
availhas, matches = avail.__contains__, 0
for elt in self.a:
if availhas(elt):
numb = avail[elt]
else:
numb = fullbcount.get(elt, 0)
avail[elt] = numb - 1
if numb > 0:
matches = matches + 1
return _calculate_ratio(matches, len(self.a) + len(self.b))
def real_quick_ratio(self):
"""Return an upper bound on ratio() very quickly.
This isn't defined beyond that it is an upper bound on .ratio(), and
is faster to compute than either .ratio() or .quick_ratio().
"""
la, lb = len(self.a), len(self.b)
# can't have more matches than the number of elements in the
# shorter sequence
return _calculate_ratio(min(la, lb), la + lb)
def get_close_matches(word, possibilities, n=3, cutoff=0.6):
"""Use SequenceMatcher to return list of the best "good enough" matches.
word is a sequence for which close matches are desired (typically a
string).
possibilities is a list of sequences against which to match word
(typically a list of strings).
Optional arg n (default 3) is the maximum number of close matches to
return. n must be > 0.
Optional arg cutoff (default 0.6) is a float in [0, 1]. Possibilities
that don't score at least that similar to word are ignored.
The best (no more than n) matches among the possibilities are returned
in a list, sorted by similarity score, most similar first.
>>> get_close_matches("appel", ["ape", "apple", "peach", "puppy"])
['apple', 'ape']
>>> import keyword as _keyword
>>> get_close_matches("wheel", _keyword.kwlist)
['while']
>>> get_close_matches("Apple", _keyword.kwlist)
[]
>>> get_close_matches("accept", _keyword.kwlist)
['except']
"""
if not n > 0:
raise ValueError("n must be > 0: %r" % (n,))
if not 0.0 <= cutoff <= 1.0:
raise ValueError("cutoff must be in [0.0, 1.0]: %r" % (cutoff,))
result = []
s = SequenceMatcher()
s.set_seq2(word)
for x in possibilities:
s.set_seq1(x)
if s.real_quick_ratio() >= cutoff and \
s.quick_ratio() >= cutoff and \
s.ratio() >= cutoff:
result.append((s.ratio(), x))
# Move the best scorers to head of list
result = heapq.nlargest(n, result)
# Strip scores for the best n matches
return [x for score, x in result]
def _count_leading(line, ch):
"""
Return number of `ch` characters at the start of `line`.
Example:
>>> _count_leading(' abc', ' ')
3
"""
i, n = 0, len(line)
while i < n and line[i] == ch:
i += 1
return i
class Differ:
r"""
Differ is a class for comparing sequences of lines of text, and
producing human-readable differences or deltas. Differ uses
SequenceMatcher both to compare sequences of lines, and to compare
sequences of characters within similar (near-matching) lines.
Each line of a Differ delta begins with a two-letter code:
'- ' line unique to sequence 1
'+ ' line unique to sequence 2
' ' line common to both sequences
'? ' line not present in either input sequence
Lines beginning with '? ' attempt to guide the eye to intraline
differences, and were not present in either input sequence. These lines
can be confusing if the sequences contain tab characters.
Note that Differ makes no claim to produce a *minimal* diff. To the
contrary, minimal diffs are often counter-intuitive, because they synch
up anywhere possible, sometimes accidental matches 100 pages apart.
Restricting synch points to contiguous matches preserves some notion of
locality, at the occasional cost of producing a longer diff.
Example: Comparing two texts.
First we set up the texts, sequences of individual single-line strings
ending with newlines (such sequences can also be obtained from the
`readlines()` method of file-like objects):
>>> text1 = ''' 1. Beautiful is better than ugly.
... 2. Explicit is better than implicit.
... 3. Simple is better than complex.
... 4. Complex is better than complicated.
... '''.splitlines(keepends=True)
>>> len(text1)
4
>>> text1[0][-1]
'\n'
>>> text2 = ''' 1. Beautiful is better than ugly.
... 3. Simple is better than complex.
... 4. Complicated is better than complex.
... 5. Flat is better than nested.
... '''.splitlines(keepends=True)
Next we instantiate a Differ object:
>>> d = Differ()
Note that when instantiating a Differ object we may pass functions to
filter out line and character 'junk'. See Differ.__init__ for details.
Finally, we compare the two:
>>> result = list(d.compare(text1, text2))
'result' is a list of strings, so let's pretty-print it:
>>> from pprint import pprint as _pprint
>>> _pprint(result)
[' 1. Beautiful is better than ugly.\n',
'- 2. Explicit is better than implicit.\n',
'- 3. Simple is better than complex.\n',
'+ 3. Simple is better than complex.\n',
'? ++\n',
'- 4. Complex is better than complicated.\n',
'? ^ ---- ^\n',
'+ 4. Complicated is better than complex.\n',
'? ++++ ^ ^\n',
'+ 5. Flat is better than nested.\n']
As a single multi-line string it looks like this:
>>> print(''.join(result), end="")
1. Beautiful is better than ugly.
- 2. Explicit is better than implicit.
- 3. Simple is better than complex.
+ 3. Simple is better than complex.
? ++
- 4. Complex is better than complicated.
? ^ ---- ^
+ 4. Complicated is better than complex.
? ++++ ^ ^
+ 5. Flat is better than nested.
Methods:
__init__(linejunk=None, charjunk=None)
Construct a text differencer, with optional filters.
compare(a, b)
Compare two sequences of lines; generate the resulting delta.
"""
def __init__(self, linejunk=None, charjunk=None):
"""
Construct a text differencer, with optional filters.
The two optional keyword parameters are for filter functions:
- `linejunk`: A function that should accept a single string argument,
and return true iff the string is junk. The module-level function
`IS_LINE_JUNK` may be used to filter out lines without visible
characters, except for at most one splat ('#'). It is recommended
to leave linejunk None; as of Python 2.3, the underlying
SequenceMatcher class has grown an adaptive notion of "noise" lines
that's better than any static definition the author has ever been
able to craft.
- `charjunk`: A function that should accept a string of length 1. The
module-level function `IS_CHARACTER_JUNK` may be used to filter out
whitespace characters (a blank or tab; **note**: bad idea to include
newline in this!). Use of IS_CHARACTER_JUNK is recommended.
"""
self.linejunk = linejunk
self.charjunk = charjunk
def compare(self, a, b):
r"""
Compare two sequences of lines; generate the resulting delta.
Each sequence must contain individual single-line strings ending with
newlines. Such sequences can be obtained from the `readlines()` method
of file-like objects. The delta generated also consists of newline-
terminated strings, ready to be printed as-is via the writeline()
method of a file-like object.
Example:
>>> print(''.join(Differ().compare('one\ntwo\nthree\n'.splitlines(True),
... 'ore\ntree\nemu\n'.splitlines(True))),
... end="")
- one
? ^
+ ore
? ^
- two
- three
? -
+ tree
+ emu
"""
cruncher = SequenceMatcher(self.linejunk, a, b)
for tag, alo, ahi, blo, bhi in cruncher.get_opcodes():
if tag == 'replace':
g = self._fancy_replace(a, alo, ahi, b, blo, bhi)
elif tag == 'delete':
g = self._dump('-', a, alo, ahi)
elif tag == 'insert':
g = self._dump('+', b, blo, bhi)
elif tag == 'equal':
g = self._dump(' ', a, alo, ahi)
else:
raise ValueError('unknown tag %r' % (tag,))
for line in g:
yield line
def _dump(self, tag, x, lo, hi):
"""Generate comparison results for a same-tagged range."""
for i in range(lo, hi):
yield '%s %s' % (tag, x[i])
def _plain_replace(self, a, alo, ahi, b, blo, bhi):
assert alo < ahi and blo < bhi
# dump the shorter block first -- reduces the burden on short-term
# memory if the blocks are of very different sizes
if bhi - blo < ahi - alo:
first = self._dump('+', b, blo, bhi)
second = self._dump('-', a, alo, ahi)
else:
first = self._dump('-', a, alo, ahi)
second = self._dump('+', b, blo, bhi)
for g in first, second:
for line in g:
yield line
def _fancy_replace(self, a, alo, ahi, b, blo, bhi):
r"""
When replacing one block of lines with another, search the blocks
for *similar* lines; the best-matching pair (if any) is used as a
synch point, and intraline difference marking is done on the
similar pair. Lots of work, but often worth it.
Example:
>>> d = Differ()
>>> results = d._fancy_replace(['abcDefghiJkl\n'], 0, 1,
... ['abcdefGhijkl\n'], 0, 1)
>>> print(''.join(results), end="")
- abcDefghiJkl
? ^ ^ ^
+ abcdefGhijkl
? ^ ^ ^
"""
# don't synch up unless the lines have a similarity score of at
# least cutoff; best_ratio tracks the best score seen so far
best_ratio, cutoff = 0.74, 0.75
cruncher = SequenceMatcher(self.charjunk)
eqi, eqj = None, None # 1st indices of equal lines (if any)
# search for the pair that matches best without being identical
# (identical lines must be junk lines, & we don't want to synch up
# on junk -- unless we have to)
for j in range(blo, bhi):
bj = b[j]
cruncher.set_seq2(bj)
for i in range(alo, ahi):
ai = a[i]
if ai == bj:
if eqi is None:
eqi, eqj = i, j
continue
cruncher.set_seq1(ai)
# computing similarity is expensive, so use the quick
# upper bounds first -- have seen this speed up messy
# compares by a factor of 3.
# note that ratio() is only expensive to compute the first
# time it's called on a sequence pair; the expensive part
# of the computation is cached by cruncher
if cruncher.real_quick_ratio() > best_ratio and \
cruncher.quick_ratio() > best_ratio and \
cruncher.ratio() > best_ratio:
best_ratio, best_i, best_j = cruncher.ratio(), i, j
if best_ratio < cutoff:
# no non-identical "pretty close" pair
if eqi is None:
# no identical pair either -- treat it as a straight replace
for line in self._plain_replace(a, alo, ahi, b, blo, bhi):
yield line
return
# no close pair, but an identical pair -- synch up on that
best_i, best_j, best_ratio = eqi, eqj, 1.0
else:
# there's a close pair, so forget the identical pair (if any)
eqi = None
# a[best_i] very similar to b[best_j]; eqi is None iff they're not
# identical
# pump out diffs from before the synch point
for line in self._fancy_helper(a, alo, best_i, b, blo, best_j):
yield line
# do intraline marking on the synch pair
aelt, belt = a[best_i], b[best_j]
if eqi is None:
# pump out a '-', '?', '+', '?' quad for the synched lines
atags = btags = ""
cruncher.set_seqs(aelt, belt)
for tag, ai1, ai2, bj1, bj2 in cruncher.get_opcodes():
la, lb = ai2 - ai1, bj2 - bj1
if tag == 'replace':
atags += '^' * la
btags += '^' * lb
elif tag == 'delete':
atags += '-' * la
elif tag == 'insert':
btags += '+' * lb
elif tag == 'equal':
atags += ' ' * la
btags += ' ' * lb
else:
raise ValueError('unknown tag %r' % (tag,))
for line in self._qformat(aelt, belt, atags, btags):
yield line
else:
# the synch pair is identical
yield ' ' + aelt
# pump out diffs from after the synch point
for line in self._fancy_helper(a, best_i+1, ahi, b, best_j+1, bhi):
yield line
def _fancy_helper(self, a, alo, ahi, b, blo, bhi):
g = []
if alo < ahi:
if blo < bhi:
g = self._fancy_replace(a, alo, ahi, b, blo, bhi)
else:
g = self._dump('-', a, alo, ahi)
elif blo < bhi:
g = self._dump('+', b, blo, bhi)
for line in g:
yield line
def _qformat(self, aline, bline, atags, btags):
r"""
Format "?" output and deal with leading tabs.
Example:
>>> d = Differ()
>>> results = d._qformat('\tabcDefghiJkl\n', '\tabcdefGhijkl\n',
... ' ^ ^ ^ ', ' ^ ^ ^ ')
>>> for line in results: print(repr(line))
...
'- \tabcDefghiJkl\n'
'? \t ^ ^ ^\n'
'+ \tabcdefGhijkl\n'
'? \t ^ ^ ^\n'
"""
# Can hurt, but will probably help most of the time.
common = min(_count_leading(aline, "\t"),
_count_leading(bline, "\t"))
common = min(common, _count_leading(atags[:common], " "))
common = min(common, _count_leading(btags[:common], " "))
atags = atags[common:].rstrip()
btags = btags[common:].rstrip()
yield "- " + aline
if atags:
yield "? %s%s\n" % ("\t" * common, atags)
yield "+ " + bline
if btags:
yield "? %s%s\n" % ("\t" * common, btags)
# With respect to junk, an earlier version of ndiff simply refused to
# *start* a match with a junk element. The result was cases like this:
# before: private Thread currentThread;
# after: private volatile Thread currentThread;
# If you consider whitespace to be junk, the longest contiguous match
# not starting with junk is "e Thread currentThread". So ndiff reported
# that "e volatil" was inserted between the 't' and the 'e' in "private".
# While an accurate view, to people that's absurd. The current version
# looks for matching blocks that are entirely junk-free, then extends the
# longest one of those as far as possible but only with matching junk.
# So now "currentThread" is matched, then extended to suck up the
# preceding blank; then "private" is matched, and extended to suck up the
# following blank; then "Thread" is matched; and finally ndiff reports
# that "volatile " was inserted before "Thread". The only quibble
# remaining is that perhaps it was really the case that " volatile"
# was inserted after "private". I can live with that <wink>.
import re
def IS_LINE_JUNK(line, pat=re.compile(r"\s*#?\s*$").match):
r"""
Return 1 for ignorable line: iff `line` is blank or contains a single '#'.
Examples:
>>> IS_LINE_JUNK('\n')
True
>>> IS_LINE_JUNK(' # \n')
True
>>> IS_LINE_JUNK('hello\n')
False
"""
return pat(line) is not None
def IS_CHARACTER_JUNK(ch, ws=" \t"):
r"""
Return 1 for ignorable character: iff `ch` is a space or tab.
Examples:
>>> IS_CHARACTER_JUNK(' ')
True
>>> IS_CHARACTER_JUNK('\t')
True
>>> IS_CHARACTER_JUNK('\n')
False
>>> IS_CHARACTER_JUNK('x')
False
"""
return ch in ws
########################################################################
### Unified Diff
########################################################################
def _format_range_unified(start, stop):
'Convert range to the "ed" format'
# Per the diff spec at http://www.unix.org/single_unix_specification/
beginning = start + 1 # lines start numbering with one
length = stop - start
if length == 1:
return '{}'.format(beginning)
if not length:
beginning -= 1 # empty ranges begin at line just before the range
return '{},{}'.format(beginning, length)
def unified_diff(a, b, fromfile='', tofile='', fromfiledate='',
tofiledate='', n=3, lineterm='\n'):
r"""
Compare two sequences of lines; generate the delta as a unified diff.
Unified diffs are a compact way of showing line changes and a few
lines of context. The number of context lines is set by 'n' which
defaults to three.
By default, the diff control lines (those with ---, +++, or @@) are
created with a trailing newline. This is helpful so that inputs
created from file.readlines() result in diffs that are suitable for
file.writelines() since both the inputs and outputs have trailing
newlines.
For inputs that do not have trailing newlines, set the lineterm
argument to "" so that the output will be uniformly newline free.
The unidiff format normally has a header for filenames and modification
times. Any or all of these may be specified using strings for
'fromfile', 'tofile', 'fromfiledate', and 'tofiledate'.
The modification times are normally expressed in the ISO 8601 format.
Example:
>>> for line in unified_diff('one two three four'.split(),
... 'zero one tree four'.split(), 'Original', 'Current',
... '2005-01-26 23:30:50', '2010-04-02 10:20:52',
... lineterm=''):
... print(line) # doctest: +NORMALIZE_WHITESPACE
--- Original 2005-01-26 23:30:50
+++ Current 2010-04-02 10:20:52
@@ -1,4 +1,4 @@
+zero
one
-two
-three
+tree
four
"""
started = False
for group in SequenceMatcher(None,a,b).get_grouped_opcodes(n):
if not started:
started = True
fromdate = '\t{}'.format(fromfiledate) if fromfiledate else ''
todate = '\t{}'.format(tofiledate) if tofiledate else ''
yield '--- {}{}{}'.format(fromfile, fromdate, lineterm)
yield '+++ {}{}{}'.format(tofile, todate, lineterm)
first, last = group[0], group[-1]
file1_range = _format_range_unified(first[1], last[2])
file2_range = _format_range_unified(first[3], last[4])
yield '@@ -{} +{} @@{}'.format(file1_range, file2_range, lineterm)
for tag, i1, i2, j1, j2 in group:
if tag == 'equal':
for line in a[i1:i2]:
yield ' ' + line
continue
if tag in {'replace', 'delete'}:
for line in a[i1:i2]:
yield '-' + line
if tag in {'replace', 'insert'}:
for line in b[j1:j2]:
yield '+' + line
########################################################################
### Context Diff
########################################################################
def _format_range_context(start, stop):
'Convert range to the "ed" format'
# Per the diff spec at http://www.unix.org/single_unix_specification/
beginning = start + 1 # lines start numbering with one
length = stop - start
if not length:
beginning -= 1 # empty ranges begin at line just before the range
if length <= 1:
return '{}'.format(beginning)
return '{},{}'.format(beginning, beginning + length - 1)
# See http://www.unix.org/single_unix_specification/
def context_diff(a, b, fromfile='', tofile='',
fromfiledate='', tofiledate='', n=3, lineterm='\n'):
r"""
Compare two sequences of lines; generate the delta as a context diff.
Context diffs are a compact way of showing line changes and a few
lines of context. The number of context lines is set by 'n' which
defaults to three.
By default, the diff control lines (those with *** or ---) are
created with a trailing newline. This is helpful so that inputs
created from file.readlines() result in diffs that are suitable for
file.writelines() since both the inputs and outputs have trailing
newlines.
For inputs that do not have trailing newlines, set the lineterm
argument to "" so that the output will be uniformly newline free.
The context diff format normally has a header for filenames and
modification times. Any or all of these may be specified using
strings for 'fromfile', 'tofile', 'fromfiledate', and 'tofiledate'.
The modification times are normally expressed in the ISO 8601 format.
If not specified, the strings default to blanks.
Example:
>>> print(''.join(context_diff('one\ntwo\nthree\nfour\n'.splitlines(True),
... 'zero\none\ntree\nfour\n'.splitlines(True), 'Original', 'Current')),
... end="")
*** Original
--- Current
***************
*** 1,4 ****
one
! two
! three
four
--- 1,4 ----
+ zero
one
! tree
four
"""
prefix = dict(insert='+ ', delete='- ', replace='! ', equal=' ')
started = False
for group in SequenceMatcher(None,a,b).get_grouped_opcodes(n):
if not started:
started = True
fromdate = '\t{}'.format(fromfiledate) if fromfiledate else ''
todate = '\t{}'.format(tofiledate) if tofiledate else ''
yield '*** {}{}{}'.format(fromfile, fromdate, lineterm)
yield '--- {}{}{}'.format(tofile, todate, lineterm)
first, last = group[0], group[-1]
yield '***************' + lineterm
file1_range = _format_range_context(first[1], last[2])
yield '*** {} ****{}'.format(file1_range, lineterm)
if any(tag in {'replace', 'delete'} for tag, _, _, _, _ in group):
for tag, i1, i2, _, _ in group:
if tag != 'insert':
for line in a[i1:i2]:
yield prefix[tag] + line
file2_range = _format_range_context(first[3], last[4])
yield '--- {} ----{}'.format(file2_range, lineterm)
if any(tag in {'replace', 'insert'} for tag, _, _, _, _ in group):
for tag, _, _, j1, j2 in group:
if tag != 'delete':
for line in b[j1:j2]:
yield prefix[tag] + line
def ndiff(a, b, linejunk=None, charjunk=IS_CHARACTER_JUNK):
r"""
Compare `a` and `b` (lists of strings); return a `Differ`-style delta.
Optional keyword parameters `linejunk` and `charjunk` are for filter
functions (or None):
- linejunk: A function that should accept a single string argument, and
return true iff the string is junk. The default is None, and is
recommended; as of Python 2.3, an adaptive notion of "noise" lines is
used that does a good job on its own.
- charjunk: A function that should accept a string of length 1. The
default is module-level function IS_CHARACTER_JUNK, which filters out
whitespace characters (a blank or tab; note: bad idea to include newline
in this!).
Tools/scripts/ndiff.py is a command-line front-end to this function.
Example:
>>> diff = ndiff('one\ntwo\nthree\n'.splitlines(keepends=True),
... 'ore\ntree\nemu\n'.splitlines(keepends=True))
>>> print(''.join(diff), end="")
- one
? ^
+ ore
? ^
- two
- three
? -
+ tree
+ emu
"""
return Differ(linejunk, charjunk).compare(a, b)
def _mdiff(fromlines, tolines, context=None, linejunk=None,
charjunk=IS_CHARACTER_JUNK):
r"""Returns generator yielding marked up from/to side by side differences.
Arguments:
fromlines -- list of text lines to compared to tolines
tolines -- list of text lines to be compared to fromlines
context -- number of context lines to display on each side of difference,
if None, all from/to text lines will be generated.
linejunk -- passed on to ndiff (see ndiff documentation)
charjunk -- passed on to ndiff (see ndiff documentation)
This function returns an iterator which returns a tuple:
(from line tuple, to line tuple, boolean flag)
from/to line tuple -- (line num, line text)
line num -- integer or None (to indicate a context separation)
line text -- original line text with following markers inserted:
'\0+' -- marks start of added text
'\0-' -- marks start of deleted text
'\0^' -- marks start of changed text
'\1' -- marks end of added/deleted/changed text
boolean flag -- None indicates context separation, True indicates
either "from" or "to" line contains a change, otherwise False.
This function/iterator was originally developed to generate side by side
file difference for making HTML pages (see HtmlDiff class for example
usage).
Note, this function utilizes the ndiff function to generate the side by
side difference markup. Optional ndiff arguments may be passed to this
function and they in turn will be passed to ndiff.
"""
import re
# regular expression for finding intraline change indices
change_re = re.compile('(\++|\-+|\^+)')
# create the difference iterator to generate the differences
diff_lines_iterator = ndiff(fromlines,tolines,linejunk,charjunk)
def _make_line(lines, format_key, side, num_lines=[0,0]):
"""Returns line of text with user's change markup and line formatting.
lines -- list of lines from the ndiff generator to produce a line of
text from. When producing the line of text to return, the
lines used are removed from this list.
format_key -- '+' return first line in list with "add" markup around
the entire line.
'-' return first line in list with "delete" markup around
the entire line.
'?' return first line in list with add/delete/change
intraline markup (indices obtained from second line)
None return first line in list with no markup
side -- indice into the num_lines list (0=from,1=to)
num_lines -- from/to current line number. This is NOT intended to be a
passed parameter. It is present as a keyword argument to
maintain memory of the current line numbers between calls
of this function.
Note, this function is purposefully not defined at the module scope so
that data it needs from its parent function (within whose context it
is defined) does not need to be of module scope.
"""
num_lines[side] += 1
# Handle case where no user markup is to be added, just return line of
# text with user's line format to allow for usage of the line number.
if format_key is None:
return (num_lines[side],lines.pop(0)[2:])
# Handle case of intraline changes
if format_key == '?':
text, markers = lines.pop(0), lines.pop(0)
# find intraline changes (store change type and indices in tuples)
sub_info = []
def record_sub_info(match_object,sub_info=sub_info):
sub_info.append([match_object.group(1)[0],match_object.span()])
return match_object.group(1)
change_re.sub(record_sub_info,markers)
# process each tuple inserting our special marks that won't be
# noticed by an xml/html escaper.
for key,(begin,end) in sub_info[::-1]:
text = text[0:begin]+'\0'+key+text[begin:end]+'\1'+text[end:]
text = text[2:]
# Handle case of add/delete entire line
else:
text = lines.pop(0)[2:]
# if line of text is just a newline, insert a space so there is
# something for the user to highlight and see.
if not text:
text = ' '
# insert marks that won't be noticed by an xml/html escaper.
text = '\0' + format_key + text + '\1'
# Return line of text, first allow user's line formatter to do its
# thing (such as adding the line number) then replace the special
# marks with what the user's change markup.
return (num_lines[side],text)
def _line_iterator():
"""Yields from/to lines of text with a change indication.
This function is an iterator. It itself pulls lines from a
differencing iterator, processes them and yields them. When it can
it yields both a "from" and a "to" line, otherwise it will yield one
or the other. In addition to yielding the lines of from/to text, a
boolean flag is yielded to indicate if the text line(s) have
differences in them.
Note, this function is purposefully not defined at the module scope so
that data it needs from its parent function (within whose context it
is defined) does not need to be of module scope.
"""
lines = []
num_blanks_pending, num_blanks_to_yield = 0, 0
while True:
# Load up next 4 lines so we can look ahead, create strings which
# are a concatenation of the first character of each of the 4 lines
# so we can do some very readable comparisons.
while len(lines) < 4:
try:
lines.append(next(diff_lines_iterator))
except StopIteration:
lines.append('X')
s = ''.join([line[0] for line in lines])
if s.startswith('X'):
# When no more lines, pump out any remaining blank lines so the
# corresponding add/delete lines get a matching blank line so
# all line pairs get yielded at the next level.
num_blanks_to_yield = num_blanks_pending
elif s.startswith('-?+?'):
# simple intraline change
yield _make_line(lines,'?',0), _make_line(lines,'?',1), True
continue
elif s.startswith('--++'):
# in delete block, add block coming: we do NOT want to get
# caught up on blank lines yet, just process the delete line
num_blanks_pending -= 1
yield _make_line(lines,'-',0), None, True
continue
elif s.startswith(('--?+', '--+', '- ')):
# in delete block and see a intraline change or unchanged line
# coming: yield the delete line and then blanks
from_line,to_line = _make_line(lines,'-',0), None
num_blanks_to_yield,num_blanks_pending = num_blanks_pending-1,0
elif s.startswith('-+?'):
# intraline change
yield _make_line(lines,None,0), _make_line(lines,'?',1), True
continue
elif s.startswith('-?+'):
# intraline change
yield _make_line(lines,'?',0), _make_line(lines,None,1), True
continue
elif s.startswith('-'):
# delete FROM line
num_blanks_pending -= 1
yield _make_line(lines,'-',0), None, True
continue
elif s.startswith('+--'):
# in add block, delete block coming: we do NOT want to get
# caught up on blank lines yet, just process the add line
num_blanks_pending += 1
yield None, _make_line(lines,'+',1), True
continue
elif s.startswith(('+ ', '+-')):
# will be leaving an add block: yield blanks then add line
from_line, to_line = None, _make_line(lines,'+',1)
num_blanks_to_yield,num_blanks_pending = num_blanks_pending+1,0
elif s.startswith('+'):
# inside an add block, yield the add line
num_blanks_pending += 1
yield None, _make_line(lines,'+',1), True
continue
elif s.startswith(' '):
# unchanged text, yield it to both sides
yield _make_line(lines[:],None,0),_make_line(lines,None,1),False
continue
# Catch up on the blank lines so when we yield the next from/to
# pair, they are lined up.
while(num_blanks_to_yield < 0):
num_blanks_to_yield += 1
yield None,('','\n'),True
while(num_blanks_to_yield > 0):
num_blanks_to_yield -= 1
yield ('','\n'),None,True
if s.startswith('X'):
raise StopIteration
else:
yield from_line,to_line,True
def _line_pair_iterator():
"""Yields from/to lines of text with a change indication.
This function is an iterator. It itself pulls lines from the line
iterator. Its difference from that iterator is that this function
always yields a pair of from/to text lines (with the change
indication). If necessary it will collect single from/to lines
until it has a matching pair from/to pair to yield.
Note, this function is purposefully not defined at the module scope so
that data it needs from its parent function (within whose context it
is defined) does not need to be of module scope.
"""
line_iterator = _line_iterator()
fromlines,tolines=[],[]
while True:
# Collecting lines of text until we have a from/to pair
while (len(fromlines)==0 or len(tolines)==0):
from_line, to_line, found_diff = next(line_iterator)
if from_line is not None:
fromlines.append((from_line,found_diff))
if to_line is not None:
tolines.append((to_line,found_diff))
# Once we have a pair, remove them from the collection and yield it
from_line, fromDiff = fromlines.pop(0)
to_line, to_diff = tolines.pop(0)
yield (from_line,to_line,fromDiff or to_diff)
# Handle case where user does not want context differencing, just yield
# them up without doing anything else with them.
line_pair_iterator = _line_pair_iterator()
if context is None:
while True:
yield next(line_pair_iterator)
# Handle case where user wants context differencing. We must do some
# storage of lines until we know for sure that they are to be yielded.
else:
context += 1
lines_to_write = 0
while True:
# Store lines up until we find a difference, note use of a
# circular queue because we only need to keep around what
# we need for context.
index, contextLines = 0, [None]*(context)
found_diff = False
while(found_diff is False):
from_line, to_line, found_diff = next(line_pair_iterator)
i = index % context
contextLines[i] = (from_line, to_line, found_diff)
index += 1
# Yield lines that we have collected so far, but first yield
# the user's separator.
if index > context:
yield None, None, None
lines_to_write = context
else:
lines_to_write = index
index = 0
while(lines_to_write):
i = index % context
index += 1
yield contextLines[i]
lines_to_write -= 1
# Now yield the context lines after the change
lines_to_write = context-1
while(lines_to_write):
from_line, to_line, found_diff = next(line_pair_iterator)
# If another change within the context, extend the context
if found_diff:
lines_to_write = context-1
else:
lines_to_write -= 1
yield from_line, to_line, found_diff
_file_template = """
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=ISO-8859-1" />
<title></title>
<style type="text/css">%(styles)s
</style>
</head>
<body>
%(table)s%(legend)s
</body>
</html>"""
_styles = """
table.diff {font-family:Courier; border:medium;}
.diff_header {background-color:#e0e0e0}
td.diff_header {text-align:right}
.diff_next {background-color:#c0c0c0}
.diff_add {background-color:#aaffaa}
.diff_chg {background-color:#ffff77}
.diff_sub {background-color:#ffaaaa}"""
_table_template = """
<table class="diff" id="difflib_chg_%(prefix)s_top"
cellspacing="0" cellpadding="0" rules="groups" >
<colgroup></colgroup> <colgroup></colgroup> <colgroup></colgroup>
<colgroup></colgroup> <colgroup></colgroup> <colgroup></colgroup>
%(header_row)s
<tbody>
%(data_rows)s </tbody>
</table>"""
_legend = """
<table class="diff" summary="Legends">
<tr> <th colspan="2"> Legends </th> </tr>
<tr> <td> <table border="" summary="Colors">
<tr><th> Colors </th> </tr>
<tr><td class="diff_add"> Added </td></tr>
<tr><td class="diff_chg">Changed</td> </tr>
<tr><td class="diff_sub">Deleted</td> </tr>
</table></td>
<td> <table border="" summary="Links">
<tr><th colspan="2"> Links </th> </tr>
<tr><td>(f)irst change</td> </tr>
<tr><td>(n)ext change</td> </tr>
<tr><td>(t)op</td> </tr>
</table></td> </tr>
</table>"""
class HtmlDiff(object):
"""For producing HTML side by side comparison with change highlights.
This class can be used to create an HTML table (or a complete HTML file
containing the table) showing a side by side, line by line comparison
of text with inter-line and intra-line change highlights. The table can
be generated in either full or contextual difference mode.
The following methods are provided for HTML generation:
make_table -- generates HTML for a single side by side table
make_file -- generates complete HTML file with a single side by side table
See tools/scripts/diff.py for an example usage of this class.
"""
_file_template = _file_template
_styles = _styles
_table_template = _table_template
_legend = _legend
_default_prefix = 0
def __init__(self,tabsize=8,wrapcolumn=None,linejunk=None,
charjunk=IS_CHARACTER_JUNK):
"""HtmlDiff instance initializer
Arguments:
tabsize -- tab stop spacing, defaults to 8.
wrapcolumn -- column number where lines are broken and wrapped,
defaults to None where lines are not wrapped.
linejunk,charjunk -- keyword arguments passed into ndiff() (used to by
HtmlDiff() to generate the side by side HTML differences). See
ndiff() documentation for argument default values and descriptions.
"""
self._tabsize = tabsize
self._wrapcolumn = wrapcolumn
self._linejunk = linejunk
self._charjunk = charjunk
def make_file(self,fromlines,tolines,fromdesc='',todesc='',context=False,
numlines=5):
"""Returns HTML file of side by side comparison with change highlights
Arguments:
fromlines -- list of "from" lines
tolines -- list of "to" lines
fromdesc -- "from" file column header string
todesc -- "to" file column header string
context -- set to True for contextual differences (defaults to False
which shows full differences).
numlines -- number of context lines. When context is set True,
controls number of lines displayed before and after the change.
When context is False, controls the number of lines to place
the "next" link anchors before the next change (so click of
"next" link jumps to just before the change).
"""
return self._file_template % dict(
styles = self._styles,
legend = self._legend,
table = self.make_table(fromlines,tolines,fromdesc,todesc,
context=context,numlines=numlines))
def _tab_newline_replace(self,fromlines,tolines):
"""Returns from/to line lists with tabs expanded and newlines removed.
Instead of tab characters being replaced by the number of spaces
needed to fill in to the next tab stop, this function will fill
the space with tab characters. This is done so that the difference
algorithms can identify changes in a file when tabs are replaced by
spaces and vice versa. At the end of the HTML generation, the tab
characters will be replaced with a nonbreakable space.
"""
def expand_tabs(line):
# hide real spaces
line = line.replace(' ','\0')
# expand tabs into spaces
line = line.expandtabs(self._tabsize)
# replace spaces from expanded tabs back into tab characters
# (we'll replace them with markup after we do differencing)
line = line.replace(' ','\t')
return line.replace('\0',' ').rstrip('\n')
fromlines = [expand_tabs(line) for line in fromlines]
tolines = [expand_tabs(line) for line in tolines]
return fromlines,tolines
def _split_line(self,data_list,line_num,text):
"""Builds list of text lines by splitting text lines at wrap point
This function will determine if the input text line needs to be
wrapped (split) into separate lines. If so, the first wrap point
will be determined and the first line appended to the output
text line list. This function is used recursively to handle
the second part of the split line to further split it.
"""
# if blank line or context separator, just add it to the output list
if not line_num:
data_list.append((line_num,text))
return
# if line text doesn't need wrapping, just add it to the output list
size = len(text)
max = self._wrapcolumn
if (size <= max) or ((size -(text.count('\0')*3)) <= max):
data_list.append((line_num,text))
return
# scan text looking for the wrap point, keeping track if the wrap
# point is inside markers
i = 0
n = 0
mark = ''
while n < max and i < size:
if text[i] == '\0':
i += 1
mark = text[i]
i += 1
elif text[i] == '\1':
i += 1
mark = ''
else:
i += 1
n += 1
# wrap point is inside text, break it up into separate lines
line1 = text[:i]
line2 = text[i:]
# if wrap point is inside markers, place end marker at end of first
# line and start marker at beginning of second line because each
# line will have its own table tag markup around it.
if mark:
line1 = line1 + '\1'
line2 = '\0' + mark + line2
# tack on first line onto the output list
data_list.append((line_num,line1))
# use this routine again to wrap the remaining text
self._split_line(data_list,'>',line2)
def _line_wrapper(self,diffs):
"""Returns iterator that splits (wraps) mdiff text lines"""
# pull from/to data and flags from mdiff iterator
for fromdata,todata,flag in diffs:
# check for context separators and pass them through
if flag is None:
yield fromdata,todata,flag
continue
(fromline,fromtext),(toline,totext) = fromdata,todata
# for each from/to line split it at the wrap column to form
# list of text lines.
fromlist,tolist = [],[]
self._split_line(fromlist,fromline,fromtext)
self._split_line(tolist,toline,totext)
# yield from/to line in pairs inserting blank lines as
# necessary when one side has more wrapped lines
while fromlist or tolist:
if fromlist:
fromdata = fromlist.pop(0)
else:
fromdata = ('',' ')
if tolist:
todata = tolist.pop(0)
else:
todata = ('',' ')
yield fromdata,todata,flag
def _collect_lines(self,diffs):
"""Collects mdiff output into separate lists
Before storing the mdiff from/to data into a list, it is converted
into a single line of text with HTML markup.
"""
fromlist,tolist,flaglist = [],[],[]
# pull from/to data and flags from mdiff style iterator
for fromdata,todata,flag in diffs:
try:
# store HTML markup of the lines into the lists
fromlist.append(self._format_line(0,flag,*fromdata))
tolist.append(self._format_line(1,flag,*todata))
except TypeError:
# exceptions occur for lines where context separators go
fromlist.append(None)
tolist.append(None)
flaglist.append(flag)
return fromlist,tolist,flaglist
def _format_line(self,side,flag,linenum,text):
"""Returns HTML markup of "from" / "to" text lines
side -- 0 or 1 indicating "from" or "to" text
flag -- indicates if difference on line
linenum -- line number (used for line number column)
text -- line text to be marked up
"""
try:
linenum = '%d' % linenum
id = ' id="%s%s"' % (self._prefix[side],linenum)
except TypeError:
# handle blank lines where linenum is '>' or ''
id = ''
# replace those things that would get confused with HTML symbols
text=text.replace("&","&").replace(">",">").replace("<","<")
# make space non-breakable so they don't get compressed or line wrapped
text = text.replace(' ',' ').rstrip()
return '<td class="diff_header"%s>%s</td><td nowrap="nowrap">%s</td>' \
% (id,linenum,text)
def _make_prefix(self):
"""Create unique anchor prefixes"""
# Generate a unique anchor prefix so multiple tables
# can exist on the same HTML page without conflicts.
fromprefix = "from%d_" % HtmlDiff._default_prefix
toprefix = "to%d_" % HtmlDiff._default_prefix
HtmlDiff._default_prefix += 1
# store prefixes so line format method has access
self._prefix = [fromprefix,toprefix]
def _convert_flags(self,fromlist,tolist,flaglist,context,numlines):
"""Makes list of "next" links"""
# all anchor names will be generated using the unique "to" prefix
toprefix = self._prefix[1]
# process change flags, generating middle column of next anchors/links
next_id = ['']*len(flaglist)
next_href = ['']*len(flaglist)
num_chg, in_change = 0, False
last = 0
for i,flag in enumerate(flaglist):
if flag:
if not in_change:
in_change = True
last = i
# at the beginning of a change, drop an anchor a few lines
# (the context lines) before the change for the previous
# link
i = max([0,i-numlines])
next_id[i] = ' id="difflib_chg_%s_%d"' % (toprefix,num_chg)
# at the beginning of a change, drop a link to the next
# change
num_chg += 1
next_href[last] = '<a href="#difflib_chg_%s_%d">n</a>' % (
toprefix,num_chg)
else:
in_change = False
# check for cases where there is no content to avoid exceptions
if not flaglist:
flaglist = [False]
next_id = ['']
next_href = ['']
last = 0
if context:
fromlist = ['<td></td><td> No Differences Found </td>']
tolist = fromlist
else:
fromlist = tolist = ['<td></td><td> Empty File </td>']
# if not a change on first line, drop a link
if not flaglist[0]:
next_href[0] = '<a href="#difflib_chg_%s_0">f</a>' % toprefix
# redo the last link to link to the top
next_href[last] = '<a href="#difflib_chg_%s_top">t</a>' % (toprefix)
return fromlist,tolist,flaglist,next_href,next_id
def make_table(self,fromlines,tolines,fromdesc='',todesc='',context=False,
numlines=5):
"""Returns HTML table of side by side comparison with change highlights
Arguments:
fromlines -- list of "from" lines
tolines -- list of "to" lines
fromdesc -- "from" file column header string
todesc -- "to" file column header string
context -- set to True for contextual differences (defaults to False
which shows full differences).
numlines -- number of context lines. When context is set True,
controls number of lines displayed before and after the change.
When context is False, controls the number of lines to place
the "next" link anchors before the next change (so click of
"next" link jumps to just before the change).
"""
# make unique anchor prefixes so that multiple tables may exist
# on the same page without conflict.
self._make_prefix()
# change tabs to spaces before it gets more difficult after we insert
# markup
fromlines,tolines = self._tab_newline_replace(fromlines,tolines)
# create diffs iterator which generates side by side from/to data
if context:
context_lines = numlines
else:
context_lines = None
diffs = _mdiff(fromlines,tolines,context_lines,linejunk=self._linejunk,
charjunk=self._charjunk)
# set up iterator to wrap lines that exceed desired width
if self._wrapcolumn:
diffs = self._line_wrapper(diffs)
# collect up from/to lines and flags into lists (also format the lines)
fromlist,tolist,flaglist = self._collect_lines(diffs)
# process change flags, generating middle column of next anchors/links
fromlist,tolist,flaglist,next_href,next_id = self._convert_flags(
fromlist,tolist,flaglist,context,numlines)
s = []
fmt = ' <tr><td class="diff_next"%s>%s</td>%s' + \
'<td class="diff_next">%s</td>%s</tr>\n'
for i in range(len(flaglist)):
if flaglist[i] is None:
# mdiff yields None on separator lines skip the bogus ones
# generated for the first line
if i > 0:
s.append(' </tbody> \n <tbody>\n')
else:
s.append( fmt % (next_id[i],next_href[i],fromlist[i],
next_href[i],tolist[i]))
if fromdesc or todesc:
header_row = '<thead><tr>%s%s%s%s</tr></thead>' % (
'<th class="diff_next"><br /></th>',
'<th colspan="2" class="diff_header">%s</th>' % fromdesc,
'<th class="diff_next"><br /></th>',
'<th colspan="2" class="diff_header">%s</th>' % todesc)
else:
header_row = ''
table = self._table_template % dict(
data_rows=''.join(s),
header_row=header_row,
prefix=self._prefix[1])
return table.replace('\0+','<span class="diff_add">'). \
replace('\0-','<span class="diff_sub">'). \
replace('\0^','<span class="diff_chg">'). \
replace('\1','</span>'). \
replace('\t',' ')
del re
def restore(delta, which):
r"""
Generate one of the two sequences that generated a delta.
Given a `delta` produced by `Differ.compare()` or `ndiff()`, extract
lines originating from file 1 or 2 (parameter `which`), stripping off line
prefixes.
Examples:
>>> diff = ndiff('one\ntwo\nthree\n'.splitlines(keepends=True),
... 'ore\ntree\nemu\n'.splitlines(keepends=True))
>>> diff = list(diff)
>>> print(''.join(restore(diff, 1)), end="")
one
two
three
>>> print(''.join(restore(diff, 2)), end="")
ore
tree
emu
"""
try:
tag = {1: "- ", 2: "+ "}[int(which)]
except KeyError:
raise ValueError('unknown delta choice (must be 1 or 2): %r'
% which)
prefixes = (" ", tag)
for line in delta:
if line[:2] in prefixes:
yield line[2:]
def _test():
import doctest, difflib
return doctest.testmod(difflib)
if __name__ == "__main__":
_test()
|
gpl-2.0
|
[
3168,
1182,
2647,
15,
1393,
15,
1813,
2366,
19,
199,
199,
624,
199,
2377,
27070,
1553,
10897,
367,
17226,
27446,
3382,
2251,
14,
199,
199,
3481,
664,
63,
1600,
63,
6742,
8,
1027,
12,
2086,
23422,
12,
302,
29,
19,
12,
17875,
29,
16,
14,
22,
304,
272,
3645,
10975,
16073,
370,
372,
769,
402,
314,
5526,
298,
8302,
8321,
2,
4450,
14,
199,
199,
3481,
1067,
63,
3028,
8,
65,
12,
330,
304,
272,
2104,
2877,
5548,
402,
3326,
12,
372,
282,
5762,
315,
1067,
3915,
1475,
14,
199,
199,
3481,
302,
3028,
8,
65,
12,
330,
304,
272,
1432,
282,
5762,
26,
314,
8865,
3382,
658,
65,
64,
436,
658,
66,
64,
334,
6717,
402,
3326,
680,
199,
199,
3481,
9066,
8,
3136,
12,
1314,
304,
272,
1432,
1373,
402,
314,
2877,
8013,
626,
4046,
376,
302,
3028,
5762,
14,
199,
199,
3481,
25344,
63,
3028,
8,
65,
12,
330,
304,
272,
2104,
2877,
5548,
402,
3326,
12,
372,
282,
5762,
315,
25344,
3915,
1475,
14,
199,
199,
2543,
10975,
16073,
26,
272,
437,
26841,
1021,
367,
20234,
6342,
402,
8013,
402,
1263,
730,
14,
199,
199,
2543,
3757,
1260,
26,
272,
2104,
27955,
11779,
13,
11875,
27446,
687,
8013,
402,
2385,
402,
1318,
14,
199,
199,
2543,
20880,
10746,
26,
272,
2104,
27955,
4163,
5366,
701,
5366,
9132,
543,
1570,
11850,
83,
14,
199,
624,
199,
199,
363,
452,
363,
275,
788,
362,
63,
1600,
63,
6742,
297,
283,
28632,
297,
283,
8011,
297,
283,
5826,
16073,
297,
1779,
283,
1341,
1260,
1673,
1311,
63,
29007,
63,
42,
8019,
297,
283,
1311,
63,
6174,
63,
42,
8019,
297,
283,
1100,
63,
3028,
297,
1779,
283,
32180,
63,
3028,
297,
283,
12957,
10746,
297,
283,
4486,
418,
199,
199,
646,
3598,
199,
646,
13295,
81,
199,
504,
5055,
492,
12863,
465,
485,
18921,
199,
199,
4486,
275,
485,
18921,
360,
4486,
297,
283,
65,
330,
1568,
358,
199,
199,
318,
485,
12063,
63,
6884,
8,
6742,
12,
2582,
304,
272,
340,
2582,
26,
267,
372,
499,
14,
16,
627,
4450,
1182,
2582,
272,
372,
413,
14,
16,
199,
199,
533,
10975,
16073,
26,
339,
408,
272,
10975,
16073,
365,
282,
26841,
1021,
367,
20234,
6342,
402,
8013,
402,
272,
1263,
730,
12,
880,
1846,
465,
314,
3414,
4008,
787,
21197,
14,
221,
710,
5678,
272,
5563,
8869,
2335,
12,
436,
365,
282,
12050,
13758,
559,
281,
2419,
12,
376,
5563,
272,
3267,
315,
314,
2465,
5851,
1257,
1159,
701,
820,
292,
2764,
556,
436,
593,
605,
609,
1357,
1334,
314,
272,
10342,
9670,
536,
298,
3199,
4478,
3851,
4877,
1674,
221,
710,
5678,
16819,
365,
370,
2342,
272,
314,
21303,
26611,
4877,
1007,
4041,
626,
3509,
949,
298,
17941,
2,
272,
4008,
334,
50,
13,
47,
3181,
1133,
2287,
24605,
680,
221,
710,
2011,
16819,
365,
2066,
6781,
272,
15035,
370,
314,
10338,
402,
314,
8013,
370,
314,
3602,
436,
370,
314,
2451,
272,
402,
314,
4877,
1007,
4041,
14,
221,
961,
1630,
440,
1995,
13460,
5283,
272,
8013,
12,
1325,
1630,
221,
7169,
370,
1995,
4450,
626,
298,
11660,
2451,
2,
370,
13135,
14,
339,
10975,
16073,
11275,
370,
4526,
282,
298,
14864,
13,
17317,
3915,
2,
3382,
2877,
272,
8013,
14,
221,
25059,
325,
14,
71,
14,
22242,
8,
7574,
9,
3915,
12,
314,
27440,
14040,
279,
949,
296,
365,
314,
272,
21303,
627,
16583,
10,
1253,
24605,
13,
4624,
4877,
1007,
4041,
14,
221,
10314,
1159,
4052,
272,
8579,
397,
4837,
411,
2978,
7,
325,
5066,
14,
221,
710,
5417,
8,
7574,
9,
4747,
3028,
965,
4573,
19604,
272,
949,
296,
12,
4092,
316,
1536,
4008,
626,
7468,
28727,
315,
1924,
3414,
14,
272,
10314,
12,
436,
314,
1083,
2348,
12,
7468,
370,
1995,
1655,
1109,
1907,
857,
8865,
272,
13924,
2419,
1630,
3915,
14,
221,
961,
1083,
11337,
370,
506,
314,
5210,
373,
21406,
461,
272,
370,
308,
5654,
316,
1536,
641,
5664,
402,
298,
17941,
2385,
401,
10617,
334,
2930,
4596,
2385,
315,
272,
24801,
1318,
1584,
12,
503,
11703,
3886,
48,
4335,
2385,
315,
4163,
1584,
680,
221,
10314,
1443,
506,
272,
2952,
642,
365,
314,
1454,
1083,
402,
314,
650,
626,
965,
282,
627,
21318,
10,
402,
272,
298,
17941,
2,
665,
87,
2292,
10827,
339,
5679,
12,
20234,
2877,
3326,
12,
436,
11201,
316,
4596,
83,
370,
506,
298,
17941,
582,
339,
1306,
308,
275,
10975,
16073,
8,
2734,
671,
26,
671,
508,
298,
3872,
272,
2263,
9326,
298,
4239,
11086,
1453,
4436,
17259,
272,
2263,
9326,
298,
4239,
5236,
23590,
11086,
1453,
4436,
15027,
272,
1306,
339,
1275,
6884,
342,
2529,
282,
2069,
315,
359,
16,
12,
413,
467,
17616,
4039,
314,
298,
21965,
2,
402,
314,
272,
8013,
14,
221,
3709,
282,
2332,
402,
21541,
12,
282,
1275,
6884,
342,
574,
1806,
378,
14,
22,
4910,
314,
272,
8013,
787,
4002,
4450,
26,
339,
1306,
870,
8,
2363,
8,
83,
14,
6884,
1062,
650,
430,
272,
378,
14,
13465,
272,
1306,
339,
982,
1265,
3984,
1454,
22201,
315,
2382,
314,
8013,
1336,
12,
272,
1275,
362,
63,
9467,
63,
4166,
342,
365,
4926,
89,
26,
339,
1306,
367,
1853,
315,
308,
14,
362,
63,
9467,
63,
4166,
837,
272,
2263,
258,
870,
480,
65,
9722,
68,
61,
436,
330,
9722,
68,
61,
1336,
367,
450,
68,
4008,
2,
450,
1853,
9,
272,
282,
59,
16,
61,
436,
330,
59,
16,
61,
1336,
367,
1695,
4008,
272,
282,
59,
24,
61,
436,
330,
59,
1196,
61,
1336,
367,
7829,
4008,
272,
282,
59,
1398,
61,
436,
330,
59,
1703,
61,
1336,
367,
378,
4008,
339,
3390,
626,
314,
2061,
2008,
2138,
701,
1275,
362,
63,
9467,
63,
4166,
342,
365,
3544,
282,
272,
7283,
12,
334,
552,
8,
65,
395,
822,
8,
66,
395,
378,
395,
436,
642,
365,
314,
1454,
1930,
315,
1314,
314,
2061,
272,
2008,
1819,
334,
1955,
402,
4008,
7838,
9,
365,
378,
14,
339,
982,
1265,
2934,
370,
5715,
4212,
370,
1570,
314,
1642,
3414,
1901,
314,
3499,
12,
272,
675,
1275,
362,
63,
22022,
837,
339,
1306,
367,
10508,
315,
308,
14,
362,
63,
22022,
837,
272,
2263,
258,
870,
3647,
22,
83,
282,
9722,
68,
2689
] |
[
1182,
2647,
15,
1393,
15,
1813,
2366,
19,
199,
199,
624,
199,
2377,
27070,
1553,
10897,
367,
17226,
27446,
3382,
2251,
14,
199,
199,
3481,
664,
63,
1600,
63,
6742,
8,
1027,
12,
2086,
23422,
12,
302,
29,
19,
12,
17875,
29,
16,
14,
22,
304,
272,
3645,
10975,
16073,
370,
372,
769,
402,
314,
5526,
298,
8302,
8321,
2,
4450,
14,
199,
199,
3481,
1067,
63,
3028,
8,
65,
12,
330,
304,
272,
2104,
2877,
5548,
402,
3326,
12,
372,
282,
5762,
315,
1067,
3915,
1475,
14,
199,
199,
3481,
302,
3028,
8,
65,
12,
330,
304,
272,
1432,
282,
5762,
26,
314,
8865,
3382,
658,
65,
64,
436,
658,
66,
64,
334,
6717,
402,
3326,
680,
199,
199,
3481,
9066,
8,
3136,
12,
1314,
304,
272,
1432,
1373,
402,
314,
2877,
8013,
626,
4046,
376,
302,
3028,
5762,
14,
199,
199,
3481,
25344,
63,
3028,
8,
65,
12,
330,
304,
272,
2104,
2877,
5548,
402,
3326,
12,
372,
282,
5762,
315,
25344,
3915,
1475,
14,
199,
199,
2543,
10975,
16073,
26,
272,
437,
26841,
1021,
367,
20234,
6342,
402,
8013,
402,
1263,
730,
14,
199,
199,
2543,
3757,
1260,
26,
272,
2104,
27955,
11779,
13,
11875,
27446,
687,
8013,
402,
2385,
402,
1318,
14,
199,
199,
2543,
20880,
10746,
26,
272,
2104,
27955,
4163,
5366,
701,
5366,
9132,
543,
1570,
11850,
83,
14,
199,
624,
199,
199,
363,
452,
363,
275,
788,
362,
63,
1600,
63,
6742,
297,
283,
28632,
297,
283,
8011,
297,
283,
5826,
16073,
297,
1779,
283,
1341,
1260,
1673,
1311,
63,
29007,
63,
42,
8019,
297,
283,
1311,
63,
6174,
63,
42,
8019,
297,
283,
1100,
63,
3028,
297,
1779,
283,
32180,
63,
3028,
297,
283,
12957,
10746,
297,
283,
4486,
418,
199,
199,
646,
3598,
199,
646,
13295,
81,
199,
504,
5055,
492,
12863,
465,
485,
18921,
199,
199,
4486,
275,
485,
18921,
360,
4486,
297,
283,
65,
330,
1568,
358,
199,
199,
318,
485,
12063,
63,
6884,
8,
6742,
12,
2582,
304,
272,
340,
2582,
26,
267,
372,
499,
14,
16,
627,
4450,
1182,
2582,
272,
372,
413,
14,
16,
199,
199,
533,
10975,
16073,
26,
339,
408,
272,
10975,
16073,
365,
282,
26841,
1021,
367,
20234,
6342,
402,
8013,
402,
272,
1263,
730,
12,
880,
1846,
465,
314,
3414,
4008,
787,
21197,
14,
221,
710,
5678,
272,
5563,
8869,
2335,
12,
436,
365,
282,
12050,
13758,
559,
281,
2419,
12,
376,
5563,
272,
3267,
315,
314,
2465,
5851,
1257,
1159,
701,
820,
292,
2764,
556,
436,
593,
605,
609,
1357,
1334,
314,
272,
10342,
9670,
536,
298,
3199,
4478,
3851,
4877,
1674,
221,
710,
5678,
16819,
365,
370,
2342,
272,
314,
21303,
26611,
4877,
1007,
4041,
626,
3509,
949,
298,
17941,
2,
272,
4008,
334,
50,
13,
47,
3181,
1133,
2287,
24605,
680,
221,
710,
2011,
16819,
365,
2066,
6781,
272,
15035,
370,
314,
10338,
402,
314,
8013,
370,
314,
3602,
436,
370,
314,
2451,
272,
402,
314,
4877,
1007,
4041,
14,
221,
961,
1630,
440,
1995,
13460,
5283,
272,
8013,
12,
1325,
1630,
221,
7169,
370,
1995,
4450,
626,
298,
11660,
2451,
2,
370,
13135,
14,
339,
10975,
16073,
11275,
370,
4526,
282,
298,
14864,
13,
17317,
3915,
2,
3382,
2877,
272,
8013,
14,
221,
25059,
325,
14,
71,
14,
22242,
8,
7574,
9,
3915,
12,
314,
27440,
14040,
279,
949,
296,
365,
314,
272,
21303,
627,
16583,
10,
1253,
24605,
13,
4624,
4877,
1007,
4041,
14,
221,
10314,
1159,
4052,
272,
8579,
397,
4837,
411,
2978,
7,
325,
5066,
14,
221,
710,
5417,
8,
7574,
9,
4747,
3028,
965,
4573,
19604,
272,
949,
296,
12,
4092,
316,
1536,
4008,
626,
7468,
28727,
315,
1924,
3414,
14,
272,
10314,
12,
436,
314,
1083,
2348,
12,
7468,
370,
1995,
1655,
1109,
1907,
857,
8865,
272,
13924,
2419,
1630,
3915,
14,
221,
961,
1083,
11337,
370,
506,
314,
5210,
373,
21406,
461,
272,
370,
308,
5654,
316,
1536,
641,
5664,
402,
298,
17941,
2385,
401,
10617,
334,
2930,
4596,
2385,
315,
272,
24801,
1318,
1584,
12,
503,
11703,
3886,
48,
4335,
2385,
315,
4163,
1584,
680,
221,
10314,
1443,
506,
272,
2952,
642,
365,
314,
1454,
1083,
402,
314,
650,
626,
965,
282,
627,
21318,
10,
402,
272,
298,
17941,
2,
665,
87,
2292,
10827,
339,
5679,
12,
20234,
2877,
3326,
12,
436,
11201,
316,
4596,
83,
370,
506,
298,
17941,
582,
339,
1306,
308,
275,
10975,
16073,
8,
2734,
671,
26,
671,
508,
298,
3872,
272,
2263,
9326,
298,
4239,
11086,
1453,
4436,
17259,
272,
2263,
9326,
298,
4239,
5236,
23590,
11086,
1453,
4436,
15027,
272,
1306,
339,
1275,
6884,
342,
2529,
282,
2069,
315,
359,
16,
12,
413,
467,
17616,
4039,
314,
298,
21965,
2,
402,
314,
272,
8013,
14,
221,
3709,
282,
2332,
402,
21541,
12,
282,
1275,
6884,
342,
574,
1806,
378,
14,
22,
4910,
314,
272,
8013,
787,
4002,
4450,
26,
339,
1306,
870,
8,
2363,
8,
83,
14,
6884,
1062,
650,
430,
272,
378,
14,
13465,
272,
1306,
339,
982,
1265,
3984,
1454,
22201,
315,
2382,
314,
8013,
1336,
12,
272,
1275,
362,
63,
9467,
63,
4166,
342,
365,
4926,
89,
26,
339,
1306,
367,
1853,
315,
308,
14,
362,
63,
9467,
63,
4166,
837,
272,
2263,
258,
870,
480,
65,
9722,
68,
61,
436,
330,
9722,
68,
61,
1336,
367,
450,
68,
4008,
2,
450,
1853,
9,
272,
282,
59,
16,
61,
436,
330,
59,
16,
61,
1336,
367,
1695,
4008,
272,
282,
59,
24,
61,
436,
330,
59,
1196,
61,
1336,
367,
7829,
4008,
272,
282,
59,
1398,
61,
436,
330,
59,
1703,
61,
1336,
367,
378,
4008,
339,
3390,
626,
314,
2061,
2008,
2138,
701,
1275,
362,
63,
9467,
63,
4166,
342,
365,
3544,
282,
272,
7283,
12,
334,
552,
8,
65,
395,
822,
8,
66,
395,
378,
395,
436,
642,
365,
314,
1454,
1930,
315,
1314,
314,
2061,
272,
2008,
1819,
334,
1955,
402,
4008,
7838,
9,
365,
378,
14,
339,
982,
1265,
2934,
370,
5715,
4212,
370,
1570,
314,
1642,
3414,
1901,
314,
3499,
12,
272,
675,
1275,
362,
63,
22022,
837,
339,
1306,
367,
10508,
315,
308,
14,
362,
63,
22022,
837,
272,
2263,
258,
870,
3647,
22,
83,
282,
9722,
68,
2689,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
40223211/cadb_g7_w18test
|
static/Brython3.1.1-20150328-091302/Lib/_struct.py
|
726
|
13787
|
#
# This module is a pure Python version of pypy.module.struct.
# It is only imported if the vastly faster pypy.module.struct is not
# compiled in. For now we keep this version for reference and
# because pypy.module.struct is not ootype-backend-friendly yet.
#
# this module 'borrowed' from
# https://bitbucket.org/pypy/pypy/src/18626459a9b2/lib_pypy/_struct.py?at=py3k-listview_str
"""Functions to convert between Python values and C structs.
Python strings are used to hold the data representing the C struct
and also as format strings to describe the layout of data in the C struct.
The optional first format char indicates byte order, size and alignment:
@: native order, size & alignment (default)
=: native order, std. size & alignment
<: little-endian, std. size & alignment
>: big-endian, std. size & alignment
!: same as >
The remaining chars indicate types of args and must match exactly;
these can be preceded by a decimal repeat count:
x: pad byte (no data);
c:char;
b:signed byte;
B:unsigned byte;
h:short;
H:unsigned short;
i:int;
I:unsigned int;
l:long;
L:unsigned long;
f:float;
d:double.
Special cases (preceding decimal count indicates length):
s:string (array of char); p: pascal string (with count byte).
Special case (only available in native format):
P:an integer type that is wide enough to hold a pointer.
Special case (not in native mode unless 'long long' in platform C):
q:long long;
Q:unsigned long long
Whitespace between formats is ignored.
The variable struct.error is an exception raised on errors."""
import math, sys
# TODO: XXX Find a way to get information on native sizes and alignments
class StructError(Exception):
pass
error = StructError
def unpack_int(data,index,size,le):
bytes = [b for b in data[index:index+size]]
if le == 'little':
bytes.reverse()
number = 0
for b in bytes:
number = number << 8 | b
return int(number)
def unpack_signed_int(data,index,size,le):
number = unpack_int(data,index,size,le)
max = 2**(size*8)
if number > 2**(size*8 - 1) - 1:
number = int(-1*(max - number))
return number
INFINITY = 1e200 * 1e200
NAN = INFINITY / INFINITY
def unpack_char(data,index,size,le):
return data[index:index+size]
def pack_int(number,size,le):
x=number
res=[]
for i in range(size):
res.append(x&0xff)
x >>= 8
if le == 'big':
res.reverse()
return bytes(res)
def pack_signed_int(number,size,le):
if not isinstance(number, int):
raise StructError("argument for i,I,l,L,q,Q,h,H must be integer")
if number > 2**(8*size-1)-1 or number < -1*2**(8*size-1):
raise OverflowError("Number:%i too large to convert" % number)
return pack_int(number,size,le)
def pack_unsigned_int(number,size,le):
if not isinstance(number, int):
raise StructError("argument for i,I,l,L,q,Q,h,H must be integer")
if number < 0:
raise TypeError("can't convert negative long to unsigned")
if number > 2**(8*size)-1:
raise OverflowError("Number:%i too large to convert" % number)
return pack_int(number,size,le)
def pack_char(char,size,le):
return bytes(char)
def isinf(x):
return x != 0.0 and x / 2 == x
def isnan(v):
return v != v*1.0 or (v == 1.0 and v == 2.0)
def pack_float(x, size, le):
unsigned = float_pack(x, size)
result = []
for i in range(8):
result.append((unsigned >> (i * 8)) & 0xFF)
if le == "big":
result.reverse()
return bytes(result)
def unpack_float(data, index, size, le):
binary = [data[i] for i in range(index, index + 8)]
if le == "big":
binary.reverse()
unsigned = 0
for i in range(8):
unsigned |= binary[i] << (i * 8)
return float_unpack(unsigned, size, le)
def round_to_nearest(x):
"""Python 3 style round: round a float x to the nearest int, but
unlike the builtin Python 2.x round function:
- return an int, not a float
- do round-half-to-even, not round-half-away-from-zero.
We assume that x is finite and nonnegative; except wrong results
if you use this for negative x.
"""
int_part = int(x)
frac_part = x - int_part
if frac_part > 0.5 or frac_part == 0.5 and int_part & 1 == 1:
int_part += 1
return int_part
def float_unpack(Q, size, le):
"""Convert a 32-bit or 64-bit integer created
by float_pack into a Python float."""
if size == 8:
MIN_EXP = -1021 # = sys.float_info.min_exp
MAX_EXP = 1024 # = sys.float_info.max_exp
MANT_DIG = 53 # = sys.float_info.mant_dig
BITS = 64
elif size == 4:
MIN_EXP = -125 # C's FLT_MIN_EXP
MAX_EXP = 128 # FLT_MAX_EXP
MANT_DIG = 24 # FLT_MANT_DIG
BITS = 32
else:
raise ValueError("invalid size value")
if Q >> BITS:
raise ValueError("input out of range")
# extract pieces
sign = Q >> BITS - 1
exp = (Q & ((1 << BITS - 1) - (1 << MANT_DIG - 1))) >> MANT_DIG - 1
mant = Q & ((1 << MANT_DIG - 1) - 1)
if exp == MAX_EXP - MIN_EXP + 2:
# nan or infinity
result = float('nan') if mant else float('inf')
elif exp == 0:
# subnormal or zero
result = math.ldexp(float(mant), MIN_EXP - MANT_DIG)
else:
# normal
mant += 1 << MANT_DIG - 1
result = math.ldexp(float(mant), exp + MIN_EXP - MANT_DIG - 1)
return -result if sign else result
def float_pack(x, size):
"""Convert a Python float x into a 64-bit unsigned integer
with the same byte representation."""
if size == 8:
MIN_EXP = -1021 # = sys.float_info.min_exp
MAX_EXP = 1024 # = sys.float_info.max_exp
MANT_DIG = 53 # = sys.float_info.mant_dig
BITS = 64
elif size == 4:
MIN_EXP = -125 # C's FLT_MIN_EXP
MAX_EXP = 128 # FLT_MAX_EXP
MANT_DIG = 24 # FLT_MANT_DIG
BITS = 32
else:
raise ValueError("invalid size value")
sign = math.copysign(1.0, x) < 0.0
if math.isinf(x):
mant = 0
exp = MAX_EXP - MIN_EXP + 2
elif math.isnan(x):
mant = 1 << (MANT_DIG-2) # other values possible
exp = MAX_EXP - MIN_EXP + 2
elif x == 0.0:
mant = 0
exp = 0
else:
m, e = math.frexp(abs(x)) # abs(x) == m * 2**e
exp = e - (MIN_EXP - 1)
if exp > 0:
# Normal case.
mant = round_to_nearest(m * (1 << MANT_DIG))
mant -= 1 << MANT_DIG - 1
else:
# Subnormal case.
if exp + MANT_DIG - 1 >= 0:
mant = round_to_nearest(m * (1 << exp + MANT_DIG - 1))
else:
mant = 0
exp = 0
# Special case: rounding produced a MANT_DIG-bit mantissa.
assert 0 <= mant <= 1 << MANT_DIG - 1
if mant == 1 << MANT_DIG - 1:
mant = 0
exp += 1
# Raise on overflow (in some circumstances, may want to return
# infinity instead).
if exp >= MAX_EXP - MIN_EXP + 2:
raise OverflowError("float too large to pack in this format")
# check constraints
assert 0 <= mant < 1 << MANT_DIG - 1
assert 0 <= exp <= MAX_EXP - MIN_EXP + 2
assert 0 <= sign <= 1
return ((sign << BITS - 1) | (exp << MANT_DIG - 1)) | mant
big_endian_format = {
'x':{ 'size' : 1, 'alignment' : 0, 'pack' : None, 'unpack' : None},
'b':{ 'size' : 1, 'alignment' : 0, 'pack' : pack_signed_int, 'unpack' : unpack_signed_int},
'B':{ 'size' : 1, 'alignment' : 0, 'pack' : pack_unsigned_int, 'unpack' : unpack_int},
'c':{ 'size' : 1, 'alignment' : 0, 'pack' : pack_char, 'unpack' : unpack_char},
's':{ 'size' : 1, 'alignment' : 0, 'pack' : None, 'unpack' : None},
'p':{ 'size' : 1, 'alignment' : 0, 'pack' : None, 'unpack' : None},
'h':{ 'size' : 2, 'alignment' : 0, 'pack' : pack_signed_int, 'unpack' : unpack_signed_int},
'H':{ 'size' : 2, 'alignment' : 0, 'pack' : pack_unsigned_int, 'unpack' : unpack_int},
'i':{ 'size' : 4, 'alignment' : 0, 'pack' : pack_signed_int, 'unpack' : unpack_signed_int},
'I':{ 'size' : 4, 'alignment' : 0, 'pack' : pack_unsigned_int, 'unpack' : unpack_int},
'l':{ 'size' : 4, 'alignment' : 0, 'pack' : pack_signed_int, 'unpack' : unpack_signed_int},
'L':{ 'size' : 4, 'alignment' : 0, 'pack' : pack_unsigned_int, 'unpack' : unpack_int},
'q':{ 'size' : 8, 'alignment' : 0, 'pack' : pack_signed_int, 'unpack' : unpack_signed_int},
'Q':{ 'size' : 8, 'alignment' : 0, 'pack' : pack_unsigned_int, 'unpack' : unpack_int},
'f':{ 'size' : 4, 'alignment' : 0, 'pack' : pack_float, 'unpack' : unpack_float},
'd':{ 'size' : 8, 'alignment' : 0, 'pack' : pack_float, 'unpack' : unpack_float},
}
default = big_endian_format
formatmode={ '<' : (default, 'little'),
'>' : (default, 'big'),
'!' : (default, 'big'),
'=' : (default, sys.byteorder),
'@' : (default, sys.byteorder)
}
def getmode(fmt):
try:
formatdef,endianness = formatmode[fmt[0]]
index = 1
except (IndexError, KeyError):
formatdef,endianness = formatmode['@']
index = 0
return formatdef,endianness,index
def getNum(fmt,i):
num=None
cur = fmt[i]
while ('0'<= cur ) and ( cur <= '9'):
if num == None:
num = int(cur)
else:
num = 10*num + int(cur)
i += 1
cur = fmt[i]
return num,i
def calcsize(fmt):
"""calcsize(fmt) -> int
Return size of C struct described by format string fmt.
See struct.__doc__ for more on format strings."""
formatdef,endianness,i = getmode(fmt)
num = 0
result = 0
while i<len(fmt):
num,i = getNum(fmt,i)
cur = fmt[i]
try:
format = formatdef[cur]
except KeyError:
raise StructError("%s is not a valid format" % cur)
if num != None :
result += num*format['size']
else:
result += format['size']
num = 0
i += 1
return result
def pack(fmt,*args):
"""pack(fmt, v1, v2, ...) -> string
Return string containing values v1, v2, ... packed according to fmt.
See struct.__doc__ for more on format strings."""
formatdef,endianness,i = getmode(fmt)
args = list(args)
n_args = len(args)
result = []
while i<len(fmt):
num,i = getNum(fmt,i)
cur = fmt[i]
try:
format = formatdef[cur]
except KeyError:
raise StructError("%s is not a valid format" % cur)
if num == None :
num_s = 0
num = 1
else:
num_s = num
if cur == 'x':
result += [b'\0'*num]
elif cur == 's':
if isinstance(args[0], bytes):
padding = num - len(args[0])
result += [args[0][:num] + b'\0'*padding]
args.pop(0)
else:
raise StructError("arg for string format not a string")
elif cur == 'p':
if isinstance(args[0], bytes):
padding = num - len(args[0]) - 1
if padding > 0:
result += [bytes([len(args[0])]) + args[0][:num-1] + b'\0'*padding]
else:
if num<255:
result += [bytes([num-1]) + args[0][:num-1]]
else:
result += [bytes([255]) + args[0][:num-1]]
args.pop(0)
else:
raise StructError("arg for string format not a string")
else:
if len(args) < num:
raise StructError("insufficient arguments to pack")
for var in args[:num]:
result += [format['pack'](var,format['size'],endianness)]
args=args[num:]
num = None
i += 1
if len(args) != 0:
raise StructError("too many arguments for pack format")
return b''.join(result)
def unpack(fmt,data):
"""unpack(fmt, string) -> (v1, v2, ...)
Unpack the string, containing packed C structure data, according
to fmt. Requires len(string)==calcsize(fmt).
See struct.__doc__ for more on format strings."""
formatdef,endianness,i = getmode(fmt)
j = 0
num = 0
result = []
length= calcsize(fmt)
if length != len (data):
raise StructError("unpack str size does not match format")
while i<len(fmt):
num,i=getNum(fmt,i)
cur = fmt[i]
i += 1
try:
format = formatdef[cur]
except KeyError:
raise StructError("%s is not a valid format" % cur)
if not num :
num = 1
if cur == 'x':
j += num
elif cur == 's':
result.append(data[j:j+num])
j += num
elif cur == 'p':
n=data[j]
if n >= num:
n = num-1
result.append(data[j+1:j+n+1])
j += num
else:
for n in range(num):
result += [format['unpack'](data,j,format['size'],endianness)]
j += format['size']
return tuple(result)
def pack_into(fmt, buf, offset, *args):
data = pack(fmt, *args)
buffer(buf)[offset:offset+len(data)] = data
def unpack_from(fmt, buf, offset=0):
size = calcsize(fmt)
data = buffer(buf)[offset:offset+size]
if len(data) != size:
raise error("unpack_from requires a buffer of at least %d bytes"
% (size,))
return unpack(fmt, data)
def _clearcache():
"Clear the internal cache."
# No cache in this implementation
|
gpl-3.0
|
[
3,
199,
3,
961,
859,
365,
282,
15111,
2018,
1015,
402,
1134,
647,
14,
578,
14,
1820,
14,
199,
3,
2779,
365,
1454,
8439,
340,
314,
373,
1810,
590,
12930,
1134,
647,
14,
578,
14,
1820,
365,
440,
199,
3,
10311,
315,
14,
221,
2104,
3063,
781,
4215,
642,
1015,
367,
3659,
436,
199,
3,
2952,
1134,
647,
14,
578,
14,
1820,
365,
440,
312,
7818,
13,
4620,
13,
17317,
5966,
14,
199,
3,
199,
199,
3,
642,
859,
283,
66,
19598,
379,
7,
687,
221,
199,
3,
4178,
921,
25668,
14,
1308,
15,
20233,
15,
20233,
15,
2164,
15,
1085,
2789,
772,
1427,
65,
25,
66,
18,
15,
773,
63,
20233,
15607,
1820,
14,
647,
31,
292,
29,
647,
19,
75,
13,
513,
1345,
63,
495,
199,
199,
624,
13967,
370,
3957,
3382,
2018,
1338,
436,
445,
2702,
83,
14,
199,
4718,
3326,
787,
1202,
370,
10266,
314,
666,
6144,
314,
445,
2702,
199,
460,
2597,
465,
1475,
3326,
370,
13743,
314,
7054,
402,
666,
315,
314,
445,
2702,
14,
199,
199,
1918,
2716,
1642,
1475,
1495,
9126,
3696,
1865,
12,
1568,
436,
13177,
26,
199,
768,
26,
5438,
1865,
12,
1568,
1253,
13177,
334,
885,
9,
199,
275,
26,
5438,
1865,
12,
2418,
14,
1568,
1253,
13177,
199,
665,
26,
12050,
13,
15009,
12,
2418,
14,
1568,
1253,
13177,
199,
690,
26,
7282,
13,
15009,
12,
2418,
14,
1568,
1253,
13177,
199,
8546,
26,
2011,
465,
690,
199,
199,
1918,
7971,
8365,
6623,
2943,
402,
1249,
436,
1471,
1336,
8840,
27,
199,
29032,
883,
506,
9222,
770,
701,
282,
6107,
11982,
2338,
26,
2043,
671,
26,
6567,
3696,
334,
889,
666,
2736,
2043,
286,
26,
1560,
27,
2043,
330,
26,
1737,
3696,
27,
2043,
699,
26,
2244,
3696,
27,
2043,
394,
26,
3612,
27,
2043,
869,
26,
2244,
3974,
27,
2043,
284,
26,
442,
27,
2043,
473,
26,
2244,
1109,
27,
2043,
634,
26,
2809,
27,
2043,
491,
26,
2244,
1846,
27,
2043,
289,
26,
1609,
27,
2043,
366,
26,
3157,
14,
199,
12246,
5560,
334,
657,
301,
1098,
6107,
2338,
9126,
2582,
304,
2043,
308,
26,
875,
334,
1144,
402,
1495,
2736,
299,
26,
19099,
915,
1059,
334,
1045,
2338,
3696,
680,
199,
12246,
1930,
334,
2118,
2808,
315,
5438,
1475,
304,
2043,
510,
26,
290,
3000,
730,
626,
365,
20239,
8321,
370,
10266,
282,
7849,
14,
199,
12246,
1930,
334,
1397,
315,
5438,
818,
7444,
283,
2809,
1846,
7,
315,
4298,
445,
304,
2043,
1894,
26,
2809,
1846,
27,
2043,
1413,
26,
2244,
1846,
1846,
199,
16552,
3382,
6752,
365,
5525,
14,
199,
199,
1918,
1750,
2702,
14,
705,
365,
376,
1919,
4915,
641,
2552,
1041,
199,
199,
646,
3473,
12,
984,
199,
199,
3,
3254,
26,
5787,
6668,
282,
4340,
370,
664,
2556,
641,
5438,
10627,
436,
6998,
1470,
199,
533,
13039,
547,
8,
1726,
304,
272,
986,
199,
705,
275,
13039,
547,
199,
318,
7787,
63,
442,
8,
576,
12,
1080,
12,
890,
12,
274,
304,
272,
2783,
275,
359,
66,
367,
330,
315,
666,
59,
1080,
26,
1080,
11,
890,
2677,
272,
340,
1026,
508,
283,
10182,
356,
267,
2783,
14,
4471,
342,
272,
1329,
275,
378,
272,
367,
330,
315,
2783,
26,
267,
1329,
275,
1329,
5213,
1695,
1204,
330,
272,
372,
1109,
8,
1955,
9,
199,
199,
318,
7787,
63,
1737,
63,
442,
8,
576,
12,
1080,
12,
890,
12,
274,
304,
272,
1329,
275,
7787,
63,
442,
8,
576,
12,
1080,
12,
890,
12,
274,
9,
272,
1390,
275,
499,
14192,
890,
10,
24,
9,
272,
340,
1329,
690,
499,
14192,
890,
10,
24,
446,
413,
9,
446,
413,
26,
267,
1329,
275,
1109,
2801,
17,
5830,
988,
446,
1329,
430,
272,
372,
1329,
199,
199,
32191,
1922,
275,
413,
69,
1840,
627,
413,
69,
1840,
199,
24040,
275,
1621,
17383,
1922,
1182,
1621,
17383,
1922,
199,
199,
318,
7787,
63,
1560,
8,
576,
12,
1080,
12,
890,
12,
274,
304,
272,
372,
666,
59,
1080,
26,
1080,
11,
890,
61,
199,
199,
318,
1706,
63,
442,
8,
1955,
12,
890,
12,
274,
304,
272,
671,
29,
1955,
272,
522,
9811,
272,
367,
284,
315,
1425,
8,
890,
304,
267,
522,
14,
740,
8,
88,
6,
16,
3581,
9,
267,
671,
4331,
29,
1695,
272,
340,
1026,
508,
283,
5076,
356,
267,
522,
14,
4471,
342,
272,
372,
2783,
8,
470,
9,
199,
199,
318,
1706,
63,
1737,
63,
442,
8,
1955,
12,
890,
12,
274,
304,
272,
340,
440,
1228,
8,
1955,
12,
1109,
304,
267,
746,
13039,
547,
480,
2094,
367,
284,
12,
41,
12,
76,
12,
44,
12,
81,
12,
49,
12,
72,
12,
40,
1471,
506,
3000,
531,
272,
340,
221,
1329,
690,
499,
14192,
24,
10,
890,
13,
17,
7216,
17,
503,
1329,
665,
446,
17,
10,
18,
14192,
24,
10,
890,
13,
17,
304,
267,
746,
23870,
480,
3259,
2689,
73,
4634,
7031,
370,
3957,
2,
450,
1329,
9,
272,
372,
1706,
63,
442,
8,
1955,
12,
890,
12,
274,
9,
199,
199,
318,
1706,
63,
2244,
63,
442,
8,
1955,
12,
890,
12,
274,
304,
272,
340,
440,
1228,
8,
1955,
12,
1109,
304,
267,
746,
13039,
547,
480,
2094,
367,
284,
12,
41,
12,
76,
12,
44,
12,
81,
12,
49,
12,
72,
12,
40,
1471,
506,
3000,
531,
272,
340,
1329,
665,
378,
26,
267,
746,
3146,
480,
2425,
1133,
3957,
6946,
1846,
370,
7381,
531,
272,
340,
1329,
690,
499,
14192,
24,
10,
890,
7216,
17,
26,
267,
746,
23870,
480,
3259,
2689,
73,
4634,
7031,
370,
3957,
2,
450,
1329,
9,
272,
372,
1706,
63,
442,
8,
1955,
12,
890,
12,
274,
9,
199,
199,
318,
1706,
63,
1560,
8,
1560,
12,
890,
12,
274,
304,
272,
372,
2783,
8,
1560,
9,
199,
199,
318,
365,
4904,
8,
88,
304,
272,
372,
671,
1137,
378,
14,
16,
436,
671,
1182,
499,
508,
671,
199,
318,
365,
4304,
8,
86,
304,
272,
372,
373,
1137,
373,
10,
17,
14,
16,
503,
334,
86,
508,
413,
14,
16,
436,
373,
508,
499,
14,
16,
9,
199,
199,
318,
1706,
63,
1609,
8,
88,
12,
1568,
12,
1026,
304,
272,
7381,
275,
2069,
63,
1389,
8
] |
[
199,
3,
961,
859,
365,
282,
15111,
2018,
1015,
402,
1134,
647,
14,
578,
14,
1820,
14,
199,
3,
2779,
365,
1454,
8439,
340,
314,
373,
1810,
590,
12930,
1134,
647,
14,
578,
14,
1820,
365,
440,
199,
3,
10311,
315,
14,
221,
2104,
3063,
781,
4215,
642,
1015,
367,
3659,
436,
199,
3,
2952,
1134,
647,
14,
578,
14,
1820,
365,
440,
312,
7818,
13,
4620,
13,
17317,
5966,
14,
199,
3,
199,
199,
3,
642,
859,
283,
66,
19598,
379,
7,
687,
221,
199,
3,
4178,
921,
25668,
14,
1308,
15,
20233,
15,
20233,
15,
2164,
15,
1085,
2789,
772,
1427,
65,
25,
66,
18,
15,
773,
63,
20233,
15607,
1820,
14,
647,
31,
292,
29,
647,
19,
75,
13,
513,
1345,
63,
495,
199,
199,
624,
13967,
370,
3957,
3382,
2018,
1338,
436,
445,
2702,
83,
14,
199,
4718,
3326,
787,
1202,
370,
10266,
314,
666,
6144,
314,
445,
2702,
199,
460,
2597,
465,
1475,
3326,
370,
13743,
314,
7054,
402,
666,
315,
314,
445,
2702,
14,
199,
199,
1918,
2716,
1642,
1475,
1495,
9126,
3696,
1865,
12,
1568,
436,
13177,
26,
199,
768,
26,
5438,
1865,
12,
1568,
1253,
13177,
334,
885,
9,
199,
275,
26,
5438,
1865,
12,
2418,
14,
1568,
1253,
13177,
199,
665,
26,
12050,
13,
15009,
12,
2418,
14,
1568,
1253,
13177,
199,
690,
26,
7282,
13,
15009,
12,
2418,
14,
1568,
1253,
13177,
199,
8546,
26,
2011,
465,
690,
199,
199,
1918,
7971,
8365,
6623,
2943,
402,
1249,
436,
1471,
1336,
8840,
27,
199,
29032,
883,
506,
9222,
770,
701,
282,
6107,
11982,
2338,
26,
2043,
671,
26,
6567,
3696,
334,
889,
666,
2736,
2043,
286,
26,
1560,
27,
2043,
330,
26,
1737,
3696,
27,
2043,
699,
26,
2244,
3696,
27,
2043,
394,
26,
3612,
27,
2043,
869,
26,
2244,
3974,
27,
2043,
284,
26,
442,
27,
2043,
473,
26,
2244,
1109,
27,
2043,
634,
26,
2809,
27,
2043,
491,
26,
2244,
1846,
27,
2043,
289,
26,
1609,
27,
2043,
366,
26,
3157,
14,
199,
12246,
5560,
334,
657,
301,
1098,
6107,
2338,
9126,
2582,
304,
2043,
308,
26,
875,
334,
1144,
402,
1495,
2736,
299,
26,
19099,
915,
1059,
334,
1045,
2338,
3696,
680,
199,
12246,
1930,
334,
2118,
2808,
315,
5438,
1475,
304,
2043,
510,
26,
290,
3000,
730,
626,
365,
20239,
8321,
370,
10266,
282,
7849,
14,
199,
12246,
1930,
334,
1397,
315,
5438,
818,
7444,
283,
2809,
1846,
7,
315,
4298,
445,
304,
2043,
1894,
26,
2809,
1846,
27,
2043,
1413,
26,
2244,
1846,
1846,
199,
16552,
3382,
6752,
365,
5525,
14,
199,
199,
1918,
1750,
2702,
14,
705,
365,
376,
1919,
4915,
641,
2552,
1041,
199,
199,
646,
3473,
12,
984,
199,
199,
3,
3254,
26,
5787,
6668,
282,
4340,
370,
664,
2556,
641,
5438,
10627,
436,
6998,
1470,
199,
533,
13039,
547,
8,
1726,
304,
272,
986,
199,
705,
275,
13039,
547,
199,
318,
7787,
63,
442,
8,
576,
12,
1080,
12,
890,
12,
274,
304,
272,
2783,
275,
359,
66,
367,
330,
315,
666,
59,
1080,
26,
1080,
11,
890,
2677,
272,
340,
1026,
508,
283,
10182,
356,
267,
2783,
14,
4471,
342,
272,
1329,
275,
378,
272,
367,
330,
315,
2783,
26,
267,
1329,
275,
1329,
5213,
1695,
1204,
330,
272,
372,
1109,
8,
1955,
9,
199,
199,
318,
7787,
63,
1737,
63,
442,
8,
576,
12,
1080,
12,
890,
12,
274,
304,
272,
1329,
275,
7787,
63,
442,
8,
576,
12,
1080,
12,
890,
12,
274,
9,
272,
1390,
275,
499,
14192,
890,
10,
24,
9,
272,
340,
1329,
690,
499,
14192,
890,
10,
24,
446,
413,
9,
446,
413,
26,
267,
1329,
275,
1109,
2801,
17,
5830,
988,
446,
1329,
430,
272,
372,
1329,
199,
199,
32191,
1922,
275,
413,
69,
1840,
627,
413,
69,
1840,
199,
24040,
275,
1621,
17383,
1922,
1182,
1621,
17383,
1922,
199,
199,
318,
7787,
63,
1560,
8,
576,
12,
1080,
12,
890,
12,
274,
304,
272,
372,
666,
59,
1080,
26,
1080,
11,
890,
61,
199,
199,
318,
1706,
63,
442,
8,
1955,
12,
890,
12,
274,
304,
272,
671,
29,
1955,
272,
522,
9811,
272,
367,
284,
315,
1425,
8,
890,
304,
267,
522,
14,
740,
8,
88,
6,
16,
3581,
9,
267,
671,
4331,
29,
1695,
272,
340,
1026,
508,
283,
5076,
356,
267,
522,
14,
4471,
342,
272,
372,
2783,
8,
470,
9,
199,
199,
318,
1706,
63,
1737,
63,
442,
8,
1955,
12,
890,
12,
274,
304,
272,
340,
440,
1228,
8,
1955,
12,
1109,
304,
267,
746,
13039,
547,
480,
2094,
367,
284,
12,
41,
12,
76,
12,
44,
12,
81,
12,
49,
12,
72,
12,
40,
1471,
506,
3000,
531,
272,
340,
221,
1329,
690,
499,
14192,
24,
10,
890,
13,
17,
7216,
17,
503,
1329,
665,
446,
17,
10,
18,
14192,
24,
10,
890,
13,
17,
304,
267,
746,
23870,
480,
3259,
2689,
73,
4634,
7031,
370,
3957,
2,
450,
1329,
9,
272,
372,
1706,
63,
442,
8,
1955,
12,
890,
12,
274,
9,
199,
199,
318,
1706,
63,
2244,
63,
442,
8,
1955,
12,
890,
12,
274,
304,
272,
340,
440,
1228,
8,
1955,
12,
1109,
304,
267,
746,
13039,
547,
480,
2094,
367,
284,
12,
41,
12,
76,
12,
44,
12,
81,
12,
49,
12,
72,
12,
40,
1471,
506,
3000,
531,
272,
340,
1329,
665,
378,
26,
267,
746,
3146,
480,
2425,
1133,
3957,
6946,
1846,
370,
7381,
531,
272,
340,
1329,
690,
499,
14192,
24,
10,
890,
7216,
17,
26,
267,
746,
23870,
480,
3259,
2689,
73,
4634,
7031,
370,
3957,
2,
450,
1329,
9,
272,
372,
1706,
63,
442,
8,
1955,
12,
890,
12,
274,
9,
199,
199,
318,
1706,
63,
1560,
8,
1560,
12,
890,
12,
274,
304,
272,
372,
2783,
8,
1560,
9,
199,
199,
318,
365,
4904,
8,
88,
304,
272,
372,
671,
1137,
378,
14,
16,
436,
671,
1182,
499,
508,
671,
199,
318,
365,
4304,
8,
86,
304,
272,
372,
373,
1137,
373,
10,
17,
14,
16,
503,
334,
86,
508,
413,
14,
16,
436,
373,
508,
499,
14,
16,
9,
199,
199,
318,
1706,
63,
1609,
8,
88,
12,
1568,
12,
1026,
304,
272,
7381,
275,
2069,
63,
1389,
8,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
Just-D/chromium-1
|
tools/telemetry/third_party/gsutilz/third_party/boto/boto/ec2/autoscale/limits.py
|
152
|
1958
|
# Copyright (c) 2013 Amazon.com, Inc. or its affiliates. All Rights Reserved
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish, dis-
# tribute, sublicense, and/or sell copies of the Software, and to permit
# persons to whom the Software is furnished to do so, subject to the fol-
# lowing conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
class AccountLimits(object):
def __init__(self, connection=None):
self.connection = connection
self.max_autoscaling_groups = None
self.max_launch_configurations = None
def __repr__(self):
return 'AccountLimits: [%s, %s]' % (self.max_autoscaling_groups,
self.max_launch_configurations)
def startElement(self, name, attrs, connection):
return None
def endElement(self, name, value, connection):
if name == 'RequestId':
self.request_id = value
elif name == 'MaxNumberOfAutoScalingGroups':
self.max_autoscaling_groups = int(value)
elif name == 'MaxNumberOfLaunchConfigurations':
self.max_launch_configurations = int(value)
else:
setattr(self, name, value)
|
bsd-3-clause
|
[
3,
1898,
334,
67,
9,
6171,
14347,
14,
957,
12,
3277,
14,
503,
2399,
29172,
2335,
14,
221,
2900,
5924,
5702,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
199,
3,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
199,
3,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
199,
3,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
2153,
13,
199,
3,
28420,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
11291,
199,
3,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
314,
1699,
13,
199,
3,
28486,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
199,
3,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
199,
3,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
28471,
13,
199,
3,
28463,
12,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
199,
3,
7000,
2334,
17632,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
199,
3,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
3,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
199,
3,
1621,
2334,
4141,
14,
421,
199,
533,
9973,
24480,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1950,
29,
403,
304,
267,
291,
14,
2105,
275,
1950,
267,
291,
14,
988,
63,
2495,
12153,
63,
2634,
275,
488,
267,
291,
14,
988,
63,
9850,
63,
10057,
275,
488,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
283,
6009,
24480,
26,
8978,
83,
12,
450,
83,
6616,
450,
334,
277,
14,
988,
63,
2495,
12153,
63,
2634,
12,
4490,
291,
14,
988,
63,
9850,
63,
10057,
9,
339,
347,
26325,
8,
277,
12,
536,
12,
3290,
12,
1950,
304,
267,
372,
488,
339,
347,
28920,
8,
277,
12,
536,
12,
574,
12,
1950,
304,
267,
340,
536,
508,
283,
2017,
1304,
356,
288,
291,
14,
1069,
63,
344,
275,
574,
267,
916,
536,
508,
283,
4261,
16030,
3358,
26416,
10177,
356,
288,
291,
14,
988,
63,
2495,
12153,
63,
2634,
275,
1109,
8,
585,
9,
267,
916,
536,
508,
283,
4261,
16030,
18543,
25808,
356,
288,
291,
14,
988,
63,
9850,
63,
10057,
275,
1109,
8,
585,
9,
267,
587,
26,
288,
5371,
8,
277,
12,
536,
12,
574,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
334,
67,
9,
6171,
14347,
14,
957,
12,
3277,
14,
503,
2399,
29172,
2335,
14,
221,
2900,
5924,
5702,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
199,
3,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
199,
3,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
199,
3,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
2153,
13,
199,
3,
28420,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
11291,
199,
3,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
314,
1699,
13,
199,
3,
28486,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
199,
3,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
199,
3,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
28471,
13,
199,
3,
28463,
12,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
199,
3,
7000,
2334,
17632,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
199,
3,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
3,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
199,
3,
1621,
2334,
4141,
14,
421,
199,
533,
9973,
24480,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1950,
29,
403,
304,
267,
291,
14,
2105,
275,
1950,
267,
291,
14,
988,
63,
2495,
12153,
63,
2634,
275,
488,
267,
291,
14,
988,
63,
9850,
63,
10057,
275,
488,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
283,
6009,
24480,
26,
8978,
83,
12,
450,
83,
6616,
450,
334,
277,
14,
988,
63,
2495,
12153,
63,
2634,
12,
4490,
291,
14,
988,
63,
9850,
63,
10057,
9,
339,
347,
26325,
8,
277,
12,
536,
12,
3290,
12,
1950,
304,
267,
372,
488,
339,
347,
28920,
8,
277,
12,
536,
12,
574,
12,
1950,
304,
267,
340,
536,
508,
283,
2017,
1304,
356,
288,
291,
14,
1069,
63,
344,
275,
574,
267,
916,
536,
508,
283,
4261,
16030,
3358,
26416,
10177,
356,
288,
291,
14,
988,
63,
2495,
12153,
63,
2634,
275,
1109,
8,
585,
9,
267,
916,
536,
508,
283,
4261,
16030,
18543,
25808,
356,
288,
291,
14,
988,
63,
9850,
63,
10057,
275,
1109,
8,
585,
9,
267,
587,
26,
288,
5371,
8,
277,
12,
536,
12,
574,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
]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
0
] |
jasco/authomatic
|
tests/functional_tests/expected_values/plurk.py
|
3
|
3359
|
# -*- coding: utf-8 -*-
import re
import fixtures
import constants
from authomatic.providers import oauth1
conf = fixtures.get_configuration('plurk')
LINK = 'http://www.plurk.com/{0}/'.format(conf.user_username)
PICTURE = 'http://avatars.plurk.com/{0}-big2.jpg'.format(conf.user_id)
CONFIG = {
'login_xpath': '//*[@id="input_nick_name"]',
'password_xpath': '//*[@id="password"]/input',
'consent_xpaths': [
'//*[@id="display_board"]/div[2]/div/form/input[5]',
],
'consent_wait_seconds': 5,
'class_': oauth1.Plurk,
'user': {
'birth_date': conf.user_birth_date_str,
'city': conf.user_city,
'country': conf.user_country,
'email': conf.user_email,
'gender': re.compile(r'^\d$'),
'id': conf.user_id,
'first_name': None,
'last_name': None,
'link': LINK,
'locale': re.compile(r'^\w{2}$'),
'location': conf.user_location,
'name': conf.user_name,
'nickname': conf.user_nickname,
'phone': None,
'picture': PICTURE,
'postal_code': None,
'timezone': 'UTC',
'username': conf.user_username,
},
'content_should_contain': [
conf.user_birth_date.strftime('%a, %d %b %Y 00:01:00 GMT'),
conf.user_city,
conf.user_country,
conf.user_email,
conf.user_id,
conf.user_location,
conf.user_name,
conf.user_nickname,
PICTURE.replace('/', r'\/'),
conf.user_username,
# User info JSON keys
'about', 'accept_private_plurk_from', 'alerts_count', 'anonymous',
'avatar', 'avatar_big', 'avatar_medium', 'avatar_small', 'bday_privacy',
'content', 'content_raw', 'date_of_birth', 'dateformat', 'default_lang',
'display_name', 'email', 'email_confirmed', 'fans_count', 'favorers',
'favorite', 'favorite_count', 'friends_count', 'full_name', 'gender',
'has_profile_image', 'has_read_permission', 'id', 'is_unread', 'karma',
'lang', 'limited_to', 'location', 'name_color', 'nick_name',
'no_comments', 'owner_id', 'page_title', 'plurk_id', 'plurk_type',
'plurks', 'plurks_count', 'plurks_users', 'porn',
'post_anonymous_plurk', 'posted', 'privacy', 'profile_views',
'qualifier', 'qualifier_translated', 'recruited', 'relationship',
'replurkable', 'replurked', 'replurker_id', 'replurkers',
'replurkers_count', 'response_count', 'responses_seen',
'setup_facebook_sync', 'setup_twitter_sync', 'setup_weibo_sync',
'timezone', 'uid', 'unread_count', 'user_id', 'user_info',
'verified_account'
],
# Case insensitive
'content_should_not_contain':
conf.no_first_name +
conf.no_last_name +
conf.no_postal_code,
# True means that any thruthy value is expected
'credentials': {
'_expiration_time': None,
'_expire_in': True,
'consumer_key': True,
'consumer_secret': True,
'provider_id': None,
'provider_name': 'plurk',
'provider_type': 'authomatic.providers.oauth1.OAuth1',
'provider_type_id': '1-4',
'refresh_status': constants.CREDENTIALS_REFRESH_NOT_SUPPORTED,
'refresh_token': None,
'token': True,
'token_secret': True,
'token_type': None,
},
}
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
646,
295,
421,
199,
646,
15188,
199,
646,
5262,
199,
504,
1790,
79,
3889,
14,
9710,
492,
9725,
17,
199,
199,
2190,
275,
15188,
14,
362,
63,
4758,
360,
1168,
300,
75,
358,
199,
199,
7916,
275,
283,
1014,
921,
1544,
14,
1168,
300,
75,
14,
957,
5321,
16,
5995,
1370,
908,
8,
2190,
14,
751,
63,
2473,
9,
199,
48,
6196,
3942,
275,
283,
1014,
921,
1214,
292,
4291,
14,
1168,
300,
75,
14,
957,
5321,
16,
17063,
5076,
18,
14,
8476,
1370,
908,
8,
2190,
14,
751,
63,
344,
9,
199,
199,
5569,
275,
469,
272,
283,
2886,
63,
8006,
356,
18290,
10,
14251,
344,
628,
1210,
63,
11082,
63,
354,
23793,
272,
283,
2060,
63,
8006,
356,
18290,
10,
14251,
344,
628,
2060,
937,
15,
1210,
297,
272,
283,
388,
1150,
63,
88,
3771,
356,
359,
267,
18290,
10,
14251,
344,
628,
2918,
63,
3576,
937,
15,
3015,
59,
18,
12978,
3015,
15,
964,
15,
1210,
59,
21,
4300,
272,
2156,
272,
283,
388,
1150,
63,
2573,
63,
4515,
356,
959,
12,
272,
283,
533,
63,
356,
9725,
17,
14,
3714,
300,
75,
12,
272,
283,
751,
356,
469,
267,
283,
10907,
63,
602,
356,
3743,
14,
751,
63,
10907,
63,
602,
63,
495,
12,
267,
283,
3690,
356,
3743,
14,
751,
63,
3690,
12,
267,
283,
6063,
356,
3743,
14,
751,
63,
6063,
12,
267,
283,
2123,
356,
3743,
14,
751,
63,
2123,
12,
267,
283,
15791,
356,
295,
14,
2014,
8,
82,
15542,
68,
26712,
267,
283,
344,
356,
3743,
14,
751,
63,
344,
12,
267,
283,
2246,
63,
354,
356,
488,
12,
267,
283,
2019,
63,
354,
356,
488,
12,
267,
283,
1073,
356,
19774,
12,
267,
283,
5508,
356,
295,
14,
2014,
8,
82,
15542,
87,
91,
18,
93,
26712,
267,
283,
1985,
356,
3743,
14,
751,
63,
1985,
12,
267,
283,
354,
356,
3743,
14,
751,
63,
354,
12,
267,
283,
18544,
356,
3743,
14,
751,
63,
18544,
12,
267,
283,
9339,
356,
488,
12,
267,
283,
12538,
356,
510,
6196,
3942,
12,
267,
283,
31580,
63,
600,
356,
488,
12,
267,
283,
7145,
356,
283,
11288,
297,
267,
283,
2473,
356,
3743,
14,
751,
63,
2473,
12,
272,
1660,
272,
283,
1317,
63,
5626,
63,
7747,
356,
359,
267,
3743,
14,
751,
63,
10907,
63,
602,
14,
6205,
3508,
65,
12,
450,
68,
450,
66,
450,
57,
8733,
26,
614,
26,
383,
19152,
659,
267,
3743,
14,
751,
63,
3690,
12,
267,
3743,
14,
751,
63,
6063,
12,
267,
3743,
14,
751,
63,
2123,
12,
267,
3743,
14,
751,
63,
344,
12,
267,
3743,
14,
751,
63,
1985,
12,
267,
3743,
14,
751,
63,
354,
12,
267,
3743,
14,
751,
63,
18544,
12,
267,
510,
6196,
3942,
14,
1814,
10998,
519,
1154,
20467,
267,
3743,
14,
751,
63,
2473,
12,
398,
327,
2876,
2256,
4840,
2883,
267,
283,
10254,
297,
283,
5694,
63,
4239,
63,
1168,
300,
75,
63,
504,
297,
283,
24501,
63,
835,
297,
283,
12628,
297,
267,
283,
14584,
297,
283,
14584,
63,
5076,
297,
283,
14584,
63,
14345,
297,
283,
14584,
63,
7241,
297,
283,
66,
2977,
63,
17258,
297,
267,
283,
1317,
297,
283,
1317,
63,
1773,
297,
283,
602,
63,
1618,
63,
10907,
297,
283,
602,
908,
297,
283,
885,
63,
4159,
297,
267,
283,
2918,
63,
354,
297,
283,
2123,
297,
283,
2123,
63,
16391,
297,
283,
70,
796,
63,
835,
297,
283,
30763,
720,
2393,
297,
267,
283,
23874,
297,
283,
23874,
63,
835,
297,
283,
18024,
63,
835,
297,
283,
2861,
63,
354,
297,
283,
15791,
297,
267,
283,
1989,
63,
2913,
63,
1569,
297,
283,
1989,
63,
739,
63,
5693,
297,
283,
344,
297,
283,
374,
63,
28677,
297,
283,
20814,
297,
267,
283,
4159,
297,
283,
14136,
63,
475,
297,
283,
1985,
297,
283,
354,
63,
2326,
297,
283,
11082,
63,
354,
297,
267,
283,
889,
63,
6223,
297,
283,
4597,
63,
344,
297,
283,
1606,
63,
1213,
297,
283,
1168,
300,
75,
63,
344,
297,
283,
1168,
300,
75,
63,
466,
297,
267,
283,
1168,
300,
6080,
297,
283,
1168,
300,
6080,
63,
835,
297,
283,
1168,
300,
6080,
63,
3707,
297,
283,
80,
6161,
297,
267,
283,
1932,
63,
12628,
63,
1168,
300,
75,
297,
283,
21760,
297,
283,
17258,
297,
283,
2913,
63,
4196,
297,
267,
283,
27005,
297,
283,
27005,
63,
18065,
297,
283,
264,
1556,
1907,
471,
297,
283,
11704,
297,
267,
283,
16349,
300,
75,
461,
297,
283,
16349,
300,
25503,
297,
283,
16349,
300,
2570,
63,
344,
297,
283,
16349,
300,
75,
1192,
297,
267,
283,
16349,
300,
75,
1192,
63,
835,
297,
283,
1310,
63,
835,
297,
283,
10360,
63,
8606,
297,
267,
283,
2758,
63,
16652,
63,
5186,
297,
283,
2758,
63,
13746,
63,
5186,
297,
283,
2758,
63,
21431,
656,
63,
5186,
297,
267,
283,
7145,
297,
283,
1535,
297,
283,
28677,
63,
835,
297,
283,
751,
63,
344,
297,
283,
751,
63,
815,
297,
267,
283,
12949,
63,
2048,
7,
272,
2156,
272,
327,
12425,
27845,
272,
283,
1317,
63,
5626,
63,
1397,
63,
7747,
356,
267,
3743,
14,
889,
63,
2246,
63,
354,
435,
267,
3743,
14,
889,
63,
2019,
63,
354,
435,
267,
3743,
14,
889,
63,
31580,
63,
600,
12,
272,
327,
715,
4910,
626,
1263,
294,
82,
762,
89,
574,
365,
1420,
272,
283,
6942,
356,
469,
267,
2513,
15469,
63,
521,
356,
488,
12,
267,
2513,
14691,
63,
262,
356,
715,
12,
267,
283,
8542,
63,
498,
356,
715,
12,
267,
283,
8542,
63,
4731,
356,
715,
12,
267,
283,
3780,
63,
344,
356,
488,
12,
267,
283,
3780,
63,
354,
356,
283,
1168,
300,
75,
297,
267,
283,
3780,
63,
466,
356,
283,
1178,
79,
3889,
14,
9710,
14,
6126,
17,
14,
12906,
17,
297,
267,
283,
3780,
63,
466,
63,
344,
356,
283,
17,
13,
20,
297,
267,
283,
6635,
63,
1205,
356,
5262,
14,
30553,
8246,
51,
63,
8279,
15098,
63,
4609,
63,
15925,
12,
267,
283,
6635,
63,
1418,
356,
488,
12,
267,
283,
1418,
356,
715,
12,
267,
283,
1418,
63,
4731,
356,
715
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
646,
295,
421,
199,
646,
15188,
199,
646,
5262,
199,
504,
1790,
79,
3889,
14,
9710,
492,
9725,
17,
199,
199,
2190,
275,
15188,
14,
362,
63,
4758,
360,
1168,
300,
75,
358,
199,
199,
7916,
275,
283,
1014,
921,
1544,
14,
1168,
300,
75,
14,
957,
5321,
16,
5995,
1370,
908,
8,
2190,
14,
751,
63,
2473,
9,
199,
48,
6196,
3942,
275,
283,
1014,
921,
1214,
292,
4291,
14,
1168,
300,
75,
14,
957,
5321,
16,
17063,
5076,
18,
14,
8476,
1370,
908,
8,
2190,
14,
751,
63,
344,
9,
199,
199,
5569,
275,
469,
272,
283,
2886,
63,
8006,
356,
18290,
10,
14251,
344,
628,
1210,
63,
11082,
63,
354,
23793,
272,
283,
2060,
63,
8006,
356,
18290,
10,
14251,
344,
628,
2060,
937,
15,
1210,
297,
272,
283,
388,
1150,
63,
88,
3771,
356,
359,
267,
18290,
10,
14251,
344,
628,
2918,
63,
3576,
937,
15,
3015,
59,
18,
12978,
3015,
15,
964,
15,
1210,
59,
21,
4300,
272,
2156,
272,
283,
388,
1150,
63,
2573,
63,
4515,
356,
959,
12,
272,
283,
533,
63,
356,
9725,
17,
14,
3714,
300,
75,
12,
272,
283,
751,
356,
469,
267,
283,
10907,
63,
602,
356,
3743,
14,
751,
63,
10907,
63,
602,
63,
495,
12,
267,
283,
3690,
356,
3743,
14,
751,
63,
3690,
12,
267,
283,
6063,
356,
3743,
14,
751,
63,
6063,
12,
267,
283,
2123,
356,
3743,
14,
751,
63,
2123,
12,
267,
283,
15791,
356,
295,
14,
2014,
8,
82,
15542,
68,
26712,
267,
283,
344,
356,
3743,
14,
751,
63,
344,
12,
267,
283,
2246,
63,
354,
356,
488,
12,
267,
283,
2019,
63,
354,
356,
488,
12,
267,
283,
1073,
356,
19774,
12,
267,
283,
5508,
356,
295,
14,
2014,
8,
82,
15542,
87,
91,
18,
93,
26712,
267,
283,
1985,
356,
3743,
14,
751,
63,
1985,
12,
267,
283,
354,
356,
3743,
14,
751,
63,
354,
12,
267,
283,
18544,
356,
3743,
14,
751,
63,
18544,
12,
267,
283,
9339,
356,
488,
12,
267,
283,
12538,
356,
510,
6196,
3942,
12,
267,
283,
31580,
63,
600,
356,
488,
12,
267,
283,
7145,
356,
283,
11288,
297,
267,
283,
2473,
356,
3743,
14,
751,
63,
2473,
12,
272,
1660,
272,
283,
1317,
63,
5626,
63,
7747,
356,
359,
267,
3743,
14,
751,
63,
10907,
63,
602,
14,
6205,
3508,
65,
12,
450,
68,
450,
66,
450,
57,
8733,
26,
614,
26,
383,
19152,
659,
267,
3743,
14,
751,
63,
3690,
12,
267,
3743,
14,
751,
63,
6063,
12,
267,
3743,
14,
751,
63,
2123,
12,
267,
3743,
14,
751,
63,
344,
12,
267,
3743,
14,
751,
63,
1985,
12,
267,
3743,
14,
751,
63,
354,
12,
267,
3743,
14,
751,
63,
18544,
12,
267,
510,
6196,
3942,
14,
1814,
10998,
519,
1154,
20467,
267,
3743,
14,
751,
63,
2473,
12,
398,
327,
2876,
2256,
4840,
2883,
267,
283,
10254,
297,
283,
5694,
63,
4239,
63,
1168,
300,
75,
63,
504,
297,
283,
24501,
63,
835,
297,
283,
12628,
297,
267,
283,
14584,
297,
283,
14584,
63,
5076,
297,
283,
14584,
63,
14345,
297,
283,
14584,
63,
7241,
297,
283,
66,
2977,
63,
17258,
297,
267,
283,
1317,
297,
283,
1317,
63,
1773,
297,
283,
602,
63,
1618,
63,
10907,
297,
283,
602,
908,
297,
283,
885,
63,
4159,
297,
267,
283,
2918,
63,
354,
297,
283,
2123,
297,
283,
2123,
63,
16391,
297,
283,
70,
796,
63,
835,
297,
283,
30763,
720,
2393,
297,
267,
283,
23874,
297,
283,
23874,
63,
835,
297,
283,
18024,
63,
835,
297,
283,
2861,
63,
354,
297,
283,
15791,
297,
267,
283,
1989,
63,
2913,
63,
1569,
297,
283,
1989,
63,
739,
63,
5693,
297,
283,
344,
297,
283,
374,
63,
28677,
297,
283,
20814,
297,
267,
283,
4159,
297,
283,
14136,
63,
475,
297,
283,
1985,
297,
283,
354,
63,
2326,
297,
283,
11082,
63,
354,
297,
267,
283,
889,
63,
6223,
297,
283,
4597,
63,
344,
297,
283,
1606,
63,
1213,
297,
283,
1168,
300,
75,
63,
344,
297,
283,
1168,
300,
75,
63,
466,
297,
267,
283,
1168,
300,
6080,
297,
283,
1168,
300,
6080,
63,
835,
297,
283,
1168,
300,
6080,
63,
3707,
297,
283,
80,
6161,
297,
267,
283,
1932,
63,
12628,
63,
1168,
300,
75,
297,
283,
21760,
297,
283,
17258,
297,
283,
2913,
63,
4196,
297,
267,
283,
27005,
297,
283,
27005,
63,
18065,
297,
283,
264,
1556,
1907,
471,
297,
283,
11704,
297,
267,
283,
16349,
300,
75,
461,
297,
283,
16349,
300,
25503,
297,
283,
16349,
300,
2570,
63,
344,
297,
283,
16349,
300,
75,
1192,
297,
267,
283,
16349,
300,
75,
1192,
63,
835,
297,
283,
1310,
63,
835,
297,
283,
10360,
63,
8606,
297,
267,
283,
2758,
63,
16652,
63,
5186,
297,
283,
2758,
63,
13746,
63,
5186,
297,
283,
2758,
63,
21431,
656,
63,
5186,
297,
267,
283,
7145,
297,
283,
1535,
297,
283,
28677,
63,
835,
297,
283,
751,
63,
344,
297,
283,
751,
63,
815,
297,
267,
283,
12949,
63,
2048,
7,
272,
2156,
272,
327,
12425,
27845,
272,
283,
1317,
63,
5626,
63,
1397,
63,
7747,
356,
267,
3743,
14,
889,
63,
2246,
63,
354,
435,
267,
3743,
14,
889,
63,
2019,
63,
354,
435,
267,
3743,
14,
889,
63,
31580,
63,
600,
12,
272,
327,
715,
4910,
626,
1263,
294,
82,
762,
89,
574,
365,
1420,
272,
283,
6942,
356,
469,
267,
2513,
15469,
63,
521,
356,
488,
12,
267,
2513,
14691,
63,
262,
356,
715,
12,
267,
283,
8542,
63,
498,
356,
715,
12,
267,
283,
8542,
63,
4731,
356,
715,
12,
267,
283,
3780,
63,
344,
356,
488,
12,
267,
283,
3780,
63,
354,
356,
283,
1168,
300,
75,
297,
267,
283,
3780,
63,
466,
356,
283,
1178,
79,
3889,
14,
9710,
14,
6126,
17,
14,
12906,
17,
297,
267,
283,
3780,
63,
466,
63,
344,
356,
283,
17,
13,
20,
297,
267,
283,
6635,
63,
1205,
356,
5262,
14,
30553,
8246,
51,
63,
8279,
15098,
63,
4609,
63,
15925,
12,
267,
283,
6635,
63,
1418,
356,
488,
12,
267,
283,
1418,
356,
715,
12,
267,
283,
1418,
63,
4731,
356,
715,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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------------------------------
# odoo cli
#
# To install your odoo development environement type:
#
# wget -O- https://raw.githubusercontent.com/odoo/odoo/10.0/setup/setup_dev.py | python
#
# The setup_* subcommands used to boostrap odoo are defined here inline and may
# only depends on the python 2.7 stdlib
#
# The rest of subcommands are defined in odoo/cli or in <module>/cli by
# subclassing the Command object
#
#----------------------------------------------------------
import os
import re
import sys
import subprocess
GIT_HOOKS_PRE_PUSH = """
#!/usr/bin/env python2
import re
import sys
if re.search('github.com[:/]odoo/odoo.git$', sys.argv[2]):
print "Pushing to /odoo/odoo.git is forbidden, please push to odoo-dev, use --no-verify to override"
sys.exit(1)
"""
def printf(f,*l):
print "odoo:" + f % l
def run(*l):
if isinstance(l[0], list):
l = l[0]
printf("running %s", " ".join(l))
subprocess.check_call(l)
def git_locate():
# Locate git dir
# TODO add support for os.environ.get('GIT_DIR')
# check for an odoo child
if os.path.isfile('odoo/.git/config'):
os.chdir('odoo')
path = os.getcwd()
while path != os.path.abspath(os.sep):
gitconfig_path = os.path.join(path, '.git/config')
if os.path.isfile(gitconfig_path):
release_py = os.path.join(path, 'odoo/release.py')
if os.path.isfile(release_py):
break
path = os.path.dirname(path)
if path == os.path.abspath(os.sep):
path = None
return path
def cmd_setup_git():
git_dir = git_locate()
if git_dir:
printf('git repo found at %s',git_dir)
else:
run("git", "init", "odoo")
os.chdir('odoo')
git_dir = os.getcwd()
if git_dir:
# push sane config for git < 2.0, and hooks
#run('git','config','push.default','simple')
# alias
run('git','config','alias.st','status')
# merge bzr style
run('git','config','merge.commit','no')
# pull let me choose between merge or rebase only works in git > 2.0, use an alias for 1
run('git','config','pull.ff','only')
run('git','config','alias.pl','pull --ff-only')
pre_push_path = os.path.join(git_dir, '.git/hooks/pre-push')
open(pre_push_path,'w').write(GIT_HOOKS_PRE_PUSH.strip())
os.chmod(pre_push_path, 0755)
# setup odoo remote
run('git','config','remote.odoo.url','https://github.com/odoo/odoo.git')
run('git','config','remote.odoo.pushurl','git@github.com:odoo/odoo.git')
run('git','config','--add','remote.odoo.fetch','dummy')
run('git','config','--unset-all','remote.odoo.fetch')
run('git','config','--add','remote.odoo.fetch','+refs/heads/*:refs/remotes/odoo/*')
# setup odoo-dev remote
run('git','config','remote.odoo-dev.url','https://github.com/odoo-dev/odoo.git')
run('git','config','remote.odoo-dev.pushurl','git@github.com:odoo-dev/odoo.git')
run('git','remote','update')
# setup 10.0 branch
run('git','config','branch.10.0.remote','odoo')
run('git','config','branch.10.0.merge','refs/heads/10.0')
run('git','checkout','10.0')
else:
printf('no git repo found')
def cmd_setup_git_dev():
git_dir = git_locate()
if git_dir:
# setup odoo-dev remote
run('git','config','--add','remote.odoo-dev.fetch','dummy')
run('git','config','--unset-all','remote.odoo-dev.fetch')
run('git','config','--add','remote.odoo-dev.fetch','+refs/heads/*:refs/remotes/odoo-dev/*')
run('git','config','--add','remote.odoo-dev.fetch','+refs/pull/*:refs/remotes/odoo-dev/pull/*')
run('git','remote','update')
def cmd_setup_git_review():
git_dir = git_locate()
if git_dir:
# setup odoo-dev remote
run('git','config','--add','remote.odoo.fetch','dummy')
run('git','config','--unset-all','remote.odoo.fetch')
run('git','config','--add','remote.odoo.fetch','+refs/heads/*:refs/remotes/odoo/*')
run('git','config','--add','remote.odoo.fetch','+refs/tags/*:refs/remotes/odoo/tags/*')
run('git','config','--add','remote.odoo.fetch','+refs/pull/*:refs/remotes/odoo/pull/*')
def setup_deps_debian(git_dir):
debian_control_path = os.path.join(git_dir, 'debian/control')
debian_control = open(debian_control_path).read()
debs = re.findall('python-[0-9a-z]+',debian_control)
debs += ["postgresql"]
proc = subprocess.Popen(['sudo','apt-get','install'] + debs, stdin=open('/dev/tty'))
proc.communicate()
def cmd_setup_deps():
git_dir = git_locate()
if git_dir:
if os.path.isfile('/etc/debian_version'):
setup_deps_debian(git_dir)
def setup_pg_debian(git_dir):
cmd = ['sudo','su','-','postgres','-c','createuser -s %s' % os.environ['USER']]
subprocess.call(cmd)
def cmd_setup_pg():
git_dir = git_locate()
if git_dir:
if os.path.isfile('/etc/debian_version'):
setup_pg_debian(git_dir)
def cmd_setup():
cmd_setup_git()
cmd_setup_deps()
cmd_setup_pg()
def main():
# registry of commands
g = globals()
cmds = dict([(i[4:],g[i]) for i in g if i.startswith('cmd_')])
# if curl URL | python2 then use command setup
if len(sys.argv) == 1 and __file__ == '<stdin>':
cmd_setup()
elif len(sys.argv) == 2 and sys.argv[1] in cmds:
cmds[sys.argv[1]]()
else:
sys.exit('Unknow command. Command available: %r' % (list(cmds,)))
if __name__ == "__main__":
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
30346,
199,
3,
28811,
5053,
199,
3,
199,
3,
4005,
3907,
2195,
28811,
16367,
655,
1042,
368,
434,
730,
26,
199,
3,
199,
3,
336,
362,
446,
47,
13,
4178,
921,
1773,
14,
5031,
751,
1317,
14,
957,
15,
22058,
15,
22058,
15,
709,
14,
16,
15,
2758,
15,
2758,
63,
2374,
14,
647,
1204,
2366,
199,
3,
199,
3,
710,
3272,
15192,
1007,
4405,
1202,
370,
20198,
1330,
28811,
787,
3247,
2348,
8308,
436,
1443,
199,
3,
1454,
8350,
641,
314,
2366,
499,
14,
23,
26678,
199,
3,
199,
3,
710,
4618,
402,
1007,
4405,
787,
3247,
315,
28811,
15,
2764,
503,
315,
665,
578,
12202,
2764,
701,
199,
3,
24572,
314,
5817,
909,
199,
3,
199,
30346,
199,
646,
747,
199,
646,
295,
199,
646,
984,
199,
646,
3873,
199,
199,
20072,
63,
28706,
51,
63,
4225,
63,
21378,
275,
408,
199,
3381,
2647,
15,
1393,
15,
1813,
2366,
18,
199,
646,
295,
199,
646,
984,
199,
692,
295,
14,
1733,
360,
5031,
14,
957,
1491,
15,
61,
22058,
15,
22058,
14,
3187,
4268,
984,
14,
3020,
59,
18,
4682,
272,
870,
298,
10731,
316,
370,
1182,
22058,
15,
22058,
14,
3187,
365,
24786,
12,
8749,
6675,
370,
28811,
13,
2374,
12,
675,
1553,
889,
13,
4712,
370,
4278,
2,
272,
984,
14,
2224,
8,
17,
9,
199,
624,
199,
199,
318,
870,
70,
8,
70,
19166,
76,
304,
272,
870,
298,
22058,
5424,
435,
289,
450,
634,
199,
199,
318,
1255,
2031,
76,
304,
272,
340,
1228,
8,
76,
59,
16,
467,
769,
304,
267,
634,
275,
634,
59,
16,
61,
272,
870,
70,
480,
5720,
450,
83,
401,
298,
3680,
904,
8,
76,
430,
272,
3873,
14,
1074,
63,
1250,
8,
76,
9,
199,
199,
318,
6135,
63,
6280,
837,
272,
327,
6263,
323,
6135,
2935,
272,
327,
3254,
1050,
2291,
367,
747,
14,
2314,
14,
362,
360,
20072,
63,
3022,
358,
339,
327,
1104,
367,
376,
28811,
1982,
272,
340,
747,
14,
515,
14,
6292,
360,
22058,
8083,
3187,
15,
888,
735,
267,
747,
14,
8563,
360,
22058,
358,
339,
931,
275,
747,
14,
9458,
342,
272,
1830,
931,
1137,
747,
14,
515,
14,
4832,
8,
736,
14,
4127,
304,
267,
6135,
888,
63,
515,
275,
747,
14,
515,
14,
904,
8,
515,
12,
1987,
3187,
15,
888,
358,
267,
340,
747,
14,
515,
14,
6292,
8,
3187,
888,
63,
515,
304,
288,
4683,
63,
647,
275,
747,
14,
515,
14,
904,
8,
515,
12,
283,
22058,
15,
3221,
14,
647,
358,
288,
340,
747,
14,
515,
14,
6292,
8,
3221,
63,
647,
304,
355,
2059,
267,
931,
275,
747,
14,
515,
14,
3475,
8,
515,
9,
272,
340,
931,
508,
747,
14,
515,
14,
4832,
8,
736,
14,
4127,
304,
267,
931,
275,
488,
272,
372,
931,
199,
199,
318,
2088,
63,
2758,
63,
3187,
837,
272,
6135,
63,
694,
275,
6135,
63,
6280,
342,
272,
340,
6135,
63,
694,
26,
267,
870,
70,
360,
3187,
3831,
1911,
737,
450,
83,
297,
3187,
63,
694,
9,
272,
587,
26,
267,
1255,
480,
3187,
401,
298,
826,
401,
298,
22058,
531,
267,
747,
14,
8563,
360,
22058,
358,
267,
6135,
63,
694,
275,
747,
14,
9458,
342,
272,
340,
6135,
63,
694,
26,
267,
327,
6675,
31648,
1101,
367,
6135,
665,
499,
14,
16,
12,
436,
12604,
267,
327,
1065,
360,
3187,
1673,
888,
1673,
5335,
14,
885,
1673,
4129,
358,
267,
327,
5162,
267,
1255,
360,
3187,
1673,
888,
1673,
3620,
14,
270,
1673,
1205,
358,
267,
327,
5389,
15055,
82,
3449,
267,
1255,
360,
3187,
1673,
888,
1673,
5628,
14,
3543,
1673,
889,
358,
267,
327,
10299,
4691,
562,
11496,
3382,
5389,
503,
295,
1095,
1454,
5419,
315,
6135,
690,
499,
14,
16,
12,
675,
376,
5162,
367,
413,
267,
1255,
360,
3187,
1673,
888,
1673,
9302,
14,
556,
1673,
2118,
358,
267,
1255,
360,
3187,
1673,
888,
1673,
3620,
14,
1168,
1673,
9302,
1553,
556,
13,
2118,
358,
267,
876,
63,
5335,
63,
515,
275,
747,
14,
515,
14,
904,
8,
3187,
63,
694,
12,
1987,
3187,
15,
7922,
15,
657,
13,
5335,
358,
267,
1551,
8,
657,
63,
5335,
63,
515,
2584,
87,
1959,
952,
8,
20072,
63,
28706,
51,
63,
4225,
63,
21378,
14,
1913,
1012,
267,
747,
14,
11693,
8,
657,
63,
5335,
63,
515,
12,
378,
12315,
9,
267,
327,
3272,
28811,
3982,
267,
1255,
360,
3187,
1673,
888,
1673,
3846,
14,
22058,
14,
633,
1673,
2859,
921,
5031,
14,
957,
15,
22058,
15,
22058,
14,
3187,
358,
267,
1255,
360,
3187,
1673,
888,
1673,
3846,
14,
22058,
14,
5335,
633,
1673,
3187,
32,
5031,
14,
957,
26,
22058,
15,
22058,
14,
3187,
358,
267,
1255,
360,
3187,
1673,
888,
28280,
525,
1673,
3846,
14,
22058,
14,
3535,
1673,
5869,
358,
267,
1255,
360,
3187,
1673,
888,
28280,
16787,
13,
452,
1673,
3846,
14,
22058,
14,
3535,
358,
267,
1255,
360,
3187,
1673,
888,
28280,
525,
1673,
3846,
14,
22058,
14,
3535,
1673,
11,
7655,
15,
17033,
6331,
26,
7655,
15,
21420,
744,
15,
22058,
6331,
358,
267,
327,
3272,
28811,
13,
2374,
3982,
267,
1255,
360,
3187,
1673,
888,
1673,
3846,
14,
22058,
13,
2374,
14,
633,
1673,
2859,
921,
5031,
14,
957,
15,
22058,
13,
2374,
15,
22058,
14,
3187,
358,
267,
1255,
360,
3187,
1673,
888,
1673,
3846,
14,
22058,
13,
2374,
14,
5335,
633,
1673,
3187,
32,
5031,
14,
957,
26,
22058,
13,
2374,
15,
22058,
14,
3187,
358,
267,
1255,
360,
3187,
1673,
3846,
1673,
873,
358,
267,
327,
3272,
1616,
14,
16,
5246,
267,
1255,
360,
3187,
1673,
888,
1673,
4694,
14,
709,
14,
16,
14,
3846,
1673,
22058,
358,
267,
1255,
360,
3187,
1673,
888,
1673,
4694,
14,
709,
14,
16,
14,
5628,
1673,
7655,
15,
17033,
15,
709,
14,
16,
358,
267,
1255,
360,
3187,
1673,
12891,
1673,
709,
14,
16,
358,
272,
587,
26,
267,
870,
70,
360,
889,
6135,
3831,
1911,
358,
199,
199,
318,
2088,
63,
2758,
63,
3187,
63,
2374,
837,
272,
6135,
63,
694,
275,
6135,
63,
6280,
342,
272,
340,
6135,
63,
694,
26,
267,
327,
3272,
28811,
13,
2374
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
30346,
199,
3,
28811,
5053,
199,
3,
199,
3,
4005,
3907,
2195,
28811,
16367,
655,
1042,
368,
434,
730,
26,
199,
3,
199,
3,
336,
362,
446,
47,
13,
4178,
921,
1773,
14,
5031,
751,
1317,
14,
957,
15,
22058,
15,
22058,
15,
709,
14,
16,
15,
2758,
15,
2758,
63,
2374,
14,
647,
1204,
2366,
199,
3,
199,
3,
710,
3272,
15192,
1007,
4405,
1202,
370,
20198,
1330,
28811,
787,
3247,
2348,
8308,
436,
1443,
199,
3,
1454,
8350,
641,
314,
2366,
499,
14,
23,
26678,
199,
3,
199,
3,
710,
4618,
402,
1007,
4405,
787,
3247,
315,
28811,
15,
2764,
503,
315,
665,
578,
12202,
2764,
701,
199,
3,
24572,
314,
5817,
909,
199,
3,
199,
30346,
199,
646,
747,
199,
646,
295,
199,
646,
984,
199,
646,
3873,
199,
199,
20072,
63,
28706,
51,
63,
4225,
63,
21378,
275,
408,
199,
3381,
2647,
15,
1393,
15,
1813,
2366,
18,
199,
646,
295,
199,
646,
984,
199,
692,
295,
14,
1733,
360,
5031,
14,
957,
1491,
15,
61,
22058,
15,
22058,
14,
3187,
4268,
984,
14,
3020,
59,
18,
4682,
272,
870,
298,
10731,
316,
370,
1182,
22058,
15,
22058,
14,
3187,
365,
24786,
12,
8749,
6675,
370,
28811,
13,
2374,
12,
675,
1553,
889,
13,
4712,
370,
4278,
2,
272,
984,
14,
2224,
8,
17,
9,
199,
624,
199,
199,
318,
870,
70,
8,
70,
19166,
76,
304,
272,
870,
298,
22058,
5424,
435,
289,
450,
634,
199,
199,
318,
1255,
2031,
76,
304,
272,
340,
1228,
8,
76,
59,
16,
467,
769,
304,
267,
634,
275,
634,
59,
16,
61,
272,
870,
70,
480,
5720,
450,
83,
401,
298,
3680,
904,
8,
76,
430,
272,
3873,
14,
1074,
63,
1250,
8,
76,
9,
199,
199,
318,
6135,
63,
6280,
837,
272,
327,
6263,
323,
6135,
2935,
272,
327,
3254,
1050,
2291,
367,
747,
14,
2314,
14,
362,
360,
20072,
63,
3022,
358,
339,
327,
1104,
367,
376,
28811,
1982,
272,
340,
747,
14,
515,
14,
6292,
360,
22058,
8083,
3187,
15,
888,
735,
267,
747,
14,
8563,
360,
22058,
358,
339,
931,
275,
747,
14,
9458,
342,
272,
1830,
931,
1137,
747,
14,
515,
14,
4832,
8,
736,
14,
4127,
304,
267,
6135,
888,
63,
515,
275,
747,
14,
515,
14,
904,
8,
515,
12,
1987,
3187,
15,
888,
358,
267,
340,
747,
14,
515,
14,
6292,
8,
3187,
888,
63,
515,
304,
288,
4683,
63,
647,
275,
747,
14,
515,
14,
904,
8,
515,
12,
283,
22058,
15,
3221,
14,
647,
358,
288,
340,
747,
14,
515,
14,
6292,
8,
3221,
63,
647,
304,
355,
2059,
267,
931,
275,
747,
14,
515,
14,
3475,
8,
515,
9,
272,
340,
931,
508,
747,
14,
515,
14,
4832,
8,
736,
14,
4127,
304,
267,
931,
275,
488,
272,
372,
931,
199,
199,
318,
2088,
63,
2758,
63,
3187,
837,
272,
6135,
63,
694,
275,
6135,
63,
6280,
342,
272,
340,
6135,
63,
694,
26,
267,
870,
70,
360,
3187,
3831,
1911,
737,
450,
83,
297,
3187,
63,
694,
9,
272,
587,
26,
267,
1255,
480,
3187,
401,
298,
826,
401,
298,
22058,
531,
267,
747,
14,
8563,
360,
22058,
358,
267,
6135,
63,
694,
275,
747,
14,
9458,
342,
272,
340,
6135,
63,
694,
26,
267,
327,
6675,
31648,
1101,
367,
6135,
665,
499,
14,
16,
12,
436,
12604,
267,
327,
1065,
360,
3187,
1673,
888,
1673,
5335,
14,
885,
1673,
4129,
358,
267,
327,
5162,
267,
1255,
360,
3187,
1673,
888,
1673,
3620,
14,
270,
1673,
1205,
358,
267,
327,
5389,
15055,
82,
3449,
267,
1255,
360,
3187,
1673,
888,
1673,
5628,
14,
3543,
1673,
889,
358,
267,
327,
10299,
4691,
562,
11496,
3382,
5389,
503,
295,
1095,
1454,
5419,
315,
6135,
690,
499,
14,
16,
12,
675,
376,
5162,
367,
413,
267,
1255,
360,
3187,
1673,
888,
1673,
9302,
14,
556,
1673,
2118,
358,
267,
1255,
360,
3187,
1673,
888,
1673,
3620,
14,
1168,
1673,
9302,
1553,
556,
13,
2118,
358,
267,
876,
63,
5335,
63,
515,
275,
747,
14,
515,
14,
904,
8,
3187,
63,
694,
12,
1987,
3187,
15,
7922,
15,
657,
13,
5335,
358,
267,
1551,
8,
657,
63,
5335,
63,
515,
2584,
87,
1959,
952,
8,
20072,
63,
28706,
51,
63,
4225,
63,
21378,
14,
1913,
1012,
267,
747,
14,
11693,
8,
657,
63,
5335,
63,
515,
12,
378,
12315,
9,
267,
327,
3272,
28811,
3982,
267,
1255,
360,
3187,
1673,
888,
1673,
3846,
14,
22058,
14,
633,
1673,
2859,
921,
5031,
14,
957,
15,
22058,
15,
22058,
14,
3187,
358,
267,
1255,
360,
3187,
1673,
888,
1673,
3846,
14,
22058,
14,
5335,
633,
1673,
3187,
32,
5031,
14,
957,
26,
22058,
15,
22058,
14,
3187,
358,
267,
1255,
360,
3187,
1673,
888,
28280,
525,
1673,
3846,
14,
22058,
14,
3535,
1673,
5869,
358,
267,
1255,
360,
3187,
1673,
888,
28280,
16787,
13,
452,
1673,
3846,
14,
22058,
14,
3535,
358,
267,
1255,
360,
3187,
1673,
888,
28280,
525,
1673,
3846,
14,
22058,
14,
3535,
1673,
11,
7655,
15,
17033,
6331,
26,
7655,
15,
21420,
744,
15,
22058,
6331,
358,
267,
327,
3272,
28811,
13,
2374,
3982,
267,
1255,
360,
3187,
1673,
888,
1673,
3846,
14,
22058,
13,
2374,
14,
633,
1673,
2859,
921,
5031,
14,
957,
15,
22058,
13,
2374,
15,
22058,
14,
3187,
358,
267,
1255,
360,
3187,
1673,
888,
1673,
3846,
14,
22058,
13,
2374,
14,
5335,
633,
1673,
3187,
32,
5031,
14,
957,
26,
22058,
13,
2374,
15,
22058,
14,
3187,
358,
267,
1255,
360,
3187,
1673,
3846,
1673,
873,
358,
267,
327,
3272,
1616,
14,
16,
5246,
267,
1255,
360,
3187,
1673,
888,
1673,
4694,
14,
709,
14,
16,
14,
3846,
1673,
22058,
358,
267,
1255,
360,
3187,
1673,
888,
1673,
4694,
14,
709,
14,
16,
14,
5628,
1673,
7655,
15,
17033,
15,
709,
14,
16,
358,
267,
1255,
360,
3187,
1673,
12891,
1673,
709,
14,
16,
358,
272,
587,
26,
267,
870,
70,
360,
889,
6135,
3831,
1911,
358,
199,
199,
318,
2088,
63,
2758,
63,
3187,
63,
2374,
837,
272,
6135,
63,
694,
275,
6135,
63,
6280,
342,
272,
340,
6135,
63,
694,
26,
267,
327,
3272,
28811,
13,
2374,
0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1,
1
] |
cyberark-bizdev/ansible
|
lib/ansible/modules/network/f5/bigip_snmp.py
|
23
|
8174
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2017 F5 Networks Inc.
# GNU General Public License v3.0 (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = r'''
module: bigip_snmp
short_description: Manipulate general SNMP settings on a BIG-IP
description:
- Manipulate general SNMP settings on a BIG-IP.
version_added: 2.4
options:
contact:
description:
- Specifies the name of the person who administers the SNMP
service for this system.
agent_status_traps:
description:
- When C(enabled), ensures that the system sends a trap whenever the
SNMP agent starts running or stops running. This is usually enabled
by default on a BIG-IP.
choices:
- enabled
- disabled
agent_authentication_traps:
description:
- When C(enabled), ensures that the system sends authentication warning
traps to the trap destinations. This is usually disabled by default on
a BIG-IP.
choices:
- enabled
- disabled
device_warning_traps:
description:
- When C(enabled), ensures that the system sends device warning traps
to the trap destinations. This is usually enabled by default on a
BIG-IP.
choices:
- enabled
- disabled
location:
description:
- Specifies the description of this system's physical location.
extends_documentation_fragment: f5
author:
- Tim Rupp (@caphrim007)
'''
EXAMPLES = r'''
- name: Set snmp contact
bigip_snmp:
contact: Joe User
password: secret
server: lb.mydomain.com
user: admin
validate_certs: false
delegate_to: localhost
- name: Set snmp location
bigip_snmp:
location: US West 1
password: secret
server: lb.mydomain.com
user: admin
validate_certs: no
delegate_to: localhost
'''
RETURN = r'''
agent_status_traps:
description: Value that the agent status traps was set to.
returned: changed
type: string
sample: enabled
agent_authentication_traps:
description: Value that the authentication status traps was set to.
returned: changed
type: string
sample: enabled
device_warning_traps:
description: Value that the warning status traps was set to.
returned: changed
type: string
sample: enabled
contact:
description: The new value for the person who administers SNMP on the device.
returned: changed
type: string
sample: Joe User
location:
description: The new value for the system's physical location.
returned: changed
type: string
sample: US West 1a
'''
from ansible.module_utils.basic import AnsibleModule
HAS_DEVEL_IMPORTS = False
try:
# Sideband repository used for dev
from library.module_utils.network.f5.bigip import HAS_F5SDK
from library.module_utils.network.f5.bigip import F5Client
from library.module_utils.network.f5.common import F5ModuleError
from library.module_utils.network.f5.common import AnsibleF5Parameters
from library.module_utils.network.f5.common import cleanup_tokens
from library.module_utils.network.f5.common import fqdn_name
from library.module_utils.network.f5.common import f5_argument_spec
try:
from library.module_utils.network.f5.common import iControlUnexpectedHTTPError
except ImportError:
HAS_F5SDK = False
HAS_DEVEL_IMPORTS = True
except ImportError:
# Upstream Ansible
from ansible.module_utils.network.f5.bigip import HAS_F5SDK
from ansible.module_utils.network.f5.bigip import F5Client
from ansible.module_utils.network.f5.common import F5ModuleError
from ansible.module_utils.network.f5.common import AnsibleF5Parameters
from ansible.module_utils.network.f5.common import cleanup_tokens
from ansible.module_utils.network.f5.common import fqdn_name
from ansible.module_utils.network.f5.common import f5_argument_spec
try:
from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError
except ImportError:
HAS_F5SDK = False
class Parameters(AnsibleF5Parameters):
api_map = {
'agentTrap': 'agent_status_traps',
'authTrap': 'agent_authentication_traps',
'bigipTraps': 'device_warning_traps',
'sysLocation': 'location',
'sysContact': 'contact'
}
updatables = [
'agent_status_traps', 'agent_authentication_traps',
'device_warning_traps', 'location', 'contact'
]
returnables = [
'agent_status_traps', 'agent_authentication_traps',
'device_warning_traps', 'location', 'contact'
]
api_attributes = [
'agentTrap', 'authTrap', 'bigipTraps', 'sysLocation', 'sysContact'
]
def to_return(self):
result = {}
for returnable in self.returnables:
result[returnable] = getattr(self, returnable)
result = self._filter_params(result)
return result
class Changes(Parameters):
pass
class ModuleManager(object):
def __init__(self, *args, **kwargs):
self.module = kwargs.get('module', None)
self.client = kwargs.get('client', None)
self.have = None
self.want = Parameters(params=self.module.params)
self.changes = Changes()
def _update_changed_options(self):
changed = {}
for key in Parameters.updatables:
if getattr(self.want, key) is not None:
attr1 = getattr(self.want, key)
attr2 = getattr(self.have, key)
if attr1 != attr2:
changed[key] = attr1
if changed:
self.changes = Changes(params=changed)
return True
return False
def exec_module(self):
result = dict()
try:
changed = self.update()
except iControlUnexpectedHTTPError as e:
raise F5ModuleError(str(e))
changes = self.changes.to_return()
result.update(**changes)
result.update(dict(changed=changed))
return result
def should_update(self):
result = self._update_changed_options()
if result:
return True
return False
def update(self):
self.have = self.read_current_from_device()
if not self.should_update():
return False
if self.module.check_mode:
return True
self.update_on_device()
return True
def update_on_device(self):
params = self.want.api_params()
result = self.client.api.tm.sys.snmp.load()
result.modify(**params)
def read_current_from_device(self):
resource = self.client.api.tm.sys.snmp.load()
result = resource.attrs
return Parameters(params=result)
class ArgumentSpec(object):
def __init__(self):
self.supports_check_mode = True
self.choices = ['enabled', 'disabled']
argument_spec = dict(
contact=dict(),
agent_status_traps=dict(
choices=self.choices
),
agent_authentication_traps=dict(
choices=self.choices
),
device_warning_traps=dict(
choices=self.choices
),
location=dict()
)
self.argument_spec = {}
self.argument_spec.update(f5_argument_spec)
self.argument_spec.update(argument_spec)
def main():
spec = ArgumentSpec()
module = AnsibleModule(
argument_spec=spec.argument_spec,
supports_check_mode=spec.supports_check_mode
)
if not HAS_F5SDK:
module.fail_json(msg="The python f5-sdk module is required")
try:
client = F5Client(**module.params)
mm = ModuleManager(module=module, client=client)
results = mm.exec_module()
cleanup_tokens(client)
module.exit_json(**results)
except F5ModuleError as ex:
cleanup_tokens(client)
module.fail_json(msg=str(ex))
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
334,
67,
9,
9708,
481,
21,
17138,
3277,
14,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
421,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
199,
199,
8948,
275,
519,
2344,
199,
578,
26,
27281,
63,
15523,
199,
3612,
63,
1802,
26,
4688,
711,
5434,
8605,
26549,
2202,
641,
282,
16524,
13,
1772,
199,
1802,
26,
523,
446,
4688,
711,
5434,
8605,
26549,
2202,
641,
282,
16524,
13,
1772,
14,
199,
1023,
63,
3270,
26,
499,
14,
20,
199,
1419,
26,
523,
8966,
26,
272,
1369,
26,
489,
446,
11015,
314,
536,
402,
314,
4954,
3963,
4628,
14186,
314,
26549,
267,
2435,
367,
642,
2656,
14,
523,
6631,
63,
1205,
63,
1239,
1190,
26,
272,
1369,
26,
489,
446,
3979,
445,
8,
3827,
395,
15620,
626,
314,
2656,
16178,
282,
22514,
18119,
314,
267,
26549,
6631,
9174,
3879,
503,
20922,
3879,
14,
961,
365,
9987,
5223,
267,
701,
849,
641,
282,
16524,
13,
1772,
14,
272,
3415,
26,
489,
446,
5223,
489,
446,
6980,
523,
6631,
63,
11725,
63,
1239,
1190,
26,
272,
1369,
26,
489,
446,
3979,
445,
8,
3827,
395,
15620,
626,
314,
2656,
16178,
6299,
5721,
267,
1468,
1190,
370,
314,
22514,
2053,
9511,
14,
961,
365,
9987,
6980,
701,
849,
641,
267,
282,
16524,
13,
1772,
14,
272,
3415,
26,
489,
446,
5223,
489,
446,
6980,
523,
2243,
63,
3764,
63,
1239,
1190,
26,
272,
1369,
26,
489,
446,
3979,
445,
8,
3827,
395,
15620,
626,
314,
2656,
16178,
2243,
5721,
1468,
1190,
267,
370,
314,
22514,
2053,
9511,
14,
961,
365,
9987,
5223,
701,
849,
641,
282,
267,
16524,
13,
1772,
14,
272,
3415,
26,
489,
446,
5223,
489,
446,
6980,
523,
2909,
26,
272,
1369,
26,
489,
446,
11015,
314,
1369,
402,
642,
2656,
1159,
14095,
2909,
14,
199,
11036,
63,
9970,
63,
7677,
26,
289,
21,
199,
2502,
26,
523,
446,
26244,
820,
384,
80,
8593,
2874,
72,
31898,
8255,
9,
199,
2344,
199,
199,
8918,
275,
519,
2344,
199,
13,
536,
26,
2494,
20143,
8966,
523,
27281,
63,
15523,
26,
272,
8966,
26,
7135,
69,
2876,
272,
2505,
26,
7565,
272,
1654,
26,
11104,
14,
30945,
14,
957,
272,
922,
26,
4628,
272,
4107,
63,
8356,
26,
3055,
523,
13080,
63,
475,
26,
11667,
199,
199,
13,
536,
26,
2494,
20143,
2909,
523,
27281,
63,
15523,
26,
272,
2909,
26,
19635,
644,
597,
413,
272,
2505,
26,
7565,
272,
1654,
26,
11104,
14,
30945,
14,
957,
272,
922,
26,
4628,
272,
4107,
63,
8356,
26,
949,
523,
13080,
63,
475,
26,
11667,
199,
2344,
199,
199,
9677,
275,
519,
2344,
199,
4054,
63,
1205,
63,
1239,
1190,
26,
523,
1369,
26,
1594,
626,
314,
6631,
2004,
1468,
1190,
1990,
663,
370,
14,
523,
2138,
26,
2896,
523,
730,
26,
1059,
523,
2690,
26,
5223,
199,
4054,
63,
11725,
63,
1239,
1190,
26,
523,
1369,
26,
1594,
626,
314,
6299,
2004,
1468,
1190,
1990,
663,
370,
14,
523,
2138,
26,
2896,
523,
730,
26,
1059,
523,
2690,
26,
5223,
199,
1782,
63,
3764,
63,
1239,
1190,
26,
523,
1369,
26,
1594,
626,
314,
5721,
2004,
1468,
1190,
1990,
663,
370,
14,
523,
2138,
26,
2896,
523,
730,
26,
1059,
523,
2690,
26,
5223,
199,
7811,
26,
523,
1369,
26,
710,
892,
574,
367,
314,
4954,
3963,
4628,
14186,
26549,
641,
314,
2243,
14,
523,
2138,
26,
2896,
523,
730,
26,
1059,
523,
2690,
26,
7135,
69,
2876,
199,
1985,
26,
523,
1369,
26,
710,
892,
574,
367,
314,
2656,
1159,
14095,
2909,
14,
523,
2138,
26,
2896,
523,
730,
26,
1059,
523,
2690,
26,
19635,
644,
597,
413,
65,
199,
2344,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
199,
13533,
63,
1093,
10429,
63,
17576,
51,
275,
756,
199,
199,
893,
26,
272,
327,
428,
2655,
7877,
7611,
1202,
367,
4866,
272,
687,
3555,
14,
578,
63,
1208,
14,
1200,
14,
70,
21,
14,
17833,
492,
7509,
63,
38,
21,
14939,
272,
687,
3555,
14,
578,
63,
1208,
14,
1200,
14,
70,
21,
14,
17833,
492,
481,
21,
3041,
272,
687,
3555,
14,
578,
63,
1208,
14,
1200,
14,
70,
21,
14,
2330,
492,
481,
21,
12232,
272,
687,
3555,
14,
578,
63,
1208,
14,
1200,
14,
70,
21,
14,
2330,
492,
2622,
38,
21,
5976,
272,
687,
3555,
14,
578,
63,
1208,
14,
1200,
14,
70,
21,
14,
2330,
492,
9058,
63,
4504,
272,
687,
3555,
14,
578,
63,
1208,
14,
1200,
14,
70,
21,
14,
2330,
492,
31039,
63,
354,
272,
687,
3555,
14,
578,
63,
1208,
14,
1200,
14,
70,
21,
14,
2330,
492,
289,
21,
63,
2094,
63,
1650,
272,
862,
26,
267,
687,
3555,
14,
578,
63,
1208,
14,
1200,
14,
70,
21,
14,
2330,
492,
284,
3717,
8708,
12815,
272,
871,
3545,
26,
267,
7509,
63,
38,
21,
14939,
275,
756,
272,
7509,
63,
1093,
10429,
63,
17576,
51,
275,
715,
199,
2590,
3545,
26,
272,
327,
4949,
1745,
2622,
272,
687,
3242,
14,
578,
63,
1208,
14,
1200,
14,
70,
21,
14,
17833,
492,
7509,
63,
38,
21,
14939,
272,
687,
3242,
14,
578,
63,
1208,
14,
1200,
14,
70,
21,
14,
17833,
492,
481,
21,
3041,
272,
687,
3242,
14,
578,
63,
1208,
14,
1200,
14,
70,
21,
14,
2330,
492,
481,
21,
12232,
272,
687,
3242,
14,
578,
63,
1208,
14,
1200,
14,
70,
21,
14,
2330,
492,
2622,
38,
21,
5976,
272,
687,
3242,
14,
578,
63,
1208,
14,
1200,
14,
70,
21,
14,
2330,
492,
9058,
63,
4504,
272,
687,
3242,
14,
578,
63,
1208,
14,
1200,
14,
70,
21,
14,
2330,
492,
31039,
63,
354,
272,
687,
3242,
14
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
334,
67,
9,
9708,
481,
21,
17138,
3277,
14,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
421,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
199,
199,
8948,
275,
519,
2344,
199,
578,
26,
27281,
63,
15523,
199,
3612,
63,
1802,
26,
4688,
711,
5434,
8605,
26549,
2202,
641,
282,
16524,
13,
1772,
199,
1802,
26,
523,
446,
4688,
711,
5434,
8605,
26549,
2202,
641,
282,
16524,
13,
1772,
14,
199,
1023,
63,
3270,
26,
499,
14,
20,
199,
1419,
26,
523,
8966,
26,
272,
1369,
26,
489,
446,
11015,
314,
536,
402,
314,
4954,
3963,
4628,
14186,
314,
26549,
267,
2435,
367,
642,
2656,
14,
523,
6631,
63,
1205,
63,
1239,
1190,
26,
272,
1369,
26,
489,
446,
3979,
445,
8,
3827,
395,
15620,
626,
314,
2656,
16178,
282,
22514,
18119,
314,
267,
26549,
6631,
9174,
3879,
503,
20922,
3879,
14,
961,
365,
9987,
5223,
267,
701,
849,
641,
282,
16524,
13,
1772,
14,
272,
3415,
26,
489,
446,
5223,
489,
446,
6980,
523,
6631,
63,
11725,
63,
1239,
1190,
26,
272,
1369,
26,
489,
446,
3979,
445,
8,
3827,
395,
15620,
626,
314,
2656,
16178,
6299,
5721,
267,
1468,
1190,
370,
314,
22514,
2053,
9511,
14,
961,
365,
9987,
6980,
701,
849,
641,
267,
282,
16524,
13,
1772,
14,
272,
3415,
26,
489,
446,
5223,
489,
446,
6980,
523,
2243,
63,
3764,
63,
1239,
1190,
26,
272,
1369,
26,
489,
446,
3979,
445,
8,
3827,
395,
15620,
626,
314,
2656,
16178,
2243,
5721,
1468,
1190,
267,
370,
314,
22514,
2053,
9511,
14,
961,
365,
9987,
5223,
701,
849,
641,
282,
267,
16524,
13,
1772,
14,
272,
3415,
26,
489,
446,
5223,
489,
446,
6980,
523,
2909,
26,
272,
1369,
26,
489,
446,
11015,
314,
1369,
402,
642,
2656,
1159,
14095,
2909,
14,
199,
11036,
63,
9970,
63,
7677,
26,
289,
21,
199,
2502,
26,
523,
446,
26244,
820,
384,
80,
8593,
2874,
72,
31898,
8255,
9,
199,
2344,
199,
199,
8918,
275,
519,
2344,
199,
13,
536,
26,
2494,
20143,
8966,
523,
27281,
63,
15523,
26,
272,
8966,
26,
7135,
69,
2876,
272,
2505,
26,
7565,
272,
1654,
26,
11104,
14,
30945,
14,
957,
272,
922,
26,
4628,
272,
4107,
63,
8356,
26,
3055,
523,
13080,
63,
475,
26,
11667,
199,
199,
13,
536,
26,
2494,
20143,
2909,
523,
27281,
63,
15523,
26,
272,
2909,
26,
19635,
644,
597,
413,
272,
2505,
26,
7565,
272,
1654,
26,
11104,
14,
30945,
14,
957,
272,
922,
26,
4628,
272,
4107,
63,
8356,
26,
949,
523,
13080,
63,
475,
26,
11667,
199,
2344,
199,
199,
9677,
275,
519,
2344,
199,
4054,
63,
1205,
63,
1239,
1190,
26,
523,
1369,
26,
1594,
626,
314,
6631,
2004,
1468,
1190,
1990,
663,
370,
14,
523,
2138,
26,
2896,
523,
730,
26,
1059,
523,
2690,
26,
5223,
199,
4054,
63,
11725,
63,
1239,
1190,
26,
523,
1369,
26,
1594,
626,
314,
6299,
2004,
1468,
1190,
1990,
663,
370,
14,
523,
2138,
26,
2896,
523,
730,
26,
1059,
523,
2690,
26,
5223,
199,
1782,
63,
3764,
63,
1239,
1190,
26,
523,
1369,
26,
1594,
626,
314,
5721,
2004,
1468,
1190,
1990,
663,
370,
14,
523,
2138,
26,
2896,
523,
730,
26,
1059,
523,
2690,
26,
5223,
199,
7811,
26,
523,
1369,
26,
710,
892,
574,
367,
314,
4954,
3963,
4628,
14186,
26549,
641,
314,
2243,
14,
523,
2138,
26,
2896,
523,
730,
26,
1059,
523,
2690,
26,
7135,
69,
2876,
199,
1985,
26,
523,
1369,
26,
710,
892,
574,
367,
314,
2656,
1159,
14095,
2909,
14,
523,
2138,
26,
2896,
523,
730,
26,
1059,
523,
2690,
26,
19635,
644,
597,
413,
65,
199,
2344,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
199,
13533,
63,
1093,
10429,
63,
17576,
51,
275,
756,
199,
199,
893,
26,
272,
327,
428,
2655,
7877,
7611,
1202,
367,
4866,
272,
687,
3555,
14,
578,
63,
1208,
14,
1200,
14,
70,
21,
14,
17833,
492,
7509,
63,
38,
21,
14939,
272,
687,
3555,
14,
578,
63,
1208,
14,
1200,
14,
70,
21,
14,
17833,
492,
481,
21,
3041,
272,
687,
3555,
14,
578,
63,
1208,
14,
1200,
14,
70,
21,
14,
2330,
492,
481,
21,
12232,
272,
687,
3555,
14,
578,
63,
1208,
14,
1200,
14,
70,
21,
14,
2330,
492,
2622,
38,
21,
5976,
272,
687,
3555,
14,
578,
63,
1208,
14,
1200,
14,
70,
21,
14,
2330,
492,
9058,
63,
4504,
272,
687,
3555,
14,
578,
63,
1208,
14,
1200,
14,
70,
21,
14,
2330,
492,
31039,
63,
354,
272,
687,
3555,
14,
578,
63,
1208,
14,
1200,
14,
70,
21,
14,
2330,
492,
289,
21,
63,
2094,
63,
1650,
272,
862,
26,
267,
687,
3555,
14,
578,
63,
1208,
14,
1200,
14,
70,
21,
14,
2330,
492,
284,
3717,
8708,
12815,
272,
871,
3545,
26,
267,
7509,
63,
38,
21,
14939,
275,
756,
272,
7509,
63,
1093,
10429,
63,
17576,
51,
275,
715,
199,
2590,
3545,
26,
272,
327,
4949,
1745,
2622,
272,
687,
3242,
14,
578,
63,
1208,
14,
1200,
14,
70,
21,
14,
17833,
492,
7509,
63,
38,
21,
14939,
272,
687,
3242,
14,
578,
63,
1208,
14,
1200,
14,
70,
21,
14,
17833,
492,
481,
21,
3041,
272,
687,
3242,
14,
578,
63,
1208,
14,
1200,
14,
70,
21,
14,
2330,
492,
481,
21,
12232,
272,
687,
3242,
14,
578,
63,
1208,
14,
1200,
14,
70,
21,
14,
2330,
492,
2622,
38,
21,
5976,
272,
687,
3242,
14,
578,
63,
1208,
14,
1200,
14,
70,
21,
14,
2330,
492,
9058,
63,
4504,
272,
687,
3242,
14,
578,
63,
1208,
14,
1200,
14,
70,
21,
14,
2330,
492,
31039,
63,
354,
272,
687,
3242,
14,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
venmo/ansible
|
lib/ansible/module_utils/gce.py
|
305
|
4179
|
# This code is part of Ansible, but is an independent component.
# This particular file snippet, and this file snippet only, is BSD licensed.
# Modules you write using this snippet, which is embedded dynamically by Ansible
# still belong to the author of the module, and may assign their own license
# to the complete work.
#
# Copyright (c), Franck Cuny <franck.cuny@gmail.com>, 2014
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
import pprint
USER_AGENT_PRODUCT="Ansible-gce"
USER_AGENT_VERSION="v1"
def gce_connect(module, provider=None):
"""Return a Google Cloud Engine connection."""
service_account_email = module.params.get('service_account_email', None)
pem_file = module.params.get('pem_file', None)
project_id = module.params.get('project_id', None)
# If any of the values are not given as parameters, check the appropriate
# environment variables.
if not service_account_email:
service_account_email = os.environ.get('GCE_EMAIL', None)
if not project_id:
project_id = os.environ.get('GCE_PROJECT', None)
if not pem_file:
pem_file = os.environ.get('GCE_PEM_FILE_PATH', None)
# If we still don't have one or more of our credentials, attempt to
# get the remaining values from the libcloud secrets file.
if service_account_email is None or pem_file is None:
try:
import secrets
except ImportError:
secrets = None
if hasattr(secrets, 'GCE_PARAMS'):
if not service_account_email:
service_account_email = secrets.GCE_PARAMS[0]
if not pem_file:
pem_file = secrets.GCE_PARAMS[1]
keyword_params = getattr(secrets, 'GCE_KEYWORD_PARAMS', {})
if not project_id:
project_id = keyword_params.get('project', None)
# If we *still* don't have the credentials we need, then it's time to
# just fail out.
if service_account_email is None or pem_file is None or project_id is None:
module.fail_json(msg='Missing GCE connection parameters in libcloud '
'secrets file.')
return None
# Allow for passing in libcloud Google DNS (e.g, Provider.GOOGLE)
if provider is None:
provider = Provider.GCE
try:
gce = get_driver(provider)(service_account_email, pem_file,
datacenter=module.params.get('zone', None),
project=project_id)
gce.connection.user_agent_append("%s/%s" % (
USER_AGENT_PRODUCT, USER_AGENT_VERSION))
except (RuntimeError, ValueError), e:
module.fail_json(msg=str(e), changed=False)
except Exception, e:
module.fail_json(msg=unexpected_error_msg(e), changed=False)
return gce
def unexpected_error_msg(error):
"""Create an error string based on passed in error."""
return 'Unexpected response: ' + pprint.pformat(vars(error))
|
gpl-3.0
|
[
3,
961,
1233,
365,
1777,
402,
2622,
12,
1325,
365,
376,
12717,
3931,
14,
199,
3,
961,
6770,
570,
17440,
12,
436,
642,
570,
17440,
1454,
12,
365,
6289,
18233,
14,
199,
3,
18167,
1265,
2218,
1808,
642,
17440,
12,
1314,
365,
12169,
18774,
701,
2622,
199,
3,
5139,
13511,
370,
314,
4132,
402,
314,
859,
12,
436,
1443,
5090,
3932,
5705,
4190,
199,
3,
370,
314,
4890,
1736,
14,
199,
3,
199,
3,
1898,
334,
67,
395,
481,
1312,
346,
445,
324,
89,
665,
70,
1312,
346,
14,
67,
324,
89,
32,
6799,
14,
957,
6244,
6927,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
7100,
12,
199,
3,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
199,
3,
199,
3,
259,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
420,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
259,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
4245,
12,
199,
3,
420,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
3794,
199,
3,
420,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
298,
1179,
2281,
2,
2401,
199,
3,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
5292,
199,
3,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
3104,
9315,
9706,
14,
199,
3,
1621,
4825,
6461,
7000,
2334,
5877,
29785,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
199,
3,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
199,
3,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
199,
3,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
199,
3,
5603,
12,
1549,
7056,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
199,
3,
4815,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
3,
199,
199,
646,
10933,
199,
199,
3791,
63,
14565,
63,
14853,
628,
10047,
13,
22833,
2,
199,
3791,
63,
14565,
63,
4612,
628,
86,
17,
2,
199,
199,
318,
21319,
63,
2242,
8,
578,
12,
5022,
29,
403,
304,
272,
408,
1767,
282,
4475,
8142,
12580,
1950,
1041,
272,
2435,
63,
2048,
63,
2123,
275,
859,
14,
1162,
14,
362,
360,
1364,
63,
2048,
63,
2123,
297,
488,
9,
272,
4837,
77,
63,
493,
275,
859,
14,
1162,
14,
362,
360,
13102,
63,
493,
297,
488,
9,
272,
2199,
63,
344,
275,
859,
14,
1162,
14,
362,
360,
1715,
63,
344,
297,
488,
9,
339,
327,
982,
1263,
402,
314,
1338,
787,
440,
1627,
465,
2633,
12,
1104,
314,
5827,
272,
327,
3734,
2860,
14,
272,
340,
440,
2435,
63,
2048,
63,
2123,
26,
267,
2435,
63,
2048,
63,
2123,
275,
747,
14,
2314,
14,
362,
360,
39,
2089,
63,
10089,
297,
488,
9,
272,
340,
440,
2199,
63,
344,
26,
267,
2199,
63,
344,
275,
747,
14,
2314,
14,
362,
360,
39,
2089,
63,
10797,
297,
488,
9,
272,
340,
440,
4837,
77,
63,
493,
26,
267,
4837,
77,
63,
493,
275,
747,
14,
2314,
14,
362,
360,
39,
2089,
63,
24160,
63,
3817,
63,
3243,
297,
488,
9,
339,
327,
982,
781,
5139,
2793,
1133,
1172,
1373,
503,
1655,
402,
4154,
6235,
12,
7427,
370,
272,
327,
664,
314,
7971,
1338,
687,
314,
17069,
25563,
570,
14,
272,
340,
2435,
63,
2048,
63,
2123,
365,
488,
503,
4837,
77,
63,
493,
365,
488,
26,
267,
862,
26,
288,
492,
25563,
267,
871,
3545,
26,
288,
25563,
275,
488,
398,
340,
2688,
8,
16153,
12,
283,
39,
2089,
63,
17978,
735,
288,
340,
440,
2435,
63,
2048,
63,
2123,
26,
355,
2435,
63,
2048,
63,
2123,
275,
25563,
14,
39,
2089,
63,
17978,
59,
16,
61,
288,
340,
440,
4837,
77,
63,
493,
26,
355,
4837,
77,
63,
493,
275,
25563,
14,
39,
2089,
63,
17978,
59,
17,
61,
267,
4252,
63,
1162,
275,
2519,
8,
16153,
12,
283,
39,
2089,
63,
17714,
63,
17978,
297,
5009,
267,
340,
440,
2199,
63,
344,
26,
288,
2199,
63,
344,
275,
4252,
63,
1162,
14,
362,
360,
1715,
297,
488,
9,
339,
327,
982,
781,
627,
32310,
10,
2793,
1133,
1172,
314,
6235,
781,
1929,
12,
2066,
652,
1159,
900,
370,
272,
327,
2951,
2449,
734,
14,
272,
340,
2435,
63,
2048,
63,
2123,
365,
488,
503,
4837,
77,
63,
493,
365,
488,
503,
2199,
63,
344,
365,
488,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
534,
7718,
31556,
1950,
2633,
315,
17069,
283,
2490,
283,
16153,
570,
2659,
267,
372,
488,
339,
327,
9812,
367,
9476,
315,
17069,
4475,
10237,
334,
69,
14,
71,
12,
18489,
14,
24243,
9,
272,
340,
5022,
365,
488,
26,
267,
5022,
275,
18489,
14,
39,
2089,
339,
862,
26,
267,
21319,
275,
664,
63,
3090,
8,
3780,
5130,
1364,
63,
2048,
63,
2123,
12,
4837,
77,
63,
493,
12,
355,
16606,
29,
578,
14,
1162,
14,
362,
360,
2619,
297,
488,
395,
355,
2199,
29,
1715,
63,
344,
9,
267,
21319,
14,
2105,
14,
751,
63,
4054,
63,
740,
3647,
83,
3149,
83,
2,
450,
334,
288,
13044,
63,
14565,
63,
14853,
12,
13044,
63,
14565,
63,
4612,
430,
272,
871,
334,
13281,
12,
1722,
395,
325,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
29,
495,
8,
69,
395,
2896,
29,
797,
9,
272,
871,
2186,
12,
325,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
29,
8953,
63,
705,
63,
1328,
8,
69,
395,
2896,
29,
797,
9,
339,
372,
21319,
199,
199,
318,
10537,
63,
705,
63,
1328,
8,
705,
304,
272,
408,
2499,
376,
1125,
1059,
4079,
641,
3032,
315,
1125,
1041,
272,
372,
283,
8708,
1177,
26,
283,
435,
10933,
14,
24225,
8,
2936,
8,
705,
430,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
961,
1233,
365,
1777,
402,
2622,
12,
1325,
365,
376,
12717,
3931,
14,
199,
3,
961,
6770,
570,
17440,
12,
436,
642,
570,
17440,
1454,
12,
365,
6289,
18233,
14,
199,
3,
18167,
1265,
2218,
1808,
642,
17440,
12,
1314,
365,
12169,
18774,
701,
2622,
199,
3,
5139,
13511,
370,
314,
4132,
402,
314,
859,
12,
436,
1443,
5090,
3932,
5705,
4190,
199,
3,
370,
314,
4890,
1736,
14,
199,
3,
199,
3,
1898,
334,
67,
395,
481,
1312,
346,
445,
324,
89,
665,
70,
1312,
346,
14,
67,
324,
89,
32,
6799,
14,
957,
6244,
6927,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
7100,
12,
199,
3,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
199,
3,
199,
3,
259,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
420,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
259,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
4245,
12,
199,
3,
420,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
3794,
199,
3,
420,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
298,
1179,
2281,
2,
2401,
199,
3,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
5292,
199,
3,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
3104,
9315,
9706,
14,
199,
3,
1621,
4825,
6461,
7000,
2334,
5877,
29785,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
199,
3,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
199,
3,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
199,
3,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
199,
3,
5603,
12,
1549,
7056,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
199,
3,
4815,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
3,
199,
199,
646,
10933,
199,
199,
3791,
63,
14565,
63,
14853,
628,
10047,
13,
22833,
2,
199,
3791,
63,
14565,
63,
4612,
628,
86,
17,
2,
199,
199,
318,
21319,
63,
2242,
8,
578,
12,
5022,
29,
403,
304,
272,
408,
1767,
282,
4475,
8142,
12580,
1950,
1041,
272,
2435,
63,
2048,
63,
2123,
275,
859,
14,
1162,
14,
362,
360,
1364,
63,
2048,
63,
2123,
297,
488,
9,
272,
4837,
77,
63,
493,
275,
859,
14,
1162,
14,
362,
360,
13102,
63,
493,
297,
488,
9,
272,
2199,
63,
344,
275,
859,
14,
1162,
14,
362,
360,
1715,
63,
344,
297,
488,
9,
339,
327,
982,
1263,
402,
314,
1338,
787,
440,
1627,
465,
2633,
12,
1104,
314,
5827,
272,
327,
3734,
2860,
14,
272,
340,
440,
2435,
63,
2048,
63,
2123,
26,
267,
2435,
63,
2048,
63,
2123,
275,
747,
14,
2314,
14,
362,
360,
39,
2089,
63,
10089,
297,
488,
9,
272,
340,
440,
2199,
63,
344,
26,
267,
2199,
63,
344,
275,
747,
14,
2314,
14,
362,
360,
39,
2089,
63,
10797,
297,
488,
9,
272,
340,
440,
4837,
77,
63,
493,
26,
267,
4837,
77,
63,
493,
275,
747,
14,
2314,
14,
362,
360,
39,
2089,
63,
24160,
63,
3817,
63,
3243,
297,
488,
9,
339,
327,
982,
781,
5139,
2793,
1133,
1172,
1373,
503,
1655,
402,
4154,
6235,
12,
7427,
370,
272,
327,
664,
314,
7971,
1338,
687,
314,
17069,
25563,
570,
14,
272,
340,
2435,
63,
2048,
63,
2123,
365,
488,
503,
4837,
77,
63,
493,
365,
488,
26,
267,
862,
26,
288,
492,
25563,
267,
871,
3545,
26,
288,
25563,
275,
488,
398,
340,
2688,
8,
16153,
12,
283,
39,
2089,
63,
17978,
735,
288,
340,
440,
2435,
63,
2048,
63,
2123,
26,
355,
2435,
63,
2048,
63,
2123,
275,
25563,
14,
39,
2089,
63,
17978,
59,
16,
61,
288,
340,
440,
4837,
77,
63,
493,
26,
355,
4837,
77,
63,
493,
275,
25563,
14,
39,
2089,
63,
17978,
59,
17,
61,
267,
4252,
63,
1162,
275,
2519,
8,
16153,
12,
283,
39,
2089,
63,
17714,
63,
17978,
297,
5009,
267,
340,
440,
2199,
63,
344,
26,
288,
2199,
63,
344,
275,
4252,
63,
1162,
14,
362,
360,
1715,
297,
488,
9,
339,
327,
982,
781,
627,
32310,
10,
2793,
1133,
1172,
314,
6235,
781,
1929,
12,
2066,
652,
1159,
900,
370,
272,
327,
2951,
2449,
734,
14,
272,
340,
2435,
63,
2048,
63,
2123,
365,
488,
503,
4837,
77,
63,
493,
365,
488,
503,
2199,
63,
344,
365,
488,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
534,
7718,
31556,
1950,
2633,
315,
17069,
283,
2490,
283,
16153,
570,
2659,
267,
372,
488,
339,
327,
9812,
367,
9476,
315,
17069,
4475,
10237,
334,
69,
14,
71,
12,
18489,
14,
24243,
9,
272,
340,
5022,
365,
488,
26,
267,
5022,
275,
18489,
14,
39,
2089,
339,
862,
26,
267,
21319,
275,
664,
63,
3090,
8,
3780,
5130,
1364,
63,
2048,
63,
2123,
12,
4837,
77,
63,
493,
12,
355,
16606,
29,
578,
14,
1162,
14,
362,
360,
2619,
297,
488,
395,
355,
2199,
29,
1715,
63,
344,
9,
267,
21319,
14,
2105,
14,
751,
63,
4054,
63,
740,
3647,
83,
3149,
83,
2,
450,
334,
288,
13044,
63,
14565,
63,
14853,
12,
13044,
63,
14565,
63,
4612,
430,
272,
871,
334,
13281,
12,
1722,
395,
325,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
29,
495,
8,
69,
395,
2896,
29,
797,
9,
272,
871,
2186,
12,
325,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
29,
8953,
63,
705,
63,
1328,
8,
69,
395,
2896,
29,
797,
9,
339,
372,
21319,
199,
199,
318,
10537,
63,
705,
63,
1328,
8,
705,
304,
272,
408,
2499,
376,
1125,
1059,
4079,
641,
3032,
315,
1125,
1041,
272,
372,
283,
8708,
1177,
26,
283,
435,
10933,
14,
24225,
8,
2936,
8,
705,
430,
199,
32768,
32768,
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,
1,
1,
1,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
def-/commandergenius
|
project/jni/python/src/Demo/sockets/gopher.py
|
47
|
9784
|
#! /usr/bin/env python
# A simple gopher client.
#
# Usage: gopher [ [selector] host [port] ]
import string
import sys
import os
import socket
# Default selector, host and port
DEF_SELECTOR = ''
DEF_HOST = 'gopher.micro.umn.edu'
DEF_PORT = 70
# Recognized file types
T_TEXTFILE = '0'
T_MENU = '1'
T_CSO = '2'
T_ERROR = '3'
T_BINHEX = '4'
T_DOS = '5'
T_UUENCODE = '6'
T_SEARCH = '7'
T_TELNET = '8'
T_BINARY = '9'
T_REDUNDANT = '+'
T_SOUND = 's'
# Dictionary mapping types to strings
typename = {'0': '<TEXT>', '1': '<DIR>', '2': '<CSO>', '3': '<ERROR>', \
'4': '<BINHEX>', '5': '<DOS>', '6': '<UUENCODE>', '7': '<SEARCH>', \
'8': '<TELNET>', '9': '<BINARY>', '+': '<REDUNDANT>', 's': '<SOUND>'}
# Oft-used characters and strings
CRLF = '\r\n'
TAB = '\t'
# Open a TCP connection to a given host and port
def open_socket(host, port):
if not port:
port = DEF_PORT
elif type(port) == type(''):
port = string.atoi(port)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host, port))
return s
# Send a selector to a given host and port, return a file with the reply
def send_request(selector, host, port):
s = open_socket(host, port)
s.send(selector + CRLF)
s.shutdown(1)
return s.makefile('r')
# Get a menu in the form of a list of entries
def get_menu(selector, host, port):
f = send_request(selector, host, port)
list = []
while 1:
line = f.readline()
if not line:
print '(Unexpected EOF from server)'
break
if line[-2:] == CRLF:
line = line[:-2]
elif line[-1:] in CRLF:
line = line[:-1]
if line == '.':
break
if not line:
print '(Empty line from server)'
continue
typechar = line[0]
parts = string.splitfields(line[1:], TAB)
if len(parts) < 4:
print '(Bad line from server: %r)' % (line,)
continue
if len(parts) > 4:
print '(Extra info from server: %r)' % (parts[4:],)
parts.insert(0, typechar)
list.append(parts)
f.close()
return list
# Get a text file as a list of lines, with trailing CRLF stripped
def get_textfile(selector, host, port):
list = []
get_alt_textfile(selector, host, port, list.append)
return list
# Get a text file and pass each line to a function, with trailing CRLF stripped
def get_alt_textfile(selector, host, port, func):
f = send_request(selector, host, port)
while 1:
line = f.readline()
if not line:
print '(Unexpected EOF from server)'
break
if line[-2:] == CRLF:
line = line[:-2]
elif line[-1:] in CRLF:
line = line[:-1]
if line == '.':
break
if line[:2] == '..':
line = line[1:]
func(line)
f.close()
# Get a binary file as one solid data block
def get_binary(selector, host, port):
f = send_request(selector, host, port)
data = f.read()
f.close()
return data
# Get a binary file and pass each block to a function
def get_alt_binary(selector, host, port, func, blocksize):
f = send_request(selector, host, port)
while 1:
data = f.read(blocksize)
if not data:
break
func(data)
# A *very* simple interactive browser
# Browser main command, has default arguments
def browser(*args):
selector = DEF_SELECTOR
host = DEF_HOST
port = DEF_PORT
n = len(args)
if n > 0 and args[0]:
selector = args[0]
if n > 1 and args[1]:
host = args[1]
if n > 2 and args[2]:
port = args[2]
if n > 3:
raise RuntimeError, 'too many args'
try:
browse_menu(selector, host, port)
except socket.error, msg:
print 'Socket error:', msg
sys.exit(1)
except KeyboardInterrupt:
print '\n[Goodbye]'
# Browse a menu
def browse_menu(selector, host, port):
list = get_menu(selector, host, port)
while 1:
print '----- MENU -----'
print 'Selector:', repr(selector)
print 'Host:', host, ' Port:', port
print
for i in range(len(list)):
item = list[i]
typechar, description = item[0], item[1]
print string.rjust(repr(i+1), 3) + ':', description,
if typename.has_key(typechar):
print typename[typechar]
else:
print '<TYPE=' + repr(typechar) + '>'
print
while 1:
try:
str = raw_input('Choice [CR == up a level]: ')
except EOFError:
print
return
if not str:
return
try:
choice = string.atoi(str)
except string.atoi_error:
print 'Choice must be a number; try again:'
continue
if not 0 < choice <= len(list):
print 'Choice out of range; try again:'
continue
break
item = list[choice-1]
typechar = item[0]
[i_selector, i_host, i_port] = item[2:5]
if typebrowser.has_key(typechar):
browserfunc = typebrowser[typechar]
try:
browserfunc(i_selector, i_host, i_port)
except (IOError, socket.error):
print '***', sys.exc_type, ':', sys.exc_value
else:
print 'Unsupported object type'
# Browse a text file
def browse_textfile(selector, host, port):
x = None
try:
p = os.popen('${PAGER-more}', 'w')
x = SaveLines(p)
get_alt_textfile(selector, host, port, x.writeln)
except IOError, msg:
print 'IOError:', msg
if x:
x.close()
f = open_savefile()
if not f:
return
x = SaveLines(f)
try:
get_alt_textfile(selector, host, port, x.writeln)
print 'Done.'
except IOError, msg:
print 'IOError:', msg
x.close()
# Browse a search index
def browse_search(selector, host, port):
while 1:
print '----- SEARCH -----'
print 'Selector:', repr(selector)
print 'Host:', host, ' Port:', port
print
try:
query = raw_input('Query [CR == up a level]: ')
except EOFError:
print
break
query = string.strip(query)
if not query:
break
if '\t' in query:
print 'Sorry, queries cannot contain tabs'
continue
browse_menu(selector + TAB + query, host, port)
# "Browse" telnet-based information, i.e. open a telnet session
def browse_telnet(selector, host, port):
if selector:
print 'Log in as', repr(selector)
if type(port) <> type(''):
port = repr(port)
sts = os.system('set -x; exec telnet ' + host + ' ' + port)
if sts:
print 'Exit status:', sts
# "Browse" a binary file, i.e. save it to a file
def browse_binary(selector, host, port):
f = open_savefile()
if not f:
return
x = SaveWithProgress(f)
get_alt_binary(selector, host, port, x.write, 8*1024)
x.close()
# "Browse" a sound file, i.e. play it or save it
def browse_sound(selector, host, port):
browse_binary(selector, host, port)
# Dictionary mapping types to browser functions
typebrowser = {'0': browse_textfile, '1': browse_menu, \
'4': browse_binary, '5': browse_binary, '6': browse_textfile, \
'7': browse_search, \
'8': browse_telnet, '9': browse_binary, 's': browse_sound}
# Class used to save lines, appending a newline to each line
class SaveLines:
def __init__(self, f):
self.f = f
def writeln(self, line):
self.f.write(line + '\n')
def close(self):
sts = self.f.close()
if sts:
print 'Exit status:', sts
# Class used to save data while showing progress
class SaveWithProgress:
def __init__(self, f):
self.f = f
def write(self, data):
sys.stdout.write('#')
sys.stdout.flush()
self.f.write(data)
def close(self):
print
sts = self.f.close()
if sts:
print 'Exit status:', sts
# Ask for and open a save file, or return None if not to save
def open_savefile():
try:
savefile = raw_input( \
'Save as file [CR == don\'t save; |pipeline or ~user/... OK]: ')
except EOFError:
print
return None
savefile = string.strip(savefile)
if not savefile:
return None
if savefile[0] == '|':
cmd = string.strip(savefile[1:])
try:
p = os.popen(cmd, 'w')
except IOError, msg:
print repr(cmd), ':', msg
return None
print 'Piping through', repr(cmd), '...'
return p
if savefile[0] == '~':
savefile = os.path.expanduser(savefile)
try:
f = open(savefile, 'w')
except IOError, msg:
print repr(savefile), ':', msg
return None
print 'Saving to', repr(savefile), '...'
return f
# Test program
def test():
if sys.argv[4:]:
print 'usage: gopher [ [selector] host [port] ]'
sys.exit(2)
elif sys.argv[3:]:
browser(sys.argv[1], sys.argv[2], sys.argv[3])
elif sys.argv[2:]:
try:
port = string.atoi(sys.argv[2])
selector = ''
host = sys.argv[1]
except string.atoi_error:
selector = sys.argv[1]
host = sys.argv[2]
port = ''
browser(selector, host, port)
elif sys.argv[1:]:
browser('', sys.argv[1])
else:
browser()
# Call the test program as a main program
test()
|
lgpl-2.1
|
[
3168,
1182,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
437,
3486,
486,
411,
2523,
1890,
14,
199,
3,
199,
3,
11028,
26,
486,
411,
2523,
359,
359,
6662,
61,
1591,
359,
719,
61,
1622,
199,
199,
646,
1059,
199,
646,
984,
199,
646,
747,
199,
646,
2838,
199,
199,
3,
3758,
9759,
12,
1591,
436,
1844,
199,
5638,
63,
25691,
275,
2125,
199,
5638,
63,
5449,
258,
275,
283,
71,
411,
2523,
14,
6453,
14,
1307,
14,
8654,
7,
199,
5638,
63,
3657,
258,
275,
10045,
199,
199,
3,
799,
9659,
570,
2943,
199,
52,
63,
3876,
3817,
221,
275,
283,
16,
7,
199,
52,
63,
18223,
420,
275,
283,
17,
7,
199,
52,
63,
3298,
47,
755,
275,
283,
18,
7,
199,
52,
63,
3170,
258,
275,
283,
19,
7,
199,
52,
63,
9431,
21377,
259,
275,
283,
20,
7,
199,
52,
63,
32735,
755,
275,
283,
21,
7,
199,
52,
63,
4622,
742,
6012,
221,
275,
283,
22,
7,
199,
52,
63,
15962,
259,
275,
283,
23,
7,
199,
52,
63,
52,
2901,
7278,
259,
275,
283,
24,
7,
199,
52,
63,
13246,
259,
275,
283,
25,
7,
199,
52,
63,
7387,
6131,
1441,
275,
20246,
199,
52,
63,
4118,
6131,
258,
275,
283,
83,
7,
199,
199,
3,
11932,
4412,
2943,
370,
3326,
199,
18596,
275,
791,
16,
356,
2650,
3876,
4206,
283,
17,
356,
2650,
3022,
4206,
283,
18,
356,
2650,
3298,
47,
4206,
283,
19,
356,
2650,
3170,
4206,
971,
267,
283,
20,
356,
2650,
9431,
21377,
4206,
283,
21,
356,
2650,
32735,
4206,
283,
22,
356,
2650,
4622,
742,
6012,
4206,
283,
23,
356,
2650,
15962,
4206,
971,
267,
283,
24,
356,
2650,
52,
2901,
7278,
4206,
283,
25,
356,
2650,
13246,
4206,
6681,
356,
2650,
7387,
6131,
1441,
4206,
283,
83,
356,
2650,
4118,
6131,
30,
936,
199,
199,
3,
593,
856,
13,
2972,
4110,
436,
3326,
199,
35,
20190,
275,
1557,
82,
60,
78,
7,
199,
10129,
275,
1557,
84,
7,
199,
199,
3,
3232,
282,
13488,
1950,
370,
282,
1627,
1591,
436,
1844,
199,
318,
1551,
63,
3450,
8,
1102,
12,
1844,
304,
272,
340,
440,
1844,
26,
267,
1844,
275,
23566,
63,
3657,
272,
916,
730,
8,
719,
9,
508,
730,
360,
735,
267,
1844,
275,
1059,
14,
11318,
73,
8,
719,
9,
272,
308,
275,
2838,
14,
3450,
8,
3450,
14,
5699,
63,
11367,
12,
2838,
14,
9469,
63,
9484,
9,
272,
308,
14,
2242,
1332,
1102,
12,
1844,
430,
272,
372,
308,
199,
199,
3,
10217,
282,
9759,
370,
282,
1627,
1591,
436,
1844,
12,
372,
282,
570,
543,
314,
9351,
199,
318,
3222,
63,
1069,
8,
6662,
12,
1591,
12,
1844,
304,
272,
308,
275,
1551,
63,
3450,
8,
1102,
12,
1844,
9,
272,
308,
14,
2254,
8,
6662,
435,
25862,
9,
272,
308,
14,
8831,
8,
17,
9,
272,
372,
308,
14,
13941,
360,
82,
358,
199,
199,
3,
2372,
282,
6269,
315,
314,
1824,
402,
282,
769,
402,
4811,
199,
318,
664,
63,
4470,
8,
6662,
12,
1591,
12,
1844,
304,
272,
289,
275,
3222,
63,
1069,
8,
6662,
12,
1591,
12,
1844,
9,
272,
769,
275,
942,
272,
1830,
413,
26,
267,
1004,
275,
289,
14,
6407,
342,
267,
340,
440,
1004,
26,
288,
870,
8189,
8708,
9027,
687,
1654,
3171,
288,
2059,
267,
340,
1004,
1988,
18,
2938,
508,
25862,
26,
288,
1004,
275,
1004,
4439,
18,
61,
267,
916,
1004,
1988,
17,
2938,
315,
25862,
26,
288,
1004,
275,
1004,
4439,
17,
61,
267,
340,
1004,
508,
26351,
288,
2059,
267,
340,
440,
1004,
26,
288,
870,
8189,
4699,
1004,
687,
1654,
3171,
288,
1980,
267,
730,
1560,
275,
1004,
59,
16,
61,
267,
4184,
275,
1059,
14,
1294,
955,
8,
604,
59,
17,
8429,
17916,
9,
267,
340,
822,
8,
4181,
9,
665,
841,
26,
288,
870,
8189,
5725,
1004,
687,
1654,
26,
450,
82,
3171,
450,
334,
604,
4258,
288,
1980,
267,
340,
822,
8,
4181,
9,
690,
841,
26,
288,
870,
8189,
7426,
2256,
687,
1654,
26,
450,
82,
3171,
450,
334,
4181,
59,
20,
8429,
9,
267,
4184,
14,
3176,
8,
16,
12,
730,
1560,
9,
267,
769,
14,
740,
8,
4181,
9,
272,
289,
14,
1600,
342,
272,
372,
769,
199,
199,
3,
2372,
282,
1318,
570,
465,
282,
769,
402,
2385,
12,
543,
8520,
25862,
14489,
199,
318,
664,
63,
505,
493,
8,
6662,
12,
1591,
12,
1844,
304,
272,
769,
275,
942,
272,
664,
63,
4478,
63,
505,
493,
8,
6662,
12,
1591,
12,
1844,
12,
769,
14,
740,
9,
272,
372,
769,
199,
199,
3,
2372,
282,
1318,
570,
436,
986,
1924,
1004,
370,
282,
805,
12,
543,
8520,
25862,
14489,
199,
318,
664,
63,
4478,
63,
505,
493,
8,
6662,
12,
1591,
12,
1844,
12,
2562,
304,
272,
289,
275,
3222,
63,
1069,
8,
6662,
12,
1591,
12,
1844,
9,
272,
1830,
413,
26,
267,
1004,
275,
289,
14,
6407,
342,
267,
340,
440,
1004,
26,
288,
870,
8189,
8708,
9027,
687,
1654,
3171,
288,
2059,
267,
340,
1004,
1988,
18,
2938,
508,
25862,
26,
288,
1004,
275,
1004,
4439,
18,
61,
267,
916,
1004,
1988,
17,
2938,
315,
25862,
26,
288,
1004,
275,
1004,
4439,
17,
61,
267,
340,
1004,
508,
26351,
288,
2059,
267,
340,
1004,
1491,
18,
61,
508,
11541,
356,
288,
1004,
275,
1004,
59,
17,
2938,
267,
2562,
8,
604,
9,
272,
289,
14,
1600,
342,
199,
199,
3,
2372,
282,
3366,
570,
465,
1373,
18609,
666,
1853,
199,
318,
664,
63,
3008,
8,
6662,
12,
1591,
12,
1844,
304,
272,
289,
275,
3222,
63,
1069,
8,
6662,
12,
1591,
12,
1844,
9,
272,
666,
275,
289,
14,
739,
342,
272,
289,
14,
1600,
342,
272,
372,
666,
199,
199,
3,
2372,
282,
3366,
570,
436,
986,
1924,
1853,
370,
282,
805,
199,
318,
664,
63,
4478,
63,
3008,
8,
6662,
12,
1591,
12,
1844,
12,
2562,
12,
27461,
304,
272,
289,
275,
3222,
63,
1069,
8,
6662,
12,
1591,
12,
1844,
9,
272,
1830,
413,
26,
267,
666,
275,
289,
14,
739,
8,
25959,
9,
267,
340,
440,
666,
26,
288,
2059,
267,
2562,
8,
576,
9,
199,
199
] |
[
1182,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
437,
3486,
486,
411,
2523,
1890,
14,
199,
3,
199,
3,
11028,
26,
486,
411,
2523,
359,
359,
6662,
61,
1591,
359,
719,
61,
1622,
199,
199,
646,
1059,
199,
646,
984,
199,
646,
747,
199,
646,
2838,
199,
199,
3,
3758,
9759,
12,
1591,
436,
1844,
199,
5638,
63,
25691,
275,
2125,
199,
5638,
63,
5449,
258,
275,
283,
71,
411,
2523,
14,
6453,
14,
1307,
14,
8654,
7,
199,
5638,
63,
3657,
258,
275,
10045,
199,
199,
3,
799,
9659,
570,
2943,
199,
52,
63,
3876,
3817,
221,
275,
283,
16,
7,
199,
52,
63,
18223,
420,
275,
283,
17,
7,
199,
52,
63,
3298,
47,
755,
275,
283,
18,
7,
199,
52,
63,
3170,
258,
275,
283,
19,
7,
199,
52,
63,
9431,
21377,
259,
275,
283,
20,
7,
199,
52,
63,
32735,
755,
275,
283,
21,
7,
199,
52,
63,
4622,
742,
6012,
221,
275,
283,
22,
7,
199,
52,
63,
15962,
259,
275,
283,
23,
7,
199,
52,
63,
52,
2901,
7278,
259,
275,
283,
24,
7,
199,
52,
63,
13246,
259,
275,
283,
25,
7,
199,
52,
63,
7387,
6131,
1441,
275,
20246,
199,
52,
63,
4118,
6131,
258,
275,
283,
83,
7,
199,
199,
3,
11932,
4412,
2943,
370,
3326,
199,
18596,
275,
791,
16,
356,
2650,
3876,
4206,
283,
17,
356,
2650,
3022,
4206,
283,
18,
356,
2650,
3298,
47,
4206,
283,
19,
356,
2650,
3170,
4206,
971,
267,
283,
20,
356,
2650,
9431,
21377,
4206,
283,
21,
356,
2650,
32735,
4206,
283,
22,
356,
2650,
4622,
742,
6012,
4206,
283,
23,
356,
2650,
15962,
4206,
971,
267,
283,
24,
356,
2650,
52,
2901,
7278,
4206,
283,
25,
356,
2650,
13246,
4206,
6681,
356,
2650,
7387,
6131,
1441,
4206,
283,
83,
356,
2650,
4118,
6131,
30,
936,
199,
199,
3,
593,
856,
13,
2972,
4110,
436,
3326,
199,
35,
20190,
275,
1557,
82,
60,
78,
7,
199,
10129,
275,
1557,
84,
7,
199,
199,
3,
3232,
282,
13488,
1950,
370,
282,
1627,
1591,
436,
1844,
199,
318,
1551,
63,
3450,
8,
1102,
12,
1844,
304,
272,
340,
440,
1844,
26,
267,
1844,
275,
23566,
63,
3657,
272,
916,
730,
8,
719,
9,
508,
730,
360,
735,
267,
1844,
275,
1059,
14,
11318,
73,
8,
719,
9,
272,
308,
275,
2838,
14,
3450,
8,
3450,
14,
5699,
63,
11367,
12,
2838,
14,
9469,
63,
9484,
9,
272,
308,
14,
2242,
1332,
1102,
12,
1844,
430,
272,
372,
308,
199,
199,
3,
10217,
282,
9759,
370,
282,
1627,
1591,
436,
1844,
12,
372,
282,
570,
543,
314,
9351,
199,
318,
3222,
63,
1069,
8,
6662,
12,
1591,
12,
1844,
304,
272,
308,
275,
1551,
63,
3450,
8,
1102,
12,
1844,
9,
272,
308,
14,
2254,
8,
6662,
435,
25862,
9,
272,
308,
14,
8831,
8,
17,
9,
272,
372,
308,
14,
13941,
360,
82,
358,
199,
199,
3,
2372,
282,
6269,
315,
314,
1824,
402,
282,
769,
402,
4811,
199,
318,
664,
63,
4470,
8,
6662,
12,
1591,
12,
1844,
304,
272,
289,
275,
3222,
63,
1069,
8,
6662,
12,
1591,
12,
1844,
9,
272,
769,
275,
942,
272,
1830,
413,
26,
267,
1004,
275,
289,
14,
6407,
342,
267,
340,
440,
1004,
26,
288,
870,
8189,
8708,
9027,
687,
1654,
3171,
288,
2059,
267,
340,
1004,
1988,
18,
2938,
508,
25862,
26,
288,
1004,
275,
1004,
4439,
18,
61,
267,
916,
1004,
1988,
17,
2938,
315,
25862,
26,
288,
1004,
275,
1004,
4439,
17,
61,
267,
340,
1004,
508,
26351,
288,
2059,
267,
340,
440,
1004,
26,
288,
870,
8189,
4699,
1004,
687,
1654,
3171,
288,
1980,
267,
730,
1560,
275,
1004,
59,
16,
61,
267,
4184,
275,
1059,
14,
1294,
955,
8,
604,
59,
17,
8429,
17916,
9,
267,
340,
822,
8,
4181,
9,
665,
841,
26,
288,
870,
8189,
5725,
1004,
687,
1654,
26,
450,
82,
3171,
450,
334,
604,
4258,
288,
1980,
267,
340,
822,
8,
4181,
9,
690,
841,
26,
288,
870,
8189,
7426,
2256,
687,
1654,
26,
450,
82,
3171,
450,
334,
4181,
59,
20,
8429,
9,
267,
4184,
14,
3176,
8,
16,
12,
730,
1560,
9,
267,
769,
14,
740,
8,
4181,
9,
272,
289,
14,
1600,
342,
272,
372,
769,
199,
199,
3,
2372,
282,
1318,
570,
465,
282,
769,
402,
2385,
12,
543,
8520,
25862,
14489,
199,
318,
664,
63,
505,
493,
8,
6662,
12,
1591,
12,
1844,
304,
272,
769,
275,
942,
272,
664,
63,
4478,
63,
505,
493,
8,
6662,
12,
1591,
12,
1844,
12,
769,
14,
740,
9,
272,
372,
769,
199,
199,
3,
2372,
282,
1318,
570,
436,
986,
1924,
1004,
370,
282,
805,
12,
543,
8520,
25862,
14489,
199,
318,
664,
63,
4478,
63,
505,
493,
8,
6662,
12,
1591,
12,
1844,
12,
2562,
304,
272,
289,
275,
3222,
63,
1069,
8,
6662,
12,
1591,
12,
1844,
9,
272,
1830,
413,
26,
267,
1004,
275,
289,
14,
6407,
342,
267,
340,
440,
1004,
26,
288,
870,
8189,
8708,
9027,
687,
1654,
3171,
288,
2059,
267,
340,
1004,
1988,
18,
2938,
508,
25862,
26,
288,
1004,
275,
1004,
4439,
18,
61,
267,
916,
1004,
1988,
17,
2938,
315,
25862,
26,
288,
1004,
275,
1004,
4439,
17,
61,
267,
340,
1004,
508,
26351,
288,
2059,
267,
340,
1004,
1491,
18,
61,
508,
11541,
356,
288,
1004,
275,
1004,
59,
17,
2938,
267,
2562,
8,
604,
9,
272,
289,
14,
1600,
342,
199,
199,
3,
2372,
282,
3366,
570,
465,
1373,
18609,
666,
1853,
199,
318,
664,
63,
3008,
8,
6662,
12,
1591,
12,
1844,
304,
272,
289,
275,
3222,
63,
1069,
8,
6662,
12,
1591,
12,
1844,
9,
272,
666,
275,
289,
14,
739,
342,
272,
289,
14,
1600,
342,
272,
372,
666,
199,
199,
3,
2372,
282,
3366,
570,
436,
986,
1924,
1853,
370,
282,
805,
199,
318,
664,
63,
4478,
63,
3008,
8,
6662,
12,
1591,
12,
1844,
12,
2562,
12,
27461,
304,
272,
289,
275,
3222,
63,
1069,
8,
6662,
12,
1591,
12,
1844,
9,
272,
1830,
413,
26,
267,
666,
275,
289,
14,
739,
8,
25959,
9,
267,
340,
440,
666,
26,
288,
2059,
267,
2562,
8,
576,
9,
199,
199,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
Communities-Communications/cc-odoo
|
addons/website_sale/controllers/main.py
|
7
|
41959
|
# -*- coding: utf-8 -*-
import werkzeug
from openerp import SUPERUSER_ID
from openerp import http
from openerp.http import request
from openerp.tools.translate import _
from openerp.addons.website.models.website import slug
from openerp.addons.web.controllers.main import login_redirect
PPG = 20 # Products Per Page
PPR = 4 # Products Per Row
class table_compute(object):
def __init__(self):
self.table = {}
def _check_place(self, posx, posy, sizex, sizey):
res = True
for y in range(sizey):
for x in range(sizex):
if posx+x>=PPR:
res = False
break
row = self.table.setdefault(posy+y, {})
if row.setdefault(posx+x) is not None:
res = False
break
for x in range(PPR):
self.table[posy+y].setdefault(x, None)
return res
def process(self, products):
# Compute products positions on the grid
minpos = 0
index = 0
maxy = 0
for p in products:
x = min(max(p.website_size_x, 1), PPR)
y = min(max(p.website_size_y, 1), PPR)
if index>=PPG:
x = y = 1
pos = minpos
while not self._check_place(pos%PPR, pos/PPR, x, y):
pos += 1
# if 21st products (index 20) and the last line is full (PPR products in it), break
# (pos + 1.0) / PPR is the line where the product would be inserted
# maxy is the number of existing lines
# + 1.0 is because pos begins at 0, thus pos 20 is actually the 21st block
# and to force python to not round the division operation
if index >= PPG and ((pos + 1.0) / PPR) > maxy:
break
if x==1 and y==1: # simple heuristic for CPU optimization
minpos = pos/PPR
for y2 in range(y):
for x2 in range(x):
self.table[(pos/PPR)+y2][(pos%PPR)+x2] = False
self.table[pos/PPR][pos%PPR] = {
'product': p, 'x':x, 'y': y,
'class': " ".join(map(lambda x: x.html_class or '', p.website_style_ids))
}
if index<=PPG:
maxy=max(maxy,y+(pos/PPR))
index += 1
# Format table according to HTML needs
rows = self.table.items()
rows.sort()
rows = map(lambda x: x[1], rows)
for col in range(len(rows)):
cols = rows[col].items()
cols.sort()
x += len(cols)
rows[col] = [c for c in map(lambda x: x[1], cols) if c != False]
return rows
# TODO keep with input type hidden
class QueryURL(object):
def __init__(self, path='', **args):
self.path = path
self.args = args
def __call__(self, path=None, **kw):
if not path:
path = self.path
for k,v in self.args.items():
kw.setdefault(k,v)
l = []
for k,v in kw.items():
if v:
if isinstance(v, list) or isinstance(v, set):
l.append(werkzeug.url_encode([(k,i) for i in v]))
else:
l.append(werkzeug.url_encode([(k,v)]))
if l:
path += '?' + '&'.join(l)
return path
def get_pricelist():
cr, uid, context, pool = request.cr, request.uid, request.context, request.registry
sale_order = context.get('sale_order')
if sale_order:
pricelist = sale_order.pricelist_id
else:
partner = pool['res.users'].browse(cr, SUPERUSER_ID, uid, context=context).partner_id
pricelist = partner.property_product_pricelist
return pricelist
class website_sale(http.Controller):
def get_pricelist(self):
return get_pricelist()
def get_attribute_value_ids(self, product):
cr, uid, context, pool = request.cr, request.uid, request.context, request.registry
currency_obj = pool['res.currency']
attribute_value_ids = []
visible_attrs = set(l.attribute_id.id
for l in product.attribute_line_ids
if len(l.value_ids) > 1)
if request.website.pricelist_id.id != context['pricelist']:
website_currency_id = request.website.currency_id.id
currency_id = self.get_pricelist().currency_id.id
for p in product.product_variant_ids:
price = currency_obj.compute(cr, uid, website_currency_id, currency_id, p.lst_price)
attribute_value_ids.append([p.id, [v.id for v in p.attribute_value_ids if v.attribute_id.id in visible_attrs], p.price, price])
else:
attribute_value_ids = [[p.id, [v.id for v in p.attribute_value_ids if v.attribute_id.id in visible_attrs], p.price, p.lst_price]
for p in product.product_variant_ids]
return attribute_value_ids
@http.route(['/shop',
'/shop/page/<int:page>',
'/shop/category/<model("product.public.category"):category>',
'/shop/category/<model("product.public.category"):category>/page/<int:page>'
], type='http', auth="public", website=True)
def shop(self, page=0, category=None, search='', **post):
cr, uid, context, pool = request.cr, request.uid, request.context, request.registry
domain = request.website.sale_product_domain()
if search:
for srch in search.split(" "):
domain += ['|', '|', '|', ('name', 'ilike', srch), ('description', 'ilike', srch),
('description_sale', 'ilike', srch), ('product_variant_ids.default_code', 'ilike', srch)]
if category:
domain += [('public_categ_ids', 'child_of', int(category))]
attrib_list = request.httprequest.args.getlist('attrib')
attrib_values = [map(int,v.split("-")) for v in attrib_list if v]
attrib_set = set([v[1] for v in attrib_values])
if attrib_values:
attrib = None
ids = []
for value in attrib_values:
if not attrib:
attrib = value[0]
ids.append(value[1])
elif value[0] == attrib:
ids.append(value[1])
else:
domain += [('attribute_line_ids.value_ids', 'in', ids)]
attrib = value[0]
ids = [value[1]]
if attrib:
domain += [('attribute_line_ids.value_ids', 'in', ids)]
keep = QueryURL('/shop', category=category and int(category), search=search, attrib=attrib_list)
if not context.get('pricelist'):
pricelist = self.get_pricelist()
context['pricelist'] = int(pricelist)
else:
pricelist = pool.get('product.pricelist').browse(cr, uid, context['pricelist'], context)
product_obj = pool.get('product.template')
url = "/shop"
product_count = product_obj.search_count(cr, uid, domain, context=context)
if search:
post["search"] = search
if category:
category = pool['product.public.category'].browse(cr, uid, int(category), context=context)
url = "/shop/category/%s" % slug(category)
pager = request.website.pager(url=url, total=product_count, page=page, step=PPG, scope=7, url_args=post)
product_ids = product_obj.search(cr, uid, domain, limit=PPG, offset=pager['offset'], order='website_published desc, website_sequence desc', context=context)
products = product_obj.browse(cr, uid, product_ids, context=context)
style_obj = pool['product.style']
style_ids = style_obj.search(cr, uid, [], context=context)
styles = style_obj.browse(cr, uid, style_ids, context=context)
category_obj = pool['product.public.category']
category_ids = category_obj.search(cr, uid, [('parent_id', '=', False)], context=context)
categs = category_obj.browse(cr, uid, category_ids, context=context)
attributes_obj = request.registry['product.attribute']
attributes_ids = attributes_obj.search(cr, uid, [], context=context)
attributes = attributes_obj.browse(cr, uid, attributes_ids, context=context)
from_currency = pool.get('product.price.type')._get_field_currency(cr, uid, 'list_price', context)
to_currency = pricelist.currency_id
compute_currency = lambda price: pool['res.currency']._compute(cr, uid, from_currency, to_currency, price, context=context)
values = {
'search': search,
'category': category,
'attrib_values': attrib_values,
'attrib_set': attrib_set,
'pager': pager,
'pricelist': pricelist,
'products': products,
'bins': table_compute().process(products),
'rows': PPR,
'styles': styles,
'categories': categs,
'attributes': attributes,
'compute_currency': compute_currency,
'keep': keep,
'style_in_product': lambda style, product: style.id in [s.id for s in product.website_style_ids],
'attrib_encode': lambda attribs: werkzeug.url_encode([('attrib',i) for i in attribs]),
}
return request.website.render("website_sale.products", values)
@http.route(['/shop/product/<model("product.template"):product>'], type='http', auth="public", website=True)
def product(self, product, category='', search='', **kwargs):
cr, uid, context, pool = request.cr, request.uid, request.context, request.registry
category_obj = pool['product.public.category']
template_obj = pool['product.template']
context.update(active_id=product.id)
if category:
category = category_obj.browse(cr, uid, int(category), context=context)
attrib_list = request.httprequest.args.getlist('attrib')
attrib_values = [map(int,v.split("-")) for v in attrib_list if v]
attrib_set = set([v[1] for v in attrib_values])
keep = QueryURL('/shop', category=category and category.id, search=search, attrib=attrib_list)
category_ids = category_obj.search(cr, uid, [], context=context)
category_list = category_obj.name_get(cr, uid, category_ids, context=context)
category_list = sorted(category_list, key=lambda category: category[1])
pricelist = self.get_pricelist()
from_currency = pool.get('product.price.type')._get_field_currency(cr, uid, 'list_price', context)
to_currency = pricelist.currency_id
compute_currency = lambda price: pool['res.currency']._compute(cr, uid, from_currency, to_currency, price, context=context)
if not context.get('pricelist'):
context['pricelist'] = int(self.get_pricelist())
product = template_obj.browse(cr, uid, int(product), context=context)
values = {
'search': search,
'category': category,
'pricelist': pricelist,
'attrib_values': attrib_values,
'compute_currency': compute_currency,
'attrib_set': attrib_set,
'keep': keep,
'category_list': category_list,
'main_object': product,
'product': product,
'get_attribute_value_ids': self.get_attribute_value_ids
}
return request.website.render("website_sale.product", values)
@http.route(['/shop/product/comment/<int:product_template_id>'], type='http', auth="public", methods=['POST'], website=True)
def product_comment(self, product_template_id, **post):
if not request.session.uid:
return login_redirect()
cr, uid, context = request.cr, request.uid, request.context
if post.get('comment'):
request.registry['product.template'].message_post(
cr, uid, product_template_id,
body=post.get('comment'),
type='comment',
subtype='mt_comment',
context=dict(context, mail_create_nosubscribe=True))
return werkzeug.utils.redirect(request.httprequest.referrer + "#comments")
@http.route(['/shop/pricelist'], type='http', auth="public", website=True)
def pricelist(self, promo, **post):
cr, uid, context = request.cr, request.uid, request.context
request.website.sale_get_order(code=promo, context=context)
return request.redirect("/shop/cart")
@http.route(['/shop/cart'], type='http', auth="public", website=True)
def cart(self, **post):
cr, uid, context, pool = request.cr, request.uid, request.context, request.registry
order = request.website.sale_get_order()
if order:
from_currency = pool.get('product.price.type')._get_field_currency(cr, uid, 'list_price', context)
to_currency = order.pricelist_id.currency_id
compute_currency = lambda price: pool['res.currency']._compute(cr, uid, from_currency, to_currency, price, context=context)
else:
compute_currency = lambda price: price
values = {
'order': order,
'compute_currency': compute_currency,
'suggested_products': [],
}
if order:
_order = order
if not context.get('pricelist'):
_order = order.with_context(pricelist=order.pricelist_id.id)
values['suggested_products'] = _order._cart_accessories()
return request.website.render("website_sale.cart", values)
@http.route(['/shop/cart/update'], type='http', auth="public", methods=['POST'], website=True)
def cart_update(self, product_id, add_qty=1, set_qty=0, **kw):
cr, uid, context = request.cr, request.uid, request.context
request.website.sale_get_order(force_create=1)._cart_update(product_id=int(product_id), add_qty=float(add_qty), set_qty=float(set_qty))
return request.redirect("/shop/cart")
@http.route(['/shop/cart/update_json'], type='json', auth="public", methods=['POST'], website=True)
def cart_update_json(self, product_id, line_id, add_qty=None, set_qty=None, display=True):
order = request.website.sale_get_order(force_create=1)
value = order._cart_update(product_id=product_id, line_id=line_id, add_qty=add_qty, set_qty=set_qty)
if not display:
return None
value['cart_quantity'] = order.cart_quantity
value['website_sale.total'] = request.website._render("website_sale.total", {
'website_sale_order': request.website.sale_get_order()
})
return value
#------------------------------------------------------
# Checkout
#------------------------------------------------------
def checkout_redirection(self, order):
cr, uid, context, registry = request.cr, request.uid, request.context, request.registry
# must have a draft sale order with lines at this point, otherwise reset
if not order or order.state != 'draft':
request.session['sale_order_id'] = None
request.session['sale_transaction_id'] = None
return request.redirect('/shop')
# if transaction pending / done: redirect to confirmation
tx = context.get('website_sale_transaction')
if tx and tx.state != 'draft':
return request.redirect('/shop/payment/confirmation/%s' % order.id)
def checkout_values(self, data=None):
cr, uid, context, registry = request.cr, request.uid, request.context, request.registry
orm_partner = registry.get('res.partner')
orm_user = registry.get('res.users')
orm_country = registry.get('res.country')
state_orm = registry.get('res.country.state')
country_ids = orm_country.search(cr, SUPERUSER_ID, [], context=context)
countries = orm_country.browse(cr, SUPERUSER_ID, country_ids, context)
states_ids = state_orm.search(cr, SUPERUSER_ID, [], context=context)
states = state_orm.browse(cr, SUPERUSER_ID, states_ids, context)
partner = orm_user.browse(cr, SUPERUSER_ID, request.uid, context).partner_id
order = None
shipping_id = None
shipping_ids = []
checkout = {}
if not data:
if request.uid != request.website.user_id.id:
checkout.update( self.checkout_parse("billing", partner) )
shipping_ids = orm_partner.search(cr, SUPERUSER_ID, [("parent_id", "=", partner.id), ('type', "=", 'delivery')], context=context)
else:
order = request.website.sale_get_order(force_create=1, context=context)
if order.partner_id:
domain = [("partner_id", "=", order.partner_id.id)]
user_ids = request.registry['res.users'].search(cr, SUPERUSER_ID, domain, context=dict(context or {}, active_test=False))
if not user_ids or request.website.user_id.id not in user_ids:
checkout.update( self.checkout_parse("billing", order.partner_id) )
else:
checkout = self.checkout_parse('billing', data)
try:
shipping_id = int(data["shipping_id"])
except ValueError:
pass
if shipping_id == -1:
checkout.update(self.checkout_parse('shipping', data))
if shipping_id is None:
if not order:
order = request.website.sale_get_order(context=context)
if order and order.partner_shipping_id:
shipping_id = order.partner_shipping_id.id
shipping_ids = list(set(shipping_ids) - set([partner.id]))
if shipping_id == partner.id:
shipping_id = 0
elif shipping_id > 0 and shipping_id not in shipping_ids:
shipping_ids.append(shipping_id)
elif shipping_id is None and shipping_ids:
shipping_id = shipping_ids[0]
ctx = dict(context, show_address=1)
shippings = []
if shipping_ids:
shippings = shipping_ids and orm_partner.browse(cr, SUPERUSER_ID, list(shipping_ids), ctx) or []
if shipping_id > 0:
shipping = orm_partner.browse(cr, SUPERUSER_ID, shipping_id, ctx)
checkout.update( self.checkout_parse("shipping", shipping) )
checkout['shipping_id'] = shipping_id
# Default search by user country
if not checkout.get('country_id'):
country_code = request.session['geoip'].get('country_code')
if country_code:
country_ids = request.registry.get('res.country').search(cr, uid, [('code', '=', country_code)], context=context)
if country_ids:
checkout['country_id'] = country_ids[0]
values = {
'countries': countries,
'states': states,
'checkout': checkout,
'shipping_id': partner.id != shipping_id and shipping_id or 0,
'shippings': shippings,
'error': {},
'has_check_vat': hasattr(registry['res.partner'], 'check_vat')
}
return values
mandatory_billing_fields = ["name", "phone", "email", "street2", "city", "country_id"]
optional_billing_fields = ["street", "state_id", "vat", "vat_subjected", "zip"]
mandatory_shipping_fields = ["name", "phone", "street", "city", "country_id"]
optional_shipping_fields = ["state_id", "zip"]
def checkout_parse(self, address_type, data, remove_prefix=False):
""" data is a dict OR a partner browse record
"""
# set mandatory and optional fields
assert address_type in ('billing', 'shipping')
if address_type == 'billing':
all_fields = self.mandatory_billing_fields + self.optional_billing_fields
prefix = ''
else:
all_fields = self.mandatory_shipping_fields + self.optional_shipping_fields
prefix = 'shipping_'
# set data
if isinstance(data, dict):
query = dict((prefix + field_name, data[prefix + field_name])
for field_name in all_fields if data.get(prefix + field_name))
else:
query = dict((prefix + field_name, getattr(data, field_name))
for field_name in all_fields if getattr(data, field_name))
if address_type == 'billing' and data.parent_id:
query[prefix + 'street'] = data.parent_id.name
if query.get(prefix + 'state_id'):
query[prefix + 'state_id'] = int(query[prefix + 'state_id'])
if query.get(prefix + 'country_id'):
query[prefix + 'country_id'] = int(query[prefix + 'country_id'])
if query.get(prefix + 'vat'):
query[prefix + 'vat_subjected'] = True
if not remove_prefix:
return query
return dict((field_name, data[prefix + field_name]) for field_name in all_fields if data.get(prefix + field_name))
def checkout_form_validate(self, data):
cr, uid, context, registry = request.cr, request.uid, request.context, request.registry
# Validation
error = dict()
for field_name in self.mandatory_billing_fields:
if not data.get(field_name):
error[field_name] = 'missing'
if data.get("vat") and hasattr(registry["res.partner"], "check_vat"):
if request.website.company_id.vat_check_vies:
# force full VIES online check
check_func = registry["res.partner"].vies_vat_check
else:
# quick and partial off-line checksum validation
check_func = registry["res.partner"].simple_vat_check
vat_country, vat_number = registry["res.partner"]._split_vat(data.get("vat"))
if not check_func(cr, uid, vat_country, vat_number, context=None): # simple_vat_check
error["vat"] = 'error'
if data.get("shipping_id") == -1:
for field_name in self.mandatory_shipping_fields:
field_name = 'shipping_' + field_name
if not data.get(field_name):
error[field_name] = 'missing'
return error
def checkout_form_save(self, checkout):
cr, uid, context, registry = request.cr, request.uid, request.context, request.registry
order = request.website.sale_get_order(force_create=1, context=context)
orm_partner = registry.get('res.partner')
orm_user = registry.get('res.users')
order_obj = request.registry.get('sale.order')
partner_lang = request.lang if request.lang in [lang.code for lang in request.website.language_ids] else None
billing_info = {}
if partner_lang:
billing_info['lang'] = partner_lang
billing_info.update(self.checkout_parse('billing', checkout, True))
# set partner_id
partner_id = None
if request.uid != request.website.user_id.id:
partner_id = orm_user.browse(cr, SUPERUSER_ID, uid, context=context).partner_id.id
elif order.partner_id:
user_ids = request.registry['res.users'].search(cr, SUPERUSER_ID,
[("partner_id", "=", order.partner_id.id)], context=dict(context or {}, active_test=False))
if not user_ids or request.website.user_id.id not in user_ids:
partner_id = order.partner_id.id
# save partner informations
if partner_id and request.website.partner_id.id != partner_id:
orm_partner.write(cr, SUPERUSER_ID, [partner_id], billing_info, context=context)
else:
# create partner
partner_id = orm_partner.create(cr, SUPERUSER_ID, billing_info, context=context)
# create a new shipping partner
if checkout.get('shipping_id') == -1:
shipping_info = {}
if partner_lang:
shipping_info['lang'] = partner_lang
shipping_info.update(self.checkout_parse('shipping', checkout, True))
shipping_info['type'] = 'delivery'
shipping_info['parent_id'] = partner_id
checkout['shipping_id'] = orm_partner.create(cr, SUPERUSER_ID, shipping_info, context)
order_info = {
'partner_id': partner_id,
'message_follower_ids': [(4, partner_id), (3, request.website.partner_id.id)],
'partner_invoice_id': partner_id,
}
order_info.update(order_obj.onchange_partner_id(cr, SUPERUSER_ID, [], partner_id, context=context)['value'])
address_change = order_obj.onchange_delivery_id(cr, SUPERUSER_ID, [], order.company_id.id, partner_id,
checkout.get('shipping_id'), None, context=context)['value']
order_info.update(address_change)
if address_change.get('fiscal_position'):
fiscal_update = order_obj.onchange_fiscal_position(cr, SUPERUSER_ID, [], address_change['fiscal_position'],
[(4, l.id) for l in order.order_line], context=None)['value']
order_info.update(fiscal_update)
order_info.pop('user_id')
order_info.update(partner_shipping_id=checkout.get('shipping_id') or partner_id)
order_obj.write(cr, SUPERUSER_ID, [order.id], order_info, context=context)
@http.route(['/shop/checkout'], type='http', auth="public", website=True)
def checkout(self, **post):
cr, uid, context = request.cr, request.uid, request.context
order = request.website.sale_get_order(force_create=1, context=context)
redirection = self.checkout_redirection(order)
if redirection:
return redirection
values = self.checkout_values()
return request.website.render("website_sale.checkout", values)
@http.route(['/shop/confirm_order'], type='http', auth="public", website=True)
def confirm_order(self, **post):
cr, uid, context, registry = request.cr, request.uid, request.context, request.registry
order = request.website.sale_get_order(context=context)
if not order:
return request.redirect("/shop")
redirection = self.checkout_redirection(order)
if redirection:
return redirection
values = self.checkout_values(post)
values["error"] = self.checkout_form_validate(values["checkout"])
if values["error"]:
return request.website.render("website_sale.checkout", values)
self.checkout_form_save(values["checkout"])
request.session['sale_last_order_id'] = order.id
request.website.sale_get_order(update_pricelist=True, context=context)
return request.redirect("/shop/payment")
#------------------------------------------------------
# Payment
#------------------------------------------------------
@http.route(['/shop/payment'], type='http', auth="public", website=True)
def payment(self, **post):
""" Payment step. This page proposes several payment means based on available
payment.acquirer. State at this point :
- a draft sale order with lines; otherwise, clean context / session and
back to the shop
- no transaction in context / session, or only a draft one, if the customer
did go to a payment.acquirer website but closed the tab without
paying / canceling
"""
cr, uid, context = request.cr, request.uid, request.context
payment_obj = request.registry.get('payment.acquirer')
sale_order_obj = request.registry.get('sale.order')
order = request.website.sale_get_order(context=context)
redirection = self.checkout_redirection(order)
if redirection:
return redirection
shipping_partner_id = False
if order:
if order.partner_shipping_id.id:
shipping_partner_id = order.partner_shipping_id.id
else:
shipping_partner_id = order.partner_invoice_id.id
values = {
'order': request.registry['sale.order'].browse(cr, SUPERUSER_ID, order.id, context=context)
}
values['errors'] = sale_order_obj._get_errors(cr, uid, order, context=context)
values.update(sale_order_obj._get_website_data(cr, uid, order, context))
# fetch all registered payment means
# if tx:
# acquirer_ids = [tx.acquirer_id.id]
# else:
if not values['errors']:
acquirer_ids = payment_obj.search(cr, SUPERUSER_ID, [('website_published', '=', True), ('company_id', '=', order.company_id.id)], context=context)
values['acquirers'] = list(payment_obj.browse(cr, uid, acquirer_ids, context=context))
render_ctx = dict(context, submit_class='btn btn-primary', submit_txt=_('Pay Now'))
for acquirer in values['acquirers']:
acquirer.button = payment_obj.render(
cr, SUPERUSER_ID, acquirer.id,
order.name,
order.amount_total,
order.pricelist_id.currency_id.id,
partner_id=shipping_partner_id,
tx_values={
'return_url': '/shop/payment/validate',
},
context=render_ctx)
return request.website.render("website_sale.payment", values)
@http.route(['/shop/payment/transaction/<int:acquirer_id>'], type='json', auth="public", website=True)
def payment_transaction(self, acquirer_id):
""" Json method that creates a payment.transaction, used to create a
transaction when the user clicks on 'pay now' button. After having
created the transaction, the event continues and the user is redirected
to the acquirer website.
:param int acquirer_id: id of a payment.acquirer record. If not set the
user is redirected to the checkout page
"""
cr, uid, context = request.cr, request.uid, request.context
transaction_obj = request.registry.get('payment.transaction')
order = request.website.sale_get_order(context=context)
if not order or not order.order_line or acquirer_id is None:
return request.redirect("/shop/checkout")
assert order.partner_id.id != request.website.partner_id.id
# find an already existing transaction
tx = request.website.sale_get_transaction()
if tx:
if tx.state == 'draft': # button cliked but no more info -> rewrite on tx or create a new one ?
tx.write({
'acquirer_id': acquirer_id,
})
tx_id = tx.id
else:
tx_id = transaction_obj.create(cr, SUPERUSER_ID, {
'acquirer_id': acquirer_id,
'type': 'form',
'amount': order.amount_total,
'currency_id': order.pricelist_id.currency_id.id,
'partner_id': order.partner_id.id,
'partner_country_id': order.partner_id.country_id.id,
'reference': order.name,
'sale_order_id': order.id,
}, context=context)
request.session['sale_transaction_id'] = tx_id
# update quotation
request.registry['sale.order'].write(
cr, SUPERUSER_ID, [order.id], {
'payment_acquirer_id': acquirer_id,
'payment_tx_id': request.session['sale_transaction_id']
}, context=context)
return tx_id
@http.route('/shop/payment/get_status/<int:sale_order_id>', type='json', auth="public", website=True)
def payment_get_status(self, sale_order_id, **post):
cr, uid, context = request.cr, request.uid, request.context
order = request.registry['sale.order'].browse(cr, SUPERUSER_ID, sale_order_id, context=context)
assert order.id == request.session.get('sale_last_order_id')
if not order:
return {
'state': 'error',
'message': '<p>%s</p>' % _('There seems to be an error with your request.'),
}
tx_ids = request.registry['payment.transaction'].search(
cr, SUPERUSER_ID, [
'|', ('sale_order_id', '=', order.id), ('reference', '=', order.name)
], context=context)
if not tx_ids:
if order.amount_total:
return {
'state': 'error',
'message': '<p>%s</p>' % _('There seems to be an error with your request.'),
}
else:
state = 'done'
message = ""
validation = None
else:
tx = request.registry['payment.transaction'].browse(cr, SUPERUSER_ID, tx_ids[0], context=context)
state = tx.state
if state == 'done':
message = '<p>%s</p>' % _('Your payment has been received.')
elif state == 'cancel':
message = '<p>%s</p>' % _('The payment seems to have been canceled.')
elif state == 'pending' and tx.acquirer_id.validation == 'manual':
message = '<p>%s</p>' % _('Your transaction is waiting confirmation.')
if tx.acquirer_id.post_msg:
message += tx.acquirer_id.post_msg
else:
message = '<p>%s</p>' % _('Your transaction is waiting confirmation.')
validation = tx.acquirer_id.validation
return {
'state': state,
'message': message,
'validation': validation
}
@http.route('/shop/payment/validate', type='http', auth="public", website=True)
def payment_validate(self, transaction_id=None, sale_order_id=None, **post):
""" Method that should be called by the server when receiving an update
for a transaction. State at this point :
- UDPATE ME
"""
cr, uid, context = request.cr, request.uid, request.context
email_act = None
sale_order_obj = request.registry['sale.order']
if transaction_id is None:
tx = request.website.sale_get_transaction()
else:
tx = request.registry['payment.transaction'].browse(cr, uid, transaction_id, context=context)
if sale_order_id is None:
order = request.website.sale_get_order(context=context)
else:
order = request.registry['sale.order'].browse(cr, SUPERUSER_ID, sale_order_id, context=context)
assert order.id == request.session.get('sale_last_order_id')
if not order or (order.amount_total and not tx):
return request.redirect('/shop')
if (not order.amount_total and not tx) or tx.state in ['pending', 'done']:
if (not order.amount_total and not tx):
# Orders are confirmed by payment transactions, but there is none for free orders,
# (e.g. free events), so confirm immediately
order.action_button_confirm()
# send by email
email_act = sale_order_obj.action_quotation_send(cr, SUPERUSER_ID, [order.id], context=request.context)
elif tx and tx.state == 'cancel':
# cancel the quotation
sale_order_obj.action_cancel(cr, SUPERUSER_ID, [order.id], context=request.context)
# send the email
if email_act and email_act.get('context'):
composer_obj = request.registry['mail.compose.message']
composer_values = {}
email_ctx = email_act['context']
template_values = [
email_ctx.get('default_template_id'),
email_ctx.get('default_composition_mode'),
email_ctx.get('default_model'),
email_ctx.get('default_res_id'),
]
composer_values.update(composer_obj.onchange_template_id(cr, SUPERUSER_ID, None, *template_values, context=context).get('value', {}))
if not composer_values.get('email_from') and uid == request.website.user_id.id:
composer_values['email_from'] = request.website.user_id.company_id.email
for key in ['attachment_ids', 'partner_ids']:
if composer_values.get(key):
composer_values[key] = [(6, 0, composer_values[key])]
composer_id = composer_obj.create(cr, SUPERUSER_ID, composer_values, context=email_ctx)
composer_obj.send_mail(cr, SUPERUSER_ID, [composer_id], context=email_ctx)
# clean context and session, then redirect to the confirmation page
request.website.sale_reset(context=context)
return request.redirect('/shop/confirmation')
@http.route(['/shop/confirmation'], type='http', auth="public", website=True)
def payment_confirmation(self, **post):
""" End of checkout process controller. Confirmation is basically seing
the status of a sale.order. State at this point :
- should not have any context / session info: clean them
- take a sale.order id, because we request a sale.order and are not
session dependant anymore
"""
cr, uid, context = request.cr, request.uid, request.context
sale_order_id = request.session.get('sale_last_order_id')
if sale_order_id:
order = request.registry['sale.order'].browse(cr, SUPERUSER_ID, sale_order_id, context=context)
else:
return request.redirect('/shop')
return request.website.render("website_sale.confirmation", {'order': order})
#------------------------------------------------------
# Edit
#------------------------------------------------------
@http.route(['/shop/add_product'], type='http', auth="user", methods=['POST'], website=True)
def add_product(self, name=None, category=0, **post):
cr, uid, context, pool = request.cr, request.uid, request.context, request.registry
if not name:
name = _("New Product")
product_obj = request.registry.get('product.product')
product_id = product_obj.create(cr, uid, { 'name': name, 'public_categ_ids': category }, context=context)
product = product_obj.browse(cr, uid, product_id, context=context)
return request.redirect("/shop/product/%s?enable_editor=1" % slug(product.product_tmpl_id))
@http.route(['/shop/change_styles'], type='json', auth="public")
def change_styles(self, id, style_id):
product_obj = request.registry.get('product.template')
product = product_obj.browse(request.cr, request.uid, id, context=request.context)
remove = []
active = False
for style in product.website_style_ids:
if style.id == style_id:
remove.append(style.id)
active = True
break
style = request.registry.get('product.style').browse(request.cr, request.uid, style_id, context=request.context)
if remove:
product.write({'website_style_ids': [(3, rid) for rid in remove]})
if not active:
product.write({'website_style_ids': [(4, style.id)]})
return not active
@http.route(['/shop/change_sequence'], type='json', auth="public")
def change_sequence(self, id, sequence):
product_obj = request.registry.get('product.template')
if sequence == "top":
product_obj.set_sequence_top(request.cr, request.uid, [id], context=request.context)
elif sequence == "bottom":
product_obj.set_sequence_bottom(request.cr, request.uid, [id], context=request.context)
elif sequence == "up":
product_obj.set_sequence_up(request.cr, request.uid, [id], context=request.context)
elif sequence == "down":
product_obj.set_sequence_down(request.cr, request.uid, [id], context=request.context)
@http.route(['/shop/change_size'], type='json', auth="public")
def change_size(self, id, x, y):
product_obj = request.registry.get('product.template')
product = product_obj.browse(request.cr, request.uid, id, context=request.context)
return product.write({'website_size_x': x, 'website_size_y': y})
def order_lines_2_google_api(self, order_lines):
""" Transforms a list of order lines into a dict for google analytics """
ret = []
for line in order_lines:
ret.append({
'id': line.order_id and line.order_id.id,
'name': line.product_id.categ_id and line.product_id.categ_id.name or '-',
'sku': line.product_id.id,
'quantity': line.product_uom_qty,
'price': line.price_unit,
})
return ret
@http.route(['/shop/tracking_last_order'], type='json', auth="public")
def tracking_cart(self, **post):
""" return data about order in JSON needed for google analytics"""
cr, uid, context = request.cr, request.uid, request.context
ret = {}
sale_order_id = request.session.get('sale_last_order_id')
if sale_order_id:
order = request.registry['sale.order'].browse(cr, SUPERUSER_ID, sale_order_id, context=context)
ret['transaction'] = {
'id': sale_order_id,
'affiliation': order.company_id.name,
'revenue': order.amount_total,
'currency': order.currency_id.name
}
ret['lines'] = self.order_lines_2_google_api(order.order_line)
return ret
# vim:expandtab:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
646,
10380,
199,
199,
504,
5166,
492,
12824,
63,
998,
199,
504,
5166,
492,
1455,
199,
504,
5166,
14,
1014,
492,
1056,
199,
504,
5166,
14,
2537,
14,
5275,
492,
485,
199,
504,
5166,
14,
10788,
14,
7360,
14,
992,
14,
7360,
492,
8889,
199,
504,
5166,
14,
10788,
14,
2520,
14,
20531,
14,
973,
492,
4676,
63,
4876,
199,
199,
7701,
39,
275,
3388,
327,
32411,
3492,
10331,
199,
48,
3311,
275,
841,
221,
327,
32411,
3492,
15231,
199,
199,
533,
1817,
63,
3357,
8,
785,
304,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
1224,
275,
1052,
339,
347,
485,
1074,
63,
2778,
8,
277,
12,
2086,
88,
12,
2086,
89,
12,
308,
565,
476,
12,
1568,
89,
304,
267,
522,
275,
715,
267,
367,
612,
315,
1425,
8,
890,
89,
304,
288,
367,
671,
315,
1425,
8,
5946,
476,
304,
355,
340,
2086,
88,
11,
88,
8119,
48,
3311,
26,
490,
522,
275,
756,
490,
2059,
355,
1962,
275,
291,
14,
1224,
14,
5486,
8,
1712,
89,
11,
89,
12,
5009,
355,
340,
1962,
14,
5486,
8,
32405,
11,
88,
9,
365,
440,
488,
26,
490,
522,
275,
756,
490,
2059,
288,
367,
671,
315,
1425,
8,
48,
3311,
304,
355,
291,
14,
1224,
59,
1712,
89,
11,
89,
1055,
5486,
8,
88,
12,
488,
9,
267,
372,
522,
339,
347,
2112,
8,
277,
12,
7585,
304,
267,
327,
8354,
7585,
12266,
641,
314,
6068,
267,
1748,
1712,
275,
378,
267,
1478,
275,
378,
267,
1390,
89,
275,
378,
267,
367,
299,
315,
7585,
26,
288,
671,
275,
1748,
8,
988,
8,
80,
14,
7360,
63,
890,
63,
88,
12,
413,
395,
510,
3311,
9,
288,
612,
275,
1748,
8,
988,
8,
80,
14,
7360,
63,
890,
63,
89,
12,
413,
395,
510,
3311,
9,
288,
340,
1478,
8119,
7701,
39,
26,
355,
671,
275,
612,
275,
413,
953,
2086,
275,
1748,
1712,
288,
1830,
440,
291,
423,
1074,
63,
2778,
8,
1712,
5,
48,
3311,
12,
2086,
15,
48,
3311,
12,
671,
12,
612,
304,
355,
2086,
847,
413,
288,
327,
340,
7829,
270,
7585,
334,
1080,
3388,
9,
436,
314,
2061,
1004,
365,
2615,
334,
48,
3311,
7585,
315,
652,
395,
2059,
288,
327,
334,
1712,
435,
413,
14,
16,
9,
1182,
510,
3311,
365,
314,
1004,
2382,
314,
3336,
3955,
506,
11788,
288,
327,
1390,
89,
365,
314,
1329,
402,
3411,
2385,
288,
327,
435,
413,
14,
16,
365,
2952,
2086,
22241,
737,
378,
12,
12850,
2086,
3388,
365,
5965,
314,
7829,
270,
1853,
288,
327,
436,
370,
3542,
2366,
370,
440,
6168,
314,
4629,
3439,
288,
340,
1478,
2356,
510,
11115,
436,
3666,
1712,
435,
413,
14,
16,
9,
1182,
510,
3311,
9,
690,
1390,
89,
26,
355,
2059,
953,
340,
671,
389,
17,
436,
612,
389,
17,
26,
257,
327,
3486,
25332,
367,
11952,
13712,
355,
1748,
1712,
275,
2086,
15,
48,
3311,
953,
367,
612,
18,
315,
1425,
8,
89,
304,
355,
367,
671,
18,
315,
1425,
8,
88,
304,
490,
291,
14,
1224,
7528,
1712,
15,
48,
3311,
6393,
89,
18,
1527,
8,
1712,
5,
48,
3311,
6393,
88,
18,
61,
275,
756,
288,
291,
14,
1224,
59,
1712,
15,
48,
3311,
1527,
1712,
5,
48,
3311,
61,
275,
469,
355,
283,
2558,
356,
299,
12,
283,
88,
356,
88,
12,
283,
89,
356,
612,
12,
355,
283,
533,
356,
298,
3680,
904,
8,
1130,
8,
2734,
671,
26,
671,
14,
1360,
63,
533,
503,
3260,
299,
14,
7360,
63,
2487,
63,
1580,
430,
288,
789,
288,
340,
1478,
12932,
7701,
39,
26,
355,
1390,
89,
29,
988,
8,
988,
89,
12,
89,
15622,
1712,
15,
48,
3311,
430,
288,
1478,
847,
413,
398,
327,
9701,
1817,
7182,
370,
4163,
4839,
267,
4730,
275,
291,
14,
1224,
14,
1744,
342,
267,
4730,
14,
3191,
342,
267,
4730,
275,
2341,
8,
2734,
671,
26,
671,
59,
17,
467,
4730,
9,
267,
367,
1048,
315,
1425,
8,
552,
8,
3838,
2298,
288,
8850,
275,
4730,
59,
761,
1055,
1744,
342,
288,
8850,
14,
3191,
342,
288,
671,
847,
822,
8,
4574,
9,
288,
4730,
59,
761,
61,
275,
359,
67,
367,
286,
315,
2341,
8,
2734,
671,
26,
671,
59,
17,
467,
8850,
9,
340,
286,
1137,
756,
61,
398,
372,
4730,
398,
327,
3254,
4215,
543,
1324,
730,
8752,
421,
199,
533,
8133,
2632,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
931,
4581,
1011,
589,
304,
267,
291,
14,
515,
275,
931,
267,
291,
14,
589,
275,
1249,
339,
347,
636,
1250,
721,
277,
12,
931,
29,
403,
12,
1011,
829,
304,
267,
340,
440,
931,
26,
288,
931,
275,
291,
14,
515,
267,
367,
1022,
12,
86,
315,
291,
14,
589,
14,
1744,
837,
288,
4775,
14,
5486,
8,
75,
12,
86,
9,
267,
634,
275,
942,
267,
367,
1022,
12,
86,
315,
4775,
14,
1744,
837,
288,
340,
373,
26,
355,
340,
1228,
8,
86,
12,
769,
9,
503,
1228,
8,
86,
12,
663,
304,
490,
634,
14,
740,
8,
17719,
14,
633,
63,
2143,
7694,
75,
12,
73,
9,
367,
284,
315,
373,
2459,
355,
587,
26,
490,
634,
14,
740,
8,
17719,
14,
633,
63,
2143,
7694,
75,
12,
86,
19563,
267,
340,
634,
26,
288,
931,
847,
15539,
435,
7673,
1370,
904,
8,
76,
9,
267,
372,
931,
421,
199,
318,
664,
63,
17385,
837,
272,
2467,
12,
1747,
12,
1067,
12,
4203,
275,
1056,
14,
1556,
12,
1056,
14,
1535,
12,
1056,
14,
1100,
12,
1056,
14,
5189,
272,
13590,
63,
1648,
275,
1067,
14,
362,
360,
8515,
63,
1648,
358,
272,
340,
13590,
63,
1648,
26,
267,
25162,
275,
13590,
63,
1648,
14,
17385,
63,
344,
272,
587,
26,
267,
5854,
275,
4203,
459,
470,
14,
3707,
2278,
4570,
8,
1556,
12,
12824,
63,
998,
12,
1747,
12,
1067,
29,
1100,
680,
3899,
63,
344,
267,
25162,
275,
5854,
14,
1829,
63,
2558,
63,
17385,
272,
372,
25162,
199,
199,
533,
10691,
63,
8515,
8,
1014,
14,
7506,
304,
339,
347,
664,
63,
17385,
8,
277,
304,
267,
372,
664,
63,
17385,
342,
339
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
646,
10380,
199,
199,
504,
5166,
492,
12824,
63,
998,
199,
504,
5166,
492,
1455,
199,
504,
5166,
14,
1014,
492,
1056,
199,
504,
5166,
14,
2537,
14,
5275,
492,
485,
199,
504,
5166,
14,
10788,
14,
7360,
14,
992,
14,
7360,
492,
8889,
199,
504,
5166,
14,
10788,
14,
2520,
14,
20531,
14,
973,
492,
4676,
63,
4876,
199,
199,
7701,
39,
275,
3388,
327,
32411,
3492,
10331,
199,
48,
3311,
275,
841,
221,
327,
32411,
3492,
15231,
199,
199,
533,
1817,
63,
3357,
8,
785,
304,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
1224,
275,
1052,
339,
347,
485,
1074,
63,
2778,
8,
277,
12,
2086,
88,
12,
2086,
89,
12,
308,
565,
476,
12,
1568,
89,
304,
267,
522,
275,
715,
267,
367,
612,
315,
1425,
8,
890,
89,
304,
288,
367,
671,
315,
1425,
8,
5946,
476,
304,
355,
340,
2086,
88,
11,
88,
8119,
48,
3311,
26,
490,
522,
275,
756,
490,
2059,
355,
1962,
275,
291,
14,
1224,
14,
5486,
8,
1712,
89,
11,
89,
12,
5009,
355,
340,
1962,
14,
5486,
8,
32405,
11,
88,
9,
365,
440,
488,
26,
490,
522,
275,
756,
490,
2059,
288,
367,
671,
315,
1425,
8,
48,
3311,
304,
355,
291,
14,
1224,
59,
1712,
89,
11,
89,
1055,
5486,
8,
88,
12,
488,
9,
267,
372,
522,
339,
347,
2112,
8,
277,
12,
7585,
304,
267,
327,
8354,
7585,
12266,
641,
314,
6068,
267,
1748,
1712,
275,
378,
267,
1478,
275,
378,
267,
1390,
89,
275,
378,
267,
367,
299,
315,
7585,
26,
288,
671,
275,
1748,
8,
988,
8,
80,
14,
7360,
63,
890,
63,
88,
12,
413,
395,
510,
3311,
9,
288,
612,
275,
1748,
8,
988,
8,
80,
14,
7360,
63,
890,
63,
89,
12,
413,
395,
510,
3311,
9,
288,
340,
1478,
8119,
7701,
39,
26,
355,
671,
275,
612,
275,
413,
953,
2086,
275,
1748,
1712,
288,
1830,
440,
291,
423,
1074,
63,
2778,
8,
1712,
5,
48,
3311,
12,
2086,
15,
48,
3311,
12,
671,
12,
612,
304,
355,
2086,
847,
413,
288,
327,
340,
7829,
270,
7585,
334,
1080,
3388,
9,
436,
314,
2061,
1004,
365,
2615,
334,
48,
3311,
7585,
315,
652,
395,
2059,
288,
327,
334,
1712,
435,
413,
14,
16,
9,
1182,
510,
3311,
365,
314,
1004,
2382,
314,
3336,
3955,
506,
11788,
288,
327,
1390,
89,
365,
314,
1329,
402,
3411,
2385,
288,
327,
435,
413,
14,
16,
365,
2952,
2086,
22241,
737,
378,
12,
12850,
2086,
3388,
365,
5965,
314,
7829,
270,
1853,
288,
327,
436,
370,
3542,
2366,
370,
440,
6168,
314,
4629,
3439,
288,
340,
1478,
2356,
510,
11115,
436,
3666,
1712,
435,
413,
14,
16,
9,
1182,
510,
3311,
9,
690,
1390,
89,
26,
355,
2059,
953,
340,
671,
389,
17,
436,
612,
389,
17,
26,
257,
327,
3486,
25332,
367,
11952,
13712,
355,
1748,
1712,
275,
2086,
15,
48,
3311,
953,
367,
612,
18,
315,
1425,
8,
89,
304,
355,
367,
671,
18,
315,
1425,
8,
88,
304,
490,
291,
14,
1224,
7528,
1712,
15,
48,
3311,
6393,
89,
18,
1527,
8,
1712,
5,
48,
3311,
6393,
88,
18,
61,
275,
756,
288,
291,
14,
1224,
59,
1712,
15,
48,
3311,
1527,
1712,
5,
48,
3311,
61,
275,
469,
355,
283,
2558,
356,
299,
12,
283,
88,
356,
88,
12,
283,
89,
356,
612,
12,
355,
283,
533,
356,
298,
3680,
904,
8,
1130,
8,
2734,
671,
26,
671,
14,
1360,
63,
533,
503,
3260,
299,
14,
7360,
63,
2487,
63,
1580,
430,
288,
789,
288,
340,
1478,
12932,
7701,
39,
26,
355,
1390,
89,
29,
988,
8,
988,
89,
12,
89,
15622,
1712,
15,
48,
3311,
430,
288,
1478,
847,
413,
398,
327,
9701,
1817,
7182,
370,
4163,
4839,
267,
4730,
275,
291,
14,
1224,
14,
1744,
342,
267,
4730,
14,
3191,
342,
267,
4730,
275,
2341,
8,
2734,
671,
26,
671,
59,
17,
467,
4730,
9,
267,
367,
1048,
315,
1425,
8,
552,
8,
3838,
2298,
288,
8850,
275,
4730,
59,
761,
1055,
1744,
342,
288,
8850,
14,
3191,
342,
288,
671,
847,
822,
8,
4574,
9,
288,
4730,
59,
761,
61,
275,
359,
67,
367,
286,
315,
2341,
8,
2734,
671,
26,
671,
59,
17,
467,
8850,
9,
340,
286,
1137,
756,
61,
398,
372,
4730,
398,
327,
3254,
4215,
543,
1324,
730,
8752,
421,
199,
533,
8133,
2632,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
931,
4581,
1011,
589,
304,
267,
291,
14,
515,
275,
931,
267,
291,
14,
589,
275,
1249,
339,
347,
636,
1250,
721,
277,
12,
931,
29,
403,
12,
1011,
829,
304,
267,
340,
440,
931,
26,
288,
931,
275,
291,
14,
515,
267,
367,
1022,
12,
86,
315,
291,
14,
589,
14,
1744,
837,
288,
4775,
14,
5486,
8,
75,
12,
86,
9,
267,
634,
275,
942,
267,
367,
1022,
12,
86,
315,
4775,
14,
1744,
837,
288,
340,
373,
26,
355,
340,
1228,
8,
86,
12,
769,
9,
503,
1228,
8,
86,
12,
663,
304,
490,
634,
14,
740,
8,
17719,
14,
633,
63,
2143,
7694,
75,
12,
73,
9,
367,
284,
315,
373,
2459,
355,
587,
26,
490,
634,
14,
740,
8,
17719,
14,
633,
63,
2143,
7694,
75,
12,
86,
19563,
267,
340,
634,
26,
288,
931,
847,
15539,
435,
7673,
1370,
904,
8,
76,
9,
267,
372,
931,
421,
199,
318,
664,
63,
17385,
837,
272,
2467,
12,
1747,
12,
1067,
12,
4203,
275,
1056,
14,
1556,
12,
1056,
14,
1535,
12,
1056,
14,
1100,
12,
1056,
14,
5189,
272,
13590,
63,
1648,
275,
1067,
14,
362,
360,
8515,
63,
1648,
358,
272,
340,
13590,
63,
1648,
26,
267,
25162,
275,
13590,
63,
1648,
14,
17385,
63,
344,
272,
587,
26,
267,
5854,
275,
4203,
459,
470,
14,
3707,
2278,
4570,
8,
1556,
12,
12824,
63,
998,
12,
1747,
12,
1067,
29,
1100,
680,
3899,
63,
344,
267,
25162,
275,
5854,
14,
1829,
63,
2558,
63,
17385,
272,
372,
25162,
199,
199,
533,
10691,
63,
8515,
8,
1014,
14,
7506,
304,
339,
347,
664,
63,
17385,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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
Venturi/cms
|
env/lib/python2.7/site-packages/cms/migrations/0002_auto_20140816_1918.py
|
45
|
8472
|
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import cms.models.static_placeholder
import cms.models.fields
from django.conf import settings
from django.contrib.auth import get_user_model
from django.db import models, migrations
import django.utils.timezone
User = get_user_model()
user_model_label = '%s.%s' % (User._meta.app_label, User._meta.model_name)
user_ptr_name = '%s_ptr' % User._meta.object_name.lower()
class Migration(migrations.Migration):
dependencies = [
('cms', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='PageUser',
fields=[
(user_ptr_name, models.OneToOneField(primary_key=True, to=settings.AUTH_USER_MODEL, auto_created=True, parent_link=True, serialize=False)),
('created_by', models.ForeignKey(to=settings.AUTH_USER_MODEL, related_name='created_users')),
],
options={
'verbose_name': 'User (page)',
'verbose_name_plural': 'Users (page)',
},
bases=(user_model_label,),
),
migrations.CreateModel(
name='PageUserGroup',
fields=[
('group_ptr', models.OneToOneField(primary_key=True, to='auth.Group', auto_created=True, parent_link=True, serialize=False)),
('created_by', models.ForeignKey(to=settings.AUTH_USER_MODEL, related_name='created_usergroups')),
],
options={
'verbose_name': 'User group (page)',
'verbose_name_plural': 'User groups (page)',
},
bases=('auth.group',),
),
migrations.CreateModel(
name='Placeholder',
fields=[
('id', models.AutoField(primary_key=True, verbose_name='ID', auto_created=True, serialize=False)),
('slot', models.CharField(db_index=True, max_length=50, verbose_name='slot', editable=False)),
('default_width', models.PositiveSmallIntegerField(null=True, verbose_name='width', editable=False)),
],
options={
},
bases=(models.Model,),
),
migrations.AddField(
model_name='page',
name='placeholders',
field=models.ManyToManyField(to='cms.Placeholder', editable=False),
preserve_default=True,
),
migrations.AlterUniqueTogether(
name='page',
unique_together=set([('publisher_is_draft', 'application_namespace'), ('reverse_id', 'site', 'publisher_is_draft')]),
),
migrations.AddField(
model_name='cmsplugin',
name='placeholder',
field=models.ForeignKey(null=True, to='cms.Placeholder', editable=False),
preserve_default=True,
),
migrations.AddField(
model_name='aliaspluginmodel',
name='alias_placeholder',
field=models.ForeignKey(null=True, to='cms.Placeholder', related_name='alias_placeholder', editable=False),
preserve_default=True,
),
migrations.CreateModel(
name='PlaceholderReference',
fields=[
('cmsplugin_ptr', models.OneToOneField(primary_key=True, to='cms.CMSPlugin', auto_created=True, parent_link=True, serialize=False)),
('name', models.CharField(max_length=255)),
('placeholder_ref', cms.models.fields.PlaceholderField(null=True, to='cms.Placeholder', slotname='clipboard', editable=False)),
],
options={
},
bases=('cms.cmsplugin',),
),
migrations.CreateModel(
name='StaticPlaceholder',
fields=[
('id', models.AutoField(primary_key=True, verbose_name='ID', auto_created=True, serialize=False)),
('name', models.CharField(max_length=255, default='', help_text='Descriptive name to identify this static placeholder. Not displayed to users.', blank=True, verbose_name='static placeholder name')),
('code', models.CharField(max_length=255, verbose_name='placeholder code', help_text='To render the static placeholder in templates.', blank=True)),
('dirty', models.BooleanField(default=False, editable=False)),
('creation_method', models.CharField(max_length=20, default='code', blank=True, verbose_name='creation_method', choices=cms.models.static_placeholder.StaticPlaceholder.CREATION_METHODS)),
('draft', cms.models.fields.PlaceholderField(null=True, to='cms.Placeholder', verbose_name='placeholder content', related_name='static_draft', slotname=cms.models.static_placeholder.static_slotname, editable=False)),
('public', cms.models.fields.PlaceholderField(null=True, to='cms.Placeholder', slotname=cms.models.static_placeholder.static_slotname, related_name='static_public', editable=False)),
('site', models.ForeignKey(null=True, to='sites.Site', blank=True)),
],
options={
'verbose_name': 'static placeholder',
'verbose_name_plural': 'static placeholders',
},
bases=(models.Model,),
),
migrations.AlterUniqueTogether(
name='staticplaceholder',
unique_together=set([('code', 'site')]),
),
migrations.CreateModel(
name='Title',
fields=[
('id', models.AutoField(primary_key=True, verbose_name='ID', auto_created=True, serialize=False)),
('language', models.CharField(db_index=True, max_length=15, verbose_name='language')),
('title', models.CharField(max_length=255, verbose_name='title')),
('page_title', models.CharField(max_length=255, null=True, help_text='overwrite the title (html title tag)', blank=True, verbose_name='title')),
('menu_title', models.CharField(max_length=255, null=True, help_text='overwrite the title in the menu', blank=True, verbose_name='title')),
('meta_description', models.TextField(max_length=155, null=True, help_text='The text displayed in search engines.', blank=True, verbose_name='description')),
('slug', models.SlugField(max_length=255, verbose_name='slug')),
('path', models.CharField(db_index=True, max_length=255, verbose_name='Path')),
('has_url_overwrite', models.BooleanField(db_index=True, default=False, editable=False, verbose_name='has url overwrite')),
('redirect', models.CharField(max_length=255, null=True, blank=True, verbose_name='redirect')),
('creation_date', models.DateTimeField(default=django.utils.timezone.now, verbose_name='creation date', editable=False)),
('published', models.BooleanField(default=False, verbose_name='is published')),
('publisher_is_draft', models.BooleanField(db_index=True, default=True, editable=False)),
('publisher_state', models.SmallIntegerField(db_index=True, default=0, editable=False)),
('page', models.ForeignKey(to='cms.Page', verbose_name='page', related_name='title_set')),
('publisher_public', models.OneToOneField(null=True, to='cms.Title', related_name='publisher_draft', editable=False)),
],
options={
},
bases=(models.Model,),
),
migrations.AlterUniqueTogether(
name='title',
unique_together=set([('language', 'page')]),
),
migrations.CreateModel(
name='UserSettings',
fields=[
('id', models.AutoField(primary_key=True, verbose_name='ID', auto_created=True, serialize=False)),
('language', models.CharField(max_length=10, choices=settings.LANGUAGES, help_text='The language for the admin interface and toolbar', verbose_name='Language')),
('clipboard', models.ForeignKey(null=True, to='cms.Placeholder', blank=True, editable=False)),
('user', models.ForeignKey(to=settings.AUTH_USER_MODEL, unique=True, related_name='djangocms_usersettings', editable=False)),
],
options={
'verbose_name': 'user setting',
'verbose_name_plural': 'user settings',
},
bases=(models.Model,),
),
]
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
19240,
14,
992,
14,
1986,
63,
6199,
199,
646,
19240,
14,
992,
14,
955,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
2828,
14,
1178,
492,
664,
63,
751,
63,
1238,
199,
504,
1639,
14,
697,
492,
1709,
12,
6180,
199,
646,
1639,
14,
1208,
14,
7145,
199,
199,
1899,
275,
664,
63,
751,
63,
1238,
342,
199,
199,
751,
63,
1238,
63,
1302,
275,
1543,
83,
4111,
83,
7,
450,
334,
1899,
423,
2024,
14,
571,
63,
1302,
12,
2876,
423,
2024,
14,
1238,
63,
354,
9,
199,
751,
63,
4695,
63,
354,
275,
1543,
83,
63,
4695,
7,
450,
2876,
423,
2024,
14,
785,
63,
354,
14,
2325,
342,
421,
199,
533,
12090,
8,
7685,
14,
9816,
304,
339,
5124,
275,
359,
267,
661,
10781,
297,
283,
4183,
63,
2747,
659,
272,
1622,
339,
5331,
275,
359,
267,
6180,
14,
14907,
8,
288,
536,
534,
3276,
1899,
297,
288,
1504,
1524,
355,
334,
751,
63,
4695,
63,
354,
12,
1709,
14,
14298,
8,
3327,
63,
498,
29,
549,
12,
370,
29,
1751,
14,
5580,
63,
3791,
63,
11429,
12,
2599,
63,
3966,
29,
549,
12,
1676,
63,
1073,
29,
549,
12,
8437,
29,
797,
1826,
355,
661,
3966,
63,
991,
297,
1709,
14,
3190,
8,
475,
29,
1751,
14,
5580,
63,
3791,
63,
11429,
12,
4048,
63,
354,
534,
3966,
63,
3707,
3855,
288,
2156,
288,
1511,
3126,
355,
283,
3832,
63,
354,
356,
283,
1899,
334,
1606,
3196,
355,
283,
3832,
63,
354,
63,
10019,
356,
283,
12117,
334,
1606,
3196,
288,
1660,
288,
9768,
2687,
751,
63,
1238,
63,
1302,
4706,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
3276,
1899,
2448,
297,
288,
1504,
1524,
355,
661,
923,
63,
4695,
297,
1709,
14,
14298,
8,
3327,
63,
498,
29,
549,
12,
370,
534,
1178,
14,
2448,
297,
2599,
63,
3966,
29,
549,
12,
1676,
63,
1073,
29,
549,
12,
8437,
29,
797,
1826,
355,
661,
3966,
63,
991,
297,
1709,
14,
3190,
8,
475,
29,
1751,
14,
5580,
63,
3791,
63,
11429,
12,
4048,
63,
354,
534,
3966,
63,
751,
2634,
3855,
288,
2156,
288,
1511,
3126,
355,
283,
3832,
63,
354,
356,
283,
1899,
1572,
334,
1606,
3196,
355,
283,
3832,
63,
354,
63,
10019,
356,
283,
1899,
4652,
334,
1606,
3196,
288,
1660,
288,
9768,
7782,
1178,
14,
923,
5529,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
20185,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3327,
63,
498,
29,
549,
12,
3376,
63,
354,
534,
998,
297,
2599,
63,
3966,
29,
549,
12,
8437,
29,
797,
1826,
355,
661,
7998,
297,
1709,
14,
2183,
8,
697,
63,
1080,
29,
549,
12,
1390,
63,
1267,
29,
1400,
12,
3376,
63,
354,
534,
7998,
297,
14783,
29,
797,
1826,
355,
661,
885,
63,
2063,
297,
1709,
14,
25197,
8,
2307,
29,
549,
12,
3376,
63,
354,
534,
2063,
297,
14783,
29,
797,
1826,
288,
2156,
288,
1511,
3126,
288,
1660,
288,
9768,
2687,
992,
14,
1685,
4706,
267,
2318,
267,
6180,
14,
18381,
8,
288,
1402,
63,
354,
534,
1606,
297,
288,
536,
534,
22100,
297,
288,
901,
29,
992,
14,
7624,
8,
475,
534,
10781,
14,
20185,
297,
14783,
29,
797,
395,
288,
11211,
63,
885,
29,
549,
12,
267,
2318,
267,
6180,
14,
14364,
11427,
1378,
4920,
8,
288,
536,
534,
1606,
297,
288,
3747,
63,
6314,
29,
409,
8318,
12789,
63,
374,
63,
7185,
297,
283,
3578,
63,
3251,
659,
661,
4471,
63,
344,
297,
283,
2124,
297,
283,
12789,
63,
374,
63,
7185,
22864,
267,
2318,
267,
6180,
14,
18381,
8,
288,
1402,
63,
354,
534,
4400,
30873,
297,
288,
536,
534,
6199,
297,
288,
901,
29,
992,
14,
3190,
8,
2307,
29,
549,
12,
370,
534,
10781,
14,
20185,
297,
14783,
29,
797,
395,
288,
11211,
63,
885,
29,
549,
12,
267,
2318,
267,
6180,
14,
18381,
8,
288,
1402,
63,
354,
534,
3620,
2718,
1238,
297,
288,
536,
534,
3620,
63,
6199,
297,
288,
901,
29,
992,
14,
3190,
8,
2307,
29,
549,
12,
370,
534,
10781,
14,
20185,
297,
4048,
63,
354,
534,
3620,
63,
6199,
297,
14783,
29,
797,
395,
288,
11211,
63,
885,
29,
549,
12,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
20185,
5083,
297,
288,
1504,
1524,
355,
661,
4400,
30873,
63,
4695,
297,
1709,
14,
14298,
8,
3327,
63,
498,
29,
549,
12,
370,
534,
10781,
14,
17834,
5061,
297,
2599,
63,
3966,
29,
549,
12,
1676,
63,
1073,
29,
549,
12,
8437,
29,
797,
1826,
355,
661,
354,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
2299,
1826,
355,
661,
6199,
63,
1121,
297,
19240,
14,
992,
14,
955,
14,
20185,
792,
8,
2307,
29,
549,
12,
370,
534,
10781,
14,
20185,
297,
9348,
354,
534,
7548,
3576,
297,
14783,
29,
797,
1826,
288,
2156,
288,
1511,
3126,
288,
1660,
288,
9768,
7782,
10781,
14,
4400,
30873,
5529,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
9278,
20185,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3327,
63,
498,
29,
549,
12,
3376,
63,
354,
534,
998,
297,
2599,
63,
3966,
29,
549,
12,
8437,
29,
797,
1826,
355,
661,
354,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
2299,
12,
849,
4581,
1720,
63,
505,
534,
16320,
21701,
536,
370,
10405,
642,
2955,
10069,
14,
2832,
9080,
370,
4390,
3130,
4596,
29,
549,
12,
3376,
63,
354,
534,
1986,
10069,
536,
3855,
355,
661,
600,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
2299,
12,
3376,
63,
354,
534,
6199,
1233,
297,
1720,
63,
505,
534,
1378,
3795,
314,
2955,
10069,
315,
7009,
3130,
4596,
29,
549,
1826,
355,
661,
8799,
297,
1709,
14,
5036,
8,
885,
29,
797,
12,
14783,
29,
797,
1826,
355,
661,
8782,
63,
765,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1165,
12,
849,
534,
600,
297,
4596,
29,
549,
12,
3376,
63,
354,
534,
8782,
63,
765,
297,
3415,
29,
10781,
14
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
19240,
14,
992,
14,
1986,
63,
6199,
199,
646,
19240,
14,
992,
14,
955,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
2828,
14,
1178,
492,
664,
63,
751,
63,
1238,
199,
504,
1639,
14,
697,
492,
1709,
12,
6180,
199,
646,
1639,
14,
1208,
14,
7145,
199,
199,
1899,
275,
664,
63,
751,
63,
1238,
342,
199,
199,
751,
63,
1238,
63,
1302,
275,
1543,
83,
4111,
83,
7,
450,
334,
1899,
423,
2024,
14,
571,
63,
1302,
12,
2876,
423,
2024,
14,
1238,
63,
354,
9,
199,
751,
63,
4695,
63,
354,
275,
1543,
83,
63,
4695,
7,
450,
2876,
423,
2024,
14,
785,
63,
354,
14,
2325,
342,
421,
199,
533,
12090,
8,
7685,
14,
9816,
304,
339,
5124,
275,
359,
267,
661,
10781,
297,
283,
4183,
63,
2747,
659,
272,
1622,
339,
5331,
275,
359,
267,
6180,
14,
14907,
8,
288,
536,
534,
3276,
1899,
297,
288,
1504,
1524,
355,
334,
751,
63,
4695,
63,
354,
12,
1709,
14,
14298,
8,
3327,
63,
498,
29,
549,
12,
370,
29,
1751,
14,
5580,
63,
3791,
63,
11429,
12,
2599,
63,
3966,
29,
549,
12,
1676,
63,
1073,
29,
549,
12,
8437,
29,
797,
1826,
355,
661,
3966,
63,
991,
297,
1709,
14,
3190,
8,
475,
29,
1751,
14,
5580,
63,
3791,
63,
11429,
12,
4048,
63,
354,
534,
3966,
63,
3707,
3855,
288,
2156,
288,
1511,
3126,
355,
283,
3832,
63,
354,
356,
283,
1899,
334,
1606,
3196,
355,
283,
3832,
63,
354,
63,
10019,
356,
283,
12117,
334,
1606,
3196,
288,
1660,
288,
9768,
2687,
751,
63,
1238,
63,
1302,
4706,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
3276,
1899,
2448,
297,
288,
1504,
1524,
355,
661,
923,
63,
4695,
297,
1709,
14,
14298,
8,
3327,
63,
498,
29,
549,
12,
370,
534,
1178,
14,
2448,
297,
2599,
63,
3966,
29,
549,
12,
1676,
63,
1073,
29,
549,
12,
8437,
29,
797,
1826,
355,
661,
3966,
63,
991,
297,
1709,
14,
3190,
8,
475,
29,
1751,
14,
5580,
63,
3791,
63,
11429,
12,
4048,
63,
354,
534,
3966,
63,
751,
2634,
3855,
288,
2156,
288,
1511,
3126,
355,
283,
3832,
63,
354,
356,
283,
1899,
1572,
334,
1606,
3196,
355,
283,
3832,
63,
354,
63,
10019,
356,
283,
1899,
4652,
334,
1606,
3196,
288,
1660,
288,
9768,
7782,
1178,
14,
923,
5529,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
20185,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3327,
63,
498,
29,
549,
12,
3376,
63,
354,
534,
998,
297,
2599,
63,
3966,
29,
549,
12,
8437,
29,
797,
1826,
355,
661,
7998,
297,
1709,
14,
2183,
8,
697,
63,
1080,
29,
549,
12,
1390,
63,
1267,
29,
1400,
12,
3376,
63,
354,
534,
7998,
297,
14783,
29,
797,
1826,
355,
661,
885,
63,
2063,
297,
1709,
14,
25197,
8,
2307,
29,
549,
12,
3376,
63,
354,
534,
2063,
297,
14783,
29,
797,
1826,
288,
2156,
288,
1511,
3126,
288,
1660,
288,
9768,
2687,
992,
14,
1685,
4706,
267,
2318,
267,
6180,
14,
18381,
8,
288,
1402,
63,
354,
534,
1606,
297,
288,
536,
534,
22100,
297,
288,
901,
29,
992,
14,
7624,
8,
475,
534,
10781,
14,
20185,
297,
14783,
29,
797,
395,
288,
11211,
63,
885,
29,
549,
12,
267,
2318,
267,
6180,
14,
14364,
11427,
1378,
4920,
8,
288,
536,
534,
1606,
297,
288,
3747,
63,
6314,
29,
409,
8318,
12789,
63,
374,
63,
7185,
297,
283,
3578,
63,
3251,
659,
661,
4471,
63,
344,
297,
283,
2124,
297,
283,
12789,
63,
374,
63,
7185,
22864,
267,
2318,
267,
6180,
14,
18381,
8,
288,
1402,
63,
354,
534,
4400,
30873,
297,
288,
536,
534,
6199,
297,
288,
901,
29,
992,
14,
3190,
8,
2307,
29,
549,
12,
370,
534,
10781,
14,
20185,
297,
14783,
29,
797,
395,
288,
11211,
63,
885,
29,
549,
12,
267,
2318,
267,
6180,
14,
18381,
8,
288,
1402,
63,
354,
534,
3620,
2718,
1238,
297,
288,
536,
534,
3620,
63,
6199,
297,
288,
901,
29,
992,
14,
3190,
8,
2307,
29,
549,
12,
370,
534,
10781,
14,
20185,
297,
4048,
63,
354,
534,
3620,
63,
6199,
297,
14783,
29,
797,
395,
288,
11211,
63,
885,
29,
549,
12,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
20185,
5083,
297,
288,
1504,
1524,
355,
661,
4400,
30873,
63,
4695,
297,
1709,
14,
14298,
8,
3327,
63,
498,
29,
549,
12,
370,
534,
10781,
14,
17834,
5061,
297,
2599,
63,
3966,
29,
549,
12,
1676,
63,
1073,
29,
549,
12,
8437,
29,
797,
1826,
355,
661,
354,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
2299,
1826,
355,
661,
6199,
63,
1121,
297,
19240,
14,
992,
14,
955,
14,
20185,
792,
8,
2307,
29,
549,
12,
370,
534,
10781,
14,
20185,
297,
9348,
354,
534,
7548,
3576,
297,
14783,
29,
797,
1826,
288,
2156,
288,
1511,
3126,
288,
1660,
288,
9768,
7782,
10781,
14,
4400,
30873,
5529,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
9278,
20185,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3327,
63,
498,
29,
549,
12,
3376,
63,
354,
534,
998,
297,
2599,
63,
3966,
29,
549,
12,
8437,
29,
797,
1826,
355,
661,
354,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
2299,
12,
849,
4581,
1720,
63,
505,
534,
16320,
21701,
536,
370,
10405,
642,
2955,
10069,
14,
2832,
9080,
370,
4390,
3130,
4596,
29,
549,
12,
3376,
63,
354,
534,
1986,
10069,
536,
3855,
355,
661,
600,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
2299,
12,
3376,
63,
354,
534,
6199,
1233,
297,
1720,
63,
505,
534,
1378,
3795,
314,
2955,
10069,
315,
7009,
3130,
4596,
29,
549,
1826,
355,
661,
8799,
297,
1709,
14,
5036,
8,
885,
29,
797,
12,
14783,
29,
797,
1826,
355,
661,
8782,
63,
765,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1165,
12,
849,
534,
600,
297,
4596,
29,
549,
12,
3376,
63,
354,
534,
8782,
63,
765,
297,
3415,
29,
10781,
14,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
viswimmer1/PythonGenerator
|
data/python_files/34574373/cmss.py
|
1
|
2623
|
import win32pipe
import win32console
import win32process
import time
import win32con
import codecs
import ctypes
user32 = ctypes.windll.user32
CONQUE_WINDOWS_VK = {
'3' : win32con.VK_CANCEL,
'8' : win32con.VK_BACK,
'9' : win32con.VK_TAB,
'12' : win32con.VK_CLEAR,
'13' : win32con.VK_RETURN,
'17' : win32con.VK_CONTROL,
'20' : win32con.VK_CAPITAL,
'27' : win32con.VK_ESCAPE,
'28' : win32con.VK_CONVERT,
'35' : win32con.VK_END,
'36' : win32con.VK_HOME,
'37' : win32con.VK_LEFT,
'38' : win32con.VK_UP,
'39' : win32con.VK_RIGHT,
'40' : win32con.VK_DOWN,
'45' : win32con.VK_INSERT,
'46' : win32con.VK_DELETE,
'47' : win32con.VK_HELP
}
def make_input_key(c, control_key_state=None):
kc = win32console.PyINPUT_RECORDType (win32console.KEY_EVENT)
kc.KeyDown = True
kc.RepeatCount = 1
cnum = ord(c)
if cnum == 3:
pid_list = win32console.GetConsoleProcessList()
win32console.GenerateConsoleCtrlEvent(win32con.CTRL_C_EVENT, 0)
return
else:
kc.Char = unicode(c)
if str(cnum) in CONQUE_WINDOWS_VK:
kc.VirtualKeyCode = CONQUE_WINDOWS_VK[str(cnum)]
else:
kc.VirtualKeyCode = ctypes.windll.user32.VkKeyScanA(cnum)
#kc.VirtualKeyCode = ctypes.windll.user32.VkKeyScanA(cnum+96)
#kc.ControlKeyState = win32con.LEFT_CTRL_PRESSED
return kc
#win32console.AttachConsole()
coord = win32console.PyCOORDType
con_stdout = win32console.GetStdHandle(win32console.STD_OUTPUT_HANDLE)
con_stdin = win32console.GetStdHandle(win32console.STD_INPUT_HANDLE)
flags = win32process.NORMAL_PRIORITY_CLASS
si = win32process.STARTUPINFO()
si.dwFlags |= win32con.STARTF_USESHOWWINDOW
(handle1, handle2, i1, i2) = win32process.CreateProcess(None, "cmd.exe", None, None, 0, flags, None, '.', si)
time.sleep(1)
#size = con_stdout.GetConsoleScreenBufferInfo()['Window']
# with codecs.open("log.txt", "w", "utf8") as f:
# for i in xrange(0, size.Bottom):
# f.write(con_stdout.ReadConsoleOutputCharacter(size.Right+1, coord(0, i)))
# f.write("\n")
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
HOST = "127.0.0.1"
PORT = 5554
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind((HOST, PORT))
s.listen(1)
(sc, scname) = s.accept()
while True:
msg = sc.recv(1)
if ord(msg) == 0:
break
keys = [make_input_key(msg)]
if keys:
con_stdin.WriteConsoleInput(keys)
win32process.TerminateProcess(handle1, 0)
|
gpl-2.0
|
[
646,
4747,
708,
4990,
202,
199,
646,
4747,
708,
6614,
202,
199,
646,
4747,
708,
1412,
202,
199,
646,
900,
202,
199,
646,
4747,
708,
388,
202,
199,
646,
6010,
202,
199,
646,
5577,
20712,
199,
751,
708,
275,
5577,
14,
25522,
14,
751,
708,
2999,
199,
1864,
10526,
63,
20509,
63,
19327,
275,
469,
1128,
283,
19,
7,
221,
520,
4747,
708,
388,
14,
19327,
63,
20707,
12,
1128,
283,
24,
7,
221,
520,
4747,
708,
388,
14,
19327,
63,
7111,
12,
1128,
283,
25,
7,
221,
520,
4747,
708,
388,
14,
19327,
63,
10129,
12,
1128,
283,
713,
7,
520,
4747,
708,
388,
14,
19327,
63,
20706,
12,
1128,
283,
969,
7,
520,
4747,
708,
388,
14,
19327,
63,
9677,
12,
1128,
283,
1196,
7,
520,
4747,
708,
388,
14,
19327,
63,
13060,
12,
1128,
283,
1165,
7,
520,
4747,
708,
388,
14,
19327,
63,
35,
2669,
12,
1128,
283,
1465,
7,
520,
4747,
708,
388,
14,
19327,
63,
28879,
12,
1128,
283,
1651,
7,
520,
4747,
708,
388,
14,
19327,
63,
1864,
8851,
12,
1128,
283,
1276,
7,
520,
4747,
708,
388,
14,
19327,
63,
3902,
12,
1128,
283,
1344,
7,
520,
4747,
708,
388,
14,
19327,
63,
9524,
12,
1128,
283,
1401,
7,
520,
4747,
708,
388,
14,
19327,
63,
9894,
12,
1128,
283,
1703,
7,
520,
4747,
708,
388,
14,
19327,
63,
2160,
12,
1128,
283,
1355,
7,
520,
4747,
708,
388,
14,
19327,
63,
12811,
12,
1128,
283,
2167,
7,
520,
4747,
708,
388,
14,
19327,
63,
8819,
12,
1128,
283,
2322,
7,
520,
4747,
708,
388,
14,
19327,
63,
10258,
12,
1128,
283,
2466,
7,
520,
4747,
708,
388,
14,
19327,
63,
7014,
12,
1128,
283,
2417,
7,
520,
4747,
708,
388,
14,
19327,
63,
17930,
202,
199,
93,
2999,
199,
318,
1852,
63,
1210,
63,
498,
8,
67,
12,
3304,
63,
498,
63,
929,
29,
403,
304,
1128,
1022,
67,
275,
4747,
708,
6614,
14,
2713,
7321,
63,
15060,
804,
334,
2676,
708,
6614,
14,
3078,
63,
8193,
9,
1128,
1022,
67,
14,
1197,
3514,
275,
715,
1128,
1022,
67,
14,
27600,
2353,
275,
413,
1128,
286,
1507,
275,
6206,
8,
67,
9,
1128,
340,
286,
1507,
508,
650,
26,
1039,
4422,
63,
513,
275,
4747,
708,
6614,
14,
1002,
9270,
3498,
1296,
342,
1039,
4747,
708,
6614,
14,
6864,
9270,
9778,
2390,
8,
2676,
708,
388,
14,
22584,
63,
35,
63,
8193,
12,
378,
9,
1039,
372,
26259,
587,
26,
1039,
1022,
67,
14,
1610,
275,
2649,
8,
67,
9,
1039,
340,
620,
8,
67,
1507,
9,
315,
1868,
10526,
63,
20509,
63,
19327,
26,
1675,
1022,
67,
14,
8735,
1197,
3034,
275,
1868,
10526,
63,
20509,
63,
19327,
59,
495,
8,
67,
1507,
1874,
1039,
587,
26,
1675,
1022,
67,
14,
8735,
1197,
3034,
275,
5577,
14,
25522,
14,
751,
708,
14,
54,
75,
1197,
15936,
33,
8,
67,
1507,
9,
1675,
327,
75,
67,
14,
8735,
1197,
3034,
275,
5577,
14,
25522,
14,
751,
708,
14,
54,
75,
1197,
15936,
33,
8,
67,
1507,
11,
2534,
9,
1675,
327,
75,
67,
14,
3717,
1197,
2223,
275,
4747,
708,
388,
14,
9894,
63,
22584,
63,
14956,
10934,
2958,
372,
1022,
67,
8065,
199,
3,
2676,
708,
6614,
14,
13240,
9270,
342,
202,
199,
7988,
275,
4747,
708,
6614,
14,
2713,
21901,
804,
2999,
199,
388,
63,
2703,
275,
4747,
708,
6614,
14,
1002,
11976,
5940,
8,
2676,
708,
6614,
14,
18472,
63,
8414,
63,
15885,
9,
202,
199,
388,
63,
6626,
275,
4747,
708,
6614,
14,
1002,
11976,
5940,
8,
2676,
708,
6614,
14,
18472,
63,
7321,
63,
15885,
9,
2999,
199,
2469,
275,
4747,
708,
1412,
14,
10765,
63,
25144,
63,
6885,
202,
199,
338,
275,
4747,
708,
1412,
14,
7363,
2160,
4531,
342,
202,
199,
338,
14,
10772,
6381,
8901,
4747,
708,
388,
14,
7363,
38,
63,
1668,
654,
16210,
15480,
2999,
199,
8,
2479,
17,
12,
2429,
18,
12,
284,
17,
12,
284,
18,
9,
275,
4747,
708,
1412,
14,
2499,
3498,
8,
403,
12,
298,
1760,
14,
5803,
401,
488,
12,
488,
12,
378,
12,
3285,
12,
488,
12,
22608,
13877,
9,
202,
199,
521,
14,
4532,
8,
17,
9,
202,
199,
3,
890,
275,
406,
63,
2703,
14,
1002,
9270,
9616,
3299,
2354,
12047,
4301,
418,
202,
199,
3,
543,
6010,
14,
1490,
480,
793,
14,
2424,
401,
298,
87,
401,
298,
1624,
24,
531,
465,
289,
26,
1223,
198,
3,
367,
284,
315,
4945,
8,
16,
12,
1568,
14,
22886,
304,
4122,
198,
3,
289,
14,
952,
8,
388,
63,
2703,
14,
3284,
9270,
2959,
14852,
8,
890,
14,
9121,
11,
17,
12,
11021,
8,
16,
12,
284,
1724,
4122,
198,
3,
289,
14,
952,
4582,
78,
531,
8065,
199,
646,
2838,
221,
2999,
199,
83,
275,
2838,
14,
3450,
8,
3450,
14,
5699,
63,
11367,
12,
2838,
14,
9469,
63,
9484,
9,
202,
199,
5449,
275,
298,
4195,
14,
16,
14,
16,
14,
17,
2,
202,
199,
3657,
275,
959,
19264,
2999,
199,
83,
14,
27689,
8,
3450,
14,
15096,
63,
17462,
12,
2838,
14,
4118,
63,
907,
4701,
7803,
12,
413,
9,
202,
199,
83,
14,
3409,
1332,
5449,
12,
25562,
430,
202,
199,
83,
14,
5859,
8,
17,
9,
2999,
199,
8,
551,
12,
4061,
354,
9,
275,
308,
14,
5694,
342,
202,
199,
6710,
715,
26,
1128,
1499,
275,
4061,
14,
7637,
8,
17,
9,
1128,
340,
6206,
8,
1328,
9,
508,
378,
26,
1039,
2059,
1128,
2883,
275,
359,
1875,
63,
1210,
63,
498,
8,
1328,
1874,
1128,
340,
2883,
26,
1039,
406,
63,
6626,
14,
3534,
9270,
3205,
8,
1612,
9,
8065,
199,
2676,
708,
1412,
14,
12154,
323,
3498,
8,
2479,
17,
12,
378,
9,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
4747,
708,
4990,
202,
199,
646,
4747,
708,
6614,
202,
199,
646,
4747,
708,
1412,
202,
199,
646,
900,
202,
199,
646,
4747,
708,
388,
202,
199,
646,
6010,
202,
199,
646,
5577,
20712,
199,
751,
708,
275,
5577,
14,
25522,
14,
751,
708,
2999,
199,
1864,
10526,
63,
20509,
63,
19327,
275,
469,
1128,
283,
19,
7,
221,
520,
4747,
708,
388,
14,
19327,
63,
20707,
12,
1128,
283,
24,
7,
221,
520,
4747,
708,
388,
14,
19327,
63,
7111,
12,
1128,
283,
25,
7,
221,
520,
4747,
708,
388,
14,
19327,
63,
10129,
12,
1128,
283,
713,
7,
520,
4747,
708,
388,
14,
19327,
63,
20706,
12,
1128,
283,
969,
7,
520,
4747,
708,
388,
14,
19327,
63,
9677,
12,
1128,
283,
1196,
7,
520,
4747,
708,
388,
14,
19327,
63,
13060,
12,
1128,
283,
1165,
7,
520,
4747,
708,
388,
14,
19327,
63,
35,
2669,
12,
1128,
283,
1465,
7,
520,
4747,
708,
388,
14,
19327,
63,
28879,
12,
1128,
283,
1651,
7,
520,
4747,
708,
388,
14,
19327,
63,
1864,
8851,
12,
1128,
283,
1276,
7,
520,
4747,
708,
388,
14,
19327,
63,
3902,
12,
1128,
283,
1344,
7,
520,
4747,
708,
388,
14,
19327,
63,
9524,
12,
1128,
283,
1401,
7,
520,
4747,
708,
388,
14,
19327,
63,
9894,
12,
1128,
283,
1703,
7,
520,
4747,
708,
388,
14,
19327,
63,
2160,
12,
1128,
283,
1355,
7,
520,
4747,
708,
388,
14,
19327,
63,
12811,
12,
1128,
283,
2167,
7,
520,
4747,
708,
388,
14,
19327,
63,
8819,
12,
1128,
283,
2322,
7,
520,
4747,
708,
388,
14,
19327,
63,
10258,
12,
1128,
283,
2466,
7,
520,
4747,
708,
388,
14,
19327,
63,
7014,
12,
1128,
283,
2417,
7,
520,
4747,
708,
388,
14,
19327,
63,
17930,
202,
199,
93,
2999,
199,
318,
1852,
63,
1210,
63,
498,
8,
67,
12,
3304,
63,
498,
63,
929,
29,
403,
304,
1128,
1022,
67,
275,
4747,
708,
6614,
14,
2713,
7321,
63,
15060,
804,
334,
2676,
708,
6614,
14,
3078,
63,
8193,
9,
1128,
1022,
67,
14,
1197,
3514,
275,
715,
1128,
1022,
67,
14,
27600,
2353,
275,
413,
1128,
286,
1507,
275,
6206,
8,
67,
9,
1128,
340,
286,
1507,
508,
650,
26,
1039,
4422,
63,
513,
275,
4747,
708,
6614,
14,
1002,
9270,
3498,
1296,
342,
1039,
4747,
708,
6614,
14,
6864,
9270,
9778,
2390,
8,
2676,
708,
388,
14,
22584,
63,
35,
63,
8193,
12,
378,
9,
1039,
372,
26259,
587,
26,
1039,
1022,
67,
14,
1610,
275,
2649,
8,
67,
9,
1039,
340,
620,
8,
67,
1507,
9,
315,
1868,
10526,
63,
20509,
63,
19327,
26,
1675,
1022,
67,
14,
8735,
1197,
3034,
275,
1868,
10526,
63,
20509,
63,
19327,
59,
495,
8,
67,
1507,
1874,
1039,
587,
26,
1675,
1022,
67,
14,
8735,
1197,
3034,
275,
5577,
14,
25522,
14,
751,
708,
14,
54,
75,
1197,
15936,
33,
8,
67,
1507,
9,
1675,
327,
75,
67,
14,
8735,
1197,
3034,
275,
5577,
14,
25522,
14,
751,
708,
14,
54,
75,
1197,
15936,
33,
8,
67,
1507,
11,
2534,
9,
1675,
327,
75,
67,
14,
3717,
1197,
2223,
275,
4747,
708,
388,
14,
9894,
63,
22584,
63,
14956,
10934,
2958,
372,
1022,
67,
8065,
199,
3,
2676,
708,
6614,
14,
13240,
9270,
342,
202,
199,
7988,
275,
4747,
708,
6614,
14,
2713,
21901,
804,
2999,
199,
388,
63,
2703,
275,
4747,
708,
6614,
14,
1002,
11976,
5940,
8,
2676,
708,
6614,
14,
18472,
63,
8414,
63,
15885,
9,
202,
199,
388,
63,
6626,
275,
4747,
708,
6614,
14,
1002,
11976,
5940,
8,
2676,
708,
6614,
14,
18472,
63,
7321,
63,
15885,
9,
2999,
199,
2469,
275,
4747,
708,
1412,
14,
10765,
63,
25144,
63,
6885,
202,
199,
338,
275,
4747,
708,
1412,
14,
7363,
2160,
4531,
342,
202,
199,
338,
14,
10772,
6381,
8901,
4747,
708,
388,
14,
7363,
38,
63,
1668,
654,
16210,
15480,
2999,
199,
8,
2479,
17,
12,
2429,
18,
12,
284,
17,
12,
284,
18,
9,
275,
4747,
708,
1412,
14,
2499,
3498,
8,
403,
12,
298,
1760,
14,
5803,
401,
488,
12,
488,
12,
378,
12,
3285,
12,
488,
12,
22608,
13877,
9,
202,
199,
521,
14,
4532,
8,
17,
9,
202,
199,
3,
890,
275,
406,
63,
2703,
14,
1002,
9270,
9616,
3299,
2354,
12047,
4301,
418,
202,
199,
3,
543,
6010,
14,
1490,
480,
793,
14,
2424,
401,
298,
87,
401,
298,
1624,
24,
531,
465,
289,
26,
1223,
198,
3,
367,
284,
315,
4945,
8,
16,
12,
1568,
14,
22886,
304,
4122,
198,
3,
289,
14,
952,
8,
388,
63,
2703,
14,
3284,
9270,
2959,
14852,
8,
890,
14,
9121,
11,
17,
12,
11021,
8,
16,
12,
284,
1724,
4122,
198,
3,
289,
14,
952,
4582,
78,
531,
8065,
199,
646,
2838,
221,
2999,
199,
83,
275,
2838,
14,
3450,
8,
3450,
14,
5699,
63,
11367,
12,
2838,
14,
9469,
63,
9484,
9,
202,
199,
5449,
275,
298,
4195,
14,
16,
14,
16,
14,
17,
2,
202,
199,
3657,
275,
959,
19264,
2999,
199,
83,
14,
27689,
8,
3450,
14,
15096,
63,
17462,
12,
2838,
14,
4118,
63,
907,
4701,
7803,
12,
413,
9,
202,
199,
83,
14,
3409,
1332,
5449,
12,
25562,
430,
202,
199,
83,
14,
5859,
8,
17,
9,
2999,
199,
8,
551,
12,
4061,
354,
9,
275,
308,
14,
5694,
342,
202,
199,
6710,
715,
26,
1128,
1499,
275,
4061,
14,
7637,
8,
17,
9,
1128,
340,
6206,
8,
1328,
9,
508,
378,
26,
1039,
2059,
1128,
2883,
275,
359,
1875,
63,
1210,
63,
498,
8,
1328,
1874,
1128,
340,
2883,
26,
1039,
406,
63,
6626,
14,
3534,
9270,
3205,
8,
1612,
9,
8065,
199,
2676,
708,
1412,
14,
12154,
323,
3498,
8,
2479,
17,
12,
378,
9,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
Immortalin/python-for-android
|
python3-alpha/extra_modules/gdata/Crypto/Util/RFC1751.py
|
43
|
20130
|
#!/usr/bin/python
# rfc1751.py : Converts between 128-bit strings and a human-readable
# sequence of words, as defined in RFC1751: "A Convention for
# Human-Readable 128-bit Keys", by Daniel L. McDonald.
__revision__ = "$Id: RFC1751.py,v 1.6 2003/04/04 15:15:10 akuchling Exp $"
import string, binascii
from functools import reduce
binary={0:'0000', 1:'0001', 2:'0010', 3:'0011', 4:'0100', 5:'0101',
6:'0110', 7:'0111', 8:'1000', 9:'1001', 10:'1010', 11:'1011',
12:'1100', 13:'1101', 14:'1110', 15:'1111'}
def _key2bin(s):
"Convert a key into a string of binary digits"
kl=[ord(x) for x in s]
kl=[binary[x/16]+binary[x&15] for x in kl]
return ''.join(kl)
def _extract(key, start, length):
"""Extract a bitstring from a string of binary digits, and return its
numeric value."""
k=key[start:start+length]
return reduce(lambda x,y: x*2+ord(y)-48, k, 0)
def key_to_english (key):
"""key_to_english(key:string) : string
Transform an arbitrary key into a string containing English words.
The key length must be a multiple of 8.
"""
english=''
for index in range(0, len(key), 8): # Loop over 8-byte subkeys
subkey=key[index:index+8]
# Compute the parity of the key
skbin=_key2bin(subkey) ; p=0
for i in range(0, 64, 2): p=p+_extract(skbin, i, 2)
# Append parity bits to the subkey
skbin=_key2bin(subkey+chr((p<<6) & 255))
for i in range(0, 64, 11):
english=english+wordlist[_extract(skbin, i, 11)]+' '
return english[:-1] # Remove the trailing space
def english_to_key (str):
"""english_to_key(string):string
Transform a string into a corresponding key.
The string must contain words separated by whitespace; the number
of words must be a multiple of 6.
"""
L=string.split(string.upper(str)) ; key=''
for index in range(0, len(L), 6):
sublist=L[index:index+6] ; char=9*[0] ; bits=0
for i in sublist:
index = wordlist.index(i)
shift = (8-(bits+11)%8) %8
y = index << shift
cl, cc, cr = (y>>16), (y>>8)&0xff, y & 0xff
if (shift>5):
char[bits/8] = char[bits/8] | cl
char[bits/8+1] = char[bits/8+1] | cc
char[bits/8+2] = char[bits/8+2] | cr
elif shift>-3:
char[bits/8] = char[bits/8] | cc
char[bits/8+1] = char[bits/8+1] | cr
else: char[bits/8] = char[bits/8] | cr
bits=bits+11
subkey=reduce(lambda x,y:x+chr(y), char, '')
# Check the parity of the resulting key
skbin=_key2bin(subkey)
p=0
for i in range(0, 64, 2): p=p+_extract(skbin, i, 2)
if (p&3) != _extract(skbin, 64, 2):
raise ValueError("Parity error in resulting key")
key=key+subkey[0:8]
return key
wordlist=[ "A", "ABE", "ACE", "ACT", "AD", "ADA", "ADD",
"AGO", "AID", "AIM", "AIR", "ALL", "ALP", "AM", "AMY", "AN", "ANA",
"AND", "ANN", "ANT", "ANY", "APE", "APS", "APT", "ARC", "ARE", "ARK",
"ARM", "ART", "AS", "ASH", "ASK", "AT", "ATE", "AUG", "AUK", "AVE",
"AWE", "AWK", "AWL", "AWN", "AX", "AYE", "BAD", "BAG", "BAH", "BAM",
"BAN", "BAR", "BAT", "BAY", "BE", "BED", "BEE", "BEG", "BEN", "BET",
"BEY", "BIB", "BID", "BIG", "BIN", "BIT", "BOB", "BOG", "BON", "BOO",
"BOP", "BOW", "BOY", "BUB", "BUD", "BUG", "BUM", "BUN", "BUS", "BUT",
"BUY", "BY", "BYE", "CAB", "CAL", "CAM", "CAN", "CAP", "CAR", "CAT",
"CAW", "COD", "COG", "COL", "CON", "COO", "COP", "COT", "COW", "COY",
"CRY", "CUB", "CUE", "CUP", "CUR", "CUT", "DAB", "DAD", "DAM", "DAN",
"DAR", "DAY", "DEE", "DEL", "DEN", "DES", "DEW", "DID", "DIE", "DIG",
"DIN", "DIP", "DO", "DOE", "DOG", "DON", "DOT", "DOW", "DRY", "DUB",
"DUD", "DUE", "DUG", "DUN", "EAR", "EAT", "ED", "EEL", "EGG", "EGO",
"ELI", "ELK", "ELM", "ELY", "EM", "END", "EST", "ETC", "EVA", "EVE",
"EWE", "EYE", "FAD", "FAN", "FAR", "FAT", "FAY", "FED", "FEE", "FEW",
"FIB", "FIG", "FIN", "FIR", "FIT", "FLO", "FLY", "FOE", "FOG", "FOR",
"FRY", "FUM", "FUN", "FUR", "GAB", "GAD", "GAG", "GAL", "GAM", "GAP",
"GAS", "GAY", "GEE", "GEL", "GEM", "GET", "GIG", "GIL", "GIN", "GO",
"GOT", "GUM", "GUN", "GUS", "GUT", "GUY", "GYM", "GYP", "HA", "HAD",
"HAL", "HAM", "HAN", "HAP", "HAS", "HAT", "HAW", "HAY", "HE", "HEM",
"HEN", "HER", "HEW", "HEY", "HI", "HID", "HIM", "HIP", "HIS", "HIT",
"HO", "HOB", "HOC", "HOE", "HOG", "HOP", "HOT", "HOW", "HUB", "HUE",
"HUG", "HUH", "HUM", "HUT", "I", "ICY", "IDA", "IF", "IKE", "ILL",
"INK", "INN", "IO", "ION", "IQ", "IRA", "IRE", "IRK", "IS", "IT",
"ITS", "IVY", "JAB", "JAG", "JAM", "JAN", "JAR", "JAW", "JAY", "JET",
"JIG", "JIM", "JO", "JOB", "JOE", "JOG", "JOT", "JOY", "JUG", "JUT",
"KAY", "KEG", "KEN", "KEY", "KID", "KIM", "KIN", "KIT", "LA", "LAB",
"LAC", "LAD", "LAG", "LAM", "LAP", "LAW", "LAY", "LEA", "LED", "LEE",
"LEG", "LEN", "LEO", "LET", "LEW", "LID", "LIE", "LIN", "LIP", "LIT",
"LO", "LOB", "LOG", "LOP", "LOS", "LOT", "LOU", "LOW", "LOY", "LUG",
"LYE", "MA", "MAC", "MAD", "MAE", "MAN", "MAO", "MAP", "MAT", "MAW",
"MAY", "ME", "MEG", "MEL", "MEN", "MET", "MEW", "MID", "MIN", "MIT",
"MOB", "MOD", "MOE", "MOO", "MOP", "MOS", "MOT", "MOW", "MUD", "MUG",
"MUM", "MY", "NAB", "NAG", "NAN", "NAP", "NAT", "NAY", "NE", "NED",
"NEE", "NET", "NEW", "NIB", "NIL", "NIP", "NIT", "NO", "NOB", "NOD",
"NON", "NOR", "NOT", "NOV", "NOW", "NU", "NUN", "NUT", "O", "OAF",
"OAK", "OAR", "OAT", "ODD", "ODE", "OF", "OFF", "OFT", "OH", "OIL",
"OK", "OLD", "ON", "ONE", "OR", "ORB", "ORE", "ORR", "OS", "OTT",
"OUR", "OUT", "OVA", "OW", "OWE", "OWL", "OWN", "OX", "PA", "PAD",
"PAL", "PAM", "PAN", "PAP", "PAR", "PAT", "PAW", "PAY", "PEA", "PEG",
"PEN", "PEP", "PER", "PET", "PEW", "PHI", "PI", "PIE", "PIN", "PIT",
"PLY", "PO", "POD", "POE", "POP", "POT", "POW", "PRO", "PRY", "PUB",
"PUG", "PUN", "PUP", "PUT", "QUO", "RAG", "RAM", "RAN", "RAP", "RAT",
"RAW", "RAY", "REB", "RED", "REP", "RET", "RIB", "RID", "RIG", "RIM",
"RIO", "RIP", "ROB", "ROD", "ROE", "RON", "ROT", "ROW", "ROY", "RUB",
"RUE", "RUG", "RUM", "RUN", "RYE", "SAC", "SAD", "SAG", "SAL", "SAM",
"SAN", "SAP", "SAT", "SAW", "SAY", "SEA", "SEC", "SEE", "SEN", "SET",
"SEW", "SHE", "SHY", "SIN", "SIP", "SIR", "SIS", "SIT", "SKI", "SKY",
"SLY", "SO", "SOB", "SOD", "SON", "SOP", "SOW", "SOY", "SPA", "SPY",
"SUB", "SUD", "SUE", "SUM", "SUN", "SUP", "TAB", "TAD", "TAG", "TAN",
"TAP", "TAR", "TEA", "TED", "TEE", "TEN", "THE", "THY", "TIC", "TIE",
"TIM", "TIN", "TIP", "TO", "TOE", "TOG", "TOM", "TON", "TOO", "TOP",
"TOW", "TOY", "TRY", "TUB", "TUG", "TUM", "TUN", "TWO", "UN", "UP",
"US", "USE", "VAN", "VAT", "VET", "VIE", "WAD", "WAG", "WAR", "WAS",
"WAY", "WE", "WEB", "WED", "WEE", "WET", "WHO", "WHY", "WIN", "WIT",
"WOK", "WON", "WOO", "WOW", "WRY", "WU", "YAM", "YAP", "YAW", "YE",
"YEA", "YES", "YET", "YOU", "ABED", "ABEL", "ABET", "ABLE", "ABUT",
"ACHE", "ACID", "ACME", "ACRE", "ACTA", "ACTS", "ADAM", "ADDS",
"ADEN", "AFAR", "AFRO", "AGEE", "AHEM", "AHOY", "AIDA", "AIDE",
"AIDS", "AIRY", "AJAR", "AKIN", "ALAN", "ALEC", "ALGA", "ALIA",
"ALLY", "ALMA", "ALOE", "ALSO", "ALTO", "ALUM", "ALVA", "AMEN",
"AMES", "AMID", "AMMO", "AMOK", "AMOS", "AMRA", "ANDY", "ANEW",
"ANNA", "ANNE", "ANTE", "ANTI", "AQUA", "ARAB", "ARCH", "AREA",
"ARGO", "ARID", "ARMY", "ARTS", "ARTY", "ASIA", "ASKS", "ATOM",
"AUNT", "AURA", "AUTO", "AVER", "AVID", "AVIS", "AVON", "AVOW",
"AWAY", "AWRY", "BABE", "BABY", "BACH", "BACK", "BADE", "BAIL",
"BAIT", "BAKE", "BALD", "BALE", "BALI", "BALK", "BALL", "BALM",
"BAND", "BANE", "BANG", "BANK", "BARB", "BARD", "BARE", "BARK",
"BARN", "BARR", "BASE", "BASH", "BASK", "BASS", "BATE", "BATH",
"BAWD", "BAWL", "BEAD", "BEAK", "BEAM", "BEAN", "BEAR", "BEAT",
"BEAU", "BECK", "BEEF", "BEEN", "BEER",
"BEET", "BELA", "BELL", "BELT", "BEND", "BENT", "BERG", "BERN",
"BERT", "BESS", "BEST", "BETA", "BETH", "BHOY", "BIAS", "BIDE",
"BIEN", "BILE", "BILK", "BILL", "BIND", "BING", "BIRD", "BITE",
"BITS", "BLAB", "BLAT", "BLED", "BLEW", "BLOB", "BLOC", "BLOT",
"BLOW", "BLUE", "BLUM", "BLUR", "BOAR", "BOAT", "BOCA", "BOCK",
"BODE", "BODY", "BOGY", "BOHR", "BOIL", "BOLD", "BOLO", "BOLT",
"BOMB", "BONA", "BOND", "BONE", "BONG", "BONN", "BONY", "BOOK",
"BOOM", "BOON", "BOOT", "BORE", "BORG", "BORN", "BOSE", "BOSS",
"BOTH", "BOUT", "BOWL", "BOYD", "BRAD", "BRAE", "BRAG", "BRAN",
"BRAY", "BRED", "BREW", "BRIG", "BRIM", "BROW", "BUCK", "BUDD",
"BUFF", "BULB", "BULK", "BULL", "BUNK", "BUNT", "BUOY", "BURG",
"BURL", "BURN", "BURR", "BURT", "BURY", "BUSH", "BUSS", "BUST",
"BUSY", "BYTE", "CADY", "CAFE", "CAGE", "CAIN", "CAKE", "CALF",
"CALL", "CALM", "CAME", "CANE", "CANT", "CARD", "CARE", "CARL",
"CARR", "CART", "CASE", "CASH", "CASK", "CAST", "CAVE", "CEIL",
"CELL", "CENT", "CERN", "CHAD", "CHAR", "CHAT", "CHAW", "CHEF",
"CHEN", "CHEW", "CHIC", "CHIN", "CHOU", "CHOW", "CHUB", "CHUG",
"CHUM", "CITE", "CITY", "CLAD", "CLAM", "CLAN", "CLAW", "CLAY",
"CLOD", "CLOG", "CLOT", "CLUB", "CLUE", "COAL", "COAT", "COCA",
"COCK", "COCO", "CODA", "CODE", "CODY", "COED", "COIL", "COIN",
"COKE", "COLA", "COLD", "COLT", "COMA", "COMB", "COME", "COOK",
"COOL", "COON", "COOT", "CORD", "CORE", "CORK", "CORN", "COST",
"COVE", "COWL", "CRAB", "CRAG", "CRAM", "CRAY", "CREW", "CRIB",
"CROW", "CRUD", "CUBA", "CUBE", "CUFF", "CULL", "CULT", "CUNY",
"CURB", "CURD", "CURE", "CURL", "CURT", "CUTS", "DADE", "DALE",
"DAME", "DANA", "DANE", "DANG", "DANK", "DARE", "DARK", "DARN",
"DART", "DASH", "DATA", "DATE", "DAVE", "DAVY", "DAWN", "DAYS",
"DEAD", "DEAF", "DEAL", "DEAN", "DEAR", "DEBT", "DECK", "DEED",
"DEEM", "DEER", "DEFT", "DEFY", "DELL", "DENT", "DENY", "DESK",
"DIAL", "DICE", "DIED", "DIET", "DIME", "DINE", "DING", "DINT",
"DIRE", "DIRT", "DISC", "DISH", "DISK", "DIVE", "DOCK", "DOES",
"DOLE", "DOLL", "DOLT", "DOME", "DONE", "DOOM", "DOOR", "DORA",
"DOSE", "DOTE", "DOUG", "DOUR", "DOVE", "DOWN", "DRAB", "DRAG",
"DRAM", "DRAW", "DREW", "DRUB", "DRUG", "DRUM", "DUAL", "DUCK",
"DUCT", "DUEL", "DUET", "DUKE", "DULL", "DUMB", "DUNE", "DUNK",
"DUSK", "DUST", "DUTY", "EACH", "EARL", "EARN", "EASE", "EAST",
"EASY", "EBEN", "ECHO", "EDDY", "EDEN", "EDGE", "EDGY", "EDIT",
"EDNA", "EGAN", "ELAN", "ELBA", "ELLA", "ELSE", "EMIL", "EMIT",
"EMMA", "ENDS", "ERIC", "EROS", "EVEN", "EVER", "EVIL", "EYED",
"FACE", "FACT", "FADE", "FAIL", "FAIN", "FAIR", "FAKE", "FALL",
"FAME", "FANG", "FARM", "FAST", "FATE", "FAWN", "FEAR", "FEAT",
"FEED", "FEEL", "FEET", "FELL", "FELT", "FEND", "FERN", "FEST",
"FEUD", "FIEF", "FIGS", "FILE", "FILL", "FILM", "FIND", "FINE",
"FINK", "FIRE", "FIRM", "FISH", "FISK", "FIST", "FITS", "FIVE",
"FLAG", "FLAK", "FLAM", "FLAT", "FLAW", "FLEA", "FLED", "FLEW",
"FLIT", "FLOC", "FLOG", "FLOW", "FLUB", "FLUE", "FOAL", "FOAM",
"FOGY", "FOIL", "FOLD", "FOLK", "FOND", "FONT", "FOOD", "FOOL",
"FOOT", "FORD", "FORE", "FORK", "FORM", "FORT", "FOSS", "FOUL",
"FOUR", "FOWL", "FRAU", "FRAY", "FRED", "FREE", "FRET", "FREY",
"FROG", "FROM", "FUEL", "FULL", "FUME", "FUND", "FUNK", "FURY",
"FUSE", "FUSS", "GAFF", "GAGE", "GAIL", "GAIN", "GAIT", "GALA",
"GALE", "GALL", "GALT", "GAME", "GANG", "GARB", "GARY", "GASH",
"GATE", "GAUL", "GAUR", "GAVE", "GAWK", "GEAR", "GELD", "GENE",
"GENT", "GERM", "GETS", "GIBE", "GIFT", "GILD", "GILL", "GILT",
"GINA", "GIRD", "GIRL", "GIST", "GIVE", "GLAD", "GLEE", "GLEN",
"GLIB", "GLOB", "GLOM", "GLOW", "GLUE", "GLUM", "GLUT", "GOAD",
"GOAL", "GOAT", "GOER", "GOES", "GOLD", "GOLF", "GONE", "GONG",
"GOOD", "GOOF", "GORE", "GORY", "GOSH", "GOUT", "GOWN", "GRAB",
"GRAD", "GRAY", "GREG", "GREW", "GREY", "GRID", "GRIM", "GRIN",
"GRIT", "GROW", "GRUB", "GULF", "GULL", "GUNK", "GURU", "GUSH",
"GUST", "GWEN", "GWYN", "HAAG", "HAAS", "HACK", "HAIL", "HAIR",
"HALE", "HALF", "HALL", "HALO", "HALT", "HAND", "HANG", "HANK",
"HANS", "HARD", "HARK", "HARM", "HART", "HASH", "HAST", "HATE",
"HATH", "HAUL", "HAVE", "HAWK", "HAYS", "HEAD", "HEAL", "HEAR",
"HEAT", "HEBE", "HECK", "HEED", "HEEL", "HEFT", "HELD", "HELL",
"HELM", "HERB", "HERD", "HERE", "HERO", "HERS", "HESS", "HEWN",
"HICK", "HIDE", "HIGH", "HIKE", "HILL", "HILT", "HIND", "HINT",
"HIRE", "HISS", "HIVE", "HOBO", "HOCK", "HOFF", "HOLD", "HOLE",
"HOLM", "HOLT", "HOME", "HONE", "HONK", "HOOD", "HOOF", "HOOK",
"HOOT", "HORN", "HOSE", "HOST", "HOUR", "HOVE", "HOWE", "HOWL",
"HOYT", "HUCK", "HUED", "HUFF", "HUGE", "HUGH", "HUGO", "HULK",
"HULL", "HUNK", "HUNT", "HURD", "HURL", "HURT", "HUSH", "HYDE",
"HYMN", "IBIS", "ICON", "IDEA", "IDLE", "IFFY", "INCA", "INCH",
"INTO", "IONS", "IOTA", "IOWA", "IRIS", "IRMA", "IRON", "ISLE",
"ITCH", "ITEM", "IVAN", "JACK", "JADE", "JAIL", "JAKE", "JANE",
"JAVA", "JEAN", "JEFF", "JERK", "JESS", "JEST", "JIBE", "JILL",
"JILT", "JIVE", "JOAN", "JOBS", "JOCK", "JOEL", "JOEY", "JOHN",
"JOIN", "JOKE", "JOLT", "JOVE", "JUDD", "JUDE", "JUDO", "JUDY",
"JUJU", "JUKE", "JULY", "JUNE", "JUNK", "JUNO", "JURY", "JUST",
"JUTE", "KAHN", "KALE", "KANE", "KANT", "KARL", "KATE", "KEEL",
"KEEN", "KENO", "KENT", "KERN", "KERR", "KEYS", "KICK", "KILL",
"KIND", "KING", "KIRK", "KISS", "KITE", "KLAN", "KNEE", "KNEW",
"KNIT", "KNOB", "KNOT", "KNOW", "KOCH", "KONG", "KUDO", "KURD",
"KURT", "KYLE", "LACE", "LACK", "LACY", "LADY", "LAID", "LAIN",
"LAIR", "LAKE", "LAMB", "LAME", "LAND", "LANE", "LANG", "LARD",
"LARK", "LASS", "LAST", "LATE", "LAUD", "LAVA", "LAWN", "LAWS",
"LAYS", "LEAD", "LEAF", "LEAK", "LEAN", "LEAR", "LEEK", "LEER",
"LEFT", "LEND", "LENS", "LENT", "LEON", "LESK", "LESS", "LEST",
"LETS", "LIAR", "LICE", "LICK", "LIED", "LIEN", "LIES", "LIEU",
"LIFE", "LIFT", "LIKE", "LILA", "LILT", "LILY", "LIMA", "LIMB",
"LIME", "LIND", "LINE", "LINK", "LINT", "LION", "LISA", "LIST",
"LIVE", "LOAD", "LOAF", "LOAM", "LOAN", "LOCK", "LOFT", "LOGE",
"LOIS", "LOLA", "LONE", "LONG", "LOOK", "LOON", "LOOT", "LORD",
"LORE", "LOSE", "LOSS", "LOST", "LOUD", "LOVE", "LOWE", "LUCK",
"LUCY", "LUGE", "LUKE", "LULU", "LUND", "LUNG", "LURA", "LURE",
"LURK", "LUSH", "LUST", "LYLE", "LYNN", "LYON", "LYRA", "MACE",
"MADE", "MAGI", "MAID", "MAIL", "MAIN", "MAKE", "MALE", "MALI",
"MALL", "MALT", "MANA", "MANN", "MANY", "MARC", "MARE", "MARK",
"MARS", "MART", "MARY", "MASH", "MASK", "MASS", "MAST", "MATE",
"MATH", "MAUL", "MAYO", "MEAD", "MEAL", "MEAN", "MEAT", "MEEK",
"MEET", "MELD", "MELT", "MEMO", "MEND", "MENU", "MERT", "MESH",
"MESS", "MICE", "MIKE", "MILD", "MILE", "MILK", "MILL", "MILT",
"MIMI", "MIND", "MINE", "MINI", "MINK", "MINT", "MIRE", "MISS",
"MIST", "MITE", "MITT", "MOAN", "MOAT", "MOCK", "MODE", "MOLD",
"MOLE", "MOLL", "MOLT", "MONA", "MONK", "MONT", "MOOD", "MOON",
"MOOR", "MOOT", "MORE", "MORN", "MORT", "MOSS", "MOST", "MOTH",
"MOVE", "MUCH", "MUCK", "MUDD", "MUFF", "MULE", "MULL", "MURK",
"MUSH", "MUST", "MUTE", "MUTT", "MYRA", "MYTH", "NAGY", "NAIL",
"NAIR", "NAME", "NARY", "NASH", "NAVE", "NAVY", "NEAL", "NEAR",
"NEAT", "NECK", "NEED", "NEIL", "NELL", "NEON", "NERO", "NESS",
"NEST", "NEWS", "NEWT", "NIBS", "NICE", "NICK", "NILE", "NINA",
"NINE", "NOAH", "NODE", "NOEL", "NOLL", "NONE", "NOOK", "NOON",
"NORM", "NOSE", "NOTE", "NOUN", "NOVA", "NUDE", "NULL", "NUMB",
"OATH", "OBEY", "OBOE", "ODIN", "OHIO", "OILY", "OINT", "OKAY",
"OLAF", "OLDY", "OLGA", "OLIN", "OMAN", "OMEN", "OMIT", "ONCE",
"ONES", "ONLY", "ONTO", "ONUS", "ORAL", "ORGY", "OSLO", "OTIS",
"OTTO", "OUCH", "OUST", "OUTS", "OVAL", "OVEN", "OVER", "OWLY",
"OWNS", "QUAD", "QUIT", "QUOD", "RACE", "RACK", "RACY", "RAFT",
"RAGE", "RAID", "RAIL", "RAIN", "RAKE", "RANK", "RANT", "RARE",
"RASH", "RATE", "RAVE", "RAYS", "READ", "REAL", "REAM", "REAR",
"RECK", "REED", "REEF", "REEK", "REEL", "REID", "REIN", "RENA",
"REND", "RENT", "REST", "RICE", "RICH", "RICK", "RIDE", "RIFT",
"RILL", "RIME", "RING", "RINK", "RISE", "RISK", "RITE", "ROAD",
"ROAM", "ROAR", "ROBE", "ROCK", "RODE", "ROIL", "ROLL", "ROME",
"ROOD", "ROOF", "ROOK", "ROOM", "ROOT", "ROSA", "ROSE", "ROSS",
"ROSY", "ROTH", "ROUT", "ROVE", "ROWE", "ROWS", "RUBE", "RUBY",
"RUDE", "RUDY", "RUIN", "RULE", "RUNG", "RUNS", "RUNT", "RUSE",
"RUSH", "RUSK", "RUSS", "RUST", "RUTH", "SACK", "SAFE", "SAGE",
"SAID", "SAIL", "SALE", "SALK", "SALT", "SAME", "SAND", "SANE",
"SANG", "SANK", "SARA", "SAUL", "SAVE", "SAYS", "SCAN", "SCAR",
"SCAT", "SCOT", "SEAL", "SEAM", "SEAR", "SEAT", "SEED", "SEEK",
"SEEM", "SEEN", "SEES", "SELF", "SELL", "SEND", "SENT", "SETS",
"SEWN", "SHAG", "SHAM", "SHAW", "SHAY", "SHED", "SHIM", "SHIN",
"SHOD", "SHOE", "SHOT", "SHOW", "SHUN", "SHUT", "SICK", "SIDE",
"SIFT", "SIGH", "SIGN", "SILK", "SILL", "SILO", "SILT", "SINE",
"SING", "SINK", "SIRE", "SITE", "SITS", "SITU", "SKAT", "SKEW",
"SKID", "SKIM", "SKIN", "SKIT", "SLAB", "SLAM", "SLAT", "SLAY",
"SLED", "SLEW", "SLID", "SLIM", "SLIT", "SLOB", "SLOG", "SLOT",
"SLOW", "SLUG", "SLUM", "SLUR", "SMOG", "SMUG", "SNAG", "SNOB",
"SNOW", "SNUB", "SNUG", "SOAK", "SOAR", "SOCK", "SODA", "SOFA",
"SOFT", "SOIL", "SOLD", "SOME", "SONG", "SOON", "SOOT", "SORE",
"SORT", "SOUL", "SOUR", "SOWN", "STAB", "STAG", "STAN", "STAR",
"STAY", "STEM", "STEW", "STIR", "STOW", "STUB", "STUN", "SUCH",
"SUDS", "SUIT", "SULK", "SUMS", "SUNG", "SUNK", "SURE", "SURF",
"SWAB", "SWAG", "SWAM", "SWAN", "SWAT", "SWAY", "SWIM", "SWUM",
"TACK", "TACT", "TAIL", "TAKE", "TALE", "TALK", "TALL", "TANK",
"TASK", "TATE", "TAUT", "TEAL", "TEAM", "TEAR", "TECH", "TEEM",
"TEEN", "TEET", "TELL", "TEND", "TENT", "TERM", "TERN", "TESS",
"TEST", "THAN", "THAT", "THEE", "THEM", "THEN", "THEY", "THIN",
"THIS", "THUD", "THUG", "TICK", "TIDE", "TIDY", "TIED", "TIER",
"TILE", "TILL", "TILT", "TIME", "TINA", "TINE", "TINT", "TINY",
"TIRE", "TOAD", "TOGO", "TOIL", "TOLD", "TOLL", "TONE", "TONG",
"TONY", "TOOK", "TOOL", "TOOT", "TORE", "TORN", "TOTE", "TOUR",
"TOUT", "TOWN", "TRAG", "TRAM", "TRAY", "TREE", "TREK", "TRIG",
"TRIM", "TRIO", "TROD", "TROT", "TROY", "TRUE", "TUBA", "TUBE",
"TUCK", "TUFT", "TUNA", "TUNE", "TUNG", "TURF", "TURN", "TUSK",
"TWIG", "TWIN", "TWIT", "ULAN", "UNIT", "URGE", "USED", "USER",
"USES", "UTAH", "VAIL", "VAIN", "VALE", "VARY", "VASE", "VAST",
"VEAL", "VEDA", "VEIL", "VEIN", "VEND", "VENT", "VERB", "VERY",
"VETO", "VICE", "VIEW", "VINE", "VISE", "VOID", "VOLT", "VOTE",
"WACK", "WADE", "WAGE", "WAIL", "WAIT", "WAKE", "WALE", "WALK",
"WALL", "WALT", "WAND", "WANE", "WANG", "WANT", "WARD", "WARM",
"WARN", "WART", "WASH", "WAST", "WATS", "WATT", "WAVE", "WAVY",
"WAYS", "WEAK", "WEAL", "WEAN", "WEAR", "WEED", "WEEK", "WEIR",
"WELD", "WELL", "WELT", "WENT", "WERE", "WERT", "WEST", "WHAM",
"WHAT", "WHEE", "WHEN", "WHET", "WHOA", "WHOM", "WICK", "WIFE",
"WILD", "WILL", "WIND", "WINE", "WING", "WINK", "WINO", "WIRE",
"WISE", "WISH", "WITH", "WOLF", "WONT", "WOOD", "WOOL", "WORD",
"WORE", "WORK", "WORM", "WORN", "WOVE", "WRIT", "WYNN", "YALE",
"YANG", "YANK", "YARD", "YARN", "YAWL", "YAWN", "YEAH", "YEAR",
"YELL", "YOGA", "YOKE" ]
if __name__=='__main__':
data = [('EB33F77EE73D4053', 'TIDE ITCH SLOW REIN RULE MOT'),
('CCAC2AED591056BE4F90FD441C534766',
'RASH BUSH MILK LOOK BAD BRIM AVID GAFF BAIT ROT POD LOVE'),
('EFF81F9BFBC65350920CDD7416DE8009',
'TROD MUTE TAIL WARM CHAR KONG HAAG CITY BORE O TEAL AWL')
]
for key, words in data:
print('Trying key', key)
key=binascii.a2b_hex(key)
w2=key_to_english(key)
if w2!=words:
print('key_to_english fails on key', repr(key), ', producing', str(w2))
k2=english_to_key(words)
if k2!=key:
print('english_to_key fails on key', repr(key), ', producing', repr(k2))
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
18158,
1196,
2869,
14,
647,
520,
19107,
3382,
7960,
13,
2075,
3326,
436,
282,
11779,
13,
11875,
199,
3,
3414,
402,
5932,
12,
465,
3247,
315,
7329,
1196,
2869,
26,
298,
33,
1448,
18803,
367,
199,
3,
869,
7652,
13,
18711,
7960,
13,
2075,
17276,
401,
701,
24747,
14769,
491,
14,
22895,
36,
8125,
68,
14,
199,
199,
363,
5792,
363,
275,
7880,
1304,
26,
7329,
1196,
2869,
14,
647,
12,
86,
413,
14,
22,
13004,
15,
966,
15,
966,
4114,
26,
1046,
26,
709,
282,
75,
2133,
2983,
7910,
2672,
2,
421,
199,
646,
1059,
12,
14755,
199,
504,
9143,
492,
7114,
199,
199,
3008,
3126,
16,
4881,
993,
297,
413,
4881,
4183,
297,
499,
4881,
17657,
297,
650,
4881,
20679,
297,
841,
4881,
16569,
297,
959,
4881,
11502,
297,
267,
1227,
4881,
614,
709,
297,
1520,
4881,
28107,
297,
1695,
4881,
5279,
297,
1749,
4881,
22167,
297,
1616,
4881,
4893,
16,
297,
4119,
4881,
4893,
17,
297,
267,
3144,
4881,
26451,
297,
4944,
4881,
24827,
297,
4329,
4881,
845,
709,
297,
4114,
4881,
6984,
936,
199,
199,
318,
485,
498,
18,
1393,
8,
83,
304,
272,
298,
7306,
282,
790,
1901,
282,
1059,
402,
3366,
7576,
2,
272,
26151,
1524,
2181,
8,
88,
9,
367,
671,
315,
308,
61,
272,
26151,
1524,
3008,
59,
88,
15,
975,
2807,
3008,
59,
88,
6,
1046,
61,
367,
671,
315,
26151,
61,
272,
372,
6522,
904,
8,
9503,
9,
199,
199,
318,
485,
5005,
8,
498,
12,
1343,
12,
2582,
304,
272,
408,
12147,
282,
4546,
875,
687,
282,
1059,
402,
3366,
7576,
12,
436,
372,
2399,
272,
8950,
574,
1041,
272,
1022,
29,
498,
59,
928,
26,
928,
11,
1267,
61,
272,
372,
7114,
8,
2734,
671,
12,
89,
26,
671,
10,
18,
11,
2181,
8,
89,
7216,
2006,
12,
1022,
12,
378,
9,
199,
199,
318,
790,
63,
475,
63,
17872,
334,
498,
304,
272,
408,
498,
63,
475,
63,
17872,
8,
498,
26,
875,
9,
520,
1059,
272,
19463,
376,
9697,
790,
1901,
282,
1059,
3035,
20144,
5932,
14,
272,
710,
790,
2582,
1471,
506,
282,
3663,
402,
1695,
14,
272,
408,
272,
20171,
1891,
19070,
272,
367,
1478,
315,
1425,
8,
16,
12,
822,
8,
498,
395,
1695,
304,
327,
18175,
1806,
1695,
13,
4414,
1007,
1612,
267,
1007,
498,
29,
498,
59,
1080,
26,
1080,
11,
24,
61,
267,
327,
8354,
314,
623,
1209,
402,
314,
790,
267,
2386,
1393,
3699,
498,
18,
1393,
8,
954,
498,
9,
8700,
299,
29,
16,
267,
367,
284,
315,
1425,
8,
16,
12,
5049,
12,
499,
304,
299,
29,
80,
6416,
5005,
8,
1339,
1393,
12,
284,
12,
499,
9,
267,
327,
18726,
623,
1209,
5821,
370,
314,
1007,
498,
267,
2386,
1393,
3699,
498,
18,
1393,
8,
954,
498,
11,
10194,
1332,
80,
8999,
22,
9,
1253,
5450,
430,
267,
367,
284,
315,
1425,
8,
16,
12,
5049,
12,
4119,
304,
288,
20171,
1891,
29,
17872,
11,
1027,
513,
13040,
5005,
8,
1339,
1393,
12,
284,
12,
4119,
1874,
4786,
283,
339,
372,
20171,
1891,
4439,
17,
61,
463,
327,
5852,
314,
8520,
4601,
199,
199,
318,
20171,
1891,
63,
475,
63,
498,
334,
495,
304,
272,
408,
17872,
63,
475,
63,
498,
8,
875,
304,
875,
272,
19463,
282,
1059,
1901,
282,
5226,
790,
14,
272,
710,
1059,
1471,
1395,
5932,
11673,
701,
8139,
27,
314,
1329,
272,
402,
5932,
1471,
506,
282,
3663,
402,
1227,
14,
272,
408,
339,
491,
29,
875,
14,
1294,
8,
875,
14,
4142,
8,
495,
430,
8700,
790,
19070,
272,
367,
1478,
315,
1425,
8,
16,
12,
822,
8,
44,
395,
1227,
304,
267,
27007,
29,
44,
59,
1080,
26,
1080,
11,
22,
61,
8700,
1495,
29,
25,
23033,
16,
61,
8700,
5821,
29,
16,
267,
367,
284,
315,
27007,
26,
288,
1478,
275,
4349,
513,
14,
1080,
8,
73,
9,
288,
7706,
275,
334,
24,
15426,
5609,
11,
845,
19656,
24,
9,
450,
24,
288,
612,
275,
1478,
5213,
7706,
288,
824,
12,
7429,
12,
2467,
275,
334,
89,
1140,
975,
395,
334,
89,
1140,
24,
9,
6,
16,
3581,
12,
612,
1253,
378,
3581,
288,
340,
334,
4723,
30,
21,
304,
355,
1495,
59,
5609,
15,
24,
61,
275,
1495,
59,
5609,
15,
24,
61,
1204,
824,
355,
1495,
59,
5609,
15,
24,
11,
17,
61,
275,
1495,
59,
5609,
15,
24,
11,
17,
61,
1204,
7429,
355,
1495,
59,
5609,
15,
24,
11,
18,
61,
275,
1495,
59,
5609,
15,
24,
11,
18,
61,
1204,
2467,
288,
916,
7706,
24860,
19,
26,
355,
1495,
59,
5609,
15,
24,
61,
275,
1495,
59,
5609,
15,
24,
61,
1204,
7429,
355,
1495,
59,
5609,
15,
24,
11,
17,
61,
275,
1495,
59,
5609,
15,
24,
11,
17,
61,
1204,
2467,
288,
587,
26,
1495,
59,
5609,
15,
24,
61,
275,
1495,
59,
5609,
15,
24,
61,
1204,
2467,
288,
5821,
29,
5609,
11,
845,
267,
1007,
498,
29,
5270,
8,
2734,
671,
12,
89,
26,
88,
11,
10194,
8,
89,
395,
1495,
12,
4074,
398,
327,
2670,
314,
623,
1209,
402,
314,
9183,
790,
267,
2386,
1393,
3699,
498,
18,
1393,
8,
954,
498,
9,
267,
299,
29,
16,
267,
367,
284,
315,
1425,
8,
16,
12,
5049,
12,
499,
304,
299,
29,
80,
6416,
5005,
8,
1339,
1393,
12,
284,
12,
499,
9,
267,
340,
334,
80,
6,
19,
9,
1137,
485,
5005,
8,
1339,
1393,
12,
5049,
12,
499,
304,
288,
746,
1722,
480,
48,
7945,
1125,
315,
9183,
790,
531,
267,
790,
29,
498,
11,
954,
498,
59,
16,
26,
24,
61,
272,
372,
790,
199,
199,
1027,
513,
1524,
298,
33,
401,
298,
1217,
37,
401,
298,
4121,
401,
298,
3036,
401,
298,
1554,
401,
298,
1554,
33,
401,
298,
9732,
401,
2043,
298,
1254,
47,
401,
298,
33,
998,
401,
298,
33,
1469,
401,
298,
33,
3927,
401,
298,
1761,
401,
298,
748,
48,
401,
298,
1156,
401,
298,
1156,
57,
401,
298,
879,
401,
298,
879,
33,
401,
2043,
298,
3649,
401,
298,
879,
46,
401,
298,
1441,
401,
298,
8974,
401,
298,
25380,
401,
298,
1282,
51,
401,
298
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
18158,
1196,
2869,
14,
647,
520,
19107,
3382,
7960,
13,
2075,
3326,
436,
282,
11779,
13,
11875,
199,
3,
3414,
402,
5932,
12,
465,
3247,
315,
7329,
1196,
2869,
26,
298,
33,
1448,
18803,
367,
199,
3,
869,
7652,
13,
18711,
7960,
13,
2075,
17276,
401,
701,
24747,
14769,
491,
14,
22895,
36,
8125,
68,
14,
199,
199,
363,
5792,
363,
275,
7880,
1304,
26,
7329,
1196,
2869,
14,
647,
12,
86,
413,
14,
22,
13004,
15,
966,
15,
966,
4114,
26,
1046,
26,
709,
282,
75,
2133,
2983,
7910,
2672,
2,
421,
199,
646,
1059,
12,
14755,
199,
504,
9143,
492,
7114,
199,
199,
3008,
3126,
16,
4881,
993,
297,
413,
4881,
4183,
297,
499,
4881,
17657,
297,
650,
4881,
20679,
297,
841,
4881,
16569,
297,
959,
4881,
11502,
297,
267,
1227,
4881,
614,
709,
297,
1520,
4881,
28107,
297,
1695,
4881,
5279,
297,
1749,
4881,
22167,
297,
1616,
4881,
4893,
16,
297,
4119,
4881,
4893,
17,
297,
267,
3144,
4881,
26451,
297,
4944,
4881,
24827,
297,
4329,
4881,
845,
709,
297,
4114,
4881,
6984,
936,
199,
199,
318,
485,
498,
18,
1393,
8,
83,
304,
272,
298,
7306,
282,
790,
1901,
282,
1059,
402,
3366,
7576,
2,
272,
26151,
1524,
2181,
8,
88,
9,
367,
671,
315,
308,
61,
272,
26151,
1524,
3008,
59,
88,
15,
975,
2807,
3008,
59,
88,
6,
1046,
61,
367,
671,
315,
26151,
61,
272,
372,
6522,
904,
8,
9503,
9,
199,
199,
318,
485,
5005,
8,
498,
12,
1343,
12,
2582,
304,
272,
408,
12147,
282,
4546,
875,
687,
282,
1059,
402,
3366,
7576,
12,
436,
372,
2399,
272,
8950,
574,
1041,
272,
1022,
29,
498,
59,
928,
26,
928,
11,
1267,
61,
272,
372,
7114,
8,
2734,
671,
12,
89,
26,
671,
10,
18,
11,
2181,
8,
89,
7216,
2006,
12,
1022,
12,
378,
9,
199,
199,
318,
790,
63,
475,
63,
17872,
334,
498,
304,
272,
408,
498,
63,
475,
63,
17872,
8,
498,
26,
875,
9,
520,
1059,
272,
19463,
376,
9697,
790,
1901,
282,
1059,
3035,
20144,
5932,
14,
272,
710,
790,
2582,
1471,
506,
282,
3663,
402,
1695,
14,
272,
408,
272,
20171,
1891,
19070,
272,
367,
1478,
315,
1425,
8,
16,
12,
822,
8,
498,
395,
1695,
304,
327,
18175,
1806,
1695,
13,
4414,
1007,
1612,
267,
1007,
498,
29,
498,
59,
1080,
26,
1080,
11,
24,
61,
267,
327,
8354,
314,
623,
1209,
402,
314,
790,
267,
2386,
1393,
3699,
498,
18,
1393,
8,
954,
498,
9,
8700,
299,
29,
16,
267,
367,
284,
315,
1425,
8,
16,
12,
5049,
12,
499,
304,
299,
29,
80,
6416,
5005,
8,
1339,
1393,
12,
284,
12,
499,
9,
267,
327,
18726,
623,
1209,
5821,
370,
314,
1007,
498,
267,
2386,
1393,
3699,
498,
18,
1393,
8,
954,
498,
11,
10194,
1332,
80,
8999,
22,
9,
1253,
5450,
430,
267,
367,
284,
315,
1425,
8,
16,
12,
5049,
12,
4119,
304,
288,
20171,
1891,
29,
17872,
11,
1027,
513,
13040,
5005,
8,
1339,
1393,
12,
284,
12,
4119,
1874,
4786,
283,
339,
372,
20171,
1891,
4439,
17,
61,
463,
327,
5852,
314,
8520,
4601,
199,
199,
318,
20171,
1891,
63,
475,
63,
498,
334,
495,
304,
272,
408,
17872,
63,
475,
63,
498,
8,
875,
304,
875,
272,
19463,
282,
1059,
1901,
282,
5226,
790,
14,
272,
710,
1059,
1471,
1395,
5932,
11673,
701,
8139,
27,
314,
1329,
272,
402,
5932,
1471,
506,
282,
3663,
402,
1227,
14,
272,
408,
339,
491,
29,
875,
14,
1294,
8,
875,
14,
4142,
8,
495,
430,
8700,
790,
19070,
272,
367,
1478,
315,
1425,
8,
16,
12,
822,
8,
44,
395,
1227,
304,
267,
27007,
29,
44,
59,
1080,
26,
1080,
11,
22,
61,
8700,
1495,
29,
25,
23033,
16,
61,
8700,
5821,
29,
16,
267,
367,
284,
315,
27007,
26,
288,
1478,
275,
4349,
513,
14,
1080,
8,
73,
9,
288,
7706,
275,
334,
24,
15426,
5609,
11,
845,
19656,
24,
9,
450,
24,
288,
612,
275,
1478,
5213,
7706,
288,
824,
12,
7429,
12,
2467,
275,
334,
89,
1140,
975,
395,
334,
89,
1140,
24,
9,
6,
16,
3581,
12,
612,
1253,
378,
3581,
288,
340,
334,
4723,
30,
21,
304,
355,
1495,
59,
5609,
15,
24,
61,
275,
1495,
59,
5609,
15,
24,
61,
1204,
824,
355,
1495,
59,
5609,
15,
24,
11,
17,
61,
275,
1495,
59,
5609,
15,
24,
11,
17,
61,
1204,
7429,
355,
1495,
59,
5609,
15,
24,
11,
18,
61,
275,
1495,
59,
5609,
15,
24,
11,
18,
61,
1204,
2467,
288,
916,
7706,
24860,
19,
26,
355,
1495,
59,
5609,
15,
24,
61,
275,
1495,
59,
5609,
15,
24,
61,
1204,
7429,
355,
1495,
59,
5609,
15,
24,
11,
17,
61,
275,
1495,
59,
5609,
15,
24,
11,
17,
61,
1204,
2467,
288,
587,
26,
1495,
59,
5609,
15,
24,
61,
275,
1495,
59,
5609,
15,
24,
61,
1204,
2467,
288,
5821,
29,
5609,
11,
845,
267,
1007,
498,
29,
5270,
8,
2734,
671,
12,
89,
26,
88,
11,
10194,
8,
89,
395,
1495,
12,
4074,
398,
327,
2670,
314,
623,
1209,
402,
314,
9183,
790,
267,
2386,
1393,
3699,
498,
18,
1393,
8,
954,
498,
9,
267,
299,
29,
16,
267,
367,
284,
315,
1425,
8,
16,
12,
5049,
12,
499,
304,
299,
29,
80,
6416,
5005,
8,
1339,
1393,
12,
284,
12,
499,
9,
267,
340,
334,
80,
6,
19,
9,
1137,
485,
5005,
8,
1339,
1393,
12,
5049,
12,
499,
304,
288,
746,
1722,
480,
48,
7945,
1125,
315,
9183,
790,
531,
267,
790,
29,
498,
11,
954,
498,
59,
16,
26,
24,
61,
272,
372,
790,
199,
199,
1027,
513,
1524,
298,
33,
401,
298,
1217,
37,
401,
298,
4121,
401,
298,
3036,
401,
298,
1554,
401,
298,
1554,
33,
401,
298,
9732,
401,
2043,
298,
1254,
47,
401,
298,
33,
998,
401,
298,
33,
1469,
401,
298,
33,
3927,
401,
298,
1761,
401,
298,
748,
48,
401,
298,
1156,
401,
298,
1156,
57,
401,
298,
879,
401,
298,
879,
33,
401,
2043,
298,
3649,
401,
298,
879,
46,
401,
298,
1441,
401,
298,
8974,
401,
298,
25380,
401,
298,
1282,
51,
401,
298,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
Dubniak/SafeDroid
|
FeatureExtractionServer/androguard/core/bytecode.py
|
2
|
13435
|
# This file is part of Androguard.
#
# Copyright (C) 2012, Anthony Desnos <desnos at t0t0.fr>
# All rights reserved.
#
# Androguard is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Androguard is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Androguard. If not, see <http://www.gnu.org/licenses/>.
from struct import unpack, pack
from androconf import Color, warning, error, CONF, disable_colors, enable_colors, remove_colors, save_colors
def disable_print_colors() :
colors = save_colors()
remove_colors()
return colors
def enable_print_colors(colors) :
enable_colors(colors)
# Handle exit message
def Exit( msg ):
warning("Error : " + msg)
raise("oops")
def Warning( msg ):
warning(msg)
def _PrintBanner() :
print_fct = CONF["PRINT_FCT"]
print_fct("*" * 75 + "\n")
def _PrintSubBanner(title=None) :
print_fct = CONF["PRINT_FCT"]
if title == None :
print_fct("#" * 20 + "\n")
else :
print_fct("#" * 10 + " " + title + "\n")
def _PrintNote(note, tab=0) :
print_fct = CONF["PRINT_FCT"]
note_color = CONF["COLORS"]["NOTE"]
normal_color = CONF["COLORS"]["NORMAL"]
print_fct("\t" * tab + "%s# %s%s" % (note_color, note, normal_color) + "\n")
# Print arg into a correct format
def _Print(name, arg) :
buff = name + " "
if type(arg).__name__ == 'int' :
buff += "0x%x" % arg
elif type(arg).__name__ == 'long' :
buff += "0x%x" % arg
elif type(arg).__name__ == 'str' :
buff += "%s" % arg
elif isinstance(arg, SV) :
buff += "0x%x" % arg.get_value()
elif isinstance(arg, SVs) :
buff += arg.get_value().__str__()
print buff
def PrettyShow( basic_blocks ) :
PrettyShow1( basic_blocks )
def PrettyShowEx( exceptions ) :
if len(exceptions) > 0 :
CONF["PRINT_FCT"]("Exceptions:\n")
for i in exceptions :
CONF["PRINT_FCT"]("\t%s%s%s\n" % (CONF["COLORS"]["EXCEPTION"], i.show_buff(), CONF["COLORS"]["NORMAL"]))
def _PrintXRef(tag, items) :
print_fct = CONF["PRINT_FCT"]
for i in items :
print_fct("%s: %s %s %s %s\n" % (tag, i[0].get_class_name(), i[0].get_name(), i[0].get_descriptor(), ' '.join("%x" % j.get_idx() for j in i[1])))
def _PrintDefault(msg) :
print_fct = CONF["PRINT_FCT"]
print_fct(msg)
def PrettyShow1( basic_blocks ) :
idx = 0
nb = 0
offset_color = CONF["COLORS"]["OFFSET"]
offset_addr_color = CONF["COLORS"]["OFFSET_ADDR"]
instruction_name_color = CONF["COLORS"]["INSTRUCTION_NAME"]
branch_false_color = CONF["COLORS"]["BRANCH_FALSE"]
branch_true_color = CONF["COLORS"]["BRANCH_TRUE"]
branch_color = CONF["COLORS"]["BRANCH"]
exception_color = CONF["COLORS"]["EXCEPTION"]
bb_color = CONF["COLORS"]["BB"]
normal_color = CONF["COLORS"]["NORMAL"]
print_fct = CONF["PRINT_FCT"]
for i in basic_blocks :
print_fct("%s%s%s : \n" % (bb_color, i.name, normal_color))
instructions = i.get_instructions()
for ins in instructions :
#for ins in i.ins :
notes = ins.get_notes()
if notes != [] :
for note in notes :
_PrintNote(note, 1)
print_fct("\t%s%-3d%s(%s%08x%s) " % (offset_color, nb, normal_color, offset_addr_color, idx, normal_color))
print_fct("%s%-20s%s %s" %(instruction_name_color, ins.get_name(), normal_color, ins.get_output(idx)))
op_value = ins.get_op_value()
if ins == instructions[-1] and i.childs != [] :
print_fct(" ")
# packed/sparse-switch
if (op_value == 0x2b or op_value == 0x2c) and len(i.childs) > 1 :
values = i.get_special_ins(idx).get_values()
print_fct("%s[ D:%s%s " % (branch_false_color, i.childs[0][2].name, branch_color))
print_fct(' '.join("%d:%s" % (values[j], i.childs[j+1][2].name) for j in range(0, len(i.childs)-1) ) + " ]%s" % normal_color)
else :
if len(i.childs) == 2 :
print_fct("%s[ %s%s " % (branch_false_color, i.childs[0][2].name, branch_true_color))
print_fct(' '.join("%s" % c[2].name for c in i.childs[1:]) + " ]%s" % normal_color)
else :
print_fct("%s[ " % branch_color + ' '.join("%s" % c[2].name for c in i.childs) + " ]%s" % normal_color)
idx += ins.get_length()
nb += 1
print_fct("\n")
if i.exception_analysis != None :
print_fct("\t%s%s%s\n" % (exception_color, i.exception_analysis.show_buff(), normal_color))
print_fct("\n")
def method2dot( mx ) :
"""
Export analysis method to dot format
@param mx : MethodAnalysis object
@rtype : dot format buffer
"""
vm = mx.get_vm()
buff = ""
for i in mx.basic_blocks.get() :
val = "green"
if len(i.childs) > 1 :
val = "red"
elif len(i.childs) == 1 :
val = "blue"
for j in i.childs :
buff += "\"%s\" -> \"%s\" [color=\"%s\"];\n" % ( i.get_name(), j[-1].get_name(), val )
if val == "red" :
val = "green"
idx = i.start
label = ""
for ins in i.get_instructions() :
label += "%x %s\l" % (idx, vm.dotbuff(ins, idx))
idx += ins.get_length()
buff += "\"%s\" [color=\"lightgray\", label=\"%s\"]\n" % (i.get_name(), label)
return buff
def method2format( output, _format="png", mx = None, raw = False ) :
"""
Export method to a specific file format
@param output : output filename
@param _format : format type (png, jpg ...) (default : png)
@param mx : specify the MethodAnalysis object
@param raw : use directly a dot raw buffer
"""
try :
import pydot
except ImportError :
error("module pydot not found")
buff = "digraph code {\n"
buff += "graph [bgcolor=white];\n"
buff += "node [color=lightgray, style=filled shape=box fontname=\"Courier\" fontsize=\"8\"];\n"
if raw == False :
buff += method2dot( mx )
else :
buff += raw
buff += "}"
d = pydot.graph_from_dot_data( buff )
if d :
getattr(d, "write_" + _format)( output )
def method2png( output, mx = None, raw = False ) :
"""
Export method to a png file format
@param output : output filename
@param mx : specify the MethodAnalysis object
@param raw : use directly a dot raw buffer
"""
buff = raw
if raw == False :
buff = method2dot( mx )
method2format( output, "png", mx, buff )
def method2jpg( output, mx = None, raw = False ) :
"""
Export method to a jpg file format
@param output : output filename
@param mx : specify the MethodAnalysis object
@param raw : use directly a dot raw buffer
"""
buff = raw
if raw == False :
buff = method2dot( mx )
method2format( output, "jpg", mx, buff )
class SV :
"""SV is used to handle more easily a value"""
def __init__(self, size, buff) :
self.__size = size
self.__value = unpack(self.__size, buff)[0]
def _get(self) :
return pack(self.__size, self.__value)
def __str__(self) :
return "0x%x" % self.__value
def __int__(self) :
return self.__value
def get_value_buff(self) :
return self._get()
def get_value(self) :
return self.__value
def set_value(self, attr) :
self.__value = attr
class SVs :
"""SVs is used to handle more easily a structure of different values"""
def __init__(self, size, ntuple, buff) :
self.__size = size
self.__value = ntuple._make( unpack( self.__size, buff ) )
def _get(self) :
l = []
for i in self.__value._fields :
l.append( getattr( self.__value, i ) )
return pack( self.__size, *l)
def _export(self) :
return [ x for x in self.__value._fields ]
def get_value_buff(self) :
return self._get()
def get_value(self) :
return self.__value
def set_value(self, attr) :
self.__value = self.__value._replace( **attr )
def __str__(self) :
return self.__value.__str__()
def object_to_str(obj) :
if isinstance(obj, str) :
return obj
elif isinstance(obj, bool) :
return ""
elif isinstance(obj, int) :
return pack("<L", obj)
elif obj == None :
return ""
else :
#print type(obj), obj
return obj.get_raw()
class MethodBC(object) :
def show(self, value) :
getattr(self, "show_" + value)()
class BuffHandle :
def __init__(self, buff) :
self.__buff = buff
self.__idx = 0
def read_b(self, size) :
return self.__buff[ self.__idx : self.__idx + size ]
def read(self, size) :
if isinstance(size, SV) :
size = size.value
buff = self.__buff[ self.__idx : self.__idx + size ]
self.__idx += size
return buff
def end(self) :
return self.__idx == len(self.__buff)
class Buff :
def __init__(self, offset, buff) :
self.offset = offset
self.buff = buff
self.size = len(buff)
class _Bytecode(object) :
def __init__(self, buff) :
try :
import psyco
psyco.full()
except ImportError :
pass
self.__buff = buff
self.__idx = 0
def read(self, size) :
if isinstance(size, SV) :
size = size.value
buff = self.__buff[ self.__idx : self.__idx + size ]
self.__idx += size
return buff
def readat(self, off) :
if isinstance(off, SV) :
off = off.value
return self.__buff[ off : ]
def read_b(self, size) :
return self.__buff[ self.__idx : self.__idx + size ]
def set_idx(self, idx) :
if isinstance(idx, SV) :
self.__idx = idx.value
else :
self.__idx = idx
def get_idx(self) :
return self.__idx
def add_idx(self, idx) :
self.__idx += idx
def register(self, type_register, fct) :
self.__registers[ type_register ].append( fct )
def get_buff(self) :
return self.__buff
def length_buff(self) :
return len( self.__buff )
def save(self, filename) :
fd = open(filename, "w")
buff = self._save()
fd.write( buff )
fd.close()
def FormatClassToJava(input) :
"""
Transofmr a typical xml format class into java format
@param input : the input class name
"""
return "L" + input.replace(".", "/") + ";"
def FormatClassToPython(input) :
i = input[:-1]
i = i.replace("/", "_")
i = i.replace("$", "_")
return i
def FormatNameToPython(input) :
i = input.replace("<", "")
i = i.replace(">", "")
i = i.replace("$", "_")
return i
def FormatDescriptorToPython(input) :
i = input.replace("/", "_")
i = i.replace(";", "")
i = i.replace("[", "")
i = i.replace("(", "")
i = i.replace(")", "")
i = i.replace(" ", "")
i = i.replace("$", "")
return i
####################### class/method/field export ########################
def ExportVMToPython(vm) :
"""
Export classes/methods/fields' names in the python namespace
@param vm : a VM object (DalvikVMFormat, JVMFormat)
"""
for _class in vm.get_classes() :
### Class
name = "CLASS_" + FormatClassToPython( _class.get_name() )
setattr( vm, name, _class )
### Methods
m = {}
for method in _class.get_methods() :
if method.get_name() not in m :
m[ method.get_name() ] = []
m[ method.get_name() ].append( method )
for i in m :
if len(m[i]) == 1 :
j = m[i][0]
name = "METHOD_" + FormatNameToPython( j.get_name() )
setattr( _class, name, j )
else :
for j in m[i] :
name = "METHOD_" + FormatNameToPython( j.get_name() ) + "_" + FormatDescriptorToPython( j.get_descriptor() )
setattr( _class, name, j )
### Fields
f = {}
for field in _class.get_fields() :
if field.get_name() not in f :
f[ field.get_name() ] = []
f[ field.get_name() ].append( field )
for i in f :
if len(f[i]) == 1 :
j = f[i][0]
name = "FIELD_" + FormatNameToPython( j.get_name() )
setattr( _class, name, j )
else :
for j in f[i] :
name = "FIELD_" + FormatNameToPython( j.get_name() ) + "_" + FormatDescriptorToPython( j.get_descriptor() )
setattr( _class, name, j )
|
gpl-3.0
|
[
3,
961,
570,
365,
1777,
402,
6061,
293,
15606,
14,
199,
3,
199,
3,
1898,
334,
35,
9,
6029,
12,
1626,
898,
89,
8055,
12712,
665,
3424,
12712,
737,
307,
16,
84,
16,
14,
4391,
30,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
6061,
293,
15606,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
6061,
293,
15606,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
844,
199,
3,
3180,
543,
6061,
293,
15606,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
504,
2702,
492,
7787,
12,
1706,
199,
199,
504,
436,
293,
2190,
492,
11581,
12,
5721,
12,
1125,
12,
6392,
12,
3507,
63,
7120,
12,
4756,
63,
7120,
12,
2813,
63,
7120,
12,
3354,
63,
7120,
199,
199,
318,
3507,
63,
1361,
63,
7120,
342,
520,
523,
9229,
275,
3354,
63,
7120,
342,
523,
2813,
63,
7120,
342,
523,
372,
9229,
9948,
199,
318,
4756,
63,
1361,
63,
7120,
8,
7120,
9,
520,
523,
4756,
63,
7120,
8,
7120,
9,
199,
199,
3,
8690,
4458,
1245,
199,
318,
18704,
8,
1499,
3461,
272,
5721,
480,
547,
520,
298,
435,
1499,
9,
272,
746,
480,
79,
1483,
531,
199,
199,
318,
15902,
8,
1499,
3461,
272,
5721,
8,
1328,
9,
199,
199,
318,
485,
5375,
22107,
342,
520,
272,
870,
63,
70,
319,
275,
6392,
905,
21754,
63,
38,
1028,
937,
272,
870,
63,
70,
319,
480,
12469,
627,
13098,
435,
1867,
78,
531,
199,
199,
318,
485,
5375,
2610,
22107,
8,
1213,
29,
403,
9,
520,
523,
870,
63,
70,
319,
275,
6392,
905,
21754,
63,
38,
1028,
937,
523,
340,
2538,
508,
488,
520,
272,
870,
63,
70,
319,
10064,
2,
627,
3388,
435,
1867,
78,
531,
523,
587,
520,
272,
870,
63,
70,
319,
10064,
2,
627,
1616,
435,
298,
298,
435,
2538,
435,
1867,
78,
531,
199,
199,
318,
485,
5375,
7443,
8,
4610,
12,
5174,
29,
16,
9,
520,
523,
870,
63,
70,
319,
275,
6392,
905,
21754,
63,
38,
1028,
937,
523,
5317,
63,
2326,
275,
6392,
905,
25671,
6611,
19855,
937,
523,
3293,
63,
2326,
275,
6392,
905,
25671,
6611,
10765,
937,
523,
870,
63,
70,
319,
4582,
84,
2,
627,
5174,
435,
2071,
83,
3,
450,
83,
5,
83,
2,
450,
334,
4610,
63,
2326,
12,
5317,
12,
3293,
63,
2326,
9,
435,
1867,
78,
531,
199,
199,
3,
9101,
1680,
1901,
282,
3211,
1475,
199,
318,
485,
5375,
8,
354,
12,
1680,
9,
520,
272,
17893,
275,
536,
435,
298,
298,
339,
340,
730,
8,
1273,
2843,
354,
363,
508,
283,
442,
7,
520,
267,
17893,
847,
298,
16,
88,
5,
88,
2,
450,
1680,
272,
916,
730,
8,
1273,
2843,
354,
363,
508,
283,
2809,
7,
520,
267,
17893,
847,
298,
16,
88,
5,
88,
2,
450,
1680,
272,
916,
730,
8,
1273,
2843,
354,
363,
508,
283,
495,
7,
520,
267,
17893,
847,
2071,
83,
2,
450,
1680,
272,
916,
1228,
8,
1273,
12,
14056,
9,
520,
267,
17893,
847,
298,
16,
88,
5,
88,
2,
450,
1680,
14,
362,
63,
585,
342,
272,
916,
1228,
8,
1273,
12,
14056,
83,
9,
520,
267,
17893,
847,
1680,
14,
362,
63,
585,
11027,
495,
4533,
339,
870,
17893,
199,
199,
318,
31651,
6824,
8,
5678,
63,
4166,
776,
520,
272,
31651,
6824,
17,
8,
5678,
63,
4166,
776,
199,
199,
318,
31651,
6824,
920,
8,
4967,
776,
520,
272,
340,
822,
8,
3924,
9,
690,
378,
520,
267,
6392,
905,
21754,
63,
38,
1028,
937,
480,
16836,
3427,
78,
531,
267,
367,
284,
315,
4967,
520,
23664,
6392,
905,
21754,
63,
38,
1028,
937,
4582,
84,
5,
83,
5,
83,
5,
83,
60,
78,
2,
450,
334,
3103,
905,
25671,
6611,
15375,
2255,
284,
14,
2384,
63,
16830,
1062,
6392,
905,
25671,
6611,
10765,
13045,
199,
199,
318,
485,
5375,
56,
2891,
8,
1450,
12,
2974,
9,
520,
523,
870,
63,
70,
319,
275,
6392,
905,
21754,
63,
38,
1028,
937,
523,
367,
284,
315,
2974,
520,
272,
870,
63,
70,
319,
3647,
83,
26,
450,
83,
450,
83,
450,
83,
450,
83,
60,
78,
2,
450,
334,
1450,
12,
284,
59,
16,
1055,
362,
63,
533,
63,
354,
1062,
284,
59,
16,
1055,
362,
63,
354,
1062,
284,
59,
16,
1055,
362,
63,
4120,
1062,
283,
1987,
904,
3647,
88,
2,
450,
1335,
14,
362,
63,
2996,
342,
367,
1335,
315,
284,
59,
17,
11845,
199,
199,
318,
485,
5375,
2698,
8,
1328,
9,
520,
523,
870,
63,
70,
319,
275,
6392,
905,
21754,
63,
38,
1028,
937,
523,
870,
63,
70,
319,
8,
1328,
9,
199,
199,
318,
31651,
6824,
17,
8,
5678,
63,
4166,
776,
520,
272,
4280,
275,
378,
272,
8526,
275,
378,
339,
3268,
63,
2326,
275,
6392,
905,
25671,
6611,
14839,
937,
272,
3268,
63,
2697,
63,
2326,
275,
6392,
905,
25671,
6611,
14839,
63,
7803,
937,
272,
16329,
63,
354,
63,
2326,
275,
6392,
905,
25671,
6611,
26347,
53,
5430,
63,
2339,
937,
272,
5246,
63,
3910,
63,
2326,
275,
6392,
905,
25671,
6611,
24776,
63,
19823,
937,
272,
5246,
63,
2052,
63,
2326,
275,
6392,
905,
25671,
6611,
24776,
63,
15064,
937,
272,
5246,
63,
2326,
275,
6392,
905,
25671,
6611,
24776,
937,
272,
1919,
63,
2326,
275,
6392,
905,
25671,
6611,
15375,
937,
272,
14027,
63,
2326,
275,
6392,
905,
25671,
6611,
5342,
937,
272,
3293,
63,
2326,
275,
6392,
905,
25671,
6611,
10765,
937,
272,
870,
63,
70,
319,
275,
6392,
905,
21754,
63
] |
[
961,
570,
365,
1777,
402,
6061,
293,
15606,
14,
199,
3,
199,
3,
1898,
334,
35,
9,
6029,
12,
1626,
898,
89,
8055,
12712,
665,
3424,
12712,
737,
307,
16,
84,
16,
14,
4391,
30,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
6061,
293,
15606,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
6061,
293,
15606,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
844,
199,
3,
3180,
543,
6061,
293,
15606,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
504,
2702,
492,
7787,
12,
1706,
199,
199,
504,
436,
293,
2190,
492,
11581,
12,
5721,
12,
1125,
12,
6392,
12,
3507,
63,
7120,
12,
4756,
63,
7120,
12,
2813,
63,
7120,
12,
3354,
63,
7120,
199,
199,
318,
3507,
63,
1361,
63,
7120,
342,
520,
523,
9229,
275,
3354,
63,
7120,
342,
523,
2813,
63,
7120,
342,
523,
372,
9229,
9948,
199,
318,
4756,
63,
1361,
63,
7120,
8,
7120,
9,
520,
523,
4756,
63,
7120,
8,
7120,
9,
199,
199,
3,
8690,
4458,
1245,
199,
318,
18704,
8,
1499,
3461,
272,
5721,
480,
547,
520,
298,
435,
1499,
9,
272,
746,
480,
79,
1483,
531,
199,
199,
318,
15902,
8,
1499,
3461,
272,
5721,
8,
1328,
9,
199,
199,
318,
485,
5375,
22107,
342,
520,
272,
870,
63,
70,
319,
275,
6392,
905,
21754,
63,
38,
1028,
937,
272,
870,
63,
70,
319,
480,
12469,
627,
13098,
435,
1867,
78,
531,
199,
199,
318,
485,
5375,
2610,
22107,
8,
1213,
29,
403,
9,
520,
523,
870,
63,
70,
319,
275,
6392,
905,
21754,
63,
38,
1028,
937,
523,
340,
2538,
508,
488,
520,
272,
870,
63,
70,
319,
10064,
2,
627,
3388,
435,
1867,
78,
531,
523,
587,
520,
272,
870,
63,
70,
319,
10064,
2,
627,
1616,
435,
298,
298,
435,
2538,
435,
1867,
78,
531,
199,
199,
318,
485,
5375,
7443,
8,
4610,
12,
5174,
29,
16,
9,
520,
523,
870,
63,
70,
319,
275,
6392,
905,
21754,
63,
38,
1028,
937,
523,
5317,
63,
2326,
275,
6392,
905,
25671,
6611,
19855,
937,
523,
3293,
63,
2326,
275,
6392,
905,
25671,
6611,
10765,
937,
523,
870,
63,
70,
319,
4582,
84,
2,
627,
5174,
435,
2071,
83,
3,
450,
83,
5,
83,
2,
450,
334,
4610,
63,
2326,
12,
5317,
12,
3293,
63,
2326,
9,
435,
1867,
78,
531,
199,
199,
3,
9101,
1680,
1901,
282,
3211,
1475,
199,
318,
485,
5375,
8,
354,
12,
1680,
9,
520,
272,
17893,
275,
536,
435,
298,
298,
339,
340,
730,
8,
1273,
2843,
354,
363,
508,
283,
442,
7,
520,
267,
17893,
847,
298,
16,
88,
5,
88,
2,
450,
1680,
272,
916,
730,
8,
1273,
2843,
354,
363,
508,
283,
2809,
7,
520,
267,
17893,
847,
298,
16,
88,
5,
88,
2,
450,
1680,
272,
916,
730,
8,
1273,
2843,
354,
363,
508,
283,
495,
7,
520,
267,
17893,
847,
2071,
83,
2,
450,
1680,
272,
916,
1228,
8,
1273,
12,
14056,
9,
520,
267,
17893,
847,
298,
16,
88,
5,
88,
2,
450,
1680,
14,
362,
63,
585,
342,
272,
916,
1228,
8,
1273,
12,
14056,
83,
9,
520,
267,
17893,
847,
1680,
14,
362,
63,
585,
11027,
495,
4533,
339,
870,
17893,
199,
199,
318,
31651,
6824,
8,
5678,
63,
4166,
776,
520,
272,
31651,
6824,
17,
8,
5678,
63,
4166,
776,
199,
199,
318,
31651,
6824,
920,
8,
4967,
776,
520,
272,
340,
822,
8,
3924,
9,
690,
378,
520,
267,
6392,
905,
21754,
63,
38,
1028,
937,
480,
16836,
3427,
78,
531,
267,
367,
284,
315,
4967,
520,
23664,
6392,
905,
21754,
63,
38,
1028,
937,
4582,
84,
5,
83,
5,
83,
5,
83,
60,
78,
2,
450,
334,
3103,
905,
25671,
6611,
15375,
2255,
284,
14,
2384,
63,
16830,
1062,
6392,
905,
25671,
6611,
10765,
13045,
199,
199,
318,
485,
5375,
56,
2891,
8,
1450,
12,
2974,
9,
520,
523,
870,
63,
70,
319,
275,
6392,
905,
21754,
63,
38,
1028,
937,
523,
367,
284,
315,
2974,
520,
272,
870,
63,
70,
319,
3647,
83,
26,
450,
83,
450,
83,
450,
83,
450,
83,
60,
78,
2,
450,
334,
1450,
12,
284,
59,
16,
1055,
362,
63,
533,
63,
354,
1062,
284,
59,
16,
1055,
362,
63,
354,
1062,
284,
59,
16,
1055,
362,
63,
4120,
1062,
283,
1987,
904,
3647,
88,
2,
450,
1335,
14,
362,
63,
2996,
342,
367,
1335,
315,
284,
59,
17,
11845,
199,
199,
318,
485,
5375,
2698,
8,
1328,
9,
520,
523,
870,
63,
70,
319,
275,
6392,
905,
21754,
63,
38,
1028,
937,
523,
870,
63,
70,
319,
8,
1328,
9,
199,
199,
318,
31651,
6824,
17,
8,
5678,
63,
4166,
776,
520,
272,
4280,
275,
378,
272,
8526,
275,
378,
339,
3268,
63,
2326,
275,
6392,
905,
25671,
6611,
14839,
937,
272,
3268,
63,
2697,
63,
2326,
275,
6392,
905,
25671,
6611,
14839,
63,
7803,
937,
272,
16329,
63,
354,
63,
2326,
275,
6392,
905,
25671,
6611,
26347,
53,
5430,
63,
2339,
937,
272,
5246,
63,
3910,
63,
2326,
275,
6392,
905,
25671,
6611,
24776,
63,
19823,
937,
272,
5246,
63,
2052,
63,
2326,
275,
6392,
905,
25671,
6611,
24776,
63,
15064,
937,
272,
5246,
63,
2326,
275,
6392,
905,
25671,
6611,
24776,
937,
272,
1919,
63,
2326,
275,
6392,
905,
25671,
6611,
15375,
937,
272,
14027,
63,
2326,
275,
6392,
905,
25671,
6611,
5342,
937,
272,
3293,
63,
2326,
275,
6392,
905,
25671,
6611,
10765,
937,
272,
870,
63,
70,
319,
275,
6392,
905,
21754,
63,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
ravibhure/ansible
|
lib/ansible/modules/cloud/google/gce_mig.py
|
23
|
30107
|
#!/usr/bin/python
# Copyright 2016 Google Inc.
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = '''
---
module: gce_mig
version_added: "2.2"
short_description: Create, Update or Destroy a Managed Instance Group (MIG).
description:
- Create, Update or Destroy a Managed Instance Group (MIG). See
U(https://cloud.google.com/compute/docs/instance-groups) for an overview.
Full install/configuration instructions for the gce* modules can
be found in the comments of ansible/test/gce_tests.py.
requirements:
- "python >= 2.6"
- "apache-libcloud >= 1.2.0"
notes:
- Resizing and Recreating VM are also supported.
- An existing instance template is required in order to create a
Managed Instance Group.
author:
- "Tom Melendez (@supertom) <tom@supertom.com>"
options:
name:
description:
- Name of the Managed Instance Group.
required: true
template:
description:
- Instance Template to be used in creating the VMs. See
U(https://cloud.google.com/compute/docs/instance-templates) to learn more
about Instance Templates. Required for creating MIGs.
required: false
size:
description:
- Size of Managed Instance Group. If MIG already exists, it will be
resized to the number provided here. Required for creating MIGs.
required: false
service_account_email:
description:
- service account email
required: false
default: null
credentials_file:
description:
- Path to the JSON file associated with the service account email
default: null
required: false
project_id:
description:
- GCE project ID
required: false
default: null
state:
description:
- desired state of the resource
required: false
default: "present"
choices: ["absent", "present"]
zone:
description:
- The GCE zone to use for this Managed Instance Group.
required: true
autoscaling:
description:
- A dictionary of configuration for the autoscaler. 'enabled (bool)', 'name (str)'
and policy.max_instances (int) are required fields if autoscaling is used. See
U(https://cloud.google.com/compute/docs/reference/beta/autoscalers) for more information
on Autoscaling.
required: false
default: null
named_ports:
version_added: "2.3"
description:
- Define named ports that backend services can forward data to. Format is a a list of
name:port dictionaries.
required: false
default: null
'''
EXAMPLES = '''
# Following playbook creates, rebuilds instances, resizes and then deletes a MIG.
# Notes:
# - Two valid Instance Templates must exist in your GCE project in order to run
# this playbook. Change the fields to match the templates used in your
# project.
# - The use of the 'pause' module is not required, it is just for convenience.
- name: Managed Instance Group Example
hosts: localhost
gather_facts: False
tasks:
- name: Create MIG
gce_mig:
name: ansible-mig-example
zone: us-central1-c
state: present
size: 1
template: my-instance-template-1
named_ports:
- name: http
port: 80
- name: foobar
port: 82
- name: Pause for 30 seconds
pause:
seconds: 30
- name: Recreate MIG Instances with Instance Template change.
gce_mig:
name: ansible-mig-example
zone: us-central1-c
state: present
template: my-instance-template-2-small
recreate_instances: yes
- name: Pause for 30 seconds
pause:
seconds: 30
- name: Resize MIG
gce_mig:
name: ansible-mig-example
zone: us-central1-c
state: present
size: 3
- name: Update MIG with Autoscaler
gce_mig:
name: ansible-mig-example
zone: us-central1-c
state: present
size: 3
template: my-instance-template-2-small
recreate_instances: yes
autoscaling:
enabled: yes
name: my-autoscaler
policy:
min_instances: 2
max_instances: 5
cool_down_period: 37
cpu_utilization:
target: .39
load_balancing_utilization:
target: 0.4
- name: Pause for 30 seconds
pause:
seconds: 30
- name: Delete MIG
gce_mig:
name: ansible-mig-example
zone: us-central1-c
state: absent
autoscaling:
enabled: no
name: my-autoscaler
'''
RETURN = '''
zone:
description: Zone in which to launch MIG.
returned: always
type: string
sample: "us-central1-b"
template:
description: Instance Template to use for VMs. Must exist prior to using with MIG.
returned: changed
type: string
sample: "my-instance-template"
name:
description: Name of the Managed Instance Group.
returned: changed
type: string
sample: "my-managed-instance-group"
named_ports:
description: list of named ports acted upon
returned: when named_ports are initially set or updated
type: list
sample: [{ "name": "http", "port": 80 }, { "name": "foo", "port": 82 }]
size:
description: Number of VMs in Managed Instance Group.
returned: changed
type: int
sample: 4
created_instances:
description: Names of instances created.
returned: When instances are created.
type: list
sample: ["ansible-mig-new-0k4y", "ansible-mig-new-0zk5", "ansible-mig-new-kp68"]
deleted_instances:
description: Names of instances deleted.
returned: When instances are deleted.
type: list
sample: ["ansible-mig-new-0k4y", "ansible-mig-new-0zk5", "ansible-mig-new-kp68"]
resize_created_instances:
description: Names of instances created during resizing.
returned: When a resize results in the creation of instances.
type: list
sample: ["ansible-mig-new-0k4y", "ansible-mig-new-0zk5", "ansible-mig-new-kp68"]
resize_deleted_instances:
description: Names of instances deleted during resizing.
returned: When a resize results in the deletion of instances.
type: list
sample: ["ansible-mig-new-0k4y", "ansible-mig-new-0zk5", "ansible-mig-new-kp68"]
recreated_instances:
description: Names of instances recreated.
returned: When instances are recreated.
type: list
sample: ["ansible-mig-new-0k4y", "ansible-mig-new-0zk5", "ansible-mig-new-kp68"]
created_autoscaler:
description: True if Autoscaler was attempted and created. False otherwise.
returned: When the creation of an Autoscaler was attempted.
type: bool
sample: true
updated_autoscaler:
description: True if an Autoscaler update was attempted and succeeded.
False returned if update failed.
returned: When the update of an Autoscaler was attempted.
type: bool
sample: true
deleted_autoscaler:
description: True if an Autoscaler delete attempted and succeeded.
False returned if delete failed.
returned: When the delete of an Autoscaler was attempted.
type: bool
sample: true
set_named_ports:
description: True if the named_ports have been set
returned: named_ports have been set
type: bool
sample: true
updated_named_ports:
description: True if the named_ports have been updated
returned: named_ports have been updated
type: bool
sample: true
'''
try:
from ast import literal_eval
HAS_PYTHON26 = True
except ImportError:
HAS_PYTHON26 = False
try:
import libcloud
from libcloud.compute.types import Provider
from libcloud.compute.providers import get_driver
from libcloud.common.google import GoogleBaseError, QuotaExceededError, \
ResourceExistsError, ResourceInUseError, ResourceNotFoundError
from libcloud.compute.drivers.gce import GCEAddress
_ = Provider.GCE
HAS_LIBCLOUD = True
except ImportError:
HAS_LIBCLOUD = False
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.gce import gce_connect
def _check_params(params, field_list):
"""
Helper to validate params.
Use this in function definitions if they require specific fields
to be present.
:param params: structure that contains the fields
:type params: ``dict``
:param field_list: list of dict representing the fields
[{'name': str, 'required': True/False', 'type': cls}]
:type field_list: ``list`` of ``dict``
:return True, exits otherwise
:rtype: ``bool``
"""
for d in field_list:
if not d['name'] in params:
if d['required'] is True:
return (False, "%s is required and must be of type: %s" %
(d['name'], str(d['type'])))
else:
if not isinstance(params[d['name']], d['type']):
return (False,
"%s must be of type: %s" % (d['name'], str(d['type'])))
return (True, '')
def _validate_autoscaling_params(params):
"""
Validate that the minimum configuration is present for autoscaling.
:param params: Ansible dictionary containing autoscaling configuration
It is expected that autoscaling config will be found at the
key 'autoscaling'.
:type params: ``dict``
:return: Tuple containing a boolean and a string. True if autoscaler
is valid, False otherwise, plus str for message.
:rtype: ``(``bool``, ``str``)``
"""
if not params['autoscaling']:
# It's optional, so if not set at all, it's valid.
return (True, '')
if not isinstance(params['autoscaling'], dict):
return (False,
'autoscaling: configuration expected to be a dictionary.')
# check first-level required fields
as_req_fields = [
{'name': 'name', 'required': True, 'type': str},
{'name': 'enabled', 'required': True, 'type': bool},
{'name': 'policy', 'required': True, 'type': dict}
] # yapf: disable
(as_req_valid, as_req_msg) = _check_params(params['autoscaling'],
as_req_fields)
if not as_req_valid:
return (False, as_req_msg)
# check policy configuration
as_policy_fields = [
{'name': 'max_instances', 'required': True, 'type': int},
{'name': 'min_instances', 'required': False, 'type': int},
{'name': 'cool_down_period', 'required': False, 'type': int}
] # yapf: disable
(as_policy_valid, as_policy_msg) = _check_params(
params['autoscaling']['policy'], as_policy_fields)
if not as_policy_valid:
return (False, as_policy_msg)
# TODO(supertom): check utilization fields
return (True, '')
def _validate_named_port_params(params):
"""
Validate the named ports parameters
:param params: Ansible dictionary containing named_ports configuration
It is expected that autoscaling config will be found at the
key 'named_ports'. That key should contain a list of
{name : port} dictionaries.
:type params: ``dict``
:return: Tuple containing a boolean and a string. True if params
are valid, False otherwise, plus str for message.
:rtype: ``(``bool``, ``str``)``
"""
if not params['named_ports']:
# It's optional, so if not set at all, it's valid.
return (True, '')
if not isinstance(params['named_ports'], list):
return (False, 'named_ports: expected list of name:port dictionaries.')
req_fields = [
{'name': 'name', 'required': True, 'type': str},
{'name': 'port', 'required': True, 'type': int}
] # yapf: disable
for np in params['named_ports']:
(valid_named_ports, np_msg) = _check_params(np, req_fields)
if not valid_named_ports:
return (False, np_msg)
return (True, '')
def _get_instance_list(mig, field='name', filter_list=None):
"""
Helper to grab field from instances response.
:param mig: Managed Instance Group Object from libcloud.
:type mig: :class: `GCEInstanceGroupManager`
:param field: Field name in list_managed_instances response. Defaults
to 'name'.
:type field: ``str``
:param filter_list: list of 'currentAction' strings to filter on. Only
items that match a currentAction in this list will
be returned. Default is "['NONE']".
:type filter_list: ``list`` of ``str``
:return: List of strings from list_managed_instances response.
:rtype: ``list``
"""
filter_list = ['NONE'] if filter_list is None else filter_list
return [x[field] for x in mig.list_managed_instances()
if x['currentAction'] in filter_list]
def _gen_gce_as_policy(as_params):
"""
Take Autoscaler params and generate GCE-compatible policy.
:param as_params: Dictionary in Ansible-playbook format
containing policy arguments.
:type as_params: ``dict``
:return: GCE-compatible policy dictionary
:rtype: ``dict``
"""
asp_data = {}
asp_data['maxNumReplicas'] = as_params['max_instances']
if 'min_instances' in as_params:
asp_data['minNumReplicas'] = as_params['min_instances']
if 'cool_down_period' in as_params:
asp_data['coolDownPeriodSec'] = as_params['cool_down_period']
if 'cpu_utilization' in as_params and 'target' in as_params[
'cpu_utilization']:
asp_data['cpuUtilization'] = {'utilizationTarget':
as_params['cpu_utilization']['target']}
if 'load_balancing_utilization' in as_params and 'target' in as_params[
'load_balancing_utilization']:
asp_data['loadBalancingUtilization'] = {
'utilizationTarget':
as_params['load_balancing_utilization']['target']
}
return asp_data
def create_autoscaler(gce, mig, params):
"""
Create a new Autoscaler for a MIG.
:param gce: An initialized GCE driver object.
:type gce: :class: `GCENodeDriver`
:param mig: An initialized GCEInstanceGroupManager.
:type mig: :class: `GCEInstanceGroupManager`
:param params: Dictionary of autoscaling parameters.
:type params: ``dict``
:return: Tuple with changed stats.
:rtype: tuple in the format of (bool, list)
"""
changed = False
as_policy = _gen_gce_as_policy(params['policy'])
autoscaler = gce.ex_create_autoscaler(name=params['name'], zone=mig.zone,
instance_group=mig, policy=as_policy)
if autoscaler:
changed = True
return changed
def update_autoscaler(gce, autoscaler, params):
"""
Update an Autoscaler.
Takes an existing Autoscaler object, and updates it with
the supplied params before calling libcloud's update method.
:param gce: An initialized GCE driver object.
:type gce: :class: `GCENodeDriver`
:param autoscaler: An initialized GCEAutoscaler.
:type autoscaler: :class: `GCEAutoscaler`
:param params: Dictionary of autoscaling parameters.
:type params: ``dict``
:return: True if changes, False otherwise.
:rtype: ``bool``
"""
as_policy = _gen_gce_as_policy(params['policy'])
if autoscaler.policy != as_policy:
autoscaler.policy = as_policy
autoscaler = gce.ex_update_autoscaler(autoscaler)
if autoscaler:
return True
return False
def delete_autoscaler(autoscaler):
"""
Delete an Autoscaler. Does not affect MIG.
:param mig: Managed Instance Group Object from Libcloud.
:type mig: :class: `GCEInstanceGroupManager`
:return: Tuple with changed stats and a list of affected instances.
:rtype: tuple in the format of (bool, list)
"""
changed = False
if autoscaler.destroy():
changed = True
return changed
def get_autoscaler(gce, name, zone):
"""
Get an Autoscaler from GCE.
If the Autoscaler is not found, None is found.
:param gce: An initialized GCE driver object.
:type gce: :class: `GCENodeDriver`
:param name: Name of the Autoscaler.
:type name: ``str``
:param zone: Zone that the Autoscaler is located in.
:type zone: ``str``
:return: A GCEAutoscaler object or None.
:rtype: :class: `GCEAutoscaler` or None
"""
try:
# Does the Autoscaler already exist?
return gce.ex_get_autoscaler(name, zone)
except ResourceNotFoundError:
return None
def create_mig(gce, params):
"""
Create a new Managed Instance Group.
:param gce: An initialized GCE driver object.
:type gce: :class: `GCENodeDriver`
:param params: Dictionary of parameters needed by the module.
:type params: ``dict``
:return: Tuple with changed stats and a list of affected instances.
:rtype: tuple in the format of (bool, list)
"""
changed = False
return_data = []
actions_filter = ['CREATING']
mig = gce.ex_create_instancegroupmanager(
name=params['name'], size=params['size'], template=params['template'],
zone=params['zone'])
if mig:
changed = True
return_data = _get_instance_list(mig, filter_list=actions_filter)
return (changed, return_data)
def delete_mig(mig):
"""
Delete a Managed Instance Group. All VMs in that MIG are also deleted."
:param mig: Managed Instance Group Object from Libcloud.
:type mig: :class: `GCEInstanceGroupManager`
:return: Tuple with changed stats and a list of affected instances.
:rtype: tuple in the format of (bool, list)
"""
changed = False
return_data = []
actions_filter = ['NONE', 'CREATING', 'RECREATING', 'DELETING',
'ABANDONING', 'RESTARTING', 'REFRESHING']
instance_names = _get_instance_list(mig, filter_list=actions_filter)
if mig.destroy():
changed = True
return_data = instance_names
return (changed, return_data)
def recreate_instances_in_mig(mig):
"""
Recreate the instances for a Managed Instance Group.
:param mig: Managed Instance Group Object from libcloud.
:type mig: :class: `GCEInstanceGroupManager`
:return: Tuple with changed stats and a list of affected instances.
:rtype: tuple in the format of (bool, list)
"""
changed = False
return_data = []
actions_filter = ['RECREATING']
if mig.recreate_instances():
changed = True
return_data = _get_instance_list(mig, filter_list=actions_filter)
return (changed, return_data)
def resize_mig(mig, size):
"""
Resize a Managed Instance Group.
Based on the size provided, GCE will automatically create and delete
VMs as needed.
:param mig: Managed Instance Group Object from libcloud.
:type mig: :class: `GCEInstanceGroupManager`
:return: Tuple with changed stats and a list of affected instances.
:rtype: tuple in the format of (bool, list)
"""
changed = False
return_data = []
actions_filter = ['CREATING', 'DELETING']
if mig.resize(size):
changed = True
return_data = _get_instance_list(mig, filter_list=actions_filter)
return (changed, return_data)
def get_mig(gce, name, zone):
"""
Get a Managed Instance Group from GCE.
If the MIG is not found, None is found.
:param gce: An initialized GCE driver object.
:type gce: :class: `GCENodeDriver`
:param name: Name of the Managed Instance Group.
:type name: ``str``
:param zone: Zone that the Managed Instance Group is located in.
:type zone: ``str``
:return: A GCEInstanceGroupManager object or None.
:rtype: :class: `GCEInstanceGroupManager` or None
"""
try:
# Does the MIG already exist?
return gce.ex_get_instancegroupmanager(name=name, zone=zone)
except ResourceNotFoundError:
return None
def update_named_ports(mig, named_ports):
"""
Set the named ports on a Managed Instance Group.
Sort the existing named ports and new. If different, update.
This also implicitly allows for the removal of named_por
:param mig: Managed Instance Group Object from libcloud.
:type mig: :class: `GCEInstanceGroupManager`
:param named_ports: list of dictionaries in the format of {'name': port}
:type named_ports: ``list`` of ``dict``
:return: True if successful
:rtype: ``bool``
"""
changed = False
existing_ports = []
new_ports = []
if hasattr(mig.instance_group, 'named_ports'):
existing_ports = sorted(mig.instance_group.named_ports,
key=lambda x: x['name'])
if named_ports is not None:
new_ports = sorted(named_ports, key=lambda x: x['name'])
if existing_ports != new_ports:
if mig.instance_group.set_named_ports(named_ports):
changed = True
return changed
def main():
module = AnsibleModule(argument_spec=dict(
name=dict(required=True),
template=dict(),
recreate_instances=dict(type='bool', default=False),
# Do not set a default size here. For Create and some update
# operations, it is required and should be explicitly set.
# Below, we set it to the existing value if it has not been set.
size=dict(type='int'),
state=dict(choices=['absent', 'present'], default='present'),
zone=dict(required=True),
autoscaling=dict(type='dict', default=None),
named_ports=dict(type='list', default=None),
service_account_email=dict(),
service_account_permissions=dict(type='list'),
pem_file=dict(type='path'),
credentials_file=dict(type='path'),
project_id=dict(), ), )
if not HAS_PYTHON26:
module.fail_json(
msg="GCE module requires python's 'ast' module, python v2.6+")
if not HAS_LIBCLOUD:
module.fail_json(
msg='libcloud with GCE Managed Instance Group support (1.2+) required for this module.')
gce = gce_connect(module)
if not hasattr(gce, 'ex_create_instancegroupmanager'):
module.fail_json(
msg='libcloud with GCE Managed Instance Group support (1.2+) required for this module.',
changed=False)
params = {}
params['state'] = module.params.get('state')
params['zone'] = module.params.get('zone')
params['name'] = module.params.get('name')
params['size'] = module.params.get('size')
params['template'] = module.params.get('template')
params['recreate_instances'] = module.params.get('recreate_instances')
params['autoscaling'] = module.params.get('autoscaling', None)
params['named_ports'] = module.params.get('named_ports', None)
(valid_autoscaling, as_msg) = _validate_autoscaling_params(params)
if not valid_autoscaling:
module.fail_json(msg=as_msg, changed=False)
if params['named_ports'] is not None and not hasattr(
gce, 'ex_instancegroup_set_named_ports'):
module.fail_json(
msg="Apache Libcloud 1.3.0+ is required to use 'named_ports' option",
changed=False)
(valid_named_ports, np_msg) = _validate_named_port_params(params)
if not valid_named_ports:
module.fail_json(msg=np_msg, changed=False)
changed = False
json_output = {'state': params['state'], 'zone': params['zone']}
mig = get_mig(gce, params['name'], params['zone'])
if not mig:
if params['state'] == 'absent':
# Doesn't exist in GCE, and state==absent.
changed = False
module.fail_json(
msg="Cannot delete unknown managed instance group: %s" %
(params['name']))
else:
# Create MIG
req_create_fields = [
{'name': 'template', 'required': True, 'type': str},
{'name': 'size', 'required': True, 'type': int}
] # yapf: disable
(valid_create_fields, valid_create_msg) = _check_params(
params, req_create_fields)
if not valid_create_fields:
module.fail_json(msg=valid_create_msg, changed=False)
(changed, json_output['created_instances']) = create_mig(gce,
params)
if params['autoscaling'] and params['autoscaling'][
'enabled'] is True:
# Fetch newly-created MIG and create Autoscaler for it.
mig = get_mig(gce, params['name'], params['zone'])
if not mig:
module.fail_json(
msg='Unable to fetch created MIG %s to create \
autoscaler in zone: %s' % (
params['name'], params['zone']), changed=False)
if not create_autoscaler(gce, mig, params['autoscaling']):
module.fail_json(
msg='Unable to fetch MIG %s to create autoscaler \
in zone: %s' % (params['name'], params['zone']),
changed=False)
json_output['created_autoscaler'] = True
# Add named ports if available
if params['named_ports']:
mig = get_mig(gce, params['name'], params['zone'])
if not mig:
module.fail_json(
msg='Unable to fetch created MIG %s to create \
autoscaler in zone: %s' % (
params['name'], params['zone']), changed=False)
json_output['set_named_ports'] = update_named_ports(
mig, params['named_ports'])
if json_output['set_named_ports']:
json_output['named_ports'] = params['named_ports']
elif params['state'] == 'absent':
# Delete MIG
# First, check and remove the autoscaler, if present.
# Note: multiple autoscalers can be associated to a single MIG. We
# only handle the one that is named, but we might want to think about this.
if params['autoscaling']:
autoscaler = get_autoscaler(gce, params['autoscaling']['name'],
params['zone'])
if not autoscaler:
module.fail_json(msg='Unable to fetch autoscaler %s to delete \
in zone: %s' % (params['autoscaling']['name'], params['zone']),
changed=False)
changed = delete_autoscaler(autoscaler)
json_output['deleted_autoscaler'] = changed
# Now, delete the MIG.
(changed, json_output['deleted_instances']) = delete_mig(mig)
else:
# Update MIG
# If we're going to update a MIG, we need a size and template values.
# If not specified, we use the values from the existing MIG.
if not params['size']:
params['size'] = mig.size
if not params['template']:
params['template'] = mig.template.name
if params['template'] != mig.template.name:
# Update Instance Template.
new_template = gce.ex_get_instancetemplate(params['template'])
mig.set_instancetemplate(new_template)
json_output['updated_instancetemplate'] = True
changed = True
if params['recreate_instances'] is True:
# Recreate Instances.
(changed, json_output['recreated_instances']
) = recreate_instances_in_mig(mig)
if params['size'] != mig.size:
# Resize MIG.
keystr = 'created' if params['size'] > mig.size else 'deleted'
(changed, json_output['resize_%s_instances' %
(keystr)]) = resize_mig(mig, params['size'])
# Update Autoscaler
if params['autoscaling']:
autoscaler = get_autoscaler(gce, params['autoscaling']['name'],
params['zone'])
if not autoscaler:
# Try to create autoscaler.
# Note: this isn't perfect, if the autoscaler name has changed
# we wouldn't know that here.
if not create_autoscaler(gce, mig, params['autoscaling']):
module.fail_json(
msg='Unable to create autoscaler %s for existing MIG %s\
in zone: %s' % (params['autoscaling']['name'],
params['name'], params['zone']),
changed=False)
json_output['created_autoscaler'] = True
changed = True
else:
if params['autoscaling']['enabled'] is False:
# Delete autoscaler
changed = delete_autoscaler(autoscaler)
json_output['delete_autoscaler'] = changed
else:
# Update policy, etc.
changed = update_autoscaler(gce, autoscaler,
params['autoscaling'])
json_output['updated_autoscaler'] = changed
named_ports = params['named_ports'] or []
json_output['updated_named_ports'] = update_named_ports(mig,
named_ports)
if json_output['updated_named_ports']:
json_output['named_ports'] = named_ports
json_output['changed'] = changed
json_output.update(params)
module.exit_json(**json_output)
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1898,
7800,
4475,
3277,
14,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
421,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
21319,
63,
4071,
199,
1023,
63,
3270,
26,
298,
18,
14,
18,
2,
199,
3612,
63,
1802,
26,
2790,
12,
6162,
503,
20547,
4813,
282,
4688,
6028,
10066,
5611,
334,
22487,
680,
199,
1802,
26,
272,
446,
2790,
12,
6162,
503,
20547,
4813,
282,
4688,
6028,
10066,
5611,
334,
22487,
680,
221,
1666,
489,
738,
8,
2859,
921,
4091,
14,
3098,
14,
957,
15,
3357,
15,
4757,
15,
842,
13,
2634,
9,
367,
376,
23503,
14,
489,
16579,
3907,
15,
4758,
15794,
367,
314,
21319,
10,
4621,
883,
489,
506,
1911,
315,
314,
6786,
402,
3242,
15,
396,
15,
22833,
63,
2219,
14,
647,
14,
199,
7538,
26,
523,
446,
298,
1548,
2356,
499,
14,
22,
2,
523,
446,
298,
3796,
13,
30651,
2356,
413,
14,
18,
14,
16,
2,
199,
5983,
26,
523,
446,
799,
30639,
436,
799,
20358,
7525,
787,
2597,
3748,
14,
523,
446,
1626,
3411,
1256,
1978,
365,
1415,
315,
1865,
370,
1218,
282,
272,
4688,
6028,
10066,
5611,
14,
199,
2502,
26,
523,
446,
298,
52,
676,
3194,
552,
271,
90,
8593,
4792,
3151,
9,
665,
3151,
32,
4792,
3151,
14,
957,
4335,
199,
1419,
26,
523,
536,
26,
272,
1369,
26,
2126,
446,
2812,
402,
314,
4688,
6028,
10066,
5611,
14,
272,
1415,
26,
2549,
523,
1978,
26,
272,
1369,
26,
2126,
446,
10066,
5458,
370,
506,
1202,
315,
6425,
314,
30641,
14,
221,
1666,
268,
738,
8,
2859,
921,
4091,
14,
3098,
14,
957,
15,
3357,
15,
4757,
15,
842,
13,
5876,
9,
370,
12537,
1655,
268,
3595,
10066,
31273,
14,
221,
11105,
367,
6425,
603,
1277,
83,
14,
272,
1415,
26,
3055,
523,
1568,
26,
272,
1369,
26,
2126,
446,
14579,
402,
4688,
6028,
10066,
5611,
14,
221,
982,
603,
1277,
2575,
3495,
12,
652,
911,
506,
268,
295,
15308,
370,
314,
1329,
2741,
2348,
14,
221,
11105,
367,
6425,
603,
1277,
83,
14,
272,
1415,
26,
3055,
523,
2435,
63,
2048,
63,
2123,
26,
272,
1369,
26,
489,
446,
2435,
2933,
3031,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
6235,
63,
493,
26,
272,
1369,
26,
489,
446,
6912,
370,
314,
4840,
570,
4568,
543,
314,
2435,
2933,
3031,
272,
849,
26,
2973,
272,
1415,
26,
3055,
523,
2199,
63,
344,
26,
272,
1369,
26,
489,
446,
31556,
2199,
2870,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
1174,
26,
272,
1369,
26,
489,
446,
6387,
1174,
402,
314,
2073,
272,
1415,
26,
3055,
272,
849,
26,
298,
1881,
2,
272,
3415,
26,
2097,
5575,
401,
298,
1881,
937,
523,
5718,
26,
272,
1369,
26,
489,
446,
710,
31556,
5718,
370,
675,
367,
642,
4688,
6028,
10066,
5611,
14,
272,
1415,
26,
2549,
523,
2599,
12153,
26,
272,
1369,
26,
489,
446,
437,
2600,
402,
2897,
367,
314,
2599,
11494,
14,
283,
3827,
334,
2245,
3196,
283,
354,
334,
495,
3171,
267,
436,
4592,
14,
988,
63,
5990,
334,
442,
9,
787,
1415,
1504,
340,
2599,
12153,
365,
1202,
14,
1666,
267,
738,
8,
2859,
921,
4091,
14,
3098,
14,
957,
15,
3357,
15,
4757,
15,
4443,
15,
5683,
15,
2495,
11494,
83,
9,
367,
1655,
2556,
267,
641,
9195,
12153,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
4310,
63,
5203,
26,
272,
1015,
63,
3270,
26,
298,
18,
14,
19,
2,
272,
1369,
26,
489,
446,
13930,
4310,
8873,
626,
4865,
8500,
883,
7568,
666,
370,
14,
221,
9701,
365,
282,
282,
769,
402,
267,
536,
26,
719,
11196,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
21876,
316,
15695,
8491,
12,
295,
10838,
4454,
12,
295,
7723,
436,
2066,
21812,
282,
603,
1277,
14,
199,
3,
8144,
26,
199,
3,
446,
16853,
1686,
10066,
31273,
1471,
2187,
315,
2195,
31556,
2199,
315,
1865,
370,
1255,
199,
3,
257,
642,
15695,
14,
221,
7743,
314,
1504,
370,
1336,
314,
7009,
1202,
315,
2195,
199,
3,
257,
2199,
14,
199,
3,
446,
710,
675,
402,
314,
283,
11241,
7,
859,
365,
440,
1415,
12,
652,
365,
2951,
367,
16777,
14,
199,
13,
536,
26,
4688,
6028,
10066,
5611,
5679,
523,
7057,
26,
11667,
523,
13082,
63,
5047,
26,
756,
523,
6527,
26,
272,
446,
536,
26,
2790,
603,
1277,
489,
21319,
63,
4071,
26,
267,
536,
26,
3242,
13,
4071,
13,
2694,
267,
5718,
26,
2739,
13,
16067,
17,
13,
67,
267,
1174,
26,
3451,
267,
1568,
26,
413,
267,
1978,
26,
3002,
13,
842,
13,
1160,
13,
17,
267,
4310,
63,
5203,
26,
267,
446,
536,
26,
1455,
881,
1844,
26,
5939,
267,
446,
536,
26,
29245,
881,
1844,
26,
18051,
339,
446,
536,
26,
10164,
1180,
367,
4233,
4696,
489,
16834,
26,
267,
4696,
26,
4233,
339,
446,
536,
26,
799,
981,
603,
1277,
10066,
83,
543,
10066,
5458,
1570,
14,
489,
21319,
63,
4071,
26,
267,
536,
26,
3242,
13,
4071,
13,
2694,
267,
5718,
26,
2739,
13,
16067,
17,
13,
67,
267,
1174,
26,
3451,
267,
1978,
26,
3002,
13,
842,
13,
1160,
13,
18,
13,
7241,
267,
23959,
63,
5990,
26,
9456,
339,
446,
536,
26,
10164,
1180,
367,
4233,
4696,
489,
16834,
26,
267,
4696,
26,
4233,
339,
446,
536,
26,
799,
890,
603,
1277,
489,
21319,
63,
4071,
26,
267,
536,
26,
3242,
13,
4071,
13,
2694,
267,
5718,
26,
2739,
13,
16067,
17,
13,
67,
267,
1174,
26,
3451,
267,
1568,
26,
650,
339,
446,
536,
26,
6162,
603,
1277,
543,
9195,
11494,
489,
21319,
63,
4071,
26,
267,
536,
26
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1898,
7800,
4475,
3277,
14,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
421,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
21319,
63,
4071,
199,
1023,
63,
3270,
26,
298,
18,
14,
18,
2,
199,
3612,
63,
1802,
26,
2790,
12,
6162,
503,
20547,
4813,
282,
4688,
6028,
10066,
5611,
334,
22487,
680,
199,
1802,
26,
272,
446,
2790,
12,
6162,
503,
20547,
4813,
282,
4688,
6028,
10066,
5611,
334,
22487,
680,
221,
1666,
489,
738,
8,
2859,
921,
4091,
14,
3098,
14,
957,
15,
3357,
15,
4757,
15,
842,
13,
2634,
9,
367,
376,
23503,
14,
489,
16579,
3907,
15,
4758,
15794,
367,
314,
21319,
10,
4621,
883,
489,
506,
1911,
315,
314,
6786,
402,
3242,
15,
396,
15,
22833,
63,
2219,
14,
647,
14,
199,
7538,
26,
523,
446,
298,
1548,
2356,
499,
14,
22,
2,
523,
446,
298,
3796,
13,
30651,
2356,
413,
14,
18,
14,
16,
2,
199,
5983,
26,
523,
446,
799,
30639,
436,
799,
20358,
7525,
787,
2597,
3748,
14,
523,
446,
1626,
3411,
1256,
1978,
365,
1415,
315,
1865,
370,
1218,
282,
272,
4688,
6028,
10066,
5611,
14,
199,
2502,
26,
523,
446,
298,
52,
676,
3194,
552,
271,
90,
8593,
4792,
3151,
9,
665,
3151,
32,
4792,
3151,
14,
957,
4335,
199,
1419,
26,
523,
536,
26,
272,
1369,
26,
2126,
446,
2812,
402,
314,
4688,
6028,
10066,
5611,
14,
272,
1415,
26,
2549,
523,
1978,
26,
272,
1369,
26,
2126,
446,
10066,
5458,
370,
506,
1202,
315,
6425,
314,
30641,
14,
221,
1666,
268,
738,
8,
2859,
921,
4091,
14,
3098,
14,
957,
15,
3357,
15,
4757,
15,
842,
13,
5876,
9,
370,
12537,
1655,
268,
3595,
10066,
31273,
14,
221,
11105,
367,
6425,
603,
1277,
83,
14,
272,
1415,
26,
3055,
523,
1568,
26,
272,
1369,
26,
2126,
446,
14579,
402,
4688,
6028,
10066,
5611,
14,
221,
982,
603,
1277,
2575,
3495,
12,
652,
911,
506,
268,
295,
15308,
370,
314,
1329,
2741,
2348,
14,
221,
11105,
367,
6425,
603,
1277,
83,
14,
272,
1415,
26,
3055,
523,
2435,
63,
2048,
63,
2123,
26,
272,
1369,
26,
489,
446,
2435,
2933,
3031,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
6235,
63,
493,
26,
272,
1369,
26,
489,
446,
6912,
370,
314,
4840,
570,
4568,
543,
314,
2435,
2933,
3031,
272,
849,
26,
2973,
272,
1415,
26,
3055,
523,
2199,
63,
344,
26,
272,
1369,
26,
489,
446,
31556,
2199,
2870,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
1174,
26,
272,
1369,
26,
489,
446,
6387,
1174,
402,
314,
2073,
272,
1415,
26,
3055,
272,
849,
26,
298,
1881,
2,
272,
3415,
26,
2097,
5575,
401,
298,
1881,
937,
523,
5718,
26,
272,
1369,
26,
489,
446,
710,
31556,
5718,
370,
675,
367,
642,
4688,
6028,
10066,
5611,
14,
272,
1415,
26,
2549,
523,
2599,
12153,
26,
272,
1369,
26,
489,
446,
437,
2600,
402,
2897,
367,
314,
2599,
11494,
14,
283,
3827,
334,
2245,
3196,
283,
354,
334,
495,
3171,
267,
436,
4592,
14,
988,
63,
5990,
334,
442,
9,
787,
1415,
1504,
340,
2599,
12153,
365,
1202,
14,
1666,
267,
738,
8,
2859,
921,
4091,
14,
3098,
14,
957,
15,
3357,
15,
4757,
15,
4443,
15,
5683,
15,
2495,
11494,
83,
9,
367,
1655,
2556,
267,
641,
9195,
12153,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
4310,
63,
5203,
26,
272,
1015,
63,
3270,
26,
298,
18,
14,
19,
2,
272,
1369,
26,
489,
446,
13930,
4310,
8873,
626,
4865,
8500,
883,
7568,
666,
370,
14,
221,
9701,
365,
282,
282,
769,
402,
267,
536,
26,
719,
11196,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
21876,
316,
15695,
8491,
12,
295,
10838,
4454,
12,
295,
7723,
436,
2066,
21812,
282,
603,
1277,
14,
199,
3,
8144,
26,
199,
3,
446,
16853,
1686,
10066,
31273,
1471,
2187,
315,
2195,
31556,
2199,
315,
1865,
370,
1255,
199,
3,
257,
642,
15695,
14,
221,
7743,
314,
1504,
370,
1336,
314,
7009,
1202,
315,
2195,
199,
3,
257,
2199,
14,
199,
3,
446,
710,
675,
402,
314,
283,
11241,
7,
859,
365,
440,
1415,
12,
652,
365,
2951,
367,
16777,
14,
199,
13,
536,
26,
4688,
6028,
10066,
5611,
5679,
523,
7057,
26,
11667,
523,
13082,
63,
5047,
26,
756,
523,
6527,
26,
272,
446,
536,
26,
2790,
603,
1277,
489,
21319,
63,
4071,
26,
267,
536,
26,
3242,
13,
4071,
13,
2694,
267,
5718,
26,
2739,
13,
16067,
17,
13,
67,
267,
1174,
26,
3451,
267,
1568,
26,
413,
267,
1978,
26,
3002,
13,
842,
13,
1160,
13,
17,
267,
4310,
63,
5203,
26,
267,
446,
536,
26,
1455,
881,
1844,
26,
5939,
267,
446,
536,
26,
29245,
881,
1844,
26,
18051,
339,
446,
536,
26,
10164,
1180,
367,
4233,
4696,
489,
16834,
26,
267,
4696,
26,
4233,
339,
446,
536,
26,
799,
981,
603,
1277,
10066,
83,
543,
10066,
5458,
1570,
14,
489,
21319,
63,
4071,
26,
267,
536,
26,
3242,
13,
4071,
13,
2694,
267,
5718,
26,
2739,
13,
16067,
17,
13,
67,
267,
1174,
26,
3451,
267,
1978,
26,
3002,
13,
842,
13,
1160,
13,
18,
13,
7241,
267,
23959,
63,
5990,
26,
9456,
339,
446,
536,
26,
10164,
1180,
367,
4233,
4696,
489,
16834,
26,
267,
4696,
26,
4233,
339,
446,
536,
26,
799,
890,
603,
1277,
489,
21319,
63,
4071,
26,
267,
536,
26,
3242,
13,
4071,
13,
2694,
267,
5718,
26,
2739,
13,
16067,
17,
13,
67,
267,
1174,
26,
3451,
267,
1568,
26,
650,
339,
446,
536,
26,
6162,
603,
1277,
543,
9195,
11494,
489,
21319,
63,
4071,
26,
267,
536,
26,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
airanmehr/bio
|
Scripts/TimeSeriesPaper/Plot/topSNPs.py
|
1
|
1589
|
'''
Copyleft Oct 14, 2016 Arya Iranmehr, PhD Student, Bafna Lab, UC San Diego, Email: airanmehr@gmail.com
'''
import numpy as np;
np.set_printoptions(linewidth=200, precision=5, suppress=True)
import pandas as pd;
pd.options.display.max_rows = 20;
pd.options.display.expand_frame_repr = False
import seaborn as sns
import matplotlib as mpl
import os;
home = os.path.expanduser('~') + '/'
import Utils.Util as utl
import Scripts.TimeSeriesPaper.RealData.Utils as rutl
a = rutl.loadAllScores().groupby(level='h', axis=1).apply(rutl.HstatisticAll)
df = pd.read_pickle(utl.outpath + 'real/scores.df')
i = df.lrd.sort_values().index[-1]
df.loc[i]
cd = pd.read_pickle(utl.outpath + 'real/CD.F59.df')
import Utils.Plots as pplt
import pylab as plt
names = rutl.loadSNPIDs()
sns.set_style("white", {"grid.color": "0.9", 'axes.linewidth': .5, "grid.linewidth": "9.99"})
mpl.rc('font', **{'family': 'serif', 'serif': ['Computer Modern']});
mpl.rc('text', usetex=True)
reload(pplt)
f, ax = plt.subplots(1, 2, sharey=True, dpi=300, figsize=(4, 2))
i = a[0.5].sort_values().index[-1]
sns.set_context("notebook", font_scale=1, rc={"lines.linewidth": 1.2})
pplt.plotSiteReal(cd.loc[i], ax=ax[0], legend=True)
ax[0].set_title('{}:{:.0f} ({})'.format(i[0], i[1], names.loc[i]), fontsize=8)
i = df.lrdiff.sort_values().index[-1]
pplt.plotSiteReal(cd.loc[i], ax=ax[1])
sns.set_context("notebook", font_scale=1, rc={"lines.linewidth": 1.2})
ax[1].set_title('{}:{:.0f} ({})'.format(i[0], i[1], names.loc[i]), fontsize=8)
plt.gcf().subplots_adjust(bottom=0.2)
pplt.savefig('topSNPs', 300)
plt.show()
|
mit
|
[
2344,
199,
5116,
3039,
18365,
4329,
12,
7800,
437,
651,
65,
473,
1312,
278,
6271,
12,
11308,
36,
17246,
12,
699,
65,
2324,
65,
16871,
12,
738,
35,
29359,
577,
1873,
1939,
12,
221,
11426,
26,
12321,
290,
278,
6271,
32,
6799,
14,
957,
199,
2344,
199,
646,
2680,
465,
980,
27,
199,
199,
1590,
14,
409,
63,
1361,
1419,
8,
24643,
29,
1840,
12,
7151,
29,
21,
12,
15678,
29,
549,
9,
199,
646,
10634,
465,
6454,
27,
199,
199,
8961,
14,
1419,
14,
2918,
14,
988,
63,
3838,
275,
3388,
27,
199,
8961,
14,
1419,
14,
2918,
14,
4441,
63,
1943,
63,
2722,
275,
756,
199,
646,
542,
371,
6161,
465,
308,
561,
199,
646,
8027,
465,
22513,
199,
646,
747,
27,
199,
199,
4219,
275,
747,
14,
515,
14,
12131,
21114,
358,
435,
7324,
199,
646,
17397,
14,
9562,
465,
11430,
76,
199,
646,
14914,
83,
14,
30887,
48,
9804,
14,
10099,
1451,
14,
7535,
465,
519,
337,
76,
199,
199,
65,
275,
519,
337,
76,
14,
912,
2422,
29654,
1252,
16968,
8,
1896,
534,
72,
297,
3114,
29,
17,
680,
4998,
8,
82,
337,
76,
14,
40,
26065,
2422,
9,
199,
1587,
275,
6454,
14,
739,
63,
8092,
8,
337,
76,
14,
548,
515,
435,
283,
3093,
15,
7107,
14,
1587,
358,
199,
73,
275,
4051,
14,
76,
6883,
14,
3191,
63,
1459,
1252,
1080,
1988,
17,
61,
199,
1587,
14,
2102,
59,
73,
61,
199,
199,
2866,
275,
6454,
14,
739,
63,
8092,
8,
337,
76,
14,
548,
515,
435,
283,
3093,
15,
7695,
14,
38,
1427,
14,
1587,
358,
199,
199,
646,
17397,
14,
48,
4555,
465,
299,
6003,
199,
646,
19199,
465,
4488,
199,
199,
1247,
275,
519,
337,
76,
14,
912,
8199,
48,
12818,
342,
199,
83,
561,
14,
409,
63,
2487,
480,
7510,
401,
2420,
3825,
14,
2326,
582,
298,
16,
14,
25,
401,
283,
6402,
14,
24643,
356,
1275,
21,
12,
298,
3825,
14,
24643,
582,
298,
25,
14,
1020,
5984,
199,
2421,
14,
1195,
360,
4246,
297,
30653,
6606,
356,
283,
24977,
297,
283,
24977,
356,
788,
2404,
2699,
4900,
11641,
13678,
27,
199,
2421,
14,
1195,
360,
505,
297,
675,
3858,
29,
549,
9,
199,
9233,
8,
802,
4116,
9,
199,
70,
12,
2185,
275,
4488,
14,
21430,
8,
17,
12,
499,
12,
8663,
89,
29,
549,
12,
26910,
29,
5863,
12,
6085,
890,
2687,
20,
12,
499,
430,
199,
73,
275,
282,
59,
16,
14,
21,
1055,
3191,
63,
1459,
1252,
1080,
1988,
17,
61,
199,
83,
561,
14,
409,
63,
1100,
480,
19174,
401,
5023,
63,
3467,
29,
17,
12,
4819,
8871,
1278,
14,
24643,
582,
413,
14,
18,
1552,
199,
199,
802,
4116,
14,
2798,
8972,
10099,
8,
2866,
14,
2102,
59,
73,
467,
2185,
29,
1219,
59,
16,
467,
15906,
29,
549,
9,
199,
1219,
59,
16,
1055,
409,
63,
1213,
17519,
14534,
14010,
16,
70,
93,
11459,
25885,
908,
8,
73,
59,
16,
467,
284,
59,
17,
467,
1561,
14,
2102,
59,
73,
2522,
19740,
29,
24,
9,
199,
199,
73,
275,
4051,
14,
7493,
3028,
14,
3191,
63,
1459,
1252,
1080,
1988,
17,
61,
199,
802,
4116,
14,
2798,
8972,
10099,
8,
2866,
14,
2102,
59,
73,
467,
2185,
29,
1219,
59,
17,
566,
199,
83,
561,
14,
409,
63,
1100,
480,
19174,
401,
5023,
63,
3467,
29,
17,
12,
4819,
8871,
1278,
14,
24643,
582,
413,
14,
18,
1552,
199,
199,
1219,
59,
17,
1055,
409,
63,
1213,
17519,
14534,
14010,
16,
70,
93,
11459,
25885,
908,
8,
73,
59,
16,
467,
284,
59,
17,
467,
1561,
14,
2102,
59,
73,
2522,
19740,
29,
24,
9,
199,
6003,
14,
71,
2177,
1252,
21430,
63,
10917,
8,
8305,
29,
16,
14,
18,
9,
199,
802,
4116,
14,
19556,
360,
2119,
8199,
25512,
297,
9601,
9,
199,
6003,
14,
2384,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
5116,
3039,
18365,
4329,
12,
7800,
437,
651,
65,
473,
1312,
278,
6271,
12,
11308,
36,
17246,
12,
699,
65,
2324,
65,
16871,
12,
738,
35,
29359,
577,
1873,
1939,
12,
221,
11426,
26,
12321,
290,
278,
6271,
32,
6799,
14,
957,
199,
2344,
199,
646,
2680,
465,
980,
27,
199,
199,
1590,
14,
409,
63,
1361,
1419,
8,
24643,
29,
1840,
12,
7151,
29,
21,
12,
15678,
29,
549,
9,
199,
646,
10634,
465,
6454,
27,
199,
199,
8961,
14,
1419,
14,
2918,
14,
988,
63,
3838,
275,
3388,
27,
199,
8961,
14,
1419,
14,
2918,
14,
4441,
63,
1943,
63,
2722,
275,
756,
199,
646,
542,
371,
6161,
465,
308,
561,
199,
646,
8027,
465,
22513,
199,
646,
747,
27,
199,
199,
4219,
275,
747,
14,
515,
14,
12131,
21114,
358,
435,
7324,
199,
646,
17397,
14,
9562,
465,
11430,
76,
199,
646,
14914,
83,
14,
30887,
48,
9804,
14,
10099,
1451,
14,
7535,
465,
519,
337,
76,
199,
199,
65,
275,
519,
337,
76,
14,
912,
2422,
29654,
1252,
16968,
8,
1896,
534,
72,
297,
3114,
29,
17,
680,
4998,
8,
82,
337,
76,
14,
40,
26065,
2422,
9,
199,
1587,
275,
6454,
14,
739,
63,
8092,
8,
337,
76,
14,
548,
515,
435,
283,
3093,
15,
7107,
14,
1587,
358,
199,
73,
275,
4051,
14,
76,
6883,
14,
3191,
63,
1459,
1252,
1080,
1988,
17,
61,
199,
1587,
14,
2102,
59,
73,
61,
199,
199,
2866,
275,
6454,
14,
739,
63,
8092,
8,
337,
76,
14,
548,
515,
435,
283,
3093,
15,
7695,
14,
38,
1427,
14,
1587,
358,
199,
199,
646,
17397,
14,
48,
4555,
465,
299,
6003,
199,
646,
19199,
465,
4488,
199,
199,
1247,
275,
519,
337,
76,
14,
912,
8199,
48,
12818,
342,
199,
83,
561,
14,
409,
63,
2487,
480,
7510,
401,
2420,
3825,
14,
2326,
582,
298,
16,
14,
25,
401,
283,
6402,
14,
24643,
356,
1275,
21,
12,
298,
3825,
14,
24643,
582,
298,
25,
14,
1020,
5984,
199,
2421,
14,
1195,
360,
4246,
297,
30653,
6606,
356,
283,
24977,
297,
283,
24977,
356,
788,
2404,
2699,
4900,
11641,
13678,
27,
199,
2421,
14,
1195,
360,
505,
297,
675,
3858,
29,
549,
9,
199,
9233,
8,
802,
4116,
9,
199,
70,
12,
2185,
275,
4488,
14,
21430,
8,
17,
12,
499,
12,
8663,
89,
29,
549,
12,
26910,
29,
5863,
12,
6085,
890,
2687,
20,
12,
499,
430,
199,
73,
275,
282,
59,
16,
14,
21,
1055,
3191,
63,
1459,
1252,
1080,
1988,
17,
61,
199,
83,
561,
14,
409,
63,
1100,
480,
19174,
401,
5023,
63,
3467,
29,
17,
12,
4819,
8871,
1278,
14,
24643,
582,
413,
14,
18,
1552,
199,
199,
802,
4116,
14,
2798,
8972,
10099,
8,
2866,
14,
2102,
59,
73,
467,
2185,
29,
1219,
59,
16,
467,
15906,
29,
549,
9,
199,
1219,
59,
16,
1055,
409,
63,
1213,
17519,
14534,
14010,
16,
70,
93,
11459,
25885,
908,
8,
73,
59,
16,
467,
284,
59,
17,
467,
1561,
14,
2102,
59,
73,
2522,
19740,
29,
24,
9,
199,
199,
73,
275,
4051,
14,
7493,
3028,
14,
3191,
63,
1459,
1252,
1080,
1988,
17,
61,
199,
802,
4116,
14,
2798,
8972,
10099,
8,
2866,
14,
2102,
59,
73,
467,
2185,
29,
1219,
59,
17,
566,
199,
83,
561,
14,
409,
63,
1100,
480,
19174,
401,
5023,
63,
3467,
29,
17,
12,
4819,
8871,
1278,
14,
24643,
582,
413,
14,
18,
1552,
199,
199,
1219,
59,
17,
1055,
409,
63,
1213,
17519,
14534,
14010,
16,
70,
93,
11459,
25885,
908,
8,
73,
59,
16,
467,
284,
59,
17,
467,
1561,
14,
2102,
59,
73,
2522,
19740,
29,
24,
9,
199,
6003,
14,
71,
2177,
1252,
21430,
63,
10917,
8,
8305,
29,
16,
14,
18,
9,
199,
802,
4116,
14,
19556,
360,
2119,
8199,
25512,
297,
9601,
9,
199,
6003,
14,
2384,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
adpg211/bitcoin-master
|
qa/rpc-tests/p2p-acceptblock.py
|
2
|
12388
|
#!/usr/bin/env python2
# Copyright (c) 2015 The Bitcoin Core developers
# Distributed under the MIT/X11 software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
#
from test_framework.mininode import *
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import *
import time
from test_framework.blocktools import create_block, create_coinbase
'''
AcceptBlockTest -- test processing of unrequested blocks.
Since behavior differs when receiving unrequested blocks from whitelisted peers
versus non-whitelisted peers, this tests the behavior of both (effectively two
separate tests running in parallel).
Setup: two nodes, node0 and node1, not connected to each other. Node0 does not
whitelist localhost, but node1 does. They will each be on their own chain for
this test.
We have one NodeConn connection to each, test_node and white_node respectively.
The test:
1. Generate one block on each node, to leave IBD.
2. Mine a new block on each tip, and deliver to each node from node's peer.
The tip should advance.
3. Mine a block that forks the previous block, and deliver to each node from
corresponding peer.
Node0 should not process this block (just accept the header), because it is
unrequested and doesn't have more work than the tip.
Node1 should process because this is coming from a whitelisted peer.
4. Send another block that builds on the forking block.
Node0 should process this block but be stuck on the shorter chain, because
it's missing an intermediate block.
Node1 should reorg to this longer chain.
4b.Send 288 more blocks on the longer chain.
Node0 should process all but the last block (too far ahead in height).
Send all headers to Node1, and then send the last block in that chain.
Node1 should accept the block because it's coming from a whitelisted peer.
5. Send a duplicate of the block in #3 to Node0.
Node0 should not process the block because it is unrequested, and stay on
the shorter chain.
6. Send Node0 an inv for the height 3 block produced in #4 above.
Node0 should figure out that Node0 has the missing height 2 block and send a
getdata.
7. Send Node0 the missing block again.
Node0 should process and the tip should advance.
'''
# TestNode: bare-bones "peer". Used mostly as a conduit for a test to sending
# p2p messages to a node, generating the messages in the main testing logic.
class TestNode(NodeConnCB):
def __init__(self):
NodeConnCB.__init__(self)
self.connection = None
self.ping_counter = 1
self.last_pong = msg_pong()
def add_connection(self, conn):
self.connection = conn
# Track the last getdata message we receive (used in the test)
def on_getdata(self, conn, message):
self.last_getdata = message
# Spin until verack message is received from the node.
# We use this to signal that our test can begin. This
# is called from the testing thread, so it needs to acquire
# the global lock.
def wait_for_verack(self):
while True:
with mininode_lock:
if self.verack_received:
return
time.sleep(0.05)
# Wrapper for the NodeConn's send_message function
def send_message(self, message):
self.connection.send_message(message)
def on_pong(self, conn, message):
self.last_pong = message
# Sync up with the node after delivery of a block
def sync_with_ping(self, timeout=30):
self.connection.send_message(msg_ping(nonce=self.ping_counter))
received_pong = False
sleep_time = 0.05
while not received_pong and timeout > 0:
time.sleep(sleep_time)
timeout -= sleep_time
with mininode_lock:
if self.last_pong.nonce == self.ping_counter:
received_pong = True
self.ping_counter += 1
return received_pong
class AcceptBlockTest(BitcoinTestFramework):
def add_options(self, parser):
parser.add_option("--testbinary", dest="testbinary",
default=os.getenv("BITCOIND", "bitcoind"),
help="bitcoind binary to test")
def setup_chain(self):
initialize_chain_clean(self.options.tmpdir, 2)
def setup_network(self):
# Node0 will be used to test behavior of processing unrequested blocks
# from peers which are not whitelisted, while Node1 will be used for
# the whitelisted case.
self.nodes = []
self.nodes.append(start_node(0, self.options.tmpdir, ["-debug"],
binary=self.options.testbinary))
self.nodes.append(start_node(1, self.options.tmpdir,
["-debug", "-whitelist=127.0.0.1"],
binary=self.options.testbinary))
def run_test(self):
# Setup the p2p connections and start up the network thread.
test_node = TestNode() # connects to node0 (not whitelisted)
white_node = TestNode() # connects to node1 (whitelisted)
connections = []
connections.append(NodeConn('127.0.0.1', p2p_port(0), self.nodes[0], test_node))
connections.append(NodeConn('127.0.0.1', p2p_port(1), self.nodes[1], white_node))
test_node.add_connection(connections[0])
white_node.add_connection(connections[1])
NetworkThread().start() # Start up network handling in another thread
# Test logic begins here
test_node.wait_for_verack()
white_node.wait_for_verack()
# 1. Have both nodes mine a block (leave IBD)
[ n.wallet.generate(1) for n in self.nodes ]
tips = [ int ("0x" + n.getbestblockhash() + "L", 0) for n in self.nodes ]
# 2. Send one block that builds on each tip.
# This should be accepted.
blocks_h2 = [] # the height 2 blocks on each node's chain
block_time = int(time.time()) + 1
for i in xrange(2):
blocks_h2.append(create_block(tips[i], create_coinbase(2), block_time))
blocks_h2[i].solve()
block_time += 1
test_node.send_message(msg_block(blocks_h2[0]))
white_node.send_message(msg_block(blocks_h2[1]))
[ x.sync_with_ping() for x in [test_node, white_node] ]
assert_equal(self.nodes[0].getblockcount(), 2)
assert_equal(self.nodes[1].getblockcount(), 2)
print "First height 2 block accepted by both nodes"
# 3. Send another block that builds on the original tip.
blocks_h2f = [] # Blocks at height 2 that fork off the main chain
for i in xrange(2):
blocks_h2f.append(create_block(tips[i], create_coinbase(2), blocks_h2[i].nTime+1))
blocks_h2f[i].solve()
test_node.send_message(msg_block(blocks_h2f[0]))
white_node.send_message(msg_block(blocks_h2f[1]))
[ x.sync_with_ping() for x in [test_node, white_node] ]
for x in self.nodes[0].getchaintips():
if x['hash'] == blocks_h2f[0].hash:
assert_equal(x['status'], "headers-only")
for x in self.nodes[1].getchaintips():
if x['hash'] == blocks_h2f[1].hash:
assert_equal(x['status'], "valid-headers")
print "Second height 2 block accepted only from whitelisted peer"
# 4. Now send another block that builds on the forking chain.
blocks_h3 = []
for i in xrange(2):
blocks_h3.append(create_block(blocks_h2f[i].sha256, create_coinbase(3), blocks_h2f[i].nTime+1))
blocks_h3[i].solve()
test_node.send_message(msg_block(blocks_h3[0]))
white_node.send_message(msg_block(blocks_h3[1]))
[ x.sync_with_ping() for x in [test_node, white_node] ]
# Since the earlier block was not processed by node0, the new block
# can't be fully validated.
for x in self.nodes[0].getchaintips():
if x['hash'] == blocks_h3[0].hash:
assert_equal(x['status'], "headers-only")
# But this block should be accepted by node0 since it has more work.
try:
self.nodes[0].getblock(blocks_h3[0].hash)
print "Unrequested more-work block accepted from non-whitelisted peer"
except:
raise AssertionError("Unrequested more work block was not processed")
# Node1 should have accepted and reorged.
assert_equal(self.nodes[1].getblockcount(), 3)
print "Successfully reorged to length 3 chain from whitelisted peer"
# 4b. Now mine 288 more blocks and deliver; all should be processed but
# the last (height-too-high) on node0. Node1 should process the tip if
# we give it the headers chain leading to the tip.
tips = blocks_h3
headers_message = msg_headers()
all_blocks = [] # node0's blocks
for j in xrange(2):
for i in xrange(288):
next_block = create_block(tips[j].sha256, create_coinbase(i + 4), tips[j].nTime+1)
next_block.solve()
if j==0:
test_node.send_message(msg_block(next_block))
all_blocks.append(next_block)
else:
headers_message.headers.append(CBlockHeader(next_block))
tips[j] = next_block
time.sleep(2)
for x in all_blocks:
try:
self.nodes[0].getblock(x.hash)
if x == all_blocks[287]:
raise AssertionError("Unrequested block too far-ahead should have been ignored")
except:
if x == all_blocks[287]:
print "Unrequested block too far-ahead not processed"
else:
raise AssertionError("Unrequested block with more work should have been accepted")
headers_message.headers.pop() # Ensure the last block is unrequested
white_node.send_message(headers_message) # Send headers leading to tip
white_node.send_message(msg_block(tips[1])) # Now deliver the tip
try:
white_node.sync_with_ping()
self.nodes[1].getblock(tips[1].hash)
print "Unrequested block far ahead of tip accepted from whitelisted peer"
except:
raise AssertionError("Unrequested block from whitelisted peer not accepted")
# 5. Test handling of unrequested block on the node that didn't process
# Should still not be processed (even though it has a child that has more
# work).
test_node.send_message(msg_block(blocks_h2f[0]))
# Here, if the sleep is too short, the test could falsely succeed (if the
# node hasn't processed the block by the time the sleep returns, and then
# the node processes it and incorrectly advances the tip).
# But this would be caught later on, when we verify that an inv triggers
# a getdata request for this block.
test_node.sync_with_ping()
assert_equal(self.nodes[0].getblockcount(), 2)
print "Unrequested block that would complete more-work chain was ignored"
# 6. Try to get node to request the missing block.
# Poke the node with an inv for block at height 3 and see if that
# triggers a getdata on block 2 (it should if block 2 is missing).
with mininode_lock:
# Clear state so we can check the getdata request
test_node.last_getdata = None
test_node.send_message(msg_inv([CInv(2, blocks_h3[0].sha256)]))
test_node.sync_with_ping()
with mininode_lock:
getdata = test_node.last_getdata
# Check that the getdata includes the right block
assert_equal(getdata.inv[0].hash, blocks_h2f[0].sha256)
print "Inv at tip triggered getdata for unprocessed block"
# 7. Send the missing block for the third time (now it is requested)
test_node.send_message(msg_block(blocks_h2f[0]))
test_node.sync_with_ping()
assert_equal(self.nodes[0].getblockcount(), 290)
print "Successfully reorged to longer chain from non-whitelisted peer"
[ c.disconnect_node() for c in connections ]
if __name__ == '__main__':
AcceptBlockTest().main()
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
18,
199,
3,
1898,
334,
67,
9,
6900,
710,
21158,
11672,
19782,
199,
3,
17484,
1334,
314,
10697,
15,
56,
845,
2032,
4190,
12,
1937,
314,
23073,
199,
3,
570,
9685,
503,
1455,
921,
1544,
14,
16374,
14,
1308,
15,
2383,
15,
1147,
13,
1682,
14,
8624,
14,
199,
3,
199,
199,
504,
511,
63,
4857,
14,
827,
15993,
492,
627,
199,
504,
511,
63,
4857,
14,
396,
63,
4857,
492,
21158,
26203,
199,
504,
511,
63,
4857,
14,
1974,
492,
627,
199,
646,
900,
199,
504,
511,
63,
4857,
14,
1457,
2537,
492,
1218,
63,
1457,
12,
1218,
63,
30488,
199,
199,
2344,
199,
8422,
3142,
774,
1553,
511,
6661,
402,
625,
11151,
5664,
14,
199,
199,
24430,
5953,
22754,
1380,
18390,
625,
11151,
5664,
687,
10424,
15023,
28166,
199,
14895,
527,
2222,
13,
7510,
15023,
28166,
12,
642,
2295,
314,
5953,
402,
3865,
334,
3609,
25222,
2877,
199,
24904,
2295,
3879,
315,
9861,
680,
199,
199,
8555,
26,
2877,
3380,
12,
1031,
16,
436,
1031,
17,
12,
440,
8539,
370,
1924,
1163,
14,
221,
5013,
16,
1630,
440,
199,
14189,
11667,
12,
1325,
1031,
17,
1630,
14,
9322,
911,
1924,
506,
641,
3932,
5705,
6036,
367,
199,
3749,
511,
14,
199,
199,
6004,
1172,
1373,
5013,
6805,
1950,
370,
1924,
12,
511,
63,
932,
436,
10424,
63,
932,
17342,
14,
199,
199,
1918,
511,
26,
199,
17,
14,
7958,
1373,
1853,
641,
1924,
1031,
12,
370,
10137,
473,
11156,
14,
199,
199,
18,
14,
603,
1132,
282,
892,
1853,
641,
1924,
19201,
12,
436,
28503,
370,
1924,
1031,
687,
1031,
1159,
9104,
14,
2043,
710,
19201,
1077,
18695,
14,
199,
199,
19,
14,
603,
1132,
282,
1853,
626,
367,
6080,
314,
4136,
1853,
12,
436,
28503,
370,
1924,
1031,
687,
2043,
5226,
9104,
14,
2043,
5013,
16,
1077,
440,
2112,
642,
1853,
334,
4764,
4729,
314,
1406,
395,
2952,
652,
365,
2043,
625,
11151,
436,
3181,
1133,
1172,
1655,
1736,
2419,
314,
19201,
14,
2043,
5013,
17,
1077,
2112,
2952,
642,
365,
17262,
687,
282,
10424,
15023,
9104,
14,
199,
199,
20,
14,
10217,
4573,
1853,
626,
14723,
641,
314,
14926,
316,
1853,
14,
2043,
5013,
16,
1077,
2112,
642,
1853,
1325,
506,
410,
10112,
641,
314,
18299,
6036,
12,
2952,
2043,
652,
1159,
4124,
376,
13197,
1853,
14,
2043,
5013,
17,
1077,
295,
1308,
370,
642,
8088,
6036,
14,
199,
199,
20,
66,
14,
6795,
32558,
1655,
5664,
641,
314,
8088,
6036,
14,
2043,
5013,
16,
1077,
2112,
1006,
1325,
314,
2061,
1853,
334,
7354,
12474,
23417,
315,
4569,
680,
2043,
10217,
1006,
2323,
370,
5013,
17,
12,
436,
2066,
3222,
314,
2061,
1853,
315,
626,
6036,
14,
2043,
5013,
17,
1077,
4729,
314,
1853,
2952,
652,
1159,
17262,
687,
282,
10424,
15023,
9104,
14,
199,
199,
21,
14,
10217,
282,
9250,
402,
314,
1853,
315,
327,
19,
370,
5013,
16,
14,
2043,
5013,
16,
1077,
440,
2112,
314,
1853,
2952,
652,
365,
625,
11151,
12,
436,
25578,
641,
2043,
314,
18299,
6036,
14,
199,
199,
22,
14,
10217,
5013,
16,
376,
4572,
367,
314,
4569,
650,
1853,
13584,
315,
327,
20,
3432,
14,
2043,
5013,
16,
1077,
9658,
734,
626,
5013,
16,
965,
314,
4124,
4569,
499,
1853,
436,
3222,
282,
2043,
664,
576,
14,
199,
199,
23,
14,
10217,
5013,
16,
314,
4124,
1853,
4020,
14,
2043,
5013,
16,
1077,
2112,
436,
314,
19201,
1077,
18695,
14,
199,
2344,
199,
199,
3,
1379,
1716,
26,
18753,
13,
66,
4548,
298,
7866,
1674,
221,
8051,
19762,
465,
282,
406,
2033,
390,
367,
282,
511,
370,
10209,
199,
3,
299,
18,
80,
3788,
370,
282,
1031,
12,
12999,
314,
3788,
315,
314,
2446,
5343,
9661,
14,
199,
533,
1379,
1716,
8,
1716,
6805,
9956,
304,
272,
347,
636,
826,
721,
277,
304,
267,
5013,
6805,
9956,
855,
826,
721,
277,
9,
267,
291,
14,
2105,
275,
488,
267,
291,
14,
4073,
63,
5337,
275,
413,
267,
291,
14,
2019,
63,
26992,
275,
1499,
63,
26992,
342,
339,
347,
1050,
63,
2105,
8,
277,
12,
2557,
304,
267,
291,
14,
2105,
275,
2557,
339,
327,
17507,
314,
2061,
664,
576,
1245,
781,
9128,
334,
2972,
315,
314,
511,
9,
272,
347,
641,
63,
29160,
8,
277,
12,
2557,
12,
1245,
304,
267,
291,
14,
2019,
63,
29160,
275,
1245,
339,
327,
428,
7751,
5133,
809,
564,
1245,
365,
3086,
687,
314,
1031,
14,
272,
327,
2136,
675,
642,
370,
4673,
626,
4154,
511,
883,
5386,
14,
961,
272,
327,
365,
2797,
687,
314,
5343,
2462,
12,
880,
652,
4839,
370,
16919,
272,
327,
314,
2288,
4650,
14,
272,
347,
3618,
63,
509,
63,
422,
564,
8,
277,
304,
267,
1830,
715,
26,
288,
543,
1748,
15993,
63,
831,
26,
355,
340,
291,
14,
422,
564,
63,
9226,
26,
490,
372,
288,
900,
14,
4532,
8,
16,
14,
1717,
9,
339,
327,
21947,
367,
314,
5013,
6805,
1159,
3222,
63,
1188,
805,
272,
347,
3222,
63,
1188,
8,
277,
12,
1245,
304,
267,
291,
14,
2105,
14,
2254,
63,
1188,
8,
1188,
9,
339,
347,
641,
63,
26992,
8,
277,
12,
2557,
12,
1245,
304,
267,
291,
14,
2019,
63,
26992,
275,
1245,
339,
327,
22407,
1536,
543,
314,
1031,
2410,
18719,
402,
282,
1853,
272,
347,
7604,
63,
1045,
63,
4073,
8,
277,
12,
2653,
29,
1216,
304,
267,
291,
14,
2105,
14,
2254,
63,
1188,
8,
1328,
63,
4073,
8,
10667,
29,
277,
14,
4073,
63,
5337,
430,
267,
3086,
63,
26992,
275,
756,
267,
9435,
63,
521,
275,
378,
14,
1717,
267,
1830,
440,
3086,
63,
26992,
436,
2653,
690,
378,
26,
288,
900,
14,
4532,
8,
4532,
63,
521,
9,
288,
2653,
4862,
9435,
63,
521,
288,
543,
1748,
15993,
63,
831,
26,
355,
340,
291,
14,
2019,
63,
26992,
14,
10667,
508,
291,
14,
4073,
63,
5337,
26,
490,
3086,
63,
26992,
275,
715,
267,
291,
14,
4073,
63,
5337,
847,
413,
267,
372,
3086,
63,
26992,
421,
199,
533,
15506,
3142,
774,
8,
4734,
9061,
26203,
304,
272,
347,
1050,
63,
1419,
8,
277,
12,
1798,
304,
267,
1798,
14,
525,
63,
1422,
6739,
396,
3008,
401,
2053,
628,
396
] |
[
2647,
15,
1393,
15,
1813,
2366,
18,
199,
3,
1898,
334,
67,
9,
6900,
710,
21158,
11672,
19782,
199,
3,
17484,
1334,
314,
10697,
15,
56,
845,
2032,
4190,
12,
1937,
314,
23073,
199,
3,
570,
9685,
503,
1455,
921,
1544,
14,
16374,
14,
1308,
15,
2383,
15,
1147,
13,
1682,
14,
8624,
14,
199,
3,
199,
199,
504,
511,
63,
4857,
14,
827,
15993,
492,
627,
199,
504,
511,
63,
4857,
14,
396,
63,
4857,
492,
21158,
26203,
199,
504,
511,
63,
4857,
14,
1974,
492,
627,
199,
646,
900,
199,
504,
511,
63,
4857,
14,
1457,
2537,
492,
1218,
63,
1457,
12,
1218,
63,
30488,
199,
199,
2344,
199,
8422,
3142,
774,
1553,
511,
6661,
402,
625,
11151,
5664,
14,
199,
199,
24430,
5953,
22754,
1380,
18390,
625,
11151,
5664,
687,
10424,
15023,
28166,
199,
14895,
527,
2222,
13,
7510,
15023,
28166,
12,
642,
2295,
314,
5953,
402,
3865,
334,
3609,
25222,
2877,
199,
24904,
2295,
3879,
315,
9861,
680,
199,
199,
8555,
26,
2877,
3380,
12,
1031,
16,
436,
1031,
17,
12,
440,
8539,
370,
1924,
1163,
14,
221,
5013,
16,
1630,
440,
199,
14189,
11667,
12,
1325,
1031,
17,
1630,
14,
9322,
911,
1924,
506,
641,
3932,
5705,
6036,
367,
199,
3749,
511,
14,
199,
199,
6004,
1172,
1373,
5013,
6805,
1950,
370,
1924,
12,
511,
63,
932,
436,
10424,
63,
932,
17342,
14,
199,
199,
1918,
511,
26,
199,
17,
14,
7958,
1373,
1853,
641,
1924,
1031,
12,
370,
10137,
473,
11156,
14,
199,
199,
18,
14,
603,
1132,
282,
892,
1853,
641,
1924,
19201,
12,
436,
28503,
370,
1924,
1031,
687,
1031,
1159,
9104,
14,
2043,
710,
19201,
1077,
18695,
14,
199,
199,
19,
14,
603,
1132,
282,
1853,
626,
367,
6080,
314,
4136,
1853,
12,
436,
28503,
370,
1924,
1031,
687,
2043,
5226,
9104,
14,
2043,
5013,
16,
1077,
440,
2112,
642,
1853,
334,
4764,
4729,
314,
1406,
395,
2952,
652,
365,
2043,
625,
11151,
436,
3181,
1133,
1172,
1655,
1736,
2419,
314,
19201,
14,
2043,
5013,
17,
1077,
2112,
2952,
642,
365,
17262,
687,
282,
10424,
15023,
9104,
14,
199,
199,
20,
14,
10217,
4573,
1853,
626,
14723,
641,
314,
14926,
316,
1853,
14,
2043,
5013,
16,
1077,
2112,
642,
1853,
1325,
506,
410,
10112,
641,
314,
18299,
6036,
12,
2952,
2043,
652,
1159,
4124,
376,
13197,
1853,
14,
2043,
5013,
17,
1077,
295,
1308,
370,
642,
8088,
6036,
14,
199,
199,
20,
66,
14,
6795,
32558,
1655,
5664,
641,
314,
8088,
6036,
14,
2043,
5013,
16,
1077,
2112,
1006,
1325,
314,
2061,
1853,
334,
7354,
12474,
23417,
315,
4569,
680,
2043,
10217,
1006,
2323,
370,
5013,
17,
12,
436,
2066,
3222,
314,
2061,
1853,
315,
626,
6036,
14,
2043,
5013,
17,
1077,
4729,
314,
1853,
2952,
652,
1159,
17262,
687,
282,
10424,
15023,
9104,
14,
199,
199,
21,
14,
10217,
282,
9250,
402,
314,
1853,
315,
327,
19,
370,
5013,
16,
14,
2043,
5013,
16,
1077,
440,
2112,
314,
1853,
2952,
652,
365,
625,
11151,
12,
436,
25578,
641,
2043,
314,
18299,
6036,
14,
199,
199,
22,
14,
10217,
5013,
16,
376,
4572,
367,
314,
4569,
650,
1853,
13584,
315,
327,
20,
3432,
14,
2043,
5013,
16,
1077,
9658,
734,
626,
5013,
16,
965,
314,
4124,
4569,
499,
1853,
436,
3222,
282,
2043,
664,
576,
14,
199,
199,
23,
14,
10217,
5013,
16,
314,
4124,
1853,
4020,
14,
2043,
5013,
16,
1077,
2112,
436,
314,
19201,
1077,
18695,
14,
199,
2344,
199,
199,
3,
1379,
1716,
26,
18753,
13,
66,
4548,
298,
7866,
1674,
221,
8051,
19762,
465,
282,
406,
2033,
390,
367,
282,
511,
370,
10209,
199,
3,
299,
18,
80,
3788,
370,
282,
1031,
12,
12999,
314,
3788,
315,
314,
2446,
5343,
9661,
14,
199,
533,
1379,
1716,
8,
1716,
6805,
9956,
304,
272,
347,
636,
826,
721,
277,
304,
267,
5013,
6805,
9956,
855,
826,
721,
277,
9,
267,
291,
14,
2105,
275,
488,
267,
291,
14,
4073,
63,
5337,
275,
413,
267,
291,
14,
2019,
63,
26992,
275,
1499,
63,
26992,
342,
339,
347,
1050,
63,
2105,
8,
277,
12,
2557,
304,
267,
291,
14,
2105,
275,
2557,
339,
327,
17507,
314,
2061,
664,
576,
1245,
781,
9128,
334,
2972,
315,
314,
511,
9,
272,
347,
641,
63,
29160,
8,
277,
12,
2557,
12,
1245,
304,
267,
291,
14,
2019,
63,
29160,
275,
1245,
339,
327,
428,
7751,
5133,
809,
564,
1245,
365,
3086,
687,
314,
1031,
14,
272,
327,
2136,
675,
642,
370,
4673,
626,
4154,
511,
883,
5386,
14,
961,
272,
327,
365,
2797,
687,
314,
5343,
2462,
12,
880,
652,
4839,
370,
16919,
272,
327,
314,
2288,
4650,
14,
272,
347,
3618,
63,
509,
63,
422,
564,
8,
277,
304,
267,
1830,
715,
26,
288,
543,
1748,
15993,
63,
831,
26,
355,
340,
291,
14,
422,
564,
63,
9226,
26,
490,
372,
288,
900,
14,
4532,
8,
16,
14,
1717,
9,
339,
327,
21947,
367,
314,
5013,
6805,
1159,
3222,
63,
1188,
805,
272,
347,
3222,
63,
1188,
8,
277,
12,
1245,
304,
267,
291,
14,
2105,
14,
2254,
63,
1188,
8,
1188,
9,
339,
347,
641,
63,
26992,
8,
277,
12,
2557,
12,
1245,
304,
267,
291,
14,
2019,
63,
26992,
275,
1245,
339,
327,
22407,
1536,
543,
314,
1031,
2410,
18719,
402,
282,
1853,
272,
347,
7604,
63,
1045,
63,
4073,
8,
277,
12,
2653,
29,
1216,
304,
267,
291,
14,
2105,
14,
2254,
63,
1188,
8,
1328,
63,
4073,
8,
10667,
29,
277,
14,
4073,
63,
5337,
430,
267,
3086,
63,
26992,
275,
756,
267,
9435,
63,
521,
275,
378,
14,
1717,
267,
1830,
440,
3086,
63,
26992,
436,
2653,
690,
378,
26,
288,
900,
14,
4532,
8,
4532,
63,
521,
9,
288,
2653,
4862,
9435,
63,
521,
288,
543,
1748,
15993,
63,
831,
26,
355,
340,
291,
14,
2019,
63,
26992,
14,
10667,
508,
291,
14,
4073,
63,
5337,
26,
490,
3086,
63,
26992,
275,
715,
267,
291,
14,
4073,
63,
5337,
847,
413,
267,
372,
3086,
63,
26992,
421,
199,
533,
15506,
3142,
774,
8,
4734,
9061,
26203,
304,
272,
347,
1050,
63,
1419,
8,
277,
12,
1798,
304,
267,
1798,
14,
525,
63,
1422,
6739,
396,
3008,
401,
2053,
628,
396,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
libvirt/autotest
|
server/hosts/base_classes.py
|
4
|
2686
|
#
# Copyright 2007 Google Inc. Released under the GPL v2
"""
This module defines the base classes for the server Host hierarchy.
Implementation details:
You should import the "hosts" package instead of importing each type of host.
Host: a machine on which you can run programs
RemoteHost: a remote machine on which you can run programs
"""
__author__ = """
mbligh@google.com (Martin J. Bligh),
poirier@google.com (Benjamin Poirier),
stutsman@google.com (Ryan Stutsman)
"""
import os
from autotest_lib.client.common_lib import hosts
from autotest_lib.server import utils
from autotest_lib.server.hosts import bootloader
class Host(hosts.Host):
"""
This class represents a machine on which you can run programs.
It may be a local machine, the one autoserv is running on, a remote
machine or a virtual machine.
Implementation details:
This is an abstract class, leaf subclasses must implement the methods
listed here. You must not instantiate this class but should
instantiate one of those leaf subclasses.
When overriding methods that raise NotImplementedError, the leaf class
is fully responsible for the implementation and should not chain calls
to super. When overriding methods that are a NOP in Host, the subclass
should chain calls to super(). The criteria for fitting a new method into
one category or the other should be:
1. If two separate generic implementations could reasonably be
concatenated, then the abstract implementation should pass and
subclasses should chain calls to super.
2. If only one class could reasonably perform the stated function
(e.g. two separate run() implementations cannot both be executed)
then the method should raise NotImplementedError in Host, and
the implementor should NOT chain calls to super, to ensure that
only one implementation ever gets executed.
"""
bootloader = None
def __init__(self, *args, **dargs):
super(Host, self).__init__(*args, **dargs)
self.start_loggers()
if self.job:
self.job.hosts.add(self)
def _initialize(self, target_file_owner=None,
*args, **dargs):
super(Host, self)._initialize(*args, **dargs)
self.serverdir = utils.get_server_dir()
self.monitordir = os.path.join(os.path.dirname(__file__), "monitors")
self.bootloader = bootloader.Bootloader(self)
self.env = {}
self.target_file_owner = target_file_owner
def close(self):
super(Host, self).close()
if self.job:
self.job.hosts.discard(self)
|
gpl-2.0
|
[
3,
199,
3,
1898,
10219,
4475,
3277,
14,
17646,
68,
1334,
314,
14629,
373,
18,
199,
199,
624,
199,
2765,
859,
7890,
314,
1300,
3992,
367,
314,
1654,
10891,
14446,
14,
199,
199,
7921,
2436,
26,
199,
5556,
1077,
492,
314,
298,
5146,
2,
2559,
3140,
402,
16306,
1924,
730,
402,
1591,
14,
398,
10891,
26,
282,
6844,
641,
1314,
1265,
883,
1255,
18572,
267,
17283,
4965,
26,
282,
3982,
6844,
641,
1314,
1265,
883,
1255,
18572,
199,
624,
199,
199,
363,
2502,
363,
275,
408,
199,
887,
18975,
32,
3098,
14,
957,
334,
45,
26788,
1603,
14,
699,
18975,
395,
199,
555,
73,
10742,
32,
3098,
14,
957,
334,
31231,
16997,
262,
4376,
73,
10742,
395,
199,
270,
14608,
1237,
32,
3098,
14,
957,
334,
50,
89,
290,
1933,
14608,
1237,
9,
199,
624,
199,
199,
646,
747,
199,
199,
504,
2599,
396,
63,
773,
14,
1258,
14,
2330,
63,
773,
492,
7057,
199,
504,
2599,
396,
63,
773,
14,
1000,
492,
3778,
199,
504,
2599,
396,
63,
773,
14,
1000,
14,
5146,
492,
8498,
3422,
421,
199,
533,
10891,
8,
5146,
14,
4965,
304,
272,
408,
272,
961,
1021,
8469,
282,
6844,
641,
1314,
1265,
883,
1255,
18572,
14,
339,
2779,
1443,
506,
282,
2257,
6844,
12,
314,
1373,
2599,
7297,
365,
3879,
641,
12,
282,
3982,
272,
6844,
503,
282,
5791,
6844,
14,
339,
24425,
2436,
26,
272,
961,
365,
376,
9006,
1021,
12,
11747,
9180,
1471,
5669,
314,
3102,
272,
10532,
2348,
14,
2047,
1471,
440,
17321,
642,
1021,
1325,
1077,
272,
17321,
1373,
402,
5204,
11747,
9180,
14,
339,
3979,
18972,
3102,
626,
746,
4279,
12,
314,
11747,
1021,
272,
365,
9999,
17845,
367,
314,
4514,
436,
1077,
440,
6036,
4882,
272,
370,
1613,
14,
3979,
18972,
3102,
626,
787,
282,
653,
1938,
315,
10891,
12,
314,
5516,
272,
1077,
6036,
4882,
370,
1613,
1252,
710,
15647,
367,
21774,
282,
892,
1083,
1901,
272,
1373,
4637,
503,
314,
1163,
1077,
506,
26,
267,
413,
14,
982,
2877,
7396,
7809,
12591,
4293,
4499,
6665,
506,
1779,
26271,
12,
2066,
314,
9006,
4514,
1077,
986,
436,
1779,
9180,
1077,
6036,
4882,
370,
1613,
14,
267,
499,
14,
982,
1454,
1373,
1021,
4293,
4499,
6665,
5147,
314,
410,
972,
805,
1779,
334,
69,
14,
71,
14,
2877,
7396,
1255,
342,
12591,
3913,
3865,
506,
7934,
9,
1779,
2066,
314,
1083,
1077,
746,
4279,
315,
10891,
12,
436,
1779,
314,
5669,
269,
1077,
2845,
6036,
4882,
370,
1613,
12,
370,
4868,
626,
1779,
1454,
1373,
4514,
14433,
7545,
7934,
14,
272,
408,
339,
8498,
3422,
275,
488,
2378,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
31895,
304,
267,
1613,
8,
4965,
12,
291,
2843,
826,
9308,
589,
12,
1011,
31895,
9,
398,
291,
14,
928,
63,
22771,
342,
267,
340,
291,
14,
2423,
26,
288,
291,
14,
2423,
14,
5146,
14,
525,
8,
277,
9,
2378,
347,
485,
8489,
8,
277,
12,
1347,
63,
493,
63,
4597,
29,
403,
12,
490,
627,
589,
12,
1011,
31895,
304,
267,
1613,
8,
4965,
12,
291,
10445,
8489,
2031,
589,
12,
1011,
31895,
9,
398,
291,
14,
1000,
694,
275,
3778,
14,
362,
63,
1000,
63,
694,
342,
267,
291,
14,
7157,
694,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
298,
24048,
531,
267,
291,
14,
4930,
3422,
275,
8498,
3422,
14,
17989,
3422,
8,
277,
9,
267,
291,
14,
1813,
275,
1052,
267,
291,
14,
1375,
63,
493,
63,
4597,
275,
1347,
63,
493,
63,
4597,
2378,
347,
4002,
8,
277,
304,
267,
1613,
8,
4965,
12,
291,
680,
1600,
342,
398,
340,
291,
14,
2423,
26,
288,
291,
14,
2423,
14,
5146,
14,
14394,
8,
277,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
3,
1898,
10219,
4475,
3277,
14,
17646,
68,
1334,
314,
14629,
373,
18,
199,
199,
624,
199,
2765,
859,
7890,
314,
1300,
3992,
367,
314,
1654,
10891,
14446,
14,
199,
199,
7921,
2436,
26,
199,
5556,
1077,
492,
314,
298,
5146,
2,
2559,
3140,
402,
16306,
1924,
730,
402,
1591,
14,
398,
10891,
26,
282,
6844,
641,
1314,
1265,
883,
1255,
18572,
267,
17283,
4965,
26,
282,
3982,
6844,
641,
1314,
1265,
883,
1255,
18572,
199,
624,
199,
199,
363,
2502,
363,
275,
408,
199,
887,
18975,
32,
3098,
14,
957,
334,
45,
26788,
1603,
14,
699,
18975,
395,
199,
555,
73,
10742,
32,
3098,
14,
957,
334,
31231,
16997,
262,
4376,
73,
10742,
395,
199,
270,
14608,
1237,
32,
3098,
14,
957,
334,
50,
89,
290,
1933,
14608,
1237,
9,
199,
624,
199,
199,
646,
747,
199,
199,
504,
2599,
396,
63,
773,
14,
1258,
14,
2330,
63,
773,
492,
7057,
199,
504,
2599,
396,
63,
773,
14,
1000,
492,
3778,
199,
504,
2599,
396,
63,
773,
14,
1000,
14,
5146,
492,
8498,
3422,
421,
199,
533,
10891,
8,
5146,
14,
4965,
304,
272,
408,
272,
961,
1021,
8469,
282,
6844,
641,
1314,
1265,
883,
1255,
18572,
14,
339,
2779,
1443,
506,
282,
2257,
6844,
12,
314,
1373,
2599,
7297,
365,
3879,
641,
12,
282,
3982,
272,
6844,
503,
282,
5791,
6844,
14,
339,
24425,
2436,
26,
272,
961,
365,
376,
9006,
1021,
12,
11747,
9180,
1471,
5669,
314,
3102,
272,
10532,
2348,
14,
2047,
1471,
440,
17321,
642,
1021,
1325,
1077,
272,
17321,
1373,
402,
5204,
11747,
9180,
14,
339,
3979,
18972,
3102,
626,
746,
4279,
12,
314,
11747,
1021,
272,
365,
9999,
17845,
367,
314,
4514,
436,
1077,
440,
6036,
4882,
272,
370,
1613,
14,
3979,
18972,
3102,
626,
787,
282,
653,
1938,
315,
10891,
12,
314,
5516,
272,
1077,
6036,
4882,
370,
1613,
1252,
710,
15647,
367,
21774,
282,
892,
1083,
1901,
272,
1373,
4637,
503,
314,
1163,
1077,
506,
26,
267,
413,
14,
982,
2877,
7396,
7809,
12591,
4293,
4499,
6665,
506,
1779,
26271,
12,
2066,
314,
9006,
4514,
1077,
986,
436,
1779,
9180,
1077,
6036,
4882,
370,
1613,
14,
267,
499,
14,
982,
1454,
1373,
1021,
4293,
4499,
6665,
5147,
314,
410,
972,
805,
1779,
334,
69,
14,
71,
14,
2877,
7396,
1255,
342,
12591,
3913,
3865,
506,
7934,
9,
1779,
2066,
314,
1083,
1077,
746,
4279,
315,
10891,
12,
436,
1779,
314,
5669,
269,
1077,
2845,
6036,
4882,
370,
1613,
12,
370,
4868,
626,
1779,
1454,
1373,
4514,
14433,
7545,
7934,
14,
272,
408,
339,
8498,
3422,
275,
488,
2378,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
31895,
304,
267,
1613,
8,
4965,
12,
291,
2843,
826,
9308,
589,
12,
1011,
31895,
9,
398,
291,
14,
928,
63,
22771,
342,
267,
340,
291,
14,
2423,
26,
288,
291,
14,
2423,
14,
5146,
14,
525,
8,
277,
9,
2378,
347,
485,
8489,
8,
277,
12,
1347,
63,
493,
63,
4597,
29,
403,
12,
490,
627,
589,
12,
1011,
31895,
304,
267,
1613,
8,
4965,
12,
291,
10445,
8489,
2031,
589,
12,
1011,
31895,
9,
398,
291,
14,
1000,
694,
275,
3778,
14,
362,
63,
1000,
63,
694,
342,
267,
291,
14,
7157,
694,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
298,
24048,
531,
267,
291,
14,
4930,
3422,
275,
8498,
3422,
14,
17989,
3422,
8,
277,
9,
267,
291,
14,
1813,
275,
1052,
267,
291,
14,
1375,
63,
493,
63,
4597,
275,
1347,
63,
493,
63,
4597,
2378,
347,
4002,
8,
277,
304,
267,
1613,
8,
4965,
12,
291,
680,
1600,
342,
398,
340,
291,
14,
2423,
26,
288,
291,
14,
2423,
14,
5146,
14,
14394,
8,
277,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
hronoses/vispy
|
examples/collections/tiger.py
|
18
|
2455
|
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vispy: testskip
# -----------------------------------------------------------------------------
# Copyright (c) 2014, Nicolas P. Rougier. All Rights Reserved.
# Distributed under the (new) BSD License.
# -----------------------------------------------------------------------------
from vispy import app, gloo
from vispy.util import load_data_file
from vispy.util.svg import Document
from vispy.visuals.collections import PathCollection, PolygonCollection
from vispy.visuals.transforms import PanZoomTransform
path = load_data_file('tiger/tiger.svg')
tiger = Document(path)
width, height = int(tiger.viewport.width), int(tiger.viewport.height)
canvas = app.Canvas(size=(width, height), show=True, keys='interactive')
gloo.set_viewport(0, 0, width, height)
gloo.set_state("translucent", depth_test=True)
panzoom = PanZoomTransform(canvas, aspect=1.0)
paths = PathCollection(
"agg+", linewidth='shared', color="shared", transform=panzoom)
polys = PolygonCollection("agg", transform=panzoom)
paths.update.connect(canvas.update)
z = 0
for path in tiger.paths:
for vertices, closed in path.vertices:
vertices = 2 * (vertices / (width, height, 1)) - 1
vertices[:, 1] = -vertices[:, 1]
if len(vertices) < 3:
continue
if path.style.stroke is not None:
vertices[:, 2] = z - 0.5 / 1000.
if path.style.stroke_width:
stroke_width = path.style.stroke_width.value
else:
stroke_width = 2.0
paths.append(vertices, closed=closed, color=path.style.stroke.rgba,
linewidth=stroke_width)
if path.style.fill is not None:
if path.style.stroke is None:
vertices[:, 2] = z - 0.25 / 1000.
paths.append(vertices, closed=closed,
color=path.style.fill.rgba,
linewidth=1)
vertices[:, 2] = z
polys.append(vertices, color=path.style.fill.rgba)
z -= 1 / 1000.
paths["linewidth"] = 1.0
paths['viewport'] = 0, 0, 800, 800
@canvas.connect
def on_draw(e):
gloo.clear('white')
polys.draw()
paths.draw()
@canvas.connect
def on_resize(e):
width, height = e.size[0], e.size[1]
gloo.set_viewport(0, 0, width, height)
paths['viewport'] = 0, 0, width, height
if __name__ == '__main__':
canvas.show()
app.run()
|
bsd-3-clause
|
[
3168,
1182,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
21370,
647,
26,
511,
2759,
199,
3,
13722,
199,
3,
1898,
334,
67,
9,
6927,
12,
30650,
761,
305,
510,
14,
19776,
71,
4446,
14,
2900,
5924,
5702,
14,
199,
3,
17484,
1334,
314,
334,
1222,
9,
6289,
844,
14,
199,
3,
13722,
199,
199,
504,
21370,
647,
492,
1145,
12,
486,
320,
79,
199,
504,
21370,
647,
14,
1974,
492,
2248,
63,
576,
63,
493,
199,
504,
21370,
647,
14,
1974,
14,
10273,
492,
7543,
199,
504,
21370,
647,
14,
16948,
83,
14,
7882,
492,
6912,
7768,
12,
17560,
7768,
199,
504,
21370,
647,
14,
16948,
83,
14,
15133,
492,
510,
290,
26798,
6939,
199,
199,
515,
275,
2248,
63,
576,
63,
493,
360,
280,
836,
15,
280,
836,
14,
10273,
358,
199,
280,
836,
275,
7543,
8,
515,
9,
199,
199,
2063,
12,
4569,
275,
1109,
8,
280,
836,
14,
25484,
14,
2063,
395,
1109,
8,
280,
836,
14,
25484,
14,
3333,
9,
199,
7682,
275,
1145,
14,
15174,
8,
890,
2687,
2063,
12,
4569,
395,
2498,
29,
549,
12,
2883,
534,
13543,
358,
199,
30737,
79,
14,
409,
63,
25484,
8,
16,
12,
378,
12,
3462,
12,
4569,
9,
199,
30737,
79,
14,
409,
63,
929,
480,
1515,
29918,
484,
401,
5818,
63,
396,
29,
549,
9,
199,
199,
10384,
10598,
275,
510,
290,
26798,
6939,
8,
7682,
12,
17435,
29,
17,
14,
16,
9,
199,
3771,
275,
6912,
7768,
8,
272,
298,
13452,
22758,
21213,
534,
5555,
297,
3164,
628,
5555,
401,
5793,
29,
10384,
10598,
9,
199,
15743,
275,
17560,
7768,
480,
13452,
401,
5793,
29,
10384,
10598,
9,
199,
3771,
14,
873,
14,
2242,
8,
7682,
14,
873,
9,
199,
199,
90,
275,
378,
199,
509,
931,
315,
3367,
836,
14,
3771,
26,
272,
367,
14971,
12,
6876,
315,
931,
14,
12637,
26,
398,
14971,
275,
499,
627,
334,
12637,
1182,
334,
2063,
12,
4569,
12,
413,
430,
446,
413,
267,
14971,
3981,
413,
61,
275,
446,
12637,
3981,
413,
61,
267,
340,
822,
8,
12637,
9,
665,
650,
26,
288,
1980,
267,
340,
931,
14,
2487,
14,
11473,
365,
440,
488,
26,
288,
14971,
3981,
499,
61,
275,
1315,
446,
378,
14,
21,
1182,
5198,
14,
288,
340,
931,
14,
2487,
14,
11473,
63,
2063,
26,
355,
22824,
63,
2063,
275,
931,
14,
2487,
14,
11473,
63,
2063,
14,
585,
288,
587,
26,
355,
22824,
63,
2063,
275,
499,
14,
16,
288,
3792,
14,
740,
8,
12637,
12,
6876,
29,
5938,
12,
3164,
29,
515,
14,
2487,
14,
11473,
14,
22118,
12,
586,
21213,
29,
11473,
63,
2063,
9,
267,
340,
931,
14,
2487,
14,
4498,
365,
440,
488,
26,
288,
340,
931,
14,
2487,
14,
11473,
365,
488,
26,
355,
14971,
3981,
499,
61,
275,
1315,
446,
378,
14,
821,
1182,
5198,
14,
355,
3792,
14,
740,
8,
12637,
12,
6876,
29,
5938,
12,
2490,
3164,
29,
515,
14,
2487,
14,
4498,
14,
22118,
12,
2490,
21213,
29,
17,
9,
288,
14971,
3981,
499,
61,
275,
1315,
288,
3708,
588,
14,
740,
8,
12637,
12,
3164,
29,
515,
14,
2487,
14,
4498,
14,
22118,
9,
272,
1315,
4862,
413,
1182,
5198,
14,
421,
199,
3771,
905,
24643,
937,
275,
413,
14,
16,
199,
3771,
459,
25484,
418,
275,
378,
12,
378,
12,
23466,
12,
23466,
421,
199,
32,
7682,
14,
2242,
199,
318,
641,
63,
5485,
8,
69,
304,
272,
486,
320,
79,
14,
3584,
360,
7510,
358,
272,
3708,
588,
14,
5485,
342,
272,
3792,
14,
5485,
342,
421,
199,
32,
7682,
14,
2242,
199,
318,
641,
63,
8709,
8,
69,
304,
272,
3462,
12,
4569,
275,
325,
14,
890,
59,
16,
467,
325,
14,
890,
59,
17,
61,
272,
486,
320,
79,
14,
409,
63,
25484,
8,
16,
12,
378,
12,
3462,
12,
4569,
9,
272,
3792,
459,
25484,
418,
275,
378,
12,
378,
12,
3462,
12,
4569,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
10218,
14,
2384,
342,
272,
1145,
14,
1065,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1182,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
21370,
647,
26,
511,
2759,
199,
3,
13722,
199,
3,
1898,
334,
67,
9,
6927,
12,
30650,
761,
305,
510,
14,
19776,
71,
4446,
14,
2900,
5924,
5702,
14,
199,
3,
17484,
1334,
314,
334,
1222,
9,
6289,
844,
14,
199,
3,
13722,
199,
199,
504,
21370,
647,
492,
1145,
12,
486,
320,
79,
199,
504,
21370,
647,
14,
1974,
492,
2248,
63,
576,
63,
493,
199,
504,
21370,
647,
14,
1974,
14,
10273,
492,
7543,
199,
504,
21370,
647,
14,
16948,
83,
14,
7882,
492,
6912,
7768,
12,
17560,
7768,
199,
504,
21370,
647,
14,
16948,
83,
14,
15133,
492,
510,
290,
26798,
6939,
199,
199,
515,
275,
2248,
63,
576,
63,
493,
360,
280,
836,
15,
280,
836,
14,
10273,
358,
199,
280,
836,
275,
7543,
8,
515,
9,
199,
199,
2063,
12,
4569,
275,
1109,
8,
280,
836,
14,
25484,
14,
2063,
395,
1109,
8,
280,
836,
14,
25484,
14,
3333,
9,
199,
7682,
275,
1145,
14,
15174,
8,
890,
2687,
2063,
12,
4569,
395,
2498,
29,
549,
12,
2883,
534,
13543,
358,
199,
30737,
79,
14,
409,
63,
25484,
8,
16,
12,
378,
12,
3462,
12,
4569,
9,
199,
30737,
79,
14,
409,
63,
929,
480,
1515,
29918,
484,
401,
5818,
63,
396,
29,
549,
9,
199,
199,
10384,
10598,
275,
510,
290,
26798,
6939,
8,
7682,
12,
17435,
29,
17,
14,
16,
9,
199,
3771,
275,
6912,
7768,
8,
272,
298,
13452,
22758,
21213,
534,
5555,
297,
3164,
628,
5555,
401,
5793,
29,
10384,
10598,
9,
199,
15743,
275,
17560,
7768,
480,
13452,
401,
5793,
29,
10384,
10598,
9,
199,
3771,
14,
873,
14,
2242,
8,
7682,
14,
873,
9,
199,
199,
90,
275,
378,
199,
509,
931,
315,
3367,
836,
14,
3771,
26,
272,
367,
14971,
12,
6876,
315,
931,
14,
12637,
26,
398,
14971,
275,
499,
627,
334,
12637,
1182,
334,
2063,
12,
4569,
12,
413,
430,
446,
413,
267,
14971,
3981,
413,
61,
275,
446,
12637,
3981,
413,
61,
267,
340,
822,
8,
12637,
9,
665,
650,
26,
288,
1980,
267,
340,
931,
14,
2487,
14,
11473,
365,
440,
488,
26,
288,
14971,
3981,
499,
61,
275,
1315,
446,
378,
14,
21,
1182,
5198,
14,
288,
340,
931,
14,
2487,
14,
11473,
63,
2063,
26,
355,
22824,
63,
2063,
275,
931,
14,
2487,
14,
11473,
63,
2063,
14,
585,
288,
587,
26,
355,
22824,
63,
2063,
275,
499,
14,
16,
288,
3792,
14,
740,
8,
12637,
12,
6876,
29,
5938,
12,
3164,
29,
515,
14,
2487,
14,
11473,
14,
22118,
12,
586,
21213,
29,
11473,
63,
2063,
9,
267,
340,
931,
14,
2487,
14,
4498,
365,
440,
488,
26,
288,
340,
931,
14,
2487,
14,
11473,
365,
488,
26,
355,
14971,
3981,
499,
61,
275,
1315,
446,
378,
14,
821,
1182,
5198,
14,
355,
3792,
14,
740,
8,
12637,
12,
6876,
29,
5938,
12,
2490,
3164,
29,
515,
14,
2487,
14,
4498,
14,
22118,
12,
2490,
21213,
29,
17,
9,
288,
14971,
3981,
499,
61,
275,
1315,
288,
3708,
588,
14,
740,
8,
12637,
12,
3164,
29,
515,
14,
2487,
14,
4498,
14,
22118,
9,
272,
1315,
4862,
413,
1182,
5198,
14,
421,
199,
3771,
905,
24643,
937,
275,
413,
14,
16,
199,
3771,
459,
25484,
418,
275,
378,
12,
378,
12,
23466,
12,
23466,
421,
199,
32,
7682,
14,
2242,
199,
318,
641,
63,
5485,
8,
69,
304,
272,
486,
320,
79,
14,
3584,
360,
7510,
358,
272,
3708,
588,
14,
5485,
342,
272,
3792,
14,
5485,
342,
421,
199,
32,
7682,
14,
2242,
199,
318,
641,
63,
8709,
8,
69,
304,
272,
3462,
12,
4569,
275,
325,
14,
890,
59,
16,
467,
325,
14,
890,
59,
17,
61,
272,
486,
320,
79,
14,
409,
63,
25484,
8,
16,
12,
378,
12,
3462,
12,
4569,
9,
272,
3792,
459,
25484,
418,
275,
378,
12,
378,
12,
3462,
12,
4569,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
10218,
14,
2384,
342,
272,
1145,
14,
1065,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
svn2github/kgyp
|
test/win/gyptest-link-generate-manifest.py
|
238
|
4708
|
#!/usr/bin/env python
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""
Make sure we generate a manifest file when linking binaries, including
handling AdditionalManifestFiles.
"""
import TestGyp
import sys
if sys.platform == 'win32':
import pywintypes
import win32api
import winerror
RT_MANIFEST = 24
class LoadLibrary(object):
"""Context manager for loading and releasing binaries in Windows.
Yields the handle of the binary loaded."""
def __init__(self, path):
self._path = path
self._handle = None
def __enter__(self):
self._handle = win32api.LoadLibrary(self._path)
return self._handle
def __exit__(self, type, value, traceback):
win32api.FreeLibrary(self._handle)
def extract_manifest(path, resource_name):
"""Reads manifest from |path| and returns it as a string.
Returns None is there is no such manifest."""
with LoadLibrary(path) as handle:
try:
return win32api.LoadResource(handle, RT_MANIFEST, resource_name)
except pywintypes.error as error:
if error.args[0] == winerror.ERROR_RESOURCE_DATA_NOT_FOUND:
return None
else:
raise
test = TestGyp.TestGyp(formats=['msvs', 'ninja'])
CHDIR = 'linker-flags'
test.run_gyp('generate-manifest.gyp', chdir=CHDIR)
test.build('generate-manifest.gyp', test.ALL, chdir=CHDIR)
# Make sure that generation of .generated.manifest does not cause a relink.
test.run_gyp('generate-manifest.gyp', chdir=CHDIR)
test.up_to_date('generate-manifest.gyp', test.ALL, chdir=CHDIR)
def test_manifest(filename, generate_manifest, embedded_manifest,
extra_manifest):
exe_file = test.built_file_path(filename, chdir=CHDIR)
if not generate_manifest:
test.must_not_exist(exe_file + '.manifest')
manifest = extract_manifest(exe_file, 1)
test.fail_test(manifest)
return
if embedded_manifest:
manifest = extract_manifest(exe_file, 1)
test.fail_test(not manifest)
else:
test.must_exist(exe_file + '.manifest')
manifest = test.read(exe_file + '.manifest')
test.fail_test(not manifest)
test.fail_test(extract_manifest(exe_file, 1))
if generate_manifest:
test.must_contain_any_line(manifest, 'requestedExecutionLevel')
if extra_manifest:
test.must_contain_any_line(manifest,
'35138b9a-5d96-4fbd-8e2d-a2440225f93a')
test.must_contain_any_line(manifest,
'e2011457-1546-43c5-a5fe-008deee3d3f0')
test_manifest('test_generate_manifest_true.exe',
generate_manifest=True,
embedded_manifest=False,
extra_manifest=False)
test_manifest('test_generate_manifest_false.exe',
generate_manifest=False,
embedded_manifest=False,
extra_manifest=False)
test_manifest('test_generate_manifest_default.exe',
generate_manifest=True,
embedded_manifest=False,
extra_manifest=False)
test_manifest('test_generate_manifest_true_as_embedded.exe',
generate_manifest=True,
embedded_manifest=True,
extra_manifest=False)
test_manifest('test_generate_manifest_false_as_embedded.exe',
generate_manifest=False,
embedded_manifest=True,
extra_manifest=False)
test_manifest('test_generate_manifest_default_as_embedded.exe',
generate_manifest=True,
embedded_manifest=True,
extra_manifest=False)
test_manifest('test_generate_manifest_true_with_extra_manifest.exe',
generate_manifest=True,
embedded_manifest=False,
extra_manifest=True)
test_manifest('test_generate_manifest_false_with_extra_manifest.exe',
generate_manifest=False,
embedded_manifest=False,
extra_manifest=True)
test_manifest('test_generate_manifest_true_with_extra_manifest_list.exe',
generate_manifest=True,
embedded_manifest=False,
extra_manifest=True)
test_manifest('test_generate_manifest_false_with_extra_manifest_list.exe',
generate_manifest=False,
embedded_manifest=False,
extra_manifest=True)
test_manifest('test_generate_manifest_default_embed_default.exe',
generate_manifest=True,
embedded_manifest=True,
extra_manifest=False)
test.pass_test()
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
1898,
334,
67,
9,
6029,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
199,
5483,
3238,
781,
3550,
282,
7712,
570,
1380,
25833,
21984,
12,
5893,
199,
22273,
10961,
11038,
5535,
14,
199,
624,
199,
199,
646,
25688,
199,
199,
646,
984,
199,
199,
692,
984,
14,
3246,
508,
283,
2676,
708,
356,
523,
492,
1134,
27171,
523,
492,
4747,
708,
1246,
523,
492,
4747,
705,
819,
24090,
63,
24067,
275,
5504,
819,
1021,
7190,
7424,
8,
785,
304,
272,
408,
2998,
5256,
367,
8697,
436,
295,
274,
11571,
21984,
315,
5417,
14,
272,
23771,
83,
314,
2429,
402,
314,
3366,
6511,
1041,
272,
347,
636,
826,
721,
277,
12,
931,
304,
489,
291,
423,
515,
275,
931,
489,
291,
423,
2479,
275,
488,
339,
347,
636,
4200,
721,
277,
304,
489,
291,
423,
2479,
275,
4747,
708,
1246,
14,
6200,
7424,
8,
277,
423,
515,
9,
489,
372,
291,
423,
2479,
339,
347,
636,
2224,
721,
277,
12,
730,
12,
574,
12,
5190,
304,
489,
4747,
708,
1246,
14,
10146,
7424,
8,
277,
423,
2479,
9,
819,
347,
5536,
63,
6418,
8,
515,
12,
2073,
63,
354,
304,
272,
408,
23614,
7712,
687,
1204,
515,
92,
436,
2529,
652,
465,
282,
1059,
14,
272,
1803,
488,
365,
2337,
365,
949,
4066,
7712,
1041,
272,
543,
7190,
7424,
8,
515,
9,
465,
2429,
26,
489,
862,
26,
267,
372,
4747,
708,
1246,
14,
6200,
4031,
8,
2479,
12,
24090,
63,
24067,
12,
2073,
63,
354,
9,
489,
871,
1134,
27171,
14,
705,
465,
1125,
26,
267,
340,
1125,
14,
589,
59,
16,
61,
508,
4747,
705,
14,
3170,
63,
14110,
63,
3998,
63,
4609,
63,
13945,
26,
881,
372,
488,
267,
587,
26,
881,
746,
819,
511,
275,
25688,
14,
774,
13899,
8,
6321,
2968,
8338,
297,
283,
8675,
1105,
819,
6624,
3022,
275,
283,
20311,
13,
2469,
7,
523,
511,
14,
1065,
63,
6179,
360,
4208,
13,
6418,
14,
6179,
297,
13097,
29,
30285,
9,
523,
511,
14,
1506,
360,
4208,
13,
6418,
14,
6179,
297,
511,
14,
1761,
12,
13097,
29,
30285,
9,
819,
327,
4155,
3238,
626,
10152,
402,
1275,
10176,
14,
6418,
1630,
440,
7675,
282,
295,
1073,
14,
523,
511,
14,
1065,
63,
6179,
360,
4208,
13,
6418,
14,
6179,
297,
13097,
29,
30285,
9,
523,
511,
14,
384,
63,
475,
63,
602,
360,
4208,
13,
6418,
14,
6179,
297,
511,
14,
1761,
12,
13097,
29,
30285,
9,
819,
347,
511,
63,
6418,
8,
1501,
12,
3550,
63,
6418,
12,
12169,
63,
6418,
12,
490,
2402,
63,
6418,
304,
272,
14778,
63,
493,
275,
511,
14,
11730,
63,
493,
63,
515,
8,
1501,
12,
13097,
29,
30285,
9,
272,
340,
440,
3550,
63,
6418,
26,
489,
511,
14,
7790,
63,
1397,
63,
4494,
8,
5803,
63,
493,
435,
1987,
6418,
358,
489,
7712,
275,
5536,
63,
6418,
8,
5803,
63,
493,
12,
413,
9,
489,
511,
14,
1633,
63,
396,
8,
6418,
9,
489,
372,
272,
340,
12169,
63,
6418,
26,
489,
7712,
275,
5536,
63,
6418,
8,
5803,
63,
493,
12,
413,
9,
489,
511,
14,
1633,
63,
396,
8,
1397,
7712,
9,
272,
587,
26,
489,
511,
14,
7790,
63,
4494,
8,
5803,
63,
493,
435,
1987,
6418,
358,
489,
7712,
275,
511,
14,
739,
8,
5803,
63,
493,
435,
1987,
6418,
358,
489,
511,
14,
1633,
63,
396,
8,
1397,
7712,
9,
489,
511,
14,
1633,
63,
396,
8,
5005,
63,
6418,
8,
5803,
63,
493,
12,
413,
430,
272,
340,
3550,
63,
6418,
26,
489,
511,
14,
7790,
63,
7747,
63,
1629,
63,
604,
8,
6418,
12,
283,
11151,
11310,
4670,
358,
272,
340,
2402,
63,
6418,
26,
489,
511,
14,
7790,
63,
7747,
63,
1629,
63,
604,
8,
6418,
12,
639,
283,
1276,
8527,
66,
25,
65,
13,
21,
68,
2534,
13,
20,
17108,
13,
24,
69,
18,
68,
13,
65,
11603,
996,
821,
70,
3129,
65,
358,
489,
511,
14,
7790,
63,
7747,
63,
1629,
63,
604,
8,
6418,
12,
639,
283,
69,
1797,
1079,
1641,
13,
1046,
2466,
13,
2824,
67,
21,
13,
65,
21,
771,
13,
8662,
271,
1024,
19,
68,
19,
70,
16,
358,
819,
511,
63,
6418,
360,
396,
63,
4208,
63,
6418,
63,
2052,
14,
5803,
297,
355,
3550,
63,
6418,
29,
549,
12,
355,
12169,
63,
6418,
29,
797,
12,
355,
2402,
63,
6418,
29,
797,
9,
523,
511,
63,
6418,
360,
396,
63,
4208,
63,
6418,
63,
3910,
14,
5803,
297,
355,
3550,
63,
6418,
29,
797,
12,
355,
12169,
63,
6418,
29,
797,
12,
355,
2402,
63,
6418,
29,
797,
9,
523,
511,
63,
6418,
360,
396,
63,
4208,
63,
6418,
63,
885,
14,
5803,
297,
355,
3550,
63,
6418,
29,
549,
12,
355,
12169,
63,
6418,
29,
797,
12,
355,
2402,
63,
6418,
29,
797,
9,
523,
511,
63,
6418,
360,
396,
63,
4208,
63,
6418,
63,
2052,
63,
305,
63,
18757,
14,
5803,
297,
355,
3550,
63,
6418,
29,
549,
12,
355,
12169,
63,
6418,
29,
549,
12,
355,
2402,
63,
6418,
29,
797,
9,
523,
511,
63,
6418,
360,
396,
63,
4208,
63,
6418,
63,
3910,
63,
305,
63,
18757,
14,
5803,
297,
355,
3550,
63,
6418,
29,
797,
12,
355,
12169,
63,
6418,
29,
549,
12,
355,
2402,
63,
6418,
29,
797,
9,
523,
511,
63,
6418,
360,
396,
63,
4208,
63,
6418,
63,
885,
63,
305,
63,
18757,
14,
5803,
297,
355,
3550,
63,
6418,
29,
549,
12,
355,
12169,
63,
6418,
29,
549,
12,
355,
2402,
63,
6418,
29,
797,
9,
523,
511,
63,
6418,
360,
396,
63,
4208,
63,
6418,
63,
2052,
63,
1045,
63,
2911,
63,
6418,
14,
5803,
297,
355,
3550,
63,
6418,
29,
549,
12,
355,
12169,
63,
6418,
29,
797,
12,
355,
2402,
63,
6418,
29,
549,
9,
523,
511,
63,
6418,
360,
396,
63,
4208,
63,
6418,
63,
3910,
63,
1045,
63,
2911,
63,
6418,
14,
5803,
297,
355,
3550,
63,
6418,
29,
797,
12
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
1898,
334,
67,
9,
6029,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
199,
5483,
3238,
781,
3550,
282,
7712,
570,
1380,
25833,
21984,
12,
5893,
199,
22273,
10961,
11038,
5535,
14,
199,
624,
199,
199,
646,
25688,
199,
199,
646,
984,
199,
199,
692,
984,
14,
3246,
508,
283,
2676,
708,
356,
523,
492,
1134,
27171,
523,
492,
4747,
708,
1246,
523,
492,
4747,
705,
819,
24090,
63,
24067,
275,
5504,
819,
1021,
7190,
7424,
8,
785,
304,
272,
408,
2998,
5256,
367,
8697,
436,
295,
274,
11571,
21984,
315,
5417,
14,
272,
23771,
83,
314,
2429,
402,
314,
3366,
6511,
1041,
272,
347,
636,
826,
721,
277,
12,
931,
304,
489,
291,
423,
515,
275,
931,
489,
291,
423,
2479,
275,
488,
339,
347,
636,
4200,
721,
277,
304,
489,
291,
423,
2479,
275,
4747,
708,
1246,
14,
6200,
7424,
8,
277,
423,
515,
9,
489,
372,
291,
423,
2479,
339,
347,
636,
2224,
721,
277,
12,
730,
12,
574,
12,
5190,
304,
489,
4747,
708,
1246,
14,
10146,
7424,
8,
277,
423,
2479,
9,
819,
347,
5536,
63,
6418,
8,
515,
12,
2073,
63,
354,
304,
272,
408,
23614,
7712,
687,
1204,
515,
92,
436,
2529,
652,
465,
282,
1059,
14,
272,
1803,
488,
365,
2337,
365,
949,
4066,
7712,
1041,
272,
543,
7190,
7424,
8,
515,
9,
465,
2429,
26,
489,
862,
26,
267,
372,
4747,
708,
1246,
14,
6200,
4031,
8,
2479,
12,
24090,
63,
24067,
12,
2073,
63,
354,
9,
489,
871,
1134,
27171,
14,
705,
465,
1125,
26,
267,
340,
1125,
14,
589,
59,
16,
61,
508,
4747,
705,
14,
3170,
63,
14110,
63,
3998,
63,
4609,
63,
13945,
26,
881,
372,
488,
267,
587,
26,
881,
746,
819,
511,
275,
25688,
14,
774,
13899,
8,
6321,
2968,
8338,
297,
283,
8675,
1105,
819,
6624,
3022,
275,
283,
20311,
13,
2469,
7,
523,
511,
14,
1065,
63,
6179,
360,
4208,
13,
6418,
14,
6179,
297,
13097,
29,
30285,
9,
523,
511,
14,
1506,
360,
4208,
13,
6418,
14,
6179,
297,
511,
14,
1761,
12,
13097,
29,
30285,
9,
819,
327,
4155,
3238,
626,
10152,
402,
1275,
10176,
14,
6418,
1630,
440,
7675,
282,
295,
1073,
14,
523,
511,
14,
1065,
63,
6179,
360,
4208,
13,
6418,
14,
6179,
297,
13097,
29,
30285,
9,
523,
511,
14,
384,
63,
475,
63,
602,
360,
4208,
13,
6418,
14,
6179,
297,
511,
14,
1761,
12,
13097,
29,
30285,
9,
819,
347,
511,
63,
6418,
8,
1501,
12,
3550,
63,
6418,
12,
12169,
63,
6418,
12,
490,
2402,
63,
6418,
304,
272,
14778,
63,
493,
275,
511,
14,
11730,
63,
493,
63,
515,
8,
1501,
12,
13097,
29,
30285,
9,
272,
340,
440,
3550,
63,
6418,
26,
489,
511,
14,
7790,
63,
1397,
63,
4494,
8,
5803,
63,
493,
435,
1987,
6418,
358,
489,
7712,
275,
5536,
63,
6418,
8,
5803,
63,
493,
12,
413,
9,
489,
511,
14,
1633,
63,
396,
8,
6418,
9,
489,
372,
272,
340,
12169,
63,
6418,
26,
489,
7712,
275,
5536,
63,
6418,
8,
5803,
63,
493,
12,
413,
9,
489,
511,
14,
1633,
63,
396,
8,
1397,
7712,
9,
272,
587,
26,
489,
511,
14,
7790,
63,
4494,
8,
5803,
63,
493,
435,
1987,
6418,
358,
489,
7712,
275,
511,
14,
739,
8,
5803,
63,
493,
435,
1987,
6418,
358,
489,
511,
14,
1633,
63,
396,
8,
1397,
7712,
9,
489,
511,
14,
1633,
63,
396,
8,
5005,
63,
6418,
8,
5803,
63,
493,
12,
413,
430,
272,
340,
3550,
63,
6418,
26,
489,
511,
14,
7790,
63,
7747,
63,
1629,
63,
604,
8,
6418,
12,
283,
11151,
11310,
4670,
358,
272,
340,
2402,
63,
6418,
26,
489,
511,
14,
7790,
63,
7747,
63,
1629,
63,
604,
8,
6418,
12,
639,
283,
1276,
8527,
66,
25,
65,
13,
21,
68,
2534,
13,
20,
17108,
13,
24,
69,
18,
68,
13,
65,
11603,
996,
821,
70,
3129,
65,
358,
489,
511,
14,
7790,
63,
7747,
63,
1629,
63,
604,
8,
6418,
12,
639,
283,
69,
1797,
1079,
1641,
13,
1046,
2466,
13,
2824,
67,
21,
13,
65,
21,
771,
13,
8662,
271,
1024,
19,
68,
19,
70,
16,
358,
819,
511,
63,
6418,
360,
396,
63,
4208,
63,
6418,
63,
2052,
14,
5803,
297,
355,
3550,
63,
6418,
29,
549,
12,
355,
12169,
63,
6418,
29,
797,
12,
355,
2402,
63,
6418,
29,
797,
9,
523,
511,
63,
6418,
360,
396,
63,
4208,
63,
6418,
63,
3910,
14,
5803,
297,
355,
3550,
63,
6418,
29,
797,
12,
355,
12169,
63,
6418,
29,
797,
12,
355,
2402,
63,
6418,
29,
797,
9,
523,
511,
63,
6418,
360,
396,
63,
4208,
63,
6418,
63,
885,
14,
5803,
297,
355,
3550,
63,
6418,
29,
549,
12,
355,
12169,
63,
6418,
29,
797,
12,
355,
2402,
63,
6418,
29,
797,
9,
523,
511,
63,
6418,
360,
396,
63,
4208,
63,
6418,
63,
2052,
63,
305,
63,
18757,
14,
5803,
297,
355,
3550,
63,
6418,
29,
549,
12,
355,
12169,
63,
6418,
29,
549,
12,
355,
2402,
63,
6418,
29,
797,
9,
523,
511,
63,
6418,
360,
396,
63,
4208,
63,
6418,
63,
3910,
63,
305,
63,
18757,
14,
5803,
297,
355,
3550,
63,
6418,
29,
797,
12,
355,
12169,
63,
6418,
29,
549,
12,
355,
2402,
63,
6418,
29,
797,
9,
523,
511,
63,
6418,
360,
396,
63,
4208,
63,
6418,
63,
885,
63,
305,
63,
18757,
14,
5803,
297,
355,
3550,
63,
6418,
29,
549,
12,
355,
12169,
63,
6418,
29,
549,
12,
355,
2402,
63,
6418,
29,
797,
9,
523,
511,
63,
6418,
360,
396,
63,
4208,
63,
6418,
63,
2052,
63,
1045,
63,
2911,
63,
6418,
14,
5803,
297,
355,
3550,
63,
6418,
29,
549,
12,
355,
12169,
63,
6418,
29,
797,
12,
355,
2402,
63,
6418,
29,
549,
9,
523,
511,
63,
6418,
360,
396,
63,
4208,
63,
6418,
63,
3910,
63,
1045,
63,
2911,
63,
6418,
14,
5803,
297,
355,
3550,
63,
6418,
29,
797,
12,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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http
from django.conf import settings
from utils import next_redirect, confirmation_view
from django.core.exceptions import ObjectDoesNotExist
from django.db import models
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.template.loader import render_to_string
from django.utils.html import escape
from django.views.decorators.http import require_POST
from django.contrib import comments
from django.contrib.comments import signals
class CommentPostBadRequest(http.HttpResponseBadRequest):
"""
Response returned when a comment post is invalid. If ``DEBUG`` is on a
nice-ish error message will be displayed (for debugging purposes), but in
production mode a simple opaque 400 page will be displayed.
"""
def __init__(self, why):
super(CommentPostBadRequest, self).__init__()
if settings.DEBUG:
self.content = render_to_string("comments/400-debug.html", {"why": why})
def post_comment(request, next=None):
"""
Post a comment.
HTTP POST is required. If ``POST['submit'] == "preview"`` or if there are
errors a preview template, ``comments/preview.html``, will be rendered.
"""
# Fill out some initial data fields from an authenticated user, if present
data = request.POST.copy()
if request.user.is_authenticated():
if not data.get('name', ''):
data["name"] = request.user.get_full_name() or request.user.username
if not data.get('email', ''):
data["email"] = request.user.email
# Look up the object we're trying to comment about
ctype = data.get("content_type")
object_pk = data.get("object_pk")
if ctype is None or object_pk is None:
return CommentPostBadRequest("Missing content_type or object_pk field.")
try:
model = models.get_model(*ctype.split(".", 1))
target = model._default_manager.get(pk=object_pk)
except TypeError:
return CommentPostBadRequest(
"Invalid content_type value: %r" % escape(ctype))
except AttributeError:
return CommentPostBadRequest(
"The given content-type %r does not resolve to a valid model." % \
escape(ctype))
except ObjectDoesNotExist:
return CommentPostBadRequest(
"No object matching content-type %r and object PK %r exists." % \
(escape(ctype), escape(object_pk)))
# Do we want to preview the comment?
preview = "preview" in data
# Construct the comment form
form = comments.get_form()(target, data=data)
# Check security information
if form.security_errors():
return CommentPostBadRequest(
"The comment form failed security verification: %s" % \
escape(str(form.security_errors())))
# If there are errors or if we requested a preview show the comment
if form.errors or preview:
template_list = [
"comments/%s_%s_preview.html" % tuple(str(model._meta).split(".")),
"comments/%s_preview.html" % model._meta.app_label,
"comments/preview.html",
]
return render_to_response(
template_list, {
"comment" : form.data.get("comment", ""),
"form" : form,
},
RequestContext(request, {})
)
# Otherwise create the comment
comment = form.get_comment_object()
comment.ip_address = request.META.get("REMOTE_ADDR", None)
if request.user.is_authenticated():
comment.user = request.user
# Signal that the comment is about to be saved
responses = signals.comment_will_be_posted.send(
sender = comment.__class__,
comment = comment,
request = request
)
for (receiver, response) in responses:
if response == False:
return CommentPostBadRequest(
"comment_will_be_posted receiver %r killed the comment" % receiver.__name__)
# Save the comment and signal that it was saved
comment.save()
signals.comment_was_posted.send(
sender = comment.__class__,
comment = comment,
request = request
)
return next_redirect(data, next, comment_done, c=comment._get_pk_val())
post_comment = require_POST(post_comment)
comment_done = confirmation_view(
template = "comments/posted.html",
doc = """Display a "comment was posted" success page."""
)
|
bsd-3-clause
|
[
504,
1639,
492,
1455,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
3778,
492,
2163,
63,
4876,
12,
18791,
63,
1345,
199,
504,
1639,
14,
1018,
14,
3924,
492,
24803,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
17469,
492,
3795,
63,
475,
63,
1310,
199,
504,
1639,
14,
1160,
492,
22538,
199,
504,
1639,
14,
1160,
14,
3422,
492,
3795,
63,
475,
63,
875,
199,
504,
1639,
14,
1208,
14,
1360,
492,
4772,
199,
504,
1639,
14,
4196,
14,
11582,
14,
1014,
492,
4409,
63,
4030,
199,
504,
1639,
14,
2828,
492,
6786,
199,
504,
1639,
14,
2828,
14,
6223,
492,
10166,
199,
199,
533,
6819,
6564,
12380,
8,
1014,
14,
16287,
12380,
304,
272,
408,
272,
7232,
2138,
1380,
282,
3721,
2963,
365,
3866,
14,
982,
1124,
5287,
1040,
365,
641,
282,
272,
14213,
13,
2453,
1125,
1245,
911,
506,
9080,
334,
509,
10201,
12901,
395,
1325,
315,
272,
9920,
818,
282,
3486,
15058,
8290,
2034,
911,
506,
9080,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
10842,
304,
267,
1613,
8,
7488,
6564,
12380,
12,
291,
2843,
826,
4533,
267,
340,
2202,
14,
5287,
26,
288,
291,
14,
1317,
275,
3795,
63,
475,
63,
875,
480,
6223,
15,
5303,
13,
1757,
14,
1360,
401,
2420,
26460,
582,
10842,
1552,
199,
199,
318,
2963,
63,
3349,
8,
1069,
12,
2163,
29,
403,
304,
272,
408,
272,
7711,
282,
3721,
14,
339,
3101,
8761,
365,
1415,
14,
982,
1124,
4030,
459,
7275,
418,
508,
298,
7780,
31002,
503,
340,
2337,
787,
272,
2552,
282,
19653,
1978,
12,
1124,
6223,
15,
7780,
14,
1360,
4542,
911,
506,
8018,
14,
272,
408,
272,
327,
24797,
734,
2005,
2536,
666,
1504,
687,
376,
15082,
922,
12,
340,
3451,
272,
666,
275,
1056,
14,
4030,
14,
1574,
342,
272,
340,
1056,
14,
751,
14,
374,
63,
12177,
837,
267,
340,
440,
666,
14,
362,
360,
354,
297,
21019,
288,
666,
905,
354,
937,
275,
1056,
14,
751,
14,
362,
63,
2861,
63,
354,
342,
503,
1056,
14,
751,
14,
2473,
267,
340,
440,
666,
14,
362,
360,
2123,
297,
21019,
288,
666,
905,
2123,
937,
275,
1056,
14,
751,
14,
2123,
339,
327,
12077,
1536,
314,
909,
781,
3984,
9936,
370,
3721,
3595,
272,
16360,
275,
666,
14,
362,
480,
1317,
63,
466,
531,
272,
909,
63,
2051,
275,
666,
14,
362,
480,
785,
63,
2051,
531,
272,
340,
16360,
365,
488,
503,
909,
63,
2051,
365,
488,
26,
267,
372,
6819,
6564,
12380,
480,
7718,
1564,
63,
466,
503,
909,
63,
2051,
901,
2685,
272,
862,
26,
267,
1402,
275,
1709,
14,
362,
63,
1238,
2031,
3667,
14,
1294,
30381,
413,
430,
267,
1347,
275,
1402,
423,
885,
63,
2609,
14,
362,
8,
2051,
29,
785,
63,
2051,
9,
272,
871,
3146,
26,
267,
372,
6819,
6564,
12380,
8,
288,
298,
3364,
1564,
63,
466,
574,
26,
450,
82,
2,
450,
4772,
8,
3667,
430,
272,
871,
4281,
26,
267,
372,
6819,
6564,
12380,
8,
288,
298,
1918,
1627,
1564,
13,
466,
450,
82,
1630,
440,
7512,
370,
282,
1686,
1402,
2122,
450,
971,
355,
4772,
8,
3667,
430,
272,
871,
24803,
26,
267,
372,
6819,
6564,
12380,
8,
288,
298,
1944,
909,
4877,
1564,
13,
466,
450,
82,
436,
909,
18368,
450,
82,
3495,
2122,
450,
971,
355,
334,
3765,
8,
3667,
395,
4772,
8,
785,
63,
2051,
1724,
339,
327,
4226,
781,
2934,
370,
19653,
314,
3721,
31,
272,
19653,
275,
298,
7780,
2,
315,
666,
339,
327,
9215,
314,
3721,
1824,
272,
1824,
275,
6786,
14,
362,
63,
964,
24851,
1375,
12,
666,
29,
576,
9,
339,
327,
2670,
6391,
2556,
272,
340,
1824,
14,
4416,
63,
2550,
837,
267,
372,
6819,
6564,
12380,
8,
288,
298,
1918,
3721,
1824,
3405,
6391,
14786,
26,
450,
83,
2,
450,
971,
355,
4772,
8,
495,
8,
964,
14,
4416,
63,
2550,
16890,
339,
327,
982,
2337,
787,
2552,
503,
340,
781,
5839,
282,
19653,
2498,
314,
3721,
272,
340,
1824,
14,
2550,
503,
19653,
26,
267,
1978,
63,
513,
275,
359,
288,
298,
6223,
3149,
83,
4970,
83,
63,
7780,
14,
1360,
2,
450,
2008,
8,
495,
8,
1238,
423,
2024,
680,
1294,
15857,
395,
288,
298,
6223,
3149,
83,
63,
7780,
14,
1360,
2,
450,
1402,
423,
2024,
14,
571,
63,
1302,
12,
288,
298,
6223,
15,
7780,
14,
1360,
401,
267,
1622,
267,
372,
3795,
63,
475,
63,
1310,
8,
288,
1978,
63,
513,
12,
469,
355,
298,
3349,
2,
520,
1824,
14,
576,
14,
362,
480,
3349,
401,
16241,
355,
298,
964,
2,
520,
1824,
12,
288,
1660,
288,
22538,
8,
1069,
12,
5009,
267,
776,
339,
327,
6630,
1218,
314,
3721,
272,
3721,
275,
1824,
14,
362,
63,
3349,
63,
785,
342,
272,
3721,
14,
711,
63,
1562,
275,
1056,
14,
10614,
14,
362,
480,
16058,
63,
7803,
401,
488,
9,
272,
340,
1056,
14,
751,
14,
374,
63,
12177,
837,
267,
3721,
14,
751,
275,
1056,
14,
751,
339,
327,
18288,
626,
314,
3721,
365,
3595,
370,
506,
6290,
272,
9320,
275,
10166,
14,
3349,
63,
14117,
63,
1235,
63,
21760,
14,
2254,
8,
267,
8904,
221,
275,
3721,
855,
533,
3108,
267,
3721,
275,
3721,
12,
267,
1056,
275,
1056,
272,
776,
339,
367,
334,
10244,
12,
1177,
9,
315,
9320,
26,
267,
340,
1177,
508,
756,
26,
288,
372,
6819,
6564,
12380,
8,
355,
298,
3349,
63,
14117,
63,
1235,
63,
21760,
13035,
450,
82,
26659,
314,
3721,
2,
450,
13035,
855,
354,
3368,
339,
327,
11063,
314,
3721,
436,
4673,
626,
652,
1990,
6290,
272,
3721,
14,
2117,
342,
272,
10166,
14,
3349,
63,
10274,
63,
21760,
14,
2254,
8,
267,
8904,
221,
275,
3721,
855,
533,
3108,
267,
3721,
275,
3721,
12,
267,
1056,
275,
1056,
272,
776,
339,
372,
2163,
63,
4876,
8,
576,
12,
2163,
12,
3721,
63,
4456,
12,
286,
29,
3349,
423,
362,
63,
2051,
63,
637,
1012,
199,
199,
1932,
63,
3349,
275,
4409,
63,
4030,
8,
1932,
63,
3349,
9,
199,
199,
3349,
63,
4456,
275,
18791,
63,
1345,
8,
272,
1978,
275,
298,
6223,
15,
21760,
14,
1360,
401,
272,
1382,
275,
408
] |
[
1639,
492,
1455,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
3778,
492,
2163,
63,
4876,
12,
18791,
63,
1345,
199,
504,
1639,
14,
1018,
14,
3924,
492,
24803,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
17469,
492,
3795,
63,
475,
63,
1310,
199,
504,
1639,
14,
1160,
492,
22538,
199,
504,
1639,
14,
1160,
14,
3422,
492,
3795,
63,
475,
63,
875,
199,
504,
1639,
14,
1208,
14,
1360,
492,
4772,
199,
504,
1639,
14,
4196,
14,
11582,
14,
1014,
492,
4409,
63,
4030,
199,
504,
1639,
14,
2828,
492,
6786,
199,
504,
1639,
14,
2828,
14,
6223,
492,
10166,
199,
199,
533,
6819,
6564,
12380,
8,
1014,
14,
16287,
12380,
304,
272,
408,
272,
7232,
2138,
1380,
282,
3721,
2963,
365,
3866,
14,
982,
1124,
5287,
1040,
365,
641,
282,
272,
14213,
13,
2453,
1125,
1245,
911,
506,
9080,
334,
509,
10201,
12901,
395,
1325,
315,
272,
9920,
818,
282,
3486,
15058,
8290,
2034,
911,
506,
9080,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
10842,
304,
267,
1613,
8,
7488,
6564,
12380,
12,
291,
2843,
826,
4533,
267,
340,
2202,
14,
5287,
26,
288,
291,
14,
1317,
275,
3795,
63,
475,
63,
875,
480,
6223,
15,
5303,
13,
1757,
14,
1360,
401,
2420,
26460,
582,
10842,
1552,
199,
199,
318,
2963,
63,
3349,
8,
1069,
12,
2163,
29,
403,
304,
272,
408,
272,
7711,
282,
3721,
14,
339,
3101,
8761,
365,
1415,
14,
982,
1124,
4030,
459,
7275,
418,
508,
298,
7780,
31002,
503,
340,
2337,
787,
272,
2552,
282,
19653,
1978,
12,
1124,
6223,
15,
7780,
14,
1360,
4542,
911,
506,
8018,
14,
272,
408,
272,
327,
24797,
734,
2005,
2536,
666,
1504,
687,
376,
15082,
922,
12,
340,
3451,
272,
666,
275,
1056,
14,
4030,
14,
1574,
342,
272,
340,
1056,
14,
751,
14,
374,
63,
12177,
837,
267,
340,
440,
666,
14,
362,
360,
354,
297,
21019,
288,
666,
905,
354,
937,
275,
1056,
14,
751,
14,
362,
63,
2861,
63,
354,
342,
503,
1056,
14,
751,
14,
2473,
267,
340,
440,
666,
14,
362,
360,
2123,
297,
21019,
288,
666,
905,
2123,
937,
275,
1056,
14,
751,
14,
2123,
339,
327,
12077,
1536,
314,
909,
781,
3984,
9936,
370,
3721,
3595,
272,
16360,
275,
666,
14,
362,
480,
1317,
63,
466,
531,
272,
909,
63,
2051,
275,
666,
14,
362,
480,
785,
63,
2051,
531,
272,
340,
16360,
365,
488,
503,
909,
63,
2051,
365,
488,
26,
267,
372,
6819,
6564,
12380,
480,
7718,
1564,
63,
466,
503,
909,
63,
2051,
901,
2685,
272,
862,
26,
267,
1402,
275,
1709,
14,
362,
63,
1238,
2031,
3667,
14,
1294,
30381,
413,
430,
267,
1347,
275,
1402,
423,
885,
63,
2609,
14,
362,
8,
2051,
29,
785,
63,
2051,
9,
272,
871,
3146,
26,
267,
372,
6819,
6564,
12380,
8,
288,
298,
3364,
1564,
63,
466,
574,
26,
450,
82,
2,
450,
4772,
8,
3667,
430,
272,
871,
4281,
26,
267,
372,
6819,
6564,
12380,
8,
288,
298,
1918,
1627,
1564,
13,
466,
450,
82,
1630,
440,
7512,
370,
282,
1686,
1402,
2122,
450,
971,
355,
4772,
8,
3667,
430,
272,
871,
24803,
26,
267,
372,
6819,
6564,
12380,
8,
288,
298,
1944,
909,
4877,
1564,
13,
466,
450,
82,
436,
909,
18368,
450,
82,
3495,
2122,
450,
971,
355,
334,
3765,
8,
3667,
395,
4772,
8,
785,
63,
2051,
1724,
339,
327,
4226,
781,
2934,
370,
19653,
314,
3721,
31,
272,
19653,
275,
298,
7780,
2,
315,
666,
339,
327,
9215,
314,
3721,
1824,
272,
1824,
275,
6786,
14,
362,
63,
964,
24851,
1375,
12,
666,
29,
576,
9,
339,
327,
2670,
6391,
2556,
272,
340,
1824,
14,
4416,
63,
2550,
837,
267,
372,
6819,
6564,
12380,
8,
288,
298,
1918,
3721,
1824,
3405,
6391,
14786,
26,
450,
83,
2,
450,
971,
355,
4772,
8,
495,
8,
964,
14,
4416,
63,
2550,
16890,
339,
327,
982,
2337,
787,
2552,
503,
340,
781,
5839,
282,
19653,
2498,
314,
3721,
272,
340,
1824,
14,
2550,
503,
19653,
26,
267,
1978,
63,
513,
275,
359,
288,
298,
6223,
3149,
83,
4970,
83,
63,
7780,
14,
1360,
2,
450,
2008,
8,
495,
8,
1238,
423,
2024,
680,
1294,
15857,
395,
288,
298,
6223,
3149,
83,
63,
7780,
14,
1360,
2,
450,
1402,
423,
2024,
14,
571,
63,
1302,
12,
288,
298,
6223,
15,
7780,
14,
1360,
401,
267,
1622,
267,
372,
3795,
63,
475,
63,
1310,
8,
288,
1978,
63,
513,
12,
469,
355,
298,
3349,
2,
520,
1824,
14,
576,
14,
362,
480,
3349,
401,
16241,
355,
298,
964,
2,
520,
1824,
12,
288,
1660,
288,
22538,
8,
1069,
12,
5009,
267,
776,
339,
327,
6630,
1218,
314,
3721,
272,
3721,
275,
1824,
14,
362,
63,
3349,
63,
785,
342,
272,
3721,
14,
711,
63,
1562,
275,
1056,
14,
10614,
14,
362,
480,
16058,
63,
7803,
401,
488,
9,
272,
340,
1056,
14,
751,
14,
374,
63,
12177,
837,
267,
3721,
14,
751,
275,
1056,
14,
751,
339,
327,
18288,
626,
314,
3721,
365,
3595,
370,
506,
6290,
272,
9320,
275,
10166,
14,
3349,
63,
14117,
63,
1235,
63,
21760,
14,
2254,
8,
267,
8904,
221,
275,
3721,
855,
533,
3108,
267,
3721,
275,
3721,
12,
267,
1056,
275,
1056,
272,
776,
339,
367,
334,
10244,
12,
1177,
9,
315,
9320,
26,
267,
340,
1177,
508,
756,
26,
288,
372,
6819,
6564,
12380,
8,
355,
298,
3349,
63,
14117,
63,
1235,
63,
21760,
13035,
450,
82,
26659,
314,
3721,
2,
450,
13035,
855,
354,
3368,
339,
327,
11063,
314,
3721,
436,
4673,
626,
652,
1990,
6290,
272,
3721,
14,
2117,
342,
272,
10166,
14,
3349,
63,
10274,
63,
21760,
14,
2254,
8,
267,
8904,
221,
275,
3721,
855,
533,
3108,
267,
3721,
275,
3721,
12,
267,
1056,
275,
1056,
272,
776,
339,
372,
2163,
63,
4876,
8,
576,
12,
2163,
12,
3721,
63,
4456,
12,
286,
29,
3349,
423,
362,
63,
2051,
63,
637,
1012,
199,
199,
1932,
63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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
SDSG-Invenio/invenio
|
invenio/modules/records/upgrades/records_2014_08_22_create_record_json.py
|
15
|
2007
|
# -*- coding: utf-8 -*-
#
# This file is part of Invenio.
# Copyright (C) 2014 CERN.
#
# Invenio is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# Invenio is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Invenio; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
import warnings
import sqlalchemy as sa
from invenio.ext.sqlalchemy import db
from invenio.modules.upgrader.api import op
depends_on = ['records_2014_04_14_json_type_fix']
def info():
return "Create table record_json."
def do_upgrade():
"""Implement your upgrades here."""
if not op.has_table("record_json"):
op.create_table(
'record_json',
sa.Column('id', db.MediumInteger(8, unsigned=True), nullable=False),
sa.Column('json', db.JSON, nullable=False),
sa.ForeignKeyConstraint(['id'], ['bibrec.id'], ),
sa.PrimaryKeyConstraint('id'),
mysql_charset='utf8',
mysql_engine='MyISAM'
)
else:
warnings.warn("*** Creation of 'record_json' table skipped! ***")
def estimate():
"""Estimate running time of upgrade in seconds (optional)."""
return 1
def pre_upgrade():
"""Run pre-upgrade checks (optional)."""
table = "record_json"
if op.has_table(table):
warnings.warn(
"*** Table {0} already exists! *** "
"This upgrade will *NOT* create the new table.".format(table)
)
def post_upgrade():
"""Run post-upgrade checks (optional)."""
pass
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
12235,
14,
199,
3,
1898,
334,
35,
9,
6927,
24354,
14,
199,
3,
199,
3,
12235,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
199,
3,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
12235,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
199,
3,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
12235,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
199,
3,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
15673,
13,
13421,
12,
8217,
14,
421,
199,
646,
3598,
199,
646,
8335,
465,
2937,
199,
504,
13640,
14,
832,
14,
14536,
492,
1592,
199,
504,
13640,
14,
3112,
14,
384,
17556,
14,
1246,
492,
1687,
421,
199,
8912,
63,
265,
275,
788,
6502,
63,
7280,
63,
966,
63,
1079,
63,
1001,
63,
466,
63,
970,
418,
421,
199,
318,
2256,
837,
272,
372,
298,
2499,
1817,
2777,
63,
1001,
2122,
421,
199,
318,
886,
63,
9375,
837,
272,
408,
26924,
2195,
1536,
18050,
2348,
1041,
272,
340,
440,
1687,
14,
1989,
63,
1224,
480,
3059,
63,
1001,
2349,
267,
1687,
14,
981,
63,
1224,
8,
288,
283,
3059,
63,
1001,
297,
288,
2937,
14,
4547,
360,
344,
297,
1592,
14,
26139,
2674,
8,
24,
12,
7381,
29,
549,
395,
7854,
29,
797,
395,
288,
2937,
14,
4547,
360,
1001,
297,
1592,
14,
6243,
12,
7854,
29,
797,
395,
288,
2937,
14,
3190,
8463,
2941,
344,
995,
788,
31547,
14,
344,
995,
2318,
288,
2937,
14,
29457,
8463,
360,
344,
659,
288,
12896,
63,
6043,
534,
1624,
24,
297,
288,
12896,
63,
3908,
534,
5713,
1311,
1156,
7,
267,
776,
272,
587,
26,
267,
3598,
14,
4050,
480,
9153,
9750,
425,
402,
283,
3059,
63,
1001,
7,
1817,
9645,
1,
19688,
531,
421,
199,
318,
14497,
837,
272,
408,
31020,
3879,
900,
402,
10754,
315,
4696,
334,
4144,
10477,
272,
372,
413,
421,
199,
318,
876,
63,
9375,
837,
272,
408,
2540,
876,
13,
9375,
5920,
334,
4144,
10477,
272,
1817,
275,
298,
3059,
63,
1001,
2,
272,
340,
1687,
14,
1989,
63,
1224,
8,
1224,
304,
267,
3598,
14,
4050,
8,
288,
298,
9153,
6957,
469,
16,
93,
2575,
3495,
1,
19688,
298,
288,
298,
2765,
10754,
911,
627,
4609,
10,
1218,
314,
892,
1817,
15848,
908,
8,
1224,
9,
267,
776,
421,
199,
318,
2963,
63,
9375,
837,
272,
408,
2540,
2963,
13,
9375,
5920,
334,
4144,
10477,
272,
986,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
12235,
14,
199,
3,
1898,
334,
35,
9,
6927,
24354,
14,
199,
3,
199,
3,
12235,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
199,
3,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
12235,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
199,
3,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
12235,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
199,
3,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
15673,
13,
13421,
12,
8217,
14,
421,
199,
646,
3598,
199,
646,
8335,
465,
2937,
199,
504,
13640,
14,
832,
14,
14536,
492,
1592,
199,
504,
13640,
14,
3112,
14,
384,
17556,
14,
1246,
492,
1687,
421,
199,
8912,
63,
265,
275,
788,
6502,
63,
7280,
63,
966,
63,
1079,
63,
1001,
63,
466,
63,
970,
418,
421,
199,
318,
2256,
837,
272,
372,
298,
2499,
1817,
2777,
63,
1001,
2122,
421,
199,
318,
886,
63,
9375,
837,
272,
408,
26924,
2195,
1536,
18050,
2348,
1041,
272,
340,
440,
1687,
14,
1989,
63,
1224,
480,
3059,
63,
1001,
2349,
267,
1687,
14,
981,
63,
1224,
8,
288,
283,
3059,
63,
1001,
297,
288,
2937,
14,
4547,
360,
344,
297,
1592,
14,
26139,
2674,
8,
24,
12,
7381,
29,
549,
395,
7854,
29,
797,
395,
288,
2937,
14,
4547,
360,
1001,
297,
1592,
14,
6243,
12,
7854,
29,
797,
395,
288,
2937,
14,
3190,
8463,
2941,
344,
995,
788,
31547,
14,
344,
995,
2318,
288,
2937,
14,
29457,
8463,
360,
344,
659,
288,
12896,
63,
6043,
534,
1624,
24,
297,
288,
12896,
63,
3908,
534,
5713,
1311,
1156,
7,
267,
776,
272,
587,
26,
267,
3598,
14,
4050,
480,
9153,
9750,
425,
402,
283,
3059,
63,
1001,
7,
1817,
9645,
1,
19688,
531,
421,
199,
318,
14497,
837,
272,
408,
31020,
3879,
900,
402,
10754,
315,
4696,
334,
4144,
10477,
272,
372,
413,
421,
199,
318,
876,
63,
9375,
837,
272,
408,
2540,
876,
13,
9375,
5920,
334,
4144,
10477,
272,
1817,
275,
298,
3059,
63,
1001,
2,
272,
340,
1687,
14,
1989,
63,
1224,
8,
1224,
304,
267,
3598,
14,
4050,
8,
288,
298,
9153,
6957,
469,
16,
93,
2575,
3495,
1,
19688,
298,
288,
298,
2765,
10754,
911,
627,
4609,
10,
1218,
314,
892,
1817,
15848,
908,
8,
1224,
9,
267,
776,
421,
199,
318,
2963,
63,
9375,
837,
272,
408,
2540,
2963,
13,
9375,
5920,
334,
4144,
10477,
272,
986,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
denisenkom/django
|
django/db/models/sql/aggregates.py
|
4
|
4124
|
"""
Classes to represent the default SQL aggregate functions
"""
import copy
from django.db.models.fields import IntegerField, FloatField
# Fake fields used to identify aggregate types in data-conversion operations.
ordinal_aggregate_field = IntegerField()
computed_aggregate_field = FloatField()
class Aggregate(object):
"""
Default SQL Aggregate.
"""
is_ordinal = False
is_computed = False
sql_template = '%(function)s(%(field)s)'
def __init__(self, col, source=None, is_summary=False, **extra):
"""Instantiate an SQL aggregate
* col is a column reference describing the subject field
of the aggregate. It can be an alias, or a tuple describing
a table and column name.
* source is the underlying field or aggregate definition for
the column reference. If the aggregate is not an ordinal or
computed type, this reference is used to determine the coerced
output type of the aggregate.
* extra is a dictionary of additional data to provide for the
aggregate definition
Also utilizes the class variables:
* sql_function, the name of the SQL function that implements the
aggregate.
* sql_template, a template string that is used to render the
aggregate into SQL.
* is_ordinal, a boolean indicating if the output of this aggregate
is an integer (e.g., a count)
* is_computed, a boolean indicating if this output of this aggregate
is a computed float (e.g., an average), regardless of the input
type.
"""
self.col = col
self.source = source
self.is_summary = is_summary
self.extra = extra
# Follow the chain of aggregate sources back until you find an
# actual field, or an aggregate that forces a particular output
# type. This type of this field will be used to coerce values
# retrieved from the database.
tmp = self
while tmp and isinstance(tmp, Aggregate):
if getattr(tmp, 'is_ordinal', False):
tmp = ordinal_aggregate_field
elif getattr(tmp, 'is_computed', False):
tmp = computed_aggregate_field
else:
tmp = tmp.source
self.field = tmp
def relabeled_clone(self, change_map):
clone = copy.copy(self)
if isinstance(self.col, (list, tuple)):
clone.col = (change_map.get(self.col[0], self.col[0]), self.col[1])
return clone
def as_sql(self, qn, connection):
"Return the aggregate, rendered as SQL with parameters."
params = []
if hasattr(self.col, 'as_sql'):
field_name, params = self.col.as_sql(qn, connection)
elif isinstance(self.col, (list, tuple)):
field_name = '.'.join(qn(c) for c in self.col)
else:
field_name = self.col
substitutions = {
'function': self.sql_function,
'field': field_name
}
substitutions.update(self.extra)
return self.sql_template % substitutions, params
class Avg(Aggregate):
is_computed = True
sql_function = 'AVG'
class Count(Aggregate):
is_ordinal = True
sql_function = 'COUNT'
sql_template = '%(function)s(%(distinct)s%(field)s)'
def __init__(self, col, distinct=False, **extra):
super(Count, self).__init__(col, distinct='DISTINCT ' if distinct else '', **extra)
class Max(Aggregate):
sql_function = 'MAX'
class Min(Aggregate):
sql_function = 'MIN'
class StdDev(Aggregate):
is_computed = True
def __init__(self, col, sample=False, **extra):
super(StdDev, self).__init__(col, **extra)
self.sql_function = 'STDDEV_SAMP' if sample else 'STDDEV_POP'
class Sum(Aggregate):
sql_function = 'SUM'
class Variance(Aggregate):
is_computed = True
def __init__(self, col, sample=False, **extra):
super(Variance, self).__init__(col, **extra)
self.sql_function = 'VAR_SAMP' if sample else 'VAR_POP'
|
bsd-3-clause
|
[
624,
199,
15711,
370,
2954,
314,
849,
5385,
9531,
3423,
199,
624,
199,
646,
1331,
199,
199,
504,
1639,
14,
697,
14,
992,
14,
955,
492,
26141,
12,
11140,
792,
199,
199,
3,
7777,
1504,
1202,
370,
10405,
9531,
2943,
315,
666,
13,
15083,
5331,
14,
199,
17460,
63,
7516,
63,
698,
275,
26141,
342,
199,
14378,
63,
7516,
63,
698,
275,
11140,
792,
342,
421,
199,
533,
29397,
8,
785,
304,
272,
408,
272,
3758,
5385,
29397,
14,
272,
408,
272,
365,
63,
17460,
275,
756,
272,
365,
63,
14378,
275,
756,
272,
3875,
63,
1160,
275,
9487,
1593,
9,
83,
12473,
698,
9,
83,
3171,
339,
347,
636,
826,
721,
277,
12,
1048,
12,
1350,
29,
403,
12,
365,
63,
4705,
29,
797,
12,
1011,
2911,
304,
267,
408,
10083,
18973,
376,
5385,
9531,
13359,
627,
1048,
365,
282,
2763,
3659,
13660,
314,
5420,
901,
1779,
402,
314,
9531,
14,
2779,
883,
506,
376,
5162,
12,
503,
282,
2008,
13660,
1779,
282,
1817,
436,
2763,
536,
14,
268,
627,
1350,
365,
314,
8793,
901,
503,
9531,
5492,
367,
1779,
314,
2763,
3659,
14,
982,
314,
9531,
365,
440,
376,
24943,
503,
1779,
9235,
730,
12,
642,
3659,
365,
1202,
370,
6705,
314,
20650,
6867,
1779,
1072,
730,
402,
314,
9531,
14,
268,
627,
2402,
365,
282,
2600,
402,
4722,
666,
370,
5647,
367,
314,
1779,
9531,
5492,
398,
6121,
7678,
19030,
397,
314,
1021,
2860,
26,
268,
627,
3875,
63,
1593,
12,
314,
536,
402,
314,
5385,
805,
626,
9031,
314,
1779,
9531,
14,
268,
627,
3875,
63,
1160,
12,
282,
1978,
1059,
626,
365,
1202,
370,
3795,
314,
1779,
9531,
1901,
5385,
14,
268,
627,
365,
63,
17460,
12,
282,
5046,
9297,
340,
314,
1072,
402,
642,
9531,
1779,
365,
376,
3000,
334,
69,
14,
71,
2020,
282,
2338,
9,
268,
627,
365,
63,
14378,
12,
282,
5046,
9297,
340,
642,
1072,
402,
642,
9531,
1779,
365,
282,
9235,
2069,
334,
69,
14,
71,
2020,
376,
8095,
395,
15270,
402,
314,
1324,
1779,
730,
14,
398,
408,
267,
291,
14,
761,
275,
1048,
267,
291,
14,
1365,
275,
1350,
267,
291,
14,
374,
63,
4705,
275,
365,
63,
4705,
267,
291,
14,
2911,
275,
2402,
398,
327,
21876,
314,
6036,
402,
9531,
5274,
1771,
5133,
1265,
2342,
376,
267,
327,
3503,
901,
12,
503,
376,
9531,
626,
25983,
282,
6770,
1072,
267,
327,
730,
14,
961,
730,
402,
642,
901,
911,
506,
1202,
370,
19874,
1338,
267,
327,
12396,
687,
314,
3050,
14,
267,
3529,
275,
291,
398,
1830,
3529,
436,
1228,
8,
2791,
12,
29397,
304,
288,
340,
2519,
8,
2791,
12,
283,
374,
63,
17460,
297,
756,
304,
355,
3529,
275,
24943,
63,
7516,
63,
698,
288,
916,
2519,
8,
2791,
12,
283,
374,
63,
14378,
297,
756,
304,
355,
3529,
275,
9235,
63,
7516,
63,
698,
288,
587,
26,
355,
3529,
275,
3529,
14,
1365,
398,
291,
14,
698,
275,
3529,
339,
347,
4668,
14502,
63,
6311,
8,
277,
12,
1570,
63,
1130,
304,
267,
7289,
275,
1331,
14,
1574,
8,
277,
9,
267,
340,
1228,
8,
277,
14,
761,
12,
334,
513,
12,
2008,
2298,
288,
7289,
14,
761,
275,
334,
1461,
63,
1130,
14,
362,
8,
277,
14,
761,
59,
16,
467,
291,
14,
761,
59,
16,
2522,
291,
14,
761,
59,
17,
566,
267,
372,
7289,
339,
347,
465,
63,
3009,
8,
277,
12,
18293,
12,
1950,
304,
267,
298,
1767,
314,
9531,
12,
8018,
465,
5385,
543,
2633,
2122,
267,
1862,
275,
942,
398,
340,
2688,
8,
277,
14,
761,
12,
283,
305,
63,
3009,
735,
288,
901,
63,
354,
12,
1862,
275,
291,
14,
761,
14,
305,
63,
3009,
8,
15156,
12,
1950,
9,
267,
916,
1228,
8,
277,
14,
761,
12,
334,
513,
12,
2008,
2298,
288,
901,
63,
354,
275,
15671,
904,
8,
15156,
8,
67,
9,
367,
286,
315,
291,
14,
761,
9,
267,
587,
26,
288,
901,
63,
354,
275,
291,
14,
761,
398,
20873,
275,
469,
288,
283,
1593,
356,
291,
14,
3009,
63,
1593,
12,
288,
283,
698,
356,
901,
63,
354,
267,
789,
267,
20873,
14,
873,
8,
277,
14,
2911,
9,
398,
372,
291,
14,
3009,
63,
1160,
450,
20873,
12,
1862,
421,
199,
533,
437,
10929,
8,
10170,
304,
272,
365,
63,
14378,
275,
715,
272,
3875,
63,
1593,
275,
283,
6087,
39,
7,
421,
199,
533,
14826,
8,
10170,
304,
272,
365,
63,
17460,
275,
715,
272,
3875,
63,
1593,
275,
283,
8760,
7,
272,
3875,
63,
1160,
275,
9487,
1593,
9,
83,
12473,
12926,
9,
83,
2840,
698,
9,
83,
3171,
339,
347,
636,
826,
721,
277,
12,
1048,
12,
15392,
29,
797,
12,
1011,
2911,
304,
267,
1613,
8,
2353,
12,
291,
2843,
826,
721,
761,
12,
15392,
534,
13783,
28437,
283,
340,
15392,
587,
3260,
1011,
2911,
9,
421,
199,
533,
8228,
8,
10170,
304,
272,
3875,
63,
1593,
275,
283,
4283,
7,
421,
199,
533,
10195,
8,
10170,
304,
272,
3875,
63,
1593,
275,
283,
4896,
7,
421,
199,
533,
20992,
12680,
8,
10170,
304,
272,
365,
63,
14378,
275,
715,
339,
347,
636,
826,
721,
277,
12,
1048,
12,
2690,
29,
797,
12,
1011,
2911,
304,
267,
1613,
8,
11976,
12680,
12,
291,
2843,
826,
721,
761,
12,
1011,
2911,
9,
267,
291,
14,
3009,
63,
1593,
275,
283,
18472,
13260,
63,
51,
7089,
7,
340,
2690,
587,
283,
18472,
13260,
63,
13531,
7,
421,
199,
533,
12094,
8,
10170,
304,
272,
3875,
63,
1593,
275,
283,
13285,
7,
421,
199,
533,
21107,
554,
8,
10170,
304,
272,
365,
63,
14378,
275,
715,
339,
347,
636,
826,
721,
277,
12,
1048,
12,
2690,
29,
797,
12,
1011,
2911,
304,
267,
1613,
8,
31805,
12,
291,
2843,
826,
721,
761,
12,
1011,
2911,
9,
267,
291,
14,
3009,
63,
1593,
275,
283,
5568,
63,
51,
7089,
7,
340,
2690,
587,
283,
5568,
63,
13531,
7,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
15711,
370,
2954,
314,
849,
5385,
9531,
3423,
199,
624,
199,
646,
1331,
199,
199,
504,
1639,
14,
697,
14,
992,
14,
955,
492,
26141,
12,
11140,
792,
199,
199,
3,
7777,
1504,
1202,
370,
10405,
9531,
2943,
315,
666,
13,
15083,
5331,
14,
199,
17460,
63,
7516,
63,
698,
275,
26141,
342,
199,
14378,
63,
7516,
63,
698,
275,
11140,
792,
342,
421,
199,
533,
29397,
8,
785,
304,
272,
408,
272,
3758,
5385,
29397,
14,
272,
408,
272,
365,
63,
17460,
275,
756,
272,
365,
63,
14378,
275,
756,
272,
3875,
63,
1160,
275,
9487,
1593,
9,
83,
12473,
698,
9,
83,
3171,
339,
347,
636,
826,
721,
277,
12,
1048,
12,
1350,
29,
403,
12,
365,
63,
4705,
29,
797,
12,
1011,
2911,
304,
267,
408,
10083,
18973,
376,
5385,
9531,
13359,
627,
1048,
365,
282,
2763,
3659,
13660,
314,
5420,
901,
1779,
402,
314,
9531,
14,
2779,
883,
506,
376,
5162,
12,
503,
282,
2008,
13660,
1779,
282,
1817,
436,
2763,
536,
14,
268,
627,
1350,
365,
314,
8793,
901,
503,
9531,
5492,
367,
1779,
314,
2763,
3659,
14,
982,
314,
9531,
365,
440,
376,
24943,
503,
1779,
9235,
730,
12,
642,
3659,
365,
1202,
370,
6705,
314,
20650,
6867,
1779,
1072,
730,
402,
314,
9531,
14,
268,
627,
2402,
365,
282,
2600,
402,
4722,
666,
370,
5647,
367,
314,
1779,
9531,
5492,
398,
6121,
7678,
19030,
397,
314,
1021,
2860,
26,
268,
627,
3875,
63,
1593,
12,
314,
536,
402,
314,
5385,
805,
626,
9031,
314,
1779,
9531,
14,
268,
627,
3875,
63,
1160,
12,
282,
1978,
1059,
626,
365,
1202,
370,
3795,
314,
1779,
9531,
1901,
5385,
14,
268,
627,
365,
63,
17460,
12,
282,
5046,
9297,
340,
314,
1072,
402,
642,
9531,
1779,
365,
376,
3000,
334,
69,
14,
71,
2020,
282,
2338,
9,
268,
627,
365,
63,
14378,
12,
282,
5046,
9297,
340,
642,
1072,
402,
642,
9531,
1779,
365,
282,
9235,
2069,
334,
69,
14,
71,
2020,
376,
8095,
395,
15270,
402,
314,
1324,
1779,
730,
14,
398,
408,
267,
291,
14,
761,
275,
1048,
267,
291,
14,
1365,
275,
1350,
267,
291,
14,
374,
63,
4705,
275,
365,
63,
4705,
267,
291,
14,
2911,
275,
2402,
398,
327,
21876,
314,
6036,
402,
9531,
5274,
1771,
5133,
1265,
2342,
376,
267,
327,
3503,
901,
12,
503,
376,
9531,
626,
25983,
282,
6770,
1072,
267,
327,
730,
14,
961,
730,
402,
642,
901,
911,
506,
1202,
370,
19874,
1338,
267,
327,
12396,
687,
314,
3050,
14,
267,
3529,
275,
291,
398,
1830,
3529,
436,
1228,
8,
2791,
12,
29397,
304,
288,
340,
2519,
8,
2791,
12,
283,
374,
63,
17460,
297,
756,
304,
355,
3529,
275,
24943,
63,
7516,
63,
698,
288,
916,
2519,
8,
2791,
12,
283,
374,
63,
14378,
297,
756,
304,
355,
3529,
275,
9235,
63,
7516,
63,
698,
288,
587,
26,
355,
3529,
275,
3529,
14,
1365,
398,
291,
14,
698,
275,
3529,
339,
347,
4668,
14502,
63,
6311,
8,
277,
12,
1570,
63,
1130,
304,
267,
7289,
275,
1331,
14,
1574,
8,
277,
9,
267,
340,
1228,
8,
277,
14,
761,
12,
334,
513,
12,
2008,
2298,
288,
7289,
14,
761,
275,
334,
1461,
63,
1130,
14,
362,
8,
277,
14,
761,
59,
16,
467,
291,
14,
761,
59,
16,
2522,
291,
14,
761,
59,
17,
566,
267,
372,
7289,
339,
347,
465,
63,
3009,
8,
277,
12,
18293,
12,
1950,
304,
267,
298,
1767,
314,
9531,
12,
8018,
465,
5385,
543,
2633,
2122,
267,
1862,
275,
942,
398,
340,
2688,
8,
277,
14,
761,
12,
283,
305,
63,
3009,
735,
288,
901,
63,
354,
12,
1862,
275,
291,
14,
761,
14,
305,
63,
3009,
8,
15156,
12,
1950,
9,
267,
916,
1228,
8,
277,
14,
761,
12,
334,
513,
12,
2008,
2298,
288,
901,
63,
354,
275,
15671,
904,
8,
15156,
8,
67,
9,
367,
286,
315,
291,
14,
761,
9,
267,
587,
26,
288,
901,
63,
354,
275,
291,
14,
761,
398,
20873,
275,
469,
288,
283,
1593,
356,
291,
14,
3009,
63,
1593,
12,
288,
283,
698,
356,
901,
63,
354,
267,
789,
267,
20873,
14,
873,
8,
277,
14,
2911,
9,
398,
372,
291,
14,
3009,
63,
1160,
450,
20873,
12,
1862,
421,
199,
533,
437,
10929,
8,
10170,
304,
272,
365,
63,
14378,
275,
715,
272,
3875,
63,
1593,
275,
283,
6087,
39,
7,
421,
199,
533,
14826,
8,
10170,
304,
272,
365,
63,
17460,
275,
715,
272,
3875,
63,
1593,
275,
283,
8760,
7,
272,
3875,
63,
1160,
275,
9487,
1593,
9,
83,
12473,
12926,
9,
83,
2840,
698,
9,
83,
3171,
339,
347,
636,
826,
721,
277,
12,
1048,
12,
15392,
29,
797,
12,
1011,
2911,
304,
267,
1613,
8,
2353,
12,
291,
2843,
826,
721,
761,
12,
15392,
534,
13783,
28437,
283,
340,
15392,
587,
3260,
1011,
2911,
9,
421,
199,
533,
8228,
8,
10170,
304,
272,
3875,
63,
1593,
275,
283,
4283,
7,
421,
199,
533,
10195,
8,
10170,
304,
272,
3875,
63,
1593,
275,
283,
4896,
7,
421,
199,
533,
20992,
12680,
8,
10170,
304,
272,
365,
63,
14378,
275,
715,
339,
347,
636,
826,
721,
277,
12,
1048,
12,
2690,
29,
797,
12,
1011,
2911,
304,
267,
1613,
8,
11976,
12680,
12,
291,
2843,
826,
721,
761,
12,
1011,
2911,
9,
267,
291,
14,
3009,
63,
1593,
275,
283,
18472,
13260,
63,
51,
7089,
7,
340,
2690,
587,
283,
18472,
13260,
63,
13531,
7,
421,
199,
533,
12094,
8,
10170,
304,
272,
3875,
63,
1593,
275,
283,
13285,
7,
421,
199,
533,
21107,
554,
8,
10170,
304,
272,
365,
63,
14378,
275,
715,
339,
347,
636,
826,
721,
277,
12,
1048,
12,
2690,
29,
797,
12,
1011,
2911,
304,
267,
1613,
8,
31805,
12,
291,
2843,
826,
721,
761,
12,
1011,
2911,
9,
267,
291,
14,
3009,
63,
1593,
275,
283,
5568,
63,
51,
7089,
7,
340,
2690,
587,
283,
5568,
63,
13531,
7,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
edensparkles/FIRSTAID
|
FIRST_AID/venv/Lib/site-packages/flask/config.py
|
45
|
9602
|
# -*- coding: utf-8 -*-
"""
flask.config
~~~~~~~~~~~~
Implements the configuration related objects.
:copyright: (c) 2015 by Armin Ronacher.
:license: BSD, see LICENSE for more details.
"""
import os
import types
import errno
from werkzeug.utils import import_string
from ._compat import string_types, iteritems
from . import json
class ConfigAttribute(object):
"""Makes an attribute forward to the config"""
def __init__(self, name, get_converter=None):
self.__name__ = name
self.get_converter = get_converter
def __get__(self, obj, type=None):
if obj is None:
return self
rv = obj.config[self.__name__]
if self.get_converter is not None:
rv = self.get_converter(rv)
return rv
def __set__(self, obj, value):
obj.config[self.__name__] = value
class Config(dict):
"""Works exactly like a dict but provides ways to fill it from files
or special dictionaries. There are two common patterns to populate the
config.
Either you can fill the config from a config file::
app.config.from_pyfile('yourconfig.cfg')
Or alternatively you can define the configuration options in the
module that calls :meth:`from_object` or provide an import path to
a module that should be loaded. It is also possible to tell it to
use the same module and with that provide the configuration values
just before the call::
DEBUG = True
SECRET_KEY = 'development key'
app.config.from_object(__name__)
In both cases (loading from any Python file or loading from modules),
only uppercase keys are added to the config. This makes it possible to use
lowercase values in the config file for temporary values that are not added
to the config or to define the config keys in the same file that implements
the application.
Probably the most interesting way to load configurations is from an
environment variable pointing to a file::
app.config.from_envvar('YOURAPPLICATION_SETTINGS')
In this case before launching the application you have to set this
environment variable to the file you want to use. On Linux and OS X
use the export statement::
export YOURAPPLICATION_SETTINGS='/path/to/config/file'
On windows use `set` instead.
:param root_path: path to which files are read relative from. When the
config object is created by the application, this is
the application's :attr:`~flask.Flask.root_path`.
:param defaults: an optional dictionary of default values
"""
def __init__(self, root_path, defaults=None):
dict.__init__(self, defaults or {})
self.root_path = root_path
def from_envvar(self, variable_name, silent=False):
"""Loads a configuration from an environment variable pointing to
a configuration file. This is basically just a shortcut with nicer
error messages for this line of code::
app.config.from_pyfile(os.environ['YOURAPPLICATION_SETTINGS'])
:param variable_name: name of the environment variable
:param silent: set to ``True`` if you want silent failure for missing
files.
:return: bool. ``True`` if able to load config, ``False`` otherwise.
"""
rv = os.environ.get(variable_name)
if not rv:
if silent:
return False
raise RuntimeError('The environment variable %r is not set '
'and as such configuration could not be '
'loaded. Set this variable and make it '
'point to a configuration file' %
variable_name)
return self.from_pyfile(rv, silent=silent)
def from_pyfile(self, filename, silent=False):
"""Updates the values in the config from a Python file. This function
behaves as if the file was imported as module with the
:meth:`from_object` function.
:param filename: the filename of the config. This can either be an
absolute filename or a filename relative to the
root path.
:param silent: set to ``True`` if you want silent failure for missing
files.
.. versionadded:: 0.7
`silent` parameter.
"""
filename = os.path.join(self.root_path, filename)
d = types.ModuleType('config')
d.__file__ = filename
try:
with open(filename) as config_file:
exec(compile(config_file.read(), filename, 'exec'), d.__dict__)
except IOError as e:
if silent and e.errno in (errno.ENOENT, errno.EISDIR):
return False
e.strerror = 'Unable to load configuration file (%s)' % e.strerror
raise
self.from_object(d)
return True
def from_object(self, obj):
"""Updates the values from the given object. An object can be of one
of the following two types:
- a string: in this case the object with that name will be imported
- an actual object reference: that object is used directly
Objects are usually either modules or classes.
Just the uppercase variables in that object are stored in the config.
Example usage::
app.config.from_object('yourapplication.default_config')
from yourapplication import default_config
app.config.from_object(default_config)
You should not use this function to load the actual configuration but
rather configuration defaults. The actual config should be loaded
with :meth:`from_pyfile` and ideally from a location not within the
package because the package might be installed system wide.
:param obj: an import name or object
"""
if isinstance(obj, string_types):
obj = import_string(obj)
for key in dir(obj):
if key.isupper():
self[key] = getattr(obj, key)
def from_json(self, filename, silent=False):
"""Updates the values in the config from a JSON file. This function
behaves as if the JSON object was a dictionary and passed to the
:meth:`from_mapping` function.
:param filename: the filename of the JSON file. This can either be an
absolute filename or a filename relative to the
root path.
:param silent: set to ``True`` if you want silent failure for missing
files.
.. versionadded:: 0.11
"""
filename = os.path.join(self.root_path, filename)
try:
with open(filename) as json_file:
obj = json.loads(json_file.read())
except IOError as e:
if silent and e.errno in (errno.ENOENT, errno.EISDIR):
return False
e.strerror = 'Unable to load configuration file (%s)' % e.strerror
raise
return self.from_mapping(obj)
def from_mapping(self, *mapping, **kwargs):
"""Updates the config like :meth:`update` ignoring items with non-upper
keys.
.. versionadded:: 0.11
"""
mappings = []
if len(mapping) == 1:
if hasattr(mapping[0], 'items'):
mappings.append(mapping[0].items())
else:
mappings.append(mapping[0])
elif len(mapping) > 1:
raise TypeError(
'expected at most 1 positional argument, got %d' % len(mapping)
)
mappings.append(kwargs.items())
for mapping in mappings:
for (key, value) in mapping:
if key.isupper():
self[key] = value
return True
def get_namespace(self, namespace, lowercase=True, trim_namespace=True):
"""Returns a dictionary containing a subset of configuration options
that match the specified namespace/prefix. Example usage::
app.config['IMAGE_STORE_TYPE'] = 'fs'
app.config['IMAGE_STORE_PATH'] = '/var/app/images'
app.config['IMAGE_STORE_BASE_URL'] = 'http://img.website.com'
image_store_config = app.config.get_namespace('IMAGE_STORE_')
The resulting dictionary `image_store_config` would look like::
{
'type': 'fs',
'path': '/var/app/images',
'base_url': 'http://img.website.com'
}
This is often useful when configuration options map directly to
keyword arguments in functions or class constructors.
:param namespace: a configuration namespace
:param lowercase: a flag indicating if the keys of the resulting
dictionary should be lowercase
:param trim_namespace: a flag indicating if the keys of the resulting
dictionary should not include the namespace
.. versionadded:: 0.11
"""
rv = {}
for k, v in iteritems(self):
if not k.startswith(namespace):
continue
if trim_namespace:
key = k[len(namespace):]
else:
key = k
if lowercase:
key = key.lower()
rv[key] = v
return rv
def __repr__(self):
return '<%s %s>' % (self.__class__.__name__, dict.__repr__(self))
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
7209,
14,
888,
272,
32202,
339,
24664,
314,
2897,
4048,
2251,
14,
339,
520,
7307,
26,
334,
67,
9,
6900,
701,
1952,
827,
32472,
19728,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
1655,
2436,
14,
199,
624,
199,
199,
646,
747,
199,
646,
2943,
199,
646,
7554,
199,
199,
504,
10380,
14,
1208,
492,
492,
63,
875,
199,
504,
13653,
5819,
492,
1059,
63,
1313,
12,
10849,
199,
504,
1275,
492,
2022,
421,
199,
533,
4094,
1646,
8,
785,
304,
272,
408,
27142,
376,
2225,
7568,
370,
314,
1101,
624,
339,
347,
636,
826,
721,
277,
12,
536,
12,
664,
63,
11256,
29,
403,
304,
267,
291,
855,
354,
363,
275,
536,
267,
291,
14,
362,
63,
11256,
275,
664,
63,
11256,
339,
347,
636,
362,
721,
277,
12,
1559,
12,
730,
29,
403,
304,
267,
340,
1559,
365,
488,
26,
288,
372,
291,
267,
4336,
275,
1559,
14,
888,
59,
277,
855,
354,
22705,
267,
340,
291,
14,
362,
63,
11256,
365,
440,
488,
26,
288,
4336,
275,
291,
14,
362,
63,
11256,
8,
6310,
9,
267,
372,
4336,
339,
347,
636,
409,
721,
277,
12,
1559,
12,
574,
304,
267,
1559,
14,
888,
59,
277,
855,
354,
22705,
275,
574,
421,
199,
533,
4094,
8,
807,
304,
272,
408,
25348,
8840,
2839,
282,
1211,
1325,
6571,
15217,
370,
5554,
652,
687,
1584,
272,
503,
4539,
11196,
14,
221,
6006,
787,
2877,
2863,
7970,
370,
13904,
314,
272,
1101,
14,
339,
13083,
1265,
883,
5554,
314,
1101,
687,
282,
1101,
570,
447,
398,
1145,
14,
888,
14,
504,
63,
14792,
360,
12695,
888,
14,
4128,
358,
339,
4236,
8679,
17330,
1265,
883,
5627,
314,
2897,
1511,
315,
314,
272,
859,
626,
4882,
520,
5247,
1705,
504,
63,
785,
64,
503,
5647,
376,
492,
931,
370,
272,
282,
859,
626,
1077,
506,
6511,
14,
221,
2779,
365,
2597,
3962,
370,
11480,
652,
370,
272,
675,
314,
2011,
859,
436,
543,
626,
5647,
314,
2897,
1338,
272,
2951,
2544,
314,
1240,
447,
398,
10990,
275,
715,
267,
5795,
11771,
63,
3078,
275,
283,
31688,
790,
7,
267,
1145,
14,
888,
14,
504,
63,
785,
3460,
354,
3368,
339,
1010,
3865,
5560,
334,
8786,
687,
1263,
2018,
570,
503,
8697,
687,
4621,
395,
272,
1454,
22681,
2883,
787,
3483,
370,
314,
1101,
14,
221,
961,
7704,
652,
3962,
370,
675,
272,
12141,
1338,
315,
314,
1101,
570,
367,
7937,
1338,
626,
787,
440,
3483,
272,
370,
314,
1101,
503,
370,
5627,
314,
1101,
2883,
315,
314,
2011,
570,
626,
9031,
272,
314,
4223,
14,
339,
22770,
6665,
314,
4750,
19604,
4340,
370,
2248,
13422,
365,
687,
376,
272,
3734,
1750,
20686,
370,
282,
570,
447,
398,
1145,
14,
888,
14,
504,
63,
1813,
1391,
360,
57,
11237,
24051,
63,
13931,
358,
339,
1010,
642,
1930,
2544,
10623,
316,
314,
4223,
1265,
1172,
370,
663,
642,
272,
3734,
1750,
370,
314,
570,
1265,
2934,
370,
675,
14,
221,
4068,
10130,
436,
4403,
1323,
272,
675,
314,
4843,
5164,
447,
398,
4843,
1488,
11237,
24051,
63,
13931,
8805,
515,
15,
475,
15,
888,
15,
493,
7,
339,
4068,
10061,
675,
658,
409,
64,
3140,
14,
339,
520,
635,
1738,
63,
515,
26,
931,
370,
1314,
1584,
787,
1586,
3847,
687,
14,
221,
3979,
314,
1993,
1101,
909,
365,
2737,
701,
314,
4223,
12,
642,
365,
1993,
314,
4223,
1159,
520,
962,
6054,
15720,
14,
14182,
14,
1231,
63,
515,
2313,
272,
520,
635,
4243,
26,
376,
2716,
2600,
402,
849,
1338,
272,
408,
339,
347,
636,
826,
721,
277,
12,
1738,
63,
515,
12,
4243,
29,
403,
304,
267,
1211,
855,
826,
721,
277,
12,
4243,
503,
5009,
267,
291,
14,
1231,
63,
515,
275,
1738,
63,
515,
339,
347,
687,
63,
1813,
1391,
8,
277,
12,
1750,
63,
354,
12,
10866,
29,
797,
304,
267,
408,
30777,
282,
2897,
687,
376,
3734,
1750,
20686,
370,
267,
282,
2897,
570,
14,
221,
961,
365,
26014,
2951,
282,
17522,
543,
30023,
267,
1125,
3788,
367,
642,
1004,
402,
1233,
447,
953,
1145,
14,
888,
14,
504,
63,
14792,
8,
736,
14,
2314,
459,
57,
11237,
24051,
63,
13931,
1105,
398,
520,
635,
1750,
63,
354,
26,
536,
402,
314,
3734,
1750,
267,
520,
635,
10866,
26,
663,
370,
1124,
549,
1040,
340,
1265,
2934,
10866,
5988,
367,
4124,
2432,
1584,
14,
267,
520,
1107,
26,
2155,
14,
1124,
549,
1040,
340,
7688,
370,
2248,
1101,
12,
1124,
797,
1040,
4257,
14,
267,
408,
267,
4336,
275,
747,
14,
2314,
14,
362,
8,
1975,
63,
354,
9,
267,
340,
440,
4336,
26,
288,
340,
10866,
26,
355,
372,
756,
288,
746,
6064,
360,
1918,
3734,
1750,
450,
82,
365,
440,
663,
283,
3044,
283,
460,
465,
4066,
2897,
4293,
440,
506,
283,
3044,
283,
4591,
14,
221,
2494,
642,
1750,
436,
1852,
652,
283,
3044,
283,
1403,
370,
282,
2897,
570,
7,
450,
3044,
1750,
63,
354,
9,
267,
372,
291,
14,
504,
63,
14792,
8,
6310,
12,
10866,
29,
14434,
9,
339,
347,
687,
63,
14792,
8,
277,
12,
1788,
12,
10866,
29,
797,
304,
267,
408,
16083,
314,
1338,
315,
314,
1101,
687,
282,
2018,
570,
14,
221,
961,
805,
267,
25113,
465,
340,
314,
570,
1990,
8439,
465,
859,
543,
314,
267,
520,
5247,
1705,
504,
63,
785,
64,
805,
14,
398,
520,
635,
1788,
26,
314,
1788,
402,
314,
1101,
14,
221,
961,
883,
1902,
506,
376,
586,
3679,
1788,
503,
282,
1788,
3847,
370,
314,
586,
1738,
931,
14,
267,
520,
635,
10866,
26,
663,
370,
1124,
549,
1040,
340,
1265,
2934,
10866,
5988,
367,
4124,
2432,
1584,
14,
398,
2508,
7445,
447,
378,
14,
23,
1779,
658,
14434,
64,
2725,
14,
267,
408,
267,
1788,
275,
747,
14,
515,
14,
904,
8,
277,
14,
1231,
63,
515,
12,
1788,
9,
267,
366,
275,
2943,
14,
21820,
360,
888,
358,
267,
366,
855,
493,
363,
275,
1788,
267,
862,
26,
288,
543,
1551,
8,
1501,
9,
465,
1101,
63,
493,
26,
355,
2146,
8,
2014,
8,
888,
63,
493,
14,
739,
1062,
1788,
12,
283,
1628,
659,
366,
855,
807,
3368
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
7209,
14,
888,
272,
32202,
339,
24664,
314,
2897,
4048,
2251,
14,
339,
520,
7307,
26,
334,
67,
9,
6900,
701,
1952,
827,
32472,
19728,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
1655,
2436,
14,
199,
624,
199,
199,
646,
747,
199,
646,
2943,
199,
646,
7554,
199,
199,
504,
10380,
14,
1208,
492,
492,
63,
875,
199,
504,
13653,
5819,
492,
1059,
63,
1313,
12,
10849,
199,
504,
1275,
492,
2022,
421,
199,
533,
4094,
1646,
8,
785,
304,
272,
408,
27142,
376,
2225,
7568,
370,
314,
1101,
624,
339,
347,
636,
826,
721,
277,
12,
536,
12,
664,
63,
11256,
29,
403,
304,
267,
291,
855,
354,
363,
275,
536,
267,
291,
14,
362,
63,
11256,
275,
664,
63,
11256,
339,
347,
636,
362,
721,
277,
12,
1559,
12,
730,
29,
403,
304,
267,
340,
1559,
365,
488,
26,
288,
372,
291,
267,
4336,
275,
1559,
14,
888,
59,
277,
855,
354,
22705,
267,
340,
291,
14,
362,
63,
11256,
365,
440,
488,
26,
288,
4336,
275,
291,
14,
362,
63,
11256,
8,
6310,
9,
267,
372,
4336,
339,
347,
636,
409,
721,
277,
12,
1559,
12,
574,
304,
267,
1559,
14,
888,
59,
277,
855,
354,
22705,
275,
574,
421,
199,
533,
4094,
8,
807,
304,
272,
408,
25348,
8840,
2839,
282,
1211,
1325,
6571,
15217,
370,
5554,
652,
687,
1584,
272,
503,
4539,
11196,
14,
221,
6006,
787,
2877,
2863,
7970,
370,
13904,
314,
272,
1101,
14,
339,
13083,
1265,
883,
5554,
314,
1101,
687,
282,
1101,
570,
447,
398,
1145,
14,
888,
14,
504,
63,
14792,
360,
12695,
888,
14,
4128,
358,
339,
4236,
8679,
17330,
1265,
883,
5627,
314,
2897,
1511,
315,
314,
272,
859,
626,
4882,
520,
5247,
1705,
504,
63,
785,
64,
503,
5647,
376,
492,
931,
370,
272,
282,
859,
626,
1077,
506,
6511,
14,
221,
2779,
365,
2597,
3962,
370,
11480,
652,
370,
272,
675,
314,
2011,
859,
436,
543,
626,
5647,
314,
2897,
1338,
272,
2951,
2544,
314,
1240,
447,
398,
10990,
275,
715,
267,
5795,
11771,
63,
3078,
275,
283,
31688,
790,
7,
267,
1145,
14,
888,
14,
504,
63,
785,
3460,
354,
3368,
339,
1010,
3865,
5560,
334,
8786,
687,
1263,
2018,
570,
503,
8697,
687,
4621,
395,
272,
1454,
22681,
2883,
787,
3483,
370,
314,
1101,
14,
221,
961,
7704,
652,
3962,
370,
675,
272,
12141,
1338,
315,
314,
1101,
570,
367,
7937,
1338,
626,
787,
440,
3483,
272,
370,
314,
1101,
503,
370,
5627,
314,
1101,
2883,
315,
314,
2011,
570,
626,
9031,
272,
314,
4223,
14,
339,
22770,
6665,
314,
4750,
19604,
4340,
370,
2248,
13422,
365,
687,
376,
272,
3734,
1750,
20686,
370,
282,
570,
447,
398,
1145,
14,
888,
14,
504,
63,
1813,
1391,
360,
57,
11237,
24051,
63,
13931,
358,
339,
1010,
642,
1930,
2544,
10623,
316,
314,
4223,
1265,
1172,
370,
663,
642,
272,
3734,
1750,
370,
314,
570,
1265,
2934,
370,
675,
14,
221,
4068,
10130,
436,
4403,
1323,
272,
675,
314,
4843,
5164,
447,
398,
4843,
1488,
11237,
24051,
63,
13931,
8805,
515,
15,
475,
15,
888,
15,
493,
7,
339,
4068,
10061,
675,
658,
409,
64,
3140,
14,
339,
520,
635,
1738,
63,
515,
26,
931,
370,
1314,
1584,
787,
1586,
3847,
687,
14,
221,
3979,
314,
1993,
1101,
909,
365,
2737,
701,
314,
4223,
12,
642,
365,
1993,
314,
4223,
1159,
520,
962,
6054,
15720,
14,
14182,
14,
1231,
63,
515,
2313,
272,
520,
635,
4243,
26,
376,
2716,
2600,
402,
849,
1338,
272,
408,
339,
347,
636,
826,
721,
277,
12,
1738,
63,
515,
12,
4243,
29,
403,
304,
267,
1211,
855,
826,
721,
277,
12,
4243,
503,
5009,
267,
291,
14,
1231,
63,
515,
275,
1738,
63,
515,
339,
347,
687,
63,
1813,
1391,
8,
277,
12,
1750,
63,
354,
12,
10866,
29,
797,
304,
267,
408,
30777,
282,
2897,
687,
376,
3734,
1750,
20686,
370,
267,
282,
2897,
570,
14,
221,
961,
365,
26014,
2951,
282,
17522,
543,
30023,
267,
1125,
3788,
367,
642,
1004,
402,
1233,
447,
953,
1145,
14,
888,
14,
504,
63,
14792,
8,
736,
14,
2314,
459,
57,
11237,
24051,
63,
13931,
1105,
398,
520,
635,
1750,
63,
354,
26,
536,
402,
314,
3734,
1750,
267,
520,
635,
10866,
26,
663,
370,
1124,
549,
1040,
340,
1265,
2934,
10866,
5988,
367,
4124,
2432,
1584,
14,
267,
520,
1107,
26,
2155,
14,
1124,
549,
1040,
340,
7688,
370,
2248,
1101,
12,
1124,
797,
1040,
4257,
14,
267,
408,
267,
4336,
275,
747,
14,
2314,
14,
362,
8,
1975,
63,
354,
9,
267,
340,
440,
4336,
26,
288,
340,
10866,
26,
355,
372,
756,
288,
746,
6064,
360,
1918,
3734,
1750,
450,
82,
365,
440,
663,
283,
3044,
283,
460,
465,
4066,
2897,
4293,
440,
506,
283,
3044,
283,
4591,
14,
221,
2494,
642,
1750,
436,
1852,
652,
283,
3044,
283,
1403,
370,
282,
2897,
570,
7,
450,
3044,
1750,
63,
354,
9,
267,
372,
291,
14,
504,
63,
14792,
8,
6310,
12,
10866,
29,
14434,
9,
339,
347,
687,
63,
14792,
8,
277,
12,
1788,
12,
10866,
29,
797,
304,
267,
408,
16083,
314,
1338,
315,
314,
1101,
687,
282,
2018,
570,
14,
221,
961,
805,
267,
25113,
465,
340,
314,
570,
1990,
8439,
465,
859,
543,
314,
267,
520,
5247,
1705,
504,
63,
785,
64,
805,
14,
398,
520,
635,
1788,
26,
314,
1788,
402,
314,
1101,
14,
221,
961,
883,
1902,
506,
376,
586,
3679,
1788,
503,
282,
1788,
3847,
370,
314,
586,
1738,
931,
14,
267,
520,
635,
10866,
26,
663,
370,
1124,
549,
1040,
340,
1265,
2934,
10866,
5988,
367,
4124,
2432,
1584,
14,
398,
2508,
7445,
447,
378,
14,
23,
1779,
658,
14434,
64,
2725,
14,
267,
408,
267,
1788,
275,
747,
14,
515,
14,
904,
8,
277,
14,
1231,
63,
515,
12,
1788,
9,
267,
366,
275,
2943,
14,
21820,
360,
888,
358,
267,
366,
855,
493,
363,
275,
1788,
267,
862,
26,
288,
543,
1551,
8,
1501,
9,
465,
1101,
63,
493,
26,
355,
2146,
8,
2014,
8,
888,
63,
493,
14,
739,
1062,
1788,
12,
283,
1628,
659,
366,
855,
807,
3368,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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 2007 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""Handles Channel API requests.
Includes a WSGI application that serves the 'jsapi' JavaScript code and handles
channel polling HTTP requests, to connect and retrieve messages.
"""
import os
import google
import webapp2
from google.appengine.api import apiproxy_stub_map
from google.appengine.api.channel import channel_service_stub
# Regex for all requests routed through this module.
# Note: Other URLs in the _ah/channel namespace may be handled by the user.
CHANNEL_URL_PATTERN = '_ah/channel/(?:jsapi|dev)'
_JSAPI_PATH = os.path.join(os.path.dirname(os.path.dirname(__file__)),
'dev-channel-js.js')
# These error statuses (including the message) are explicitly mandated in the
# Channel JavaScript documentation.
INVALID_TOKEN_STATUS = '401 Invalid+token.'
TOKEN_TIMED_OUT_STATUS = '401 Token+timed+out.'
def _get_channel_stub():
"""Gets the ChannelServiceStub instance from the API proxy stub map.
Returns:
The ChannelServiceStub instance as registered in the API stub map.
"""
return apiproxy_stub_map.apiproxy.GetStub('channel')
class DevHandler(webapp2.RequestHandler):
"""The request handler for the 'connect' and 'poll' requests."""
def get(self):
# Remove the default Content-Type. If there is any content, the correct
# Content-Type will be set later.
del self.response.headers['Content-Type']
stub = _get_channel_stub()
command = self.request.get('command', None)
token = self.request.get('channel', None)
if command is None or token is None:
self.response.status = 400
return
if command == 'connect':
try:
stub.connect_channel(token)
except channel_service_stub.InvalidTokenError:
self.response.status = INVALID_TOKEN_STATUS
return
except channel_service_stub.TokenTimedOutError:
self.response.status = TOKEN_TIMED_OUT_STATUS
return
self.response.headers['Content-Type'] = 'text/plain'
self.response.out.write('1')
elif command == 'poll':
try:
# TODO: Wait up to N seconds for a message to arrive before
# returning empty (long poll).
message = stub.connect_and_pop_first_message(token)
except channel_service_stub.InvalidTokenError:
self.response.status = INVALID_TOKEN_STATUS
return
except channel_service_stub.TokenTimedOutError:
self.response.status = TOKEN_TIMED_OUT_STATUS
return
if message is not None:
self.response.headers['Content-Type'] = 'application/json'
self.response.out.write(message)
else:
self.response.status = 400
class JSAPIHandler(webapp2.RequestHandler):
"""The request handler for the jsapi static JavaScript code."""
def get(self):
# TODO: Reuse code in static_files_handler to do cache control.
self.response.headers['Content-Type'] = 'text/javascript'
self.response.out.write(open(_JSAPI_PATH).read())
application = webapp2.WSGIApplication([
('/_ah/channel/dev', DevHandler),
('/_ah/channel/jsapi', JSAPIHandler),
], debug=True)
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
10219,
4475,
3277,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
199,
624,
23555,
17270,
3261,
4145,
14,
199,
199,
22792,
282,
9279,
4223,
626,
23739,
314,
283,
3596,
1246,
7,
15250,
1233,
436,
10022,
199,
2775,
12353,
3101,
4145,
12,
370,
4907,
436,
8044,
3788,
14,
199,
624,
4388,
199,
646,
747,
199,
199,
646,
6233,
199,
646,
24812,
18,
199,
199,
504,
6233,
14,
15358,
14,
1246,
492,
2986,
3280,
63,
5811,
63,
1130,
199,
504,
6233,
14,
15358,
14,
1246,
14,
2775,
492,
3623,
63,
1364,
63,
5811,
199,
199,
3,
12939,
367,
1006,
4145,
882,
4241,
4012,
642,
859,
14,
199,
3,
3390,
26,
5439,
10867,
315,
314,
485,
11326,
15,
2775,
3231,
1443,
506,
8860,
701,
314,
922,
14,
199,
14833,
63,
2632,
63,
10764,
275,
2513,
11326,
15,
2775,
32576,
3596,
1246,
92,
2374,
3171,
199,
199,
63,
11378,
3735,
63,
3243,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
3475,
3460,
493,
22159,
2574,
283,
2374,
13,
2775,
13,
3596,
14,
3596,
358,
199,
199,
3,
5723,
1125,
24498,
334,
15768,
314,
1245,
9,
787,
7662,
333,
460,
972,
315,
314,
199,
3,
17270,
15250,
3794,
14,
199,
9692,
63,
8803,
63,
6305,
275,
283,
8854,
6378,
11,
1418,
3530,
199,
8803,
63,
11342,
1149,
63,
1877,
63,
6305,
275,
283,
8854,
8767,
11,
26687,
11,
548,
3530,
421,
199,
318,
485,
362,
63,
2775,
63,
5811,
837,
523,
408,
14426,
314,
17270,
3167,
8067,
1256,
687,
314,
3261,
4566,
10098,
2341,
14,
819,
1803,
26,
272,
710,
17270,
3167,
8067,
1256,
465,
7264,
315,
314,
3261,
10098,
2341,
14,
523,
408,
523,
372,
2986,
3280,
63,
5811,
63,
1130,
14,
1246,
3280,
14,
1002,
8067,
360,
2775,
358,
421,
199,
533,
29314,
2461,
8,
22632,
18,
14,
11149,
304,
523,
408,
1918,
1056,
3016,
367,
314,
283,
2242,
7,
436,
283,
6843,
7,
4145,
1041,
819,
347,
664,
8,
277,
304,
272,
327,
5852,
314,
849,
6646,
13,
804,
14,
982,
2337,
365,
1263,
1564,
12,
314,
3211,
272,
327,
6646,
13,
804,
911,
506,
663,
2945,
14,
272,
2150,
291,
14,
1310,
14,
2139,
459,
2714,
13,
804,
418,
272,
10098,
275,
485,
362,
63,
2775,
63,
5811,
342,
339,
1414,
275,
291,
14,
1069,
14,
362,
360,
1531,
297,
488,
9,
272,
1526,
275,
291,
14,
1069,
14,
362,
360,
2775,
297,
488,
9,
272,
340,
1414,
365,
488,
503,
1526,
365,
488,
26,
489,
291,
14,
1310,
14,
1205,
275,
8290,
489,
372,
339,
340,
1414,
508,
283,
2242,
356,
489,
862,
26,
267,
10098,
14,
2242,
63,
2775,
8,
1418,
9,
489,
871,
3623,
63,
1364,
63,
5811,
14,
3364,
3264,
547,
26,
267,
291,
14,
1310,
14,
1205,
275,
29901,
63,
8803,
63,
6305,
267,
372,
489,
871,
3623,
63,
1364,
63,
5811,
14,
3264,
28682,
2204,
547,
26,
267,
291,
14,
1310,
14,
1205,
275,
18243,
63,
11342,
1149,
63,
1877,
63,
6305,
267,
372,
489,
291,
14,
1310,
14,
2139,
459,
2714,
13,
804,
418,
275,
283,
505,
15,
6104,
7,
489,
291,
14,
1310,
14,
548,
14,
952,
360,
17,
358,
272,
916,
1414,
508,
283,
6843,
356,
489,
862,
26,
267,
327,
3254,
26,
13144,
1536,
370,
653,
4696,
367,
282,
1245,
370,
601,
6053,
2544,
267,
327,
8152,
2701,
334,
2809,
11271,
680,
267,
1245,
275,
10098,
14,
2242,
63,
460,
63,
1935,
63,
2246,
63,
1188,
8,
1418,
9,
489,
871,
3623,
63,
1364,
63,
5811,
14,
3364,
3264,
547,
26,
267,
291,
14,
1310,
14,
1205,
275,
29901,
63,
8803,
63,
6305,
267,
372,
489,
871,
3623,
63,
1364,
63,
5811,
14,
3264,
28682,
2204,
547,
26,
267,
291,
14,
1310,
14,
1205,
275,
18243,
63,
11342,
1149,
63,
1877,
63,
6305,
267,
372,
489,
340,
1245,
365,
440,
488,
26,
267,
291,
14,
1310,
14,
2139,
459,
2714,
13,
804,
418,
275,
283,
3578,
15,
1001,
7,
267,
291,
14,
1310,
14,
548,
14,
952,
8,
1188,
9,
272,
587,
26,
489,
291,
14,
1310,
14,
1205,
275,
8290,
421,
199,
533,
18001,
3735,
2461,
8,
22632,
18,
14,
11149,
304,
523,
408,
1918,
1056,
3016,
367,
314,
8586,
1246,
2955,
15250,
1233,
1041,
819,
347,
664,
8,
277,
304,
272,
327,
3254,
26,
799,
1180,
1233,
315,
2955,
63,
1725,
63,
2232,
370,
886,
2581,
3304,
14,
272,
291,
14,
1310,
14,
2139,
459,
2714,
13,
804,
418,
275,
283,
505,
15,
9554,
7,
272,
291,
14,
1310,
14,
548,
14,
952,
8,
1490,
1547,
11378,
3735,
63,
3243,
680,
739,
1012,
421,
199,
3578,
275,
24812,
18,
14,
16828,
5039,
779,
272,
14606,
63,
11326,
15,
2775,
15,
2374,
297,
29314,
2461,
395,
272,
14606,
63,
11326,
15,
2775,
15,
3596,
1246,
297,
18001,
3735,
2461,
395,
199,
467,
3105,
29,
549,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
10219,
4475,
3277,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
199,
624,
23555,
17270,
3261,
4145,
14,
199,
199,
22792,
282,
9279,
4223,
626,
23739,
314,
283,
3596,
1246,
7,
15250,
1233,
436,
10022,
199,
2775,
12353,
3101,
4145,
12,
370,
4907,
436,
8044,
3788,
14,
199,
624,
4388,
199,
646,
747,
199,
199,
646,
6233,
199,
646,
24812,
18,
199,
199,
504,
6233,
14,
15358,
14,
1246,
492,
2986,
3280,
63,
5811,
63,
1130,
199,
504,
6233,
14,
15358,
14,
1246,
14,
2775,
492,
3623,
63,
1364,
63,
5811,
199,
199,
3,
12939,
367,
1006,
4145,
882,
4241,
4012,
642,
859,
14,
199,
3,
3390,
26,
5439,
10867,
315,
314,
485,
11326,
15,
2775,
3231,
1443,
506,
8860,
701,
314,
922,
14,
199,
14833,
63,
2632,
63,
10764,
275,
2513,
11326,
15,
2775,
32576,
3596,
1246,
92,
2374,
3171,
199,
199,
63,
11378,
3735,
63,
3243,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
3475,
3460,
493,
22159,
2574,
283,
2374,
13,
2775,
13,
3596,
14,
3596,
358,
199,
199,
3,
5723,
1125,
24498,
334,
15768,
314,
1245,
9,
787,
7662,
333,
460,
972,
315,
314,
199,
3,
17270,
15250,
3794,
14,
199,
9692,
63,
8803,
63,
6305,
275,
283,
8854,
6378,
11,
1418,
3530,
199,
8803,
63,
11342,
1149,
63,
1877,
63,
6305,
275,
283,
8854,
8767,
11,
26687,
11,
548,
3530,
421,
199,
318,
485,
362,
63,
2775,
63,
5811,
837,
523,
408,
14426,
314,
17270,
3167,
8067,
1256,
687,
314,
3261,
4566,
10098,
2341,
14,
819,
1803,
26,
272,
710,
17270,
3167,
8067,
1256,
465,
7264,
315,
314,
3261,
10098,
2341,
14,
523,
408,
523,
372,
2986,
3280,
63,
5811,
63,
1130,
14,
1246,
3280,
14,
1002,
8067,
360,
2775,
358,
421,
199,
533,
29314,
2461,
8,
22632,
18,
14,
11149,
304,
523,
408,
1918,
1056,
3016,
367,
314,
283,
2242,
7,
436,
283,
6843,
7,
4145,
1041,
819,
347,
664,
8,
277,
304,
272,
327,
5852,
314,
849,
6646,
13,
804,
14,
982,
2337,
365,
1263,
1564,
12,
314,
3211,
272,
327,
6646,
13,
804,
911,
506,
663,
2945,
14,
272,
2150,
291,
14,
1310,
14,
2139,
459,
2714,
13,
804,
418,
272,
10098,
275,
485,
362,
63,
2775,
63,
5811,
342,
339,
1414,
275,
291,
14,
1069,
14,
362,
360,
1531,
297,
488,
9,
272,
1526,
275,
291,
14,
1069,
14,
362,
360,
2775,
297,
488,
9,
272,
340,
1414,
365,
488,
503,
1526,
365,
488,
26,
489,
291,
14,
1310,
14,
1205,
275,
8290,
489,
372,
339,
340,
1414,
508,
283,
2242,
356,
489,
862,
26,
267,
10098,
14,
2242,
63,
2775,
8,
1418,
9,
489,
871,
3623,
63,
1364,
63,
5811,
14,
3364,
3264,
547,
26,
267,
291,
14,
1310,
14,
1205,
275,
29901,
63,
8803,
63,
6305,
267,
372,
489,
871,
3623,
63,
1364,
63,
5811,
14,
3264,
28682,
2204,
547,
26,
267,
291,
14,
1310,
14,
1205,
275,
18243,
63,
11342,
1149,
63,
1877,
63,
6305,
267,
372,
489,
291,
14,
1310,
14,
2139,
459,
2714,
13,
804,
418,
275,
283,
505,
15,
6104,
7,
489,
291,
14,
1310,
14,
548,
14,
952,
360,
17,
358,
272,
916,
1414,
508,
283,
6843,
356,
489,
862,
26,
267,
327,
3254,
26,
13144,
1536,
370,
653,
4696,
367,
282,
1245,
370,
601,
6053,
2544,
267,
327,
8152,
2701,
334,
2809,
11271,
680,
267,
1245,
275,
10098,
14,
2242,
63,
460,
63,
1935,
63,
2246,
63,
1188,
8,
1418,
9,
489,
871,
3623,
63,
1364,
63,
5811,
14,
3364,
3264,
547,
26,
267,
291,
14,
1310,
14,
1205,
275,
29901,
63,
8803,
63,
6305,
267,
372,
489,
871,
3623,
63,
1364,
63,
5811,
14,
3264,
28682,
2204,
547,
26,
267,
291,
14,
1310,
14,
1205,
275,
18243,
63,
11342,
1149,
63,
1877,
63,
6305,
267,
372,
489,
340,
1245,
365,
440,
488,
26,
267,
291,
14,
1310,
14,
2139,
459,
2714,
13,
804,
418,
275,
283,
3578,
15,
1001,
7,
267,
291,
14,
1310,
14,
548,
14,
952,
8,
1188,
9,
272,
587,
26,
489,
291,
14,
1310,
14,
1205,
275,
8290,
421,
199,
533,
18001,
3735,
2461,
8,
22632,
18,
14,
11149,
304,
523,
408,
1918,
1056,
3016,
367,
314,
8586,
1246,
2955,
15250,
1233,
1041,
819,
347,
664,
8,
277,
304,
272,
327,
3254,
26,
799,
1180,
1233,
315,
2955,
63,
1725,
63,
2232,
370,
886,
2581,
3304,
14,
272,
291,
14,
1310,
14,
2139,
459,
2714,
13,
804,
418,
275,
283,
505,
15,
9554,
7,
272,
291,
14,
1310,
14,
548,
14,
952,
8,
1490,
1547,
11378,
3735,
63,
3243,
680,
739,
1012,
421,
199,
3578,
275,
24812,
18,
14,
16828,
5039,
779,
272,
14606,
63,
11326,
15,
2775,
15,
2374,
297,
29314,
2461,
395,
272,
14606,
63,
11326,
15,
2775,
15,
3596,
1246,
297,
18001,
3735,
2461,
395,
199,
467,
3105,
29,
549,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
krisys/django
|
tests/check_framework/test_multi_db.py
|
50
|
1661
|
from django.db import connections, models
from django.test import TestCase, mock
from django.test.utils import isolate_apps, override_settings
class TestRouter(object):
"""
Routes to the 'other' database if the model name starts with 'Other'.
"""
def allow_migrate(self, db, app_label, model_name=None, **hints):
return db == ('other' if model_name.startswith('other') else 'default')
@override_settings(DATABASE_ROUTERS=[TestRouter()])
@isolate_apps('check_framework')
class TestMultiDBChecks(TestCase):
multi_db = True
def _patch_check_field_on(self, db):
return mock.patch.object(connections[db].validation, 'check_field')
def test_checks_called_on_the_default_database(self):
class Model(models.Model):
field = models.CharField(max_length=100)
model = Model()
with self._patch_check_field_on('default') as mock_check_field_default:
with self._patch_check_field_on('other') as mock_check_field_other:
model.check()
self.assertTrue(mock_check_field_default.called)
self.assertFalse(mock_check_field_other.called)
def test_checks_called_on_the_other_database(self):
class OtherModel(models.Model):
field = models.CharField(max_length=100)
model = OtherModel()
with self._patch_check_field_on('other') as mock_check_field_other:
with self._patch_check_field_on('default') as mock_check_field_default:
model.check()
self.assertTrue(mock_check_field_other.called)
self.assertFalse(mock_check_field_default.called)
|
bsd-3-clause
|
[
504,
1639,
14,
697,
492,
6947,
12,
1709,
199,
504,
1639,
14,
396,
492,
7640,
12,
1683,
199,
504,
1639,
14,
396,
14,
1208,
492,
365,
16288,
63,
5181,
12,
4278,
63,
1751,
421,
199,
533,
1379,
11691,
8,
785,
304,
272,
408,
272,
19776,
744,
370,
314,
283,
1848,
7,
3050,
340,
314,
1402,
536,
9174,
543,
283,
8632,
1370,
272,
408,
272,
347,
2040,
63,
8462,
8,
277,
12,
1592,
12,
1145,
63,
1302,
12,
1402,
63,
354,
29,
403,
12,
1011,
12354,
304,
267,
372,
1592,
508,
661,
1848,
7,
340,
1402,
63,
354,
14,
2460,
360,
1848,
358,
587,
283,
885,
358,
421,
199,
32,
4415,
63,
1751,
8,
17873,
63,
14999,
3960,
1524,
774,
11691,
9383,
199,
32,
31188,
63,
5181,
360,
1074,
63,
4857,
358,
199,
533,
1379,
3947,
2846,
11834,
8,
1746,
304,
272,
3510,
63,
697,
275,
715,
339,
347,
485,
2068,
63,
1074,
63,
698,
63,
265,
8,
277,
12,
1592,
304,
267,
372,
1683,
14,
2068,
14,
785,
8,
7995,
59,
697,
1055,
6136,
12,
283,
1074,
63,
698,
358,
339,
347,
511,
63,
8625,
63,
3527,
63,
265,
63,
1589,
63,
885,
63,
4659,
8,
277,
304,
267,
1021,
5822,
8,
992,
14,
1685,
304,
288,
901,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
9,
398,
1402,
275,
5822,
342,
267,
543,
291,
423,
2068,
63,
1074,
63,
698,
63,
265,
360,
885,
358,
465,
1683,
63,
1074,
63,
698,
63,
885,
26,
288,
543,
291,
423,
2068,
63,
1074,
63,
698,
63,
265,
360,
1848,
358,
465,
1683,
63,
1074,
63,
698,
63,
1848,
26,
355,
1402,
14,
1074,
342,
355,
291,
14,
1815,
8,
1805,
63,
1074,
63,
698,
63,
885,
14,
3527,
9,
355,
291,
14,
3334,
8,
1805,
63,
1074,
63,
698,
63,
1848,
14,
3527,
9,
339,
347,
511,
63,
8625,
63,
3527,
63,
265,
63,
1589,
63,
1848,
63,
4659,
8,
277,
304,
267,
1021,
5439,
1685,
8,
992,
14,
1685,
304,
288,
901,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
9,
398,
1402,
275,
5439,
1685,
342,
267,
543,
291,
423,
2068,
63,
1074,
63,
698,
63,
265,
360,
1848,
358,
465,
1683,
63,
1074,
63,
698,
63,
1848,
26,
288,
543,
291,
423,
2068,
63,
1074,
63,
698,
63,
265,
360,
885,
358,
465,
1683,
63,
1074,
63,
698,
63,
885,
26,
355,
1402,
14,
1074,
342,
355,
291,
14,
1815,
8,
1805,
63,
1074,
63,
698,
63,
1848,
14,
3527,
9,
355,
291,
14,
3334,
8,
1805,
63,
1074,
63,
698,
63,
885,
14,
3527,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1639,
14,
697,
492,
6947,
12,
1709,
199,
504,
1639,
14,
396,
492,
7640,
12,
1683,
199,
504,
1639,
14,
396,
14,
1208,
492,
365,
16288,
63,
5181,
12,
4278,
63,
1751,
421,
199,
533,
1379,
11691,
8,
785,
304,
272,
408,
272,
19776,
744,
370,
314,
283,
1848,
7,
3050,
340,
314,
1402,
536,
9174,
543,
283,
8632,
1370,
272,
408,
272,
347,
2040,
63,
8462,
8,
277,
12,
1592,
12,
1145,
63,
1302,
12,
1402,
63,
354,
29,
403,
12,
1011,
12354,
304,
267,
372,
1592,
508,
661,
1848,
7,
340,
1402,
63,
354,
14,
2460,
360,
1848,
358,
587,
283,
885,
358,
421,
199,
32,
4415,
63,
1751,
8,
17873,
63,
14999,
3960,
1524,
774,
11691,
9383,
199,
32,
31188,
63,
5181,
360,
1074,
63,
4857,
358,
199,
533,
1379,
3947,
2846,
11834,
8,
1746,
304,
272,
3510,
63,
697,
275,
715,
339,
347,
485,
2068,
63,
1074,
63,
698,
63,
265,
8,
277,
12,
1592,
304,
267,
372,
1683,
14,
2068,
14,
785,
8,
7995,
59,
697,
1055,
6136,
12,
283,
1074,
63,
698,
358,
339,
347,
511,
63,
8625,
63,
3527,
63,
265,
63,
1589,
63,
885,
63,
4659,
8,
277,
304,
267,
1021,
5822,
8,
992,
14,
1685,
304,
288,
901,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
9,
398,
1402,
275,
5822,
342,
267,
543,
291,
423,
2068,
63,
1074,
63,
698,
63,
265,
360,
885,
358,
465,
1683,
63,
1074,
63,
698,
63,
885,
26,
288,
543,
291,
423,
2068,
63,
1074,
63,
698,
63,
265,
360,
1848,
358,
465,
1683,
63,
1074,
63,
698,
63,
1848,
26,
355,
1402,
14,
1074,
342,
355,
291,
14,
1815,
8,
1805,
63,
1074,
63,
698,
63,
885,
14,
3527,
9,
355,
291,
14,
3334,
8,
1805,
63,
1074,
63,
698,
63,
1848,
14,
3527,
9,
339,
347,
511,
63,
8625,
63,
3527,
63,
265,
63,
1589,
63,
1848,
63,
4659,
8,
277,
304,
267,
1021,
5439,
1685,
8,
992,
14,
1685,
304,
288,
901,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
9,
398,
1402,
275,
5439,
1685,
342,
267,
543,
291,
423,
2068,
63,
1074,
63,
698,
63,
265,
360,
1848,
358,
465,
1683,
63,
1074,
63,
698,
63,
1848,
26,
288,
543,
291,
423,
2068,
63,
1074,
63,
698,
63,
265,
360,
885,
358,
465,
1683,
63,
1074,
63,
698,
63,
885,
26,
355,
1402,
14,
1074,
342,
355,
291,
14,
1815,
8,
1805,
63,
1074,
63,
698,
63,
1848,
14,
3527,
9,
355,
291,
14,
3334,
8,
1805,
63,
1074,
63,
698,
63,
885,
14,
3527,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
edx/edx-load-tests
|
util/generate_summary.py
|
1
|
3450
|
# -*- coding: utf-8 -*-
"""
Generate a summary of a previous loadtest run in this environment.
See for usage example in a jenkins job dsl:
https://github.com/edx/jenkins-job-dsl/blob/master/testeng/jobs/loadtestDriver.groovy
Prerequisites:
A logfile produced by util/run-loadtest.sh should be present in its
standard location.
Output:
Produces summary on standard output in YAML format. The structure is as
follows:
* monitoring_links:
* list of link text/url pairs pointing to monitoring dashboards.
* timeline:
* begin: ISO 8601 date for when the test began.
* end: ISO 8601 date for when the test ended.
"""
from datetime import timedelta
import yaml
import helpers.markers
from util.app_monitors_config import MONITORS
# Refer to util/run-loadtest.sh in case this file path changes.
STANDARD_LOGFILE_PATH = "results/log.txt"
def parse_logfile_events(logfile):
"""
Parse the logfile for events
Parameters:
logfile (file): the file containing locust logs for a single load test
Returns:
iterator of (datetime.datetime, str) tuples: the parsed events in the
order they are encountered.
"""
for line in logfile:
data = helpers.markers.parse_logfile_event_marker(line)
if data is not None:
yield (data['time'], data['event'])
def get_time_bounds(logfile):
"""
Determine when the load test started and stopped.
Parameters:
logfile (file): the file containing locust logs for a single load test
Returns:
two-tuple of datetime.datetime: the time bounds of the load test
"""
begin_time = end_time = None
relevant_events = ['locust_start_hatching', 'edx_heartbeat', 'quitting']
relevant_times = [
time
for time, event
in parse_logfile_events(logfile)
if event in relevant_events
]
begin_time, end_time = (min(relevant_times), max(relevant_times))
return (begin_time, end_time)
def main():
"""
Generate a summary of a previous load test run.
This script assumes "results/log.txt" is the logfile in question.
"""
with open(STANDARD_LOGFILE_PATH) as logfile:
loadtest_begin_time, loadtest_end_time = get_time_bounds(logfile)
monitoring_links = []
for monitor in MONITORS:
monitoring_links.append({
'url': monitor.url(
begin_time=loadtest_begin_time,
end_time=loadtest_end_time,
),
'text': u'{}: {} ({} — {})'.format(
monitor.monitoring_service_name,
monitor.app_name,
# We use naive datetimes (i.e. no attached tz) and just
# assume UTC all along. Tacking on the "Z" implies UTC.
loadtest_begin_time.strftime('%Y-%m-%dT%H:%M:%SZ'),
loadtest_end_time.strftime('%Y-%m-%dT%H:%M:%SZ'),
),
})
print(yaml.dump(
{
'timeline': {
'begin': loadtest_begin_time.strftime('%Y-%m-%dT%H:%M:%SZ'),
'end': loadtest_end_time.strftime('%Y-%m-%dT%H:%M:%SZ'),
},
'monitoring_links': monitoring_links
},
default_flow_style=False, # Represent objects using indented blocks
# rather than inline enclosures.
allow_unicode=True,
))
if __name__ == "__main__":
main()
|
apache-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
6864,
282,
6212,
402,
282,
4136,
2248,
396,
1255,
315,
642,
3734,
14,
199,
199,
9295,
367,
4503,
2893,
315,
282,
29537,
3906,
366,
2482,
26,
199,
199,
2859,
921,
5031,
14,
957,
15,
8268,
15,
25622,
13,
2423,
13,
795,
76,
15,
6582,
15,
4133,
15,
744,
724,
71,
15,
6920,
15,
912,
396,
6158,
14,
23260,
8822,
89,
199,
199,
2398,
30140,
26,
272,
437,
17251,
13584,
701,
4884,
15,
1065,
13,
912,
396,
14,
609,
1077,
506,
3451,
315,
2399,
272,
4465,
2909,
14,
199,
199,
2959,
26,
272,
2165,
10569,
6212,
641,
4465,
1072,
315,
18916,
1475,
14,
221,
710,
5523,
365,
465,
272,
11924,
26,
339,
627,
20391,
63,
4614,
26,
267,
627,
769,
402,
2142,
1318,
15,
633,
6342,
20686,
370,
20391,
11847,
19267,
14,
272,
627,
20780,
26,
267,
627,
5386,
26,
9055,
10300,
614,
1434,
367,
1380,
314,
511,
506,
24975,
14,
267,
627,
1284,
26,
9055,
10300,
614,
1434,
367,
1380,
314,
511,
22480,
14,
199,
624,
199,
504,
2197,
492,
6871,
199,
646,
8864,
199,
646,
10897,
14,
16835,
199,
504,
4884,
14,
571,
63,
24048,
63,
888,
492,
603,
615,
649,
4149,
199,
199,
3,
21751,
370,
4884,
15,
1065,
13,
912,
396,
14,
609,
315,
1930,
642,
570,
931,
4493,
14,
199,
19547,
63,
4947,
3817,
63,
3243,
275,
298,
2604,
15,
793,
14,
2424,
2,
421,
199,
318,
2198,
63,
12804,
63,
4368,
8,
12804,
304,
272,
408,
272,
6077,
314,
17251,
367,
4474,
339,
3897,
26,
267,
17251,
334,
493,
304,
314,
570,
3035,
4355,
833,
9610,
367,
282,
2849,
2248,
511,
339,
1803,
26,
267,
6122,
402,
334,
2083,
14,
2083,
12,
620,
9,
6346,
26,
314,
4565,
4474,
315,
314,
288,
1865,
2985,
787,
14556,
14,
272,
408,
272,
367,
1004,
315,
17251,
26,
267,
666,
275,
10897,
14,
16835,
14,
1122,
63,
12804,
63,
1430,
63,
4211,
8,
604,
9,
267,
340,
666,
365,
440,
488,
26,
288,
1995,
334,
576,
459,
521,
995,
666,
459,
1430,
1105,
421,
199,
318,
664,
63,
521,
63,
9632,
8,
12804,
304,
272,
408,
272,
14703,
1380,
314,
2248,
511,
8239,
436,
15248,
14,
339,
3897,
26,
267,
17251,
334,
493,
304,
314,
570,
3035,
4355,
833,
9610,
367,
282,
2849,
2248,
511,
339,
1803,
26,
267,
2877,
13,
2960,
402,
2197,
14,
2083,
26,
314,
900,
10461,
402,
314,
2248,
511,
272,
408,
272,
5386,
63,
521,
275,
1284,
63,
521,
275,
488,
272,
12082,
63,
4368,
275,
788,
2102,
833,
63,
928,
63,
72,
693,
316,
297,
283,
8268,
63,
22685,
297,
283,
10589,
1337,
418,
272,
12082,
63,
4508,
275,
359,
267,
900,
267,
367,
900,
12,
1566,
267,
315,
2198,
63,
12804,
63,
4368,
8,
12804,
9,
267,
340,
1566,
315,
12082,
63,
4368,
272,
1622,
272,
5386,
63,
521,
12,
1284,
63,
521,
275,
334,
827,
8,
21906,
63,
4508,
395,
1390,
8,
21906,
63,
4508,
430,
272,
372,
334,
5037,
63,
521,
12,
1284,
63,
521,
9,
421,
199,
318,
2446,
837,
272,
408,
272,
7958,
282,
6212,
402,
282,
4136,
2248,
511,
1255,
14,
339,
961,
2884,
15194,
298,
2604,
15,
793,
14,
2424,
2,
365,
314,
17251,
315,
7894,
14,
272,
408,
272,
543,
1551,
8,
19547,
63,
4947,
3817,
63,
3243,
9,
465,
17251,
26,
267,
2248,
396,
63,
5037,
63,
521,
12,
2248,
396,
63,
500,
63,
521,
275,
664,
63,
521,
63,
9632,
8,
12804,
9,
339,
20391,
63,
4614,
275,
942,
272,
367,
8372,
315,
603,
615,
649,
4149,
26,
267,
20391,
63,
4614,
14,
740,
2561,
288,
283,
633,
356,
8372,
14,
633,
8,
355,
5386,
63,
521,
29,
912,
396,
63,
5037,
63,
521,
12,
355,
1284,
63,
521,
29,
912,
396,
63,
500,
63,
521,
12,
288,
2318,
288,
283,
505,
356,
399,
7,
2440,
26,
1052,
334,
2440,
221,
20292,
5009,
1370,
908,
8,
355,
8372,
14,
20554,
63,
1364,
63,
354,
12,
355,
8372,
14,
571,
63,
354,
12,
355,
327,
2136,
675,
19995,
29297,
334,
73,
14,
69,
14,
949,
10102,
5823,
9,
436,
2951,
355,
327,
5534,
12174,
1006,
3180,
14,
221,
377,
564,
316,
641,
314,
298,
58,
2,
22660,
12174,
14,
355,
2248,
396,
63,
5037,
63,
521,
14,
6205,
3508,
57,
3295,
77,
3295,
19772,
5,
40,
2689,
45,
2689,
18101,
659,
355,
2248,
396,
63,
500,
63,
521,
14,
6205,
3508,
57,
3295,
77,
3295,
19772,
5,
40,
2689,
45,
2689,
18101,
659,
288,
2318,
267,
3828,
272,
870,
8,
5963,
14,
2724,
8,
267,
469,
288,
283,
19369,
356,
469,
355,
283,
5037,
356,
2248,
396,
63,
5037,
63,
521,
14,
6205,
3508,
57,
3295,
77,
3295,
19772,
5,
40,
2689,
45,
2689,
18101,
659,
355,
283,
500,
356,
2248,
396,
63,
500,
63,
521,
14,
6205,
3508,
57,
3295,
77,
3295,
19772,
5,
40,
2689,
45,
2689,
18101,
659,
288,
1660,
288,
283,
20554,
63,
4614,
356,
20391,
63,
4614,
267,
1660,
267,
849,
63,
1659,
63,
2487,
29,
797,
12,
221,
327,
17634,
2251,
1808,
19197,
5664,
3521,
327,
7830,
2419,
8308,
655,
1251,
83,
1482,
14,
267,
2040,
63,
2975,
29,
549,
12,
272,
5082,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
2446,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
6864,
282,
6212,
402,
282,
4136,
2248,
396,
1255,
315,
642,
3734,
14,
199,
199,
9295,
367,
4503,
2893,
315,
282,
29537,
3906,
366,
2482,
26,
199,
199,
2859,
921,
5031,
14,
957,
15,
8268,
15,
25622,
13,
2423,
13,
795,
76,
15,
6582,
15,
4133,
15,
744,
724,
71,
15,
6920,
15,
912,
396,
6158,
14,
23260,
8822,
89,
199,
199,
2398,
30140,
26,
272,
437,
17251,
13584,
701,
4884,
15,
1065,
13,
912,
396,
14,
609,
1077,
506,
3451,
315,
2399,
272,
4465,
2909,
14,
199,
199,
2959,
26,
272,
2165,
10569,
6212,
641,
4465,
1072,
315,
18916,
1475,
14,
221,
710,
5523,
365,
465,
272,
11924,
26,
339,
627,
20391,
63,
4614,
26,
267,
627,
769,
402,
2142,
1318,
15,
633,
6342,
20686,
370,
20391,
11847,
19267,
14,
272,
627,
20780,
26,
267,
627,
5386,
26,
9055,
10300,
614,
1434,
367,
1380,
314,
511,
506,
24975,
14,
267,
627,
1284,
26,
9055,
10300,
614,
1434,
367,
1380,
314,
511,
22480,
14,
199,
624,
199,
504,
2197,
492,
6871,
199,
646,
8864,
199,
646,
10897,
14,
16835,
199,
504,
4884,
14,
571,
63,
24048,
63,
888,
492,
603,
615,
649,
4149,
199,
199,
3,
21751,
370,
4884,
15,
1065,
13,
912,
396,
14,
609,
315,
1930,
642,
570,
931,
4493,
14,
199,
19547,
63,
4947,
3817,
63,
3243,
275,
298,
2604,
15,
793,
14,
2424,
2,
421,
199,
318,
2198,
63,
12804,
63,
4368,
8,
12804,
304,
272,
408,
272,
6077,
314,
17251,
367,
4474,
339,
3897,
26,
267,
17251,
334,
493,
304,
314,
570,
3035,
4355,
833,
9610,
367,
282,
2849,
2248,
511,
339,
1803,
26,
267,
6122,
402,
334,
2083,
14,
2083,
12,
620,
9,
6346,
26,
314,
4565,
4474,
315,
314,
288,
1865,
2985,
787,
14556,
14,
272,
408,
272,
367,
1004,
315,
17251,
26,
267,
666,
275,
10897,
14,
16835,
14,
1122,
63,
12804,
63,
1430,
63,
4211,
8,
604,
9,
267,
340,
666,
365,
440,
488,
26,
288,
1995,
334,
576,
459,
521,
995,
666,
459,
1430,
1105,
421,
199,
318,
664,
63,
521,
63,
9632,
8,
12804,
304,
272,
408,
272,
14703,
1380,
314,
2248,
511,
8239,
436,
15248,
14,
339,
3897,
26,
267,
17251,
334,
493,
304,
314,
570,
3035,
4355,
833,
9610,
367,
282,
2849,
2248,
511,
339,
1803,
26,
267,
2877,
13,
2960,
402,
2197,
14,
2083,
26,
314,
900,
10461,
402,
314,
2248,
511,
272,
408,
272,
5386,
63,
521,
275,
1284,
63,
521,
275,
488,
272,
12082,
63,
4368,
275,
788,
2102,
833,
63,
928,
63,
72,
693,
316,
297,
283,
8268,
63,
22685,
297,
283,
10589,
1337,
418,
272,
12082,
63,
4508,
275,
359,
267,
900,
267,
367,
900,
12,
1566,
267,
315,
2198,
63,
12804,
63,
4368,
8,
12804,
9,
267,
340,
1566,
315,
12082,
63,
4368,
272,
1622,
272,
5386,
63,
521,
12,
1284,
63,
521,
275,
334,
827,
8,
21906,
63,
4508,
395,
1390,
8,
21906,
63,
4508,
430,
272,
372,
334,
5037,
63,
521,
12,
1284,
63,
521,
9,
421,
199,
318,
2446,
837,
272,
408,
272,
7958,
282,
6212,
402,
282,
4136,
2248,
511,
1255,
14,
339,
961,
2884,
15194,
298,
2604,
15,
793,
14,
2424,
2,
365,
314,
17251,
315,
7894,
14,
272,
408,
272,
543,
1551,
8,
19547,
63,
4947,
3817,
63,
3243,
9,
465,
17251,
26,
267,
2248,
396,
63,
5037,
63,
521,
12,
2248,
396,
63,
500,
63,
521,
275,
664,
63,
521,
63,
9632,
8,
12804,
9,
339,
20391,
63,
4614,
275,
942,
272,
367,
8372,
315,
603,
615,
649,
4149,
26,
267,
20391,
63,
4614,
14,
740,
2561,
288,
283,
633,
356,
8372,
14,
633,
8,
355,
5386,
63,
521,
29,
912,
396,
63,
5037,
63,
521,
12,
355,
1284,
63,
521,
29,
912,
396,
63,
500,
63,
521,
12,
288,
2318,
288,
283,
505,
356,
399,
7,
2440,
26,
1052,
334,
2440,
221,
20292,
5009,
1370,
908,
8,
355,
8372,
14,
20554,
63,
1364,
63,
354,
12,
355,
8372,
14,
571,
63,
354,
12,
355,
327,
2136,
675,
19995,
29297,
334,
73,
14,
69,
14,
949,
10102,
5823,
9,
436,
2951,
355,
327,
5534,
12174,
1006,
3180,
14,
221,
377,
564,
316,
641,
314,
298,
58,
2,
22660,
12174,
14,
355,
2248,
396,
63,
5037,
63,
521,
14,
6205,
3508,
57,
3295,
77,
3295,
19772,
5,
40,
2689,
45,
2689,
18101,
659,
355,
2248,
396,
63,
500,
63,
521,
14,
6205,
3508,
57,
3295,
77,
3295,
19772,
5,
40,
2689,
45,
2689,
18101,
659,
288,
2318,
267,
3828,
272,
870,
8,
5963,
14,
2724,
8,
267,
469,
288,
283,
19369,
356,
469,
355,
283,
5037,
356,
2248,
396,
63,
5037,
63,
521,
14,
6205,
3508,
57,
3295,
77,
3295,
19772,
5,
40,
2689,
45,
2689,
18101,
659,
355,
283,
500,
356,
2248,
396,
63,
500,
63,
521,
14,
6205,
3508,
57,
3295,
77,
3295,
19772,
5,
40,
2689,
45,
2689,
18101,
659,
288,
1660,
288,
283,
20554,
63,
4614,
356,
20391,
63,
4614,
267,
1660,
267,
849,
63,
1659,
63,
2487,
29,
797,
12,
221,
327,
17634,
2251,
1808,
19197,
5664,
3521,
327,
7830,
2419,
8308,
655,
1251,
83,
1482,
14,
267,
2040,
63,
2975,
29,
549,
12,
272,
5082,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
2446,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
davidmueller13/ZenKernel_Flounder
|
tools/perf/scripts/python/netdev-times.py
|
11271
|
15048
|
# Display a process of packets and processed time.
# It helps us to investigate networking or network device.
#
# options
# tx: show only tx chart
# rx: show only rx chart
# dev=: show only thing related to specified device
# debug: work with debug mode. It shows buffer status.
import os
import sys
sys.path.append(os.environ['PERF_EXEC_PATH'] + \
'/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
from perf_trace_context import *
from Core import *
from Util import *
all_event_list = []; # insert all tracepoint event related with this script
irq_dic = {}; # key is cpu and value is a list which stacks irqs
# which raise NET_RX softirq
net_rx_dic = {}; # key is cpu and value include time of NET_RX softirq-entry
# and a list which stacks receive
receive_hunk_list = []; # a list which include a sequence of receive events
rx_skb_list = []; # received packet list for matching
# skb_copy_datagram_iovec
buffer_budget = 65536; # the budget of rx_skb_list, tx_queue_list and
# tx_xmit_list
of_count_rx_skb_list = 0; # overflow count
tx_queue_list = []; # list of packets which pass through dev_queue_xmit
of_count_tx_queue_list = 0; # overflow count
tx_xmit_list = []; # list of packets which pass through dev_hard_start_xmit
of_count_tx_xmit_list = 0; # overflow count
tx_free_list = []; # list of packets which is freed
# options
show_tx = 0;
show_rx = 0;
dev = 0; # store a name of device specified by option "dev="
debug = 0;
# indices of event_info tuple
EINFO_IDX_NAME= 0
EINFO_IDX_CONTEXT=1
EINFO_IDX_CPU= 2
EINFO_IDX_TIME= 3
EINFO_IDX_PID= 4
EINFO_IDX_COMM= 5
# Calculate a time interval(msec) from src(nsec) to dst(nsec)
def diff_msec(src, dst):
return (dst - src) / 1000000.0
# Display a process of transmitting a packet
def print_transmit(hunk):
if dev != 0 and hunk['dev'].find(dev) < 0:
return
print "%7s %5d %6d.%06dsec %12.3fmsec %12.3fmsec" % \
(hunk['dev'], hunk['len'],
nsecs_secs(hunk['queue_t']),
nsecs_nsecs(hunk['queue_t'])/1000,
diff_msec(hunk['queue_t'], hunk['xmit_t']),
diff_msec(hunk['xmit_t'], hunk['free_t']))
# Format for displaying rx packet processing
PF_IRQ_ENTRY= " irq_entry(+%.3fmsec irq=%d:%s)"
PF_SOFT_ENTRY=" softirq_entry(+%.3fmsec)"
PF_NAPI_POLL= " napi_poll_exit(+%.3fmsec %s)"
PF_JOINT= " |"
PF_WJOINT= " | |"
PF_NET_RECV= " |---netif_receive_skb(+%.3fmsec skb=%x len=%d)"
PF_NET_RX= " |---netif_rx(+%.3fmsec skb=%x)"
PF_CPY_DGRAM= " | skb_copy_datagram_iovec(+%.3fmsec %d:%s)"
PF_KFREE_SKB= " | kfree_skb(+%.3fmsec location=%x)"
PF_CONS_SKB= " | consume_skb(+%.3fmsec)"
# Display a process of received packets and interrputs associated with
# a NET_RX softirq
def print_receive(hunk):
show_hunk = 0
irq_list = hunk['irq_list']
cpu = irq_list[0]['cpu']
base_t = irq_list[0]['irq_ent_t']
# check if this hunk should be showed
if dev != 0:
for i in range(len(irq_list)):
if irq_list[i]['name'].find(dev) >= 0:
show_hunk = 1
break
else:
show_hunk = 1
if show_hunk == 0:
return
print "%d.%06dsec cpu=%d" % \
(nsecs_secs(base_t), nsecs_nsecs(base_t)/1000, cpu)
for i in range(len(irq_list)):
print PF_IRQ_ENTRY % \
(diff_msec(base_t, irq_list[i]['irq_ent_t']),
irq_list[i]['irq'], irq_list[i]['name'])
print PF_JOINT
irq_event_list = irq_list[i]['event_list']
for j in range(len(irq_event_list)):
irq_event = irq_event_list[j]
if irq_event['event'] == 'netif_rx':
print PF_NET_RX % \
(diff_msec(base_t, irq_event['time']),
irq_event['skbaddr'])
print PF_JOINT
print PF_SOFT_ENTRY % \
diff_msec(base_t, hunk['sirq_ent_t'])
print PF_JOINT
event_list = hunk['event_list']
for i in range(len(event_list)):
event = event_list[i]
if event['event_name'] == 'napi_poll':
print PF_NAPI_POLL % \
(diff_msec(base_t, event['event_t']), event['dev'])
if i == len(event_list) - 1:
print ""
else:
print PF_JOINT
else:
print PF_NET_RECV % \
(diff_msec(base_t, event['event_t']), event['skbaddr'],
event['len'])
if 'comm' in event.keys():
print PF_WJOINT
print PF_CPY_DGRAM % \
(diff_msec(base_t, event['comm_t']),
event['pid'], event['comm'])
elif 'handle' in event.keys():
print PF_WJOINT
if event['handle'] == "kfree_skb":
print PF_KFREE_SKB % \
(diff_msec(base_t,
event['comm_t']),
event['location'])
elif event['handle'] == "consume_skb":
print PF_CONS_SKB % \
diff_msec(base_t,
event['comm_t'])
print PF_JOINT
def trace_begin():
global show_tx
global show_rx
global dev
global debug
for i in range(len(sys.argv)):
if i == 0:
continue
arg = sys.argv[i]
if arg == 'tx':
show_tx = 1
elif arg =='rx':
show_rx = 1
elif arg.find('dev=',0, 4) >= 0:
dev = arg[4:]
elif arg == 'debug':
debug = 1
if show_tx == 0 and show_rx == 0:
show_tx = 1
show_rx = 1
def trace_end():
# order all events in time
all_event_list.sort(lambda a,b :cmp(a[EINFO_IDX_TIME],
b[EINFO_IDX_TIME]))
# process all events
for i in range(len(all_event_list)):
event_info = all_event_list[i]
name = event_info[EINFO_IDX_NAME]
if name == 'irq__softirq_exit':
handle_irq_softirq_exit(event_info)
elif name == 'irq__softirq_entry':
handle_irq_softirq_entry(event_info)
elif name == 'irq__softirq_raise':
handle_irq_softirq_raise(event_info)
elif name == 'irq__irq_handler_entry':
handle_irq_handler_entry(event_info)
elif name == 'irq__irq_handler_exit':
handle_irq_handler_exit(event_info)
elif name == 'napi__napi_poll':
handle_napi_poll(event_info)
elif name == 'net__netif_receive_skb':
handle_netif_receive_skb(event_info)
elif name == 'net__netif_rx':
handle_netif_rx(event_info)
elif name == 'skb__skb_copy_datagram_iovec':
handle_skb_copy_datagram_iovec(event_info)
elif name == 'net__net_dev_queue':
handle_net_dev_queue(event_info)
elif name == 'net__net_dev_xmit':
handle_net_dev_xmit(event_info)
elif name == 'skb__kfree_skb':
handle_kfree_skb(event_info)
elif name == 'skb__consume_skb':
handle_consume_skb(event_info)
# display receive hunks
if show_rx:
for i in range(len(receive_hunk_list)):
print_receive(receive_hunk_list[i])
# display transmit hunks
if show_tx:
print " dev len Qdisc " \
" netdevice free"
for i in range(len(tx_free_list)):
print_transmit(tx_free_list[i])
if debug:
print "debug buffer status"
print "----------------------------"
print "xmit Qdisc:remain:%d overflow:%d" % \
(len(tx_queue_list), of_count_tx_queue_list)
print "xmit netdevice:remain:%d overflow:%d" % \
(len(tx_xmit_list), of_count_tx_xmit_list)
print "receive:remain:%d overflow:%d" % \
(len(rx_skb_list), of_count_rx_skb_list)
# called from perf, when it finds a correspoinding event
def irq__softirq_entry(name, context, cpu, sec, nsec, pid, comm, vec):
if symbol_str("irq__softirq_entry", "vec", vec) != "NET_RX":
return
event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm, vec)
all_event_list.append(event_info)
def irq__softirq_exit(name, context, cpu, sec, nsec, pid, comm, vec):
if symbol_str("irq__softirq_entry", "vec", vec) != "NET_RX":
return
event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm, vec)
all_event_list.append(event_info)
def irq__softirq_raise(name, context, cpu, sec, nsec, pid, comm, vec):
if symbol_str("irq__softirq_entry", "vec", vec) != "NET_RX":
return
event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm, vec)
all_event_list.append(event_info)
def irq__irq_handler_entry(name, context, cpu, sec, nsec, pid, comm,
irq, irq_name):
event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm,
irq, irq_name)
all_event_list.append(event_info)
def irq__irq_handler_exit(name, context, cpu, sec, nsec, pid, comm, irq, ret):
event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm, irq, ret)
all_event_list.append(event_info)
def napi__napi_poll(name, context, cpu, sec, nsec, pid, comm, napi, dev_name):
event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm,
napi, dev_name)
all_event_list.append(event_info)
def net__netif_receive_skb(name, context, cpu, sec, nsec, pid, comm, skbaddr,
skblen, dev_name):
event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm,
skbaddr, skblen, dev_name)
all_event_list.append(event_info)
def net__netif_rx(name, context, cpu, sec, nsec, pid, comm, skbaddr,
skblen, dev_name):
event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm,
skbaddr, skblen, dev_name)
all_event_list.append(event_info)
def net__net_dev_queue(name, context, cpu, sec, nsec, pid, comm,
skbaddr, skblen, dev_name):
event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm,
skbaddr, skblen, dev_name)
all_event_list.append(event_info)
def net__net_dev_xmit(name, context, cpu, sec, nsec, pid, comm,
skbaddr, skblen, rc, dev_name):
event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm,
skbaddr, skblen, rc ,dev_name)
all_event_list.append(event_info)
def skb__kfree_skb(name, context, cpu, sec, nsec, pid, comm,
skbaddr, protocol, location):
event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm,
skbaddr, protocol, location)
all_event_list.append(event_info)
def skb__consume_skb(name, context, cpu, sec, nsec, pid, comm, skbaddr):
event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm,
skbaddr)
all_event_list.append(event_info)
def skb__skb_copy_datagram_iovec(name, context, cpu, sec, nsec, pid, comm,
skbaddr, skblen):
event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm,
skbaddr, skblen)
all_event_list.append(event_info)
def handle_irq_handler_entry(event_info):
(name, context, cpu, time, pid, comm, irq, irq_name) = event_info
if cpu not in irq_dic.keys():
irq_dic[cpu] = []
irq_record = {'irq':irq, 'name':irq_name, 'cpu':cpu, 'irq_ent_t':time}
irq_dic[cpu].append(irq_record)
def handle_irq_handler_exit(event_info):
(name, context, cpu, time, pid, comm, irq, ret) = event_info
if cpu not in irq_dic.keys():
return
irq_record = irq_dic[cpu].pop()
if irq != irq_record['irq']:
return
irq_record.update({'irq_ext_t':time})
# if an irq doesn't include NET_RX softirq, drop.
if 'event_list' in irq_record.keys():
irq_dic[cpu].append(irq_record)
def handle_irq_softirq_raise(event_info):
(name, context, cpu, time, pid, comm, vec) = event_info
if cpu not in irq_dic.keys() \
or len(irq_dic[cpu]) == 0:
return
irq_record = irq_dic[cpu].pop()
if 'event_list' in irq_record.keys():
irq_event_list = irq_record['event_list']
else:
irq_event_list = []
irq_event_list.append({'time':time, 'event':'sirq_raise'})
irq_record.update({'event_list':irq_event_list})
irq_dic[cpu].append(irq_record)
def handle_irq_softirq_entry(event_info):
(name, context, cpu, time, pid, comm, vec) = event_info
net_rx_dic[cpu] = {'sirq_ent_t':time, 'event_list':[]}
def handle_irq_softirq_exit(event_info):
(name, context, cpu, time, pid, comm, vec) = event_info
irq_list = []
event_list = 0
if cpu in irq_dic.keys():
irq_list = irq_dic[cpu]
del irq_dic[cpu]
if cpu in net_rx_dic.keys():
sirq_ent_t = net_rx_dic[cpu]['sirq_ent_t']
event_list = net_rx_dic[cpu]['event_list']
del net_rx_dic[cpu]
if irq_list == [] or event_list == 0:
return
rec_data = {'sirq_ent_t':sirq_ent_t, 'sirq_ext_t':time,
'irq_list':irq_list, 'event_list':event_list}
# merge information realted to a NET_RX softirq
receive_hunk_list.append(rec_data)
def handle_napi_poll(event_info):
(name, context, cpu, time, pid, comm, napi, dev_name) = event_info
if cpu in net_rx_dic.keys():
event_list = net_rx_dic[cpu]['event_list']
rec_data = {'event_name':'napi_poll',
'dev':dev_name, 'event_t':time}
event_list.append(rec_data)
def handle_netif_rx(event_info):
(name, context, cpu, time, pid, comm,
skbaddr, skblen, dev_name) = event_info
if cpu not in irq_dic.keys() \
or len(irq_dic[cpu]) == 0:
return
irq_record = irq_dic[cpu].pop()
if 'event_list' in irq_record.keys():
irq_event_list = irq_record['event_list']
else:
irq_event_list = []
irq_event_list.append({'time':time, 'event':'netif_rx',
'skbaddr':skbaddr, 'skblen':skblen, 'dev_name':dev_name})
irq_record.update({'event_list':irq_event_list})
irq_dic[cpu].append(irq_record)
def handle_netif_receive_skb(event_info):
global of_count_rx_skb_list
(name, context, cpu, time, pid, comm,
skbaddr, skblen, dev_name) = event_info
if cpu in net_rx_dic.keys():
rec_data = {'event_name':'netif_receive_skb',
'event_t':time, 'skbaddr':skbaddr, 'len':skblen}
event_list = net_rx_dic[cpu]['event_list']
event_list.append(rec_data)
rx_skb_list.insert(0, rec_data)
if len(rx_skb_list) > buffer_budget:
rx_skb_list.pop()
of_count_rx_skb_list += 1
def handle_net_dev_queue(event_info):
global of_count_tx_queue_list
(name, context, cpu, time, pid, comm,
skbaddr, skblen, dev_name) = event_info
skb = {'dev':dev_name, 'skbaddr':skbaddr, 'len':skblen, 'queue_t':time}
tx_queue_list.insert(0, skb)
if len(tx_queue_list) > buffer_budget:
tx_queue_list.pop()
of_count_tx_queue_list += 1
def handle_net_dev_xmit(event_info):
global of_count_tx_xmit_list
(name, context, cpu, time, pid, comm,
skbaddr, skblen, rc, dev_name) = event_info
if rc == 0: # NETDEV_TX_OK
for i in range(len(tx_queue_list)):
skb = tx_queue_list[i]
if skb['skbaddr'] == skbaddr:
skb['xmit_t'] = time
tx_xmit_list.insert(0, skb)
del tx_queue_list[i]
if len(tx_xmit_list) > buffer_budget:
tx_xmit_list.pop()
of_count_tx_xmit_list += 1
return
def handle_kfree_skb(event_info):
(name, context, cpu, time, pid, comm,
skbaddr, protocol, location) = event_info
for i in range(len(tx_queue_list)):
skb = tx_queue_list[i]
if skb['skbaddr'] == skbaddr:
del tx_queue_list[i]
return
for i in range(len(tx_xmit_list)):
skb = tx_xmit_list[i]
if skb['skbaddr'] == skbaddr:
skb['free_t'] = time
tx_free_list.append(skb)
del tx_xmit_list[i]
return
for i in range(len(rx_skb_list)):
rec_data = rx_skb_list[i]
if rec_data['skbaddr'] == skbaddr:
rec_data.update({'handle':"kfree_skb",
'comm':comm, 'pid':pid, 'comm_t':time})
del rx_skb_list[i]
return
def handle_consume_skb(event_info):
(name, context, cpu, time, pid, comm, skbaddr) = event_info
for i in range(len(tx_xmit_list)):
skb = tx_xmit_list[i]
if skb['skbaddr'] == skbaddr:
skb['free_t'] = time
tx_free_list.append(skb)
del tx_xmit_list[i]
return
def handle_skb_copy_datagram_iovec(event_info):
(name, context, cpu, time, pid, comm, skbaddr, skblen) = event_info
for i in range(len(rx_skb_list)):
rec_data = rx_skb_list[i]
if skbaddr == rec_data['skbaddr']:
rec_data.update({'handle':"skb_copy_datagram_iovec",
'comm':comm, 'pid':pid, 'comm_t':time})
del rx_skb_list[i]
return
|
gpl-2.0
|
[
3,
12175,
282,
2112,
402,
14593,
436,
7686,
900,
14,
199,
3,
2779,
22577,
2739,
370,
315,
27174,
323,
2784,
316,
503,
2784,
2243,
14,
199,
3,
199,
3,
1511,
199,
3,
4773,
26,
2498,
1454,
4773,
10943,
199,
3,
12951,
26,
2498,
1454,
12951,
10943,
199,
3,
4866,
29,
26,
2498,
1454,
8377,
4048,
370,
2013,
2243,
199,
3,
3105,
26,
1736,
543,
3105,
818,
14,
2779,
13703,
3335,
2004,
14,
199,
199,
646,
747,
199,
646,
984,
199,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
2314,
459,
17038,
63,
10276,
63,
3243,
418,
435,
971,
199,
198,
9807,
6429,
15,
1548,
15,
12387,
13,
3921,
13,
9562,
15,
773,
15,
12387,
15,
3921,
358,
199,
199,
504,
8582,
63,
3446,
63,
1100,
492,
627,
199,
504,
11672,
492,
627,
199,
504,
21248,
492,
627,
199,
199,
452,
63,
1430,
63,
513,
275,
22750,
327,
5518,
1006,
3307,
1403,
1566,
4048,
543,
642,
2884,
199,
7277,
63,
5000,
275,
27978,
327,
790,
365,
5033,
436,
574,
365,
282,
769,
1314,
26733,
10476,
83,
1598,
327,
1314,
746,
18340,
63,
15361,
880,
15493,
199,
846,
63,
6872,
63,
5000,
275,
27978,
327,
790,
365,
5033,
436,
574,
2387,
900,
402,
18340,
63,
15361,
880,
15493,
13,
2373,
686,
327,
436,
282,
769,
1314,
26733,
9128,
199,
9391,
63,
17428,
63,
513,
275,
22750,
327,
282,
769,
1314,
2387,
282,
3414,
402,
9128,
4474,
199,
6872,
63,
6852,
63,
513,
275,
22750,
327,
3086,
3644,
769,
367,
4877,
686,
755,
327,
11448,
63,
1574,
63,
25443,
63,
30463,
199,
199,
2738,
63,
16501,
275,
25980,
27,
327,
314,
1032,
14080,
402,
12951,
63,
6852,
63,
513,
12,
4773,
63,
1825,
63,
513,
436,
686,
755,
327,
4773,
63,
14217,
63,
513,
199,
1618,
63,
835,
63,
6872,
63,
6852,
63,
513,
275,
378,
27,
327,
15784,
2338,
199,
199,
2347,
63,
1825,
63,
513,
275,
22750,
327,
769,
402,
14593,
1314,
986,
4012,
4866,
63,
1825,
63,
14217,
199,
1618,
63,
835,
63,
2347,
63,
1825,
63,
513,
275,
378,
27,
327,
15784,
2338,
199,
199,
2347,
63,
14217,
63,
513,
275,
22750,
221,
327,
769,
402,
14593,
1314,
986,
4012,
4866,
63,
8726,
63,
928,
63,
14217,
199,
1618,
63,
835,
63,
2347,
63,
14217,
63,
513,
275,
378,
27,
327,
15784,
2338,
199,
199,
2347,
63,
4624,
63,
513,
275,
22750,
221,
327,
769,
402,
14593,
1314,
365,
23694,
199,
199,
3,
1511,
199,
2384,
63,
2347,
275,
378,
27,
199,
2384,
63,
6872,
275,
378,
27,
199,
2374,
275,
378,
27,
327,
3877,
282,
536,
402,
2243,
2013,
701,
945,
298,
2374,
628,
199,
1757,
275,
378,
27,
199,
199,
3,
4918,
402,
1566,
63,
815,
2008,
199,
26556,
63,
20037,
63,
2339,
29,
257,
378,
199,
26556,
63,
20037,
63,
9059,
29,
17,
199,
26556,
63,
20037,
63,
11011,
29,
259,
499,
199,
26556,
63,
20037,
63,
4961,
29,
257,
650,
199,
26556,
63,
20037,
63,
16098,
29,
259,
841,
199,
26556,
63,
20037,
63,
5378,
29,
257,
959,
199,
199,
3,
12707,
282,
900,
6252,
8,
19764,
9,
687,
2928,
8,
78,
3321,
9,
370,
5042,
8,
78,
3321,
9,
199,
318,
3915,
63,
19764,
8,
2164,
12,
5042,
304,
199,
198,
1107,
334,
5119,
446,
2928,
9,
1182,
19492,
14,
16,
199,
199,
3,
12175,
282,
2112,
402,
27754,
1337,
282,
3644,
199,
318,
870,
63,
31399,
8,
17428,
304,
199,
198,
692,
4866,
1137,
378,
436,
19988,
459,
2374,
2278,
1623,
8,
2374,
9,
665,
378,
26,
507,
198,
1107,
199,
198,
1361,
2071,
23,
83,
450,
21,
68,
450,
22,
68,
4111,
1690,
68,
3321,
450,
713,
14,
19,
25154,
420,
450,
713,
14,
19,
25154,
2,
450,
971,
507,
198,
8,
17428,
459,
2374,
995,
19988,
459,
552,
995,
507,
198,
9618,
63,
4855,
8,
17428,
459,
1825,
63,
84,
3815,
507,
198,
9618,
63,
9618,
8,
17428,
459,
1825,
63,
84,
1105,
15,
5279,
12,
507,
198,
3028,
63,
19764,
8,
17428,
459,
1825,
63,
84,
995,
19988,
459,
14217,
63,
84,
3815,
507,
198,
3028,
63,
19764,
8,
17428,
459,
14217,
63,
84,
995,
19988,
459,
4624,
63,
84,
5156,
199,
199,
3,
9701,
367,
20589,
12951,
3644,
6661,
199,
10966,
63,
3927,
49,
63,
7285,
29,
298,
221,
10476,
63,
2373,
28643,
19,
25154,
10476,
2458,
68,
2689,
83,
2924,
199,
10966,
63,
26999,
63,
7285,
628,
221,
880,
15493,
63,
2373,
28643,
19,
25154,
2924,
199,
10966,
63,
46,
3735,
63,
16428,
29,
298,
221,
302,
1246,
63,
6843,
63,
2224,
28643,
19,
25154,
450,
83,
2924,
199,
10966,
63,
24931,
29,
258,
298,
260,
1204,
2,
199,
10966,
63,
55,
24931,
29,
259,
298,
260,
1204,
3322,
1204,
2,
199,
10966,
63,
7278,
63,
9481,
54,
29,
221,
298,
260,
1204,
2595,
20869,
63,
9391,
63,
6852,
28643,
19,
25154,
11448,
2458,
88,
822,
2458,
68,
2924,
199,
10966,
63,
7278,
63,
15361,
29,
259,
298,
260,
1204,
2595,
20869,
63,
6872,
28643,
19,
25154,
11448,
2458,
88,
2924,
199,
10966,
63,
2890,
57,
63,
25351,
29,
298,
260,
1204,
420,
11448,
63,
1574,
63,
25443,
63,
30463,
28643,
19,
25154,
450,
68,
2689,
83,
2924,
199,
10966,
63,
17706,
5271,
63,
8656,
34,
29,
298,
260,
1204,
420,
1022,
4624,
63,
6852,
28643,
19,
25154,
2909,
2458,
88,
2924,
199,
10966,
63,
1864,
51,
63,
8656,
34,
29,
221,
298,
260,
1204,
420,
9451,
63,
6852,
28643,
19,
25154,
2924,
199,
199,
3,
12175,
282,
2112,
402,
3086,
14593,
436,
1640,
82,
524,
83,
4568,
543,
199,
3,
282,
18340,
63,
15361,
880,
15493,
199,
318,
870,
63,
9391,
8,
17428,
304,
199,
198,
2384,
63,
17428,
275,
378,
199,
198,
7277,
63,
513,
275,
19988,
459,
7277,
63,
513,
418,
199,
198,
3541,
275,
10476,
63,
513,
59,
16,
2733,
3541,
418,
199,
198,
1095,
63,
84,
275,
10476,
63,
513,
59,
16,
2733,
7277,
63,
484,
63,
84,
418,
199,
198,
3,
1104,
340,
642,
19988,
1077,
506,
2498,
379,
199,
198,
692,
4866,
1137,
378,
26,
507,
198,
509,
284,
315,
1425,
8,
552,
8,
7277,
63,
513,
2298,
686,
198,
692,
10476,
63,
513
] |
[
12175,
282,
2112,
402,
14593,
436,
7686,
900,
14,
199,
3,
2779,
22577,
2739,
370,
315,
27174,
323,
2784,
316,
503,
2784,
2243,
14,
199,
3,
199,
3,
1511,
199,
3,
4773,
26,
2498,
1454,
4773,
10943,
199,
3,
12951,
26,
2498,
1454,
12951,
10943,
199,
3,
4866,
29,
26,
2498,
1454,
8377,
4048,
370,
2013,
2243,
199,
3,
3105,
26,
1736,
543,
3105,
818,
14,
2779,
13703,
3335,
2004,
14,
199,
199,
646,
747,
199,
646,
984,
199,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
2314,
459,
17038,
63,
10276,
63,
3243,
418,
435,
971,
199,
198,
9807,
6429,
15,
1548,
15,
12387,
13,
3921,
13,
9562,
15,
773,
15,
12387,
15,
3921,
358,
199,
199,
504,
8582,
63,
3446,
63,
1100,
492,
627,
199,
504,
11672,
492,
627,
199,
504,
21248,
492,
627,
199,
199,
452,
63,
1430,
63,
513,
275,
22750,
327,
5518,
1006,
3307,
1403,
1566,
4048,
543,
642,
2884,
199,
7277,
63,
5000,
275,
27978,
327,
790,
365,
5033,
436,
574,
365,
282,
769,
1314,
26733,
10476,
83,
1598,
327,
1314,
746,
18340,
63,
15361,
880,
15493,
199,
846,
63,
6872,
63,
5000,
275,
27978,
327,
790,
365,
5033,
436,
574,
2387,
900,
402,
18340,
63,
15361,
880,
15493,
13,
2373,
686,
327,
436,
282,
769,
1314,
26733,
9128,
199,
9391,
63,
17428,
63,
513,
275,
22750,
327,
282,
769,
1314,
2387,
282,
3414,
402,
9128,
4474,
199,
6872,
63,
6852,
63,
513,
275,
22750,
327,
3086,
3644,
769,
367,
4877,
686,
755,
327,
11448,
63,
1574,
63,
25443,
63,
30463,
199,
199,
2738,
63,
16501,
275,
25980,
27,
327,
314,
1032,
14080,
402,
12951,
63,
6852,
63,
513,
12,
4773,
63,
1825,
63,
513,
436,
686,
755,
327,
4773,
63,
14217,
63,
513,
199,
1618,
63,
835,
63,
6872,
63,
6852,
63,
513,
275,
378,
27,
327,
15784,
2338,
199,
199,
2347,
63,
1825,
63,
513,
275,
22750,
327,
769,
402,
14593,
1314,
986,
4012,
4866,
63,
1825,
63,
14217,
199,
1618,
63,
835,
63,
2347,
63,
1825,
63,
513,
275,
378,
27,
327,
15784,
2338,
199,
199,
2347,
63,
14217,
63,
513,
275,
22750,
221,
327,
769,
402,
14593,
1314,
986,
4012,
4866,
63,
8726,
63,
928,
63,
14217,
199,
1618,
63,
835,
63,
2347,
63,
14217,
63,
513,
275,
378,
27,
327,
15784,
2338,
199,
199,
2347,
63,
4624,
63,
513,
275,
22750,
221,
327,
769,
402,
14593,
1314,
365,
23694,
199,
199,
3,
1511,
199,
2384,
63,
2347,
275,
378,
27,
199,
2384,
63,
6872,
275,
378,
27,
199,
2374,
275,
378,
27,
327,
3877,
282,
536,
402,
2243,
2013,
701,
945,
298,
2374,
628,
199,
1757,
275,
378,
27,
199,
199,
3,
4918,
402,
1566,
63,
815,
2008,
199,
26556,
63,
20037,
63,
2339,
29,
257,
378,
199,
26556,
63,
20037,
63,
9059,
29,
17,
199,
26556,
63,
20037,
63,
11011,
29,
259,
499,
199,
26556,
63,
20037,
63,
4961,
29,
257,
650,
199,
26556,
63,
20037,
63,
16098,
29,
259,
841,
199,
26556,
63,
20037,
63,
5378,
29,
257,
959,
199,
199,
3,
12707,
282,
900,
6252,
8,
19764,
9,
687,
2928,
8,
78,
3321,
9,
370,
5042,
8,
78,
3321,
9,
199,
318,
3915,
63,
19764,
8,
2164,
12,
5042,
304,
199,
198,
1107,
334,
5119,
446,
2928,
9,
1182,
19492,
14,
16,
199,
199,
3,
12175,
282,
2112,
402,
27754,
1337,
282,
3644,
199,
318,
870,
63,
31399,
8,
17428,
304,
199,
198,
692,
4866,
1137,
378,
436,
19988,
459,
2374,
2278,
1623,
8,
2374,
9,
665,
378,
26,
507,
198,
1107,
199,
198,
1361,
2071,
23,
83,
450,
21,
68,
450,
22,
68,
4111,
1690,
68,
3321,
450,
713,
14,
19,
25154,
420,
450,
713,
14,
19,
25154,
2,
450,
971,
507,
198,
8,
17428,
459,
2374,
995,
19988,
459,
552,
995,
507,
198,
9618,
63,
4855,
8,
17428,
459,
1825,
63,
84,
3815,
507,
198,
9618,
63,
9618,
8,
17428,
459,
1825,
63,
84,
1105,
15,
5279,
12,
507,
198,
3028,
63,
19764,
8,
17428,
459,
1825,
63,
84,
995,
19988,
459,
14217,
63,
84,
3815,
507,
198,
3028,
63,
19764,
8,
17428,
459,
14217,
63,
84,
995,
19988,
459,
4624,
63,
84,
5156,
199,
199,
3,
9701,
367,
20589,
12951,
3644,
6661,
199,
10966,
63,
3927,
49,
63,
7285,
29,
298,
221,
10476,
63,
2373,
28643,
19,
25154,
10476,
2458,
68,
2689,
83,
2924,
199,
10966,
63,
26999,
63,
7285,
628,
221,
880,
15493,
63,
2373,
28643,
19,
25154,
2924,
199,
10966,
63,
46,
3735,
63,
16428,
29,
298,
221,
302,
1246,
63,
6843,
63,
2224,
28643,
19,
25154,
450,
83,
2924,
199,
10966,
63,
24931,
29,
258,
298,
260,
1204,
2,
199,
10966,
63,
55,
24931,
29,
259,
298,
260,
1204,
3322,
1204,
2,
199,
10966,
63,
7278,
63,
9481,
54,
29,
221,
298,
260,
1204,
2595,
20869,
63,
9391,
63,
6852,
28643,
19,
25154,
11448,
2458,
88,
822,
2458,
68,
2924,
199,
10966,
63,
7278,
63,
15361,
29,
259,
298,
260,
1204,
2595,
20869,
63,
6872,
28643,
19,
25154,
11448,
2458,
88,
2924,
199,
10966,
63,
2890,
57,
63,
25351,
29,
298,
260,
1204,
420,
11448,
63,
1574,
63,
25443,
63,
30463,
28643,
19,
25154,
450,
68,
2689,
83,
2924,
199,
10966,
63,
17706,
5271,
63,
8656,
34,
29,
298,
260,
1204,
420,
1022,
4624,
63,
6852,
28643,
19,
25154,
2909,
2458,
88,
2924,
199,
10966,
63,
1864,
51,
63,
8656,
34,
29,
221,
298,
260,
1204,
420,
9451,
63,
6852,
28643,
19,
25154,
2924,
199,
199,
3,
12175,
282,
2112,
402,
3086,
14593,
436,
1640,
82,
524,
83,
4568,
543,
199,
3,
282,
18340,
63,
15361,
880,
15493,
199,
318,
870,
63,
9391,
8,
17428,
304,
199,
198,
2384,
63,
17428,
275,
378,
199,
198,
7277,
63,
513,
275,
19988,
459,
7277,
63,
513,
418,
199,
198,
3541,
275,
10476,
63,
513,
59,
16,
2733,
3541,
418,
199,
198,
1095,
63,
84,
275,
10476,
63,
513,
59,
16,
2733,
7277,
63,
484,
63,
84,
418,
199,
198,
3,
1104,
340,
642,
19988,
1077,
506,
2498,
379,
199,
198,
692,
4866,
1137,
378,
26,
507,
198,
509,
284,
315,
1425,
8,
552,
8,
7277,
63,
513,
2298,
686,
198,
692,
10476,
63,
513,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
windyuuy/opera
|
chromium/src/third_party/python_26/Lib/site-packages/isapi/samples/test.py
|
21
|
6282
|
# This extension is used mainly for testing purposes - it is not
# designed to be a simple sample, but instead is a hotch-potch of things
# that attempts to exercise the framework.
from isapi import isapicon
from isapi.simple import SimpleExtension
import sys, os, stat
if hasattr(sys, "isapidllhandle"):
import win32traceutil
# We use the same reload support as 'advanced.py' demonstrates.
from isapi import InternalReloadException
import win32event, win32file, winerror, win32con, threading
# A watcher thread that checks for __file__ changing.
# When it detects it, it simply sets "change_detected" to true.
class ReloadWatcherThread(threading.Thread):
def __init__(self):
self.change_detected = False
self.filename = __file__
if self.filename.endswith("c") or self.filename.endswith("o"):
self.filename = self.filename[:-1]
self.handle = win32file.FindFirstChangeNotification(
os.path.dirname(self.filename),
False, # watch tree?
win32con.FILE_NOTIFY_CHANGE_LAST_WRITE)
threading.Thread.__init__(self)
def run(self):
last_time = os.stat(self.filename)[stat.ST_MTIME]
while 1:
try:
rc = win32event.WaitForSingleObject(self.handle,
win32event.INFINITE)
win32file.FindNextChangeNotification(self.handle)
except win32event.error, details:
# handle closed - thread should terminate.
if details[0] != winerror.ERROR_INVALID_HANDLE:
raise
break
this_time = os.stat(self.filename)[stat.ST_MTIME]
if this_time != last_time:
print "Detected file change - flagging for reload."
self.change_detected = True
last_time = this_time
def stop(self):
win32file.FindCloseChangeNotification(self.handle)
def TransmitFileCallback(ecb, hFile, cbIO, errCode):
print "Transmit complete!"
ecb.close()
# The ISAPI extension - handles requests in our virtual dir, and sends the
# response to the client.
class Extension(SimpleExtension):
"Python test Extension"
def __init__(self):
self.reload_watcher = ReloadWatcherThread()
self.reload_watcher.start()
def HttpExtensionProc(self, ecb):
# NOTE: If you use a ThreadPoolExtension, you must still perform
# this check in HttpExtensionProc - raising the exception from
# The "Dispatch" method will just cause the exception to be
# rendered to the browser.
if self.reload_watcher.change_detected:
print "Doing reload"
raise InternalReloadException
if ecb.GetServerVariable("URL").endswith("test.py"):
file_flags = win32con.FILE_FLAG_SEQUENTIAL_SCAN | win32con.FILE_FLAG_OVERLAPPED
hfile = win32file.CreateFile(__file__, win32con.GENERIC_READ,
0, None, win32con.OPEN_EXISTING,
file_flags, None)
flags = isapicon.HSE_IO_ASYNC | isapicon.HSE_IO_DISCONNECT_AFTER_SEND | \
isapicon.HSE_IO_SEND_HEADERS
# We pass hFile to the callback simply as a way of keeping it alive
# for the duration of the transmission
try:
ecb.TransmitFile(TransmitFileCallback, hfile,
int(hfile),
"200 OK",
0, 0, None, None, flags)
except:
# Errors keep this source file open!
hfile.Close()
raise
else:
# default response
ecb.SendResponseHeaders("200 OK", "Content-Type: text/html\r\n\r\n", 0)
print >> ecb, "<HTML><BODY>"
print >> ecb, "The root of this site is at", ecb.MapURLToPath("/")
print >> ecb, "</BODY></HTML>"
ecb.close()
return isapicon.HSE_STATUS_SUCCESS
def TerminateExtension(self, status):
self.reload_watcher.stop()
# The entry points for the ISAPI extension.
def __ExtensionFactory__():
return Extension()
# Our special command line customization.
# Pre-install hook for our virtual directory.
def PreInstallDirectory(params, options):
# If the user used our special '--description' option,
# then we override our default.
if options.description:
params.Description = options.description
# Post install hook for our entire script
def PostInstall(params, options):
print
print "The sample has been installed."
print "Point your browser to /PyISAPITest"
# Handler for our custom 'status' argument.
def status_handler(options, log, arg):
"Query the status of something"
print "Everything seems to be fine!"
custom_arg_handlers = {"status": status_handler}
if __name__=='__main__':
# If run from the command-line, install ourselves.
from isapi.install import *
params = ISAPIParameters(PostInstall = PostInstall)
# Setup the virtual directories - this is a list of directories our
# extension uses - in this case only 1.
# Each extension has a "script map" - this is the mapping of ISAPI
# extensions.
sm = [
ScriptMapParams(Extension="*", Flags=0)
]
vd = VirtualDirParameters(Name="PyISAPITest",
Description = Extension.__doc__,
ScriptMaps = sm,
ScriptMapUpdate = "replace",
# specify the pre-install hook.
PreInstall = PreInstallDirectory
)
params.VirtualDirs = [vd]
# Setup our custom option parser.
from optparse import OptionParser
parser = OptionParser('') # blank usage, so isapi sets it.
parser.add_option("", "--description",
action="store",
help="custom description to use for the virtual directory")
HandleCommandLine(params, opt_parser=parser,
custom_arg_handlers = custom_arg_handlers)
|
bsd-3-clause
|
[
3,
961,
3329,
365,
1202,
27580,
367,
5343,
12901,
446,
652,
365,
440,
199,
3,
19829,
370,
506,
282,
3486,
2690,
12,
1325,
3140,
365,
282,
18469,
335,
13,
14173,
335,
402,
7645,
199,
3,
626,
12454,
370,
26511,
314,
10059,
14,
199,
199,
504,
365,
1246,
492,
365,
1246,
388,
199,
504,
365,
1246,
14,
4129,
492,
5870,
6382,
199,
646,
984,
12,
747,
12,
5672,
199,
199,
692,
2688,
8,
1274,
12,
298,
374,
27703,
914,
2479,
2349,
272,
492,
4747,
708,
3446,
1974,
199,
199,
3,
2136,
675,
314,
2011,
13101,
2291,
465,
283,
14652,
14,
647,
7,
23789,
31216,
14,
199,
504,
365,
1246,
492,
12624,
30590,
1726,
199,
646,
4747,
708,
1430,
12,
4747,
708,
493,
12,
4747,
705,
12,
4747,
708,
388,
12,
5796,
199,
199,
3,
437,
9626,
281,
2462,
626,
5920,
367,
636,
493,
363,
13729,
14,
199,
3,
3979,
652,
477,
28853,
652,
12,
652,
9329,
5951,
298,
1461,
63,
25577,
2,
370,
2549,
14,
199,
533,
799,
912,
13978,
281,
4436,
8,
12562,
14,
4436,
304,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
1461,
63,
25577,
275,
756,
267,
291,
14,
1501,
275,
636,
493,
363,
267,
340,
291,
14,
1501,
14,
4130,
480,
67,
531,
503,
291,
14,
1501,
14,
4130,
480,
79,
2349,
288,
291,
14,
1501,
275,
291,
14,
1501,
4439,
17,
61,
267,
291,
14,
2479,
275,
4747,
708,
493,
14,
6591,
7147,
4001,
11598,
8,
717,
747,
14,
515,
14,
3475,
8,
277,
14,
1501,
395,
717,
756,
12,
327,
9626,
3123,
31,
717,
4747,
708,
388,
14,
3817,
63,
24972,
63,
16062,
63,
16901,
63,
10387,
9,
267,
5796,
14,
4436,
855,
826,
721,
277,
9,
339,
347,
1255,
8,
277,
304,
267,
2061,
63,
521,
275,
747,
14,
3736,
8,
277,
14,
1501,
2788,
3736,
14,
840,
63,
45,
4961,
61,
267,
1830,
413,
26,
288,
862,
26,
355,
4819,
275,
4747,
708,
1430,
14,
21433,
7200,
1692,
8,
277,
14,
2479,
12,
221,
8105,
4747,
708,
1430,
14,
32191,
4427,
9,
355,
4747,
708,
493,
14,
6591,
5765,
4001,
11598,
8,
277,
14,
2479,
9,
288,
871,
4747,
708,
1430,
14,
705,
12,
2436,
26,
355,
327,
2429,
6876,
446,
2462,
1077,
15095,
14,
355,
340,
2436,
59,
16,
61,
1137,
4747,
705,
14,
3170,
63,
9692,
63,
15885,
26,
490,
746,
355,
2059,
288,
642,
63,
521,
275,
747,
14,
3736,
8,
277,
14,
1501,
2788,
3736,
14,
840,
63,
45,
4961,
61,
288,
340,
642,
63,
521,
1137,
2061,
63,
521,
26,
355,
870,
298,
872,
4530,
570,
1570,
446,
3305,
1540,
367,
13101,
2122,
355,
291,
14,
1461,
63,
25577,
275,
715,
355,
2061,
63,
521,
275,
642,
63,
521,
2286,
347,
3631,
8,
277,
304,
267,
4747,
708,
493,
14,
6591,
4724,
4001,
11598,
8,
277,
14,
2479,
9,
199,
199,
318,
6266,
1147,
1173,
2806,
8,
25467,
12,
394,
1173,
12,
7434,
2090,
12,
2329,
3034,
304,
272,
870,
298,
3188,
1147,
4890,
9539,
272,
325,
2894,
14,
1600,
342,
1362,
199,
3,
710,
2281,
3735,
3329,
446,
10022,
4145,
315,
4154,
5791,
2935,
12,
436,
16178,
314,
199,
3,
1177,
370,
314,
1890,
14,
199,
533,
13282,
8,
3184,
6382,
304,
272,
298,
4718,
511,
13282,
2,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
9233,
63,
22226,
275,
799,
912,
13978,
281,
4436,
342,
267,
291,
14,
9233,
63,
22226,
14,
928,
342,
339,
347,
4760,
6382,
15019,
8,
277,
12,
325,
2894,
304,
267,
327,
6944,
26,
982,
1265,
675,
282,
11086,
5453,
6382,
12,
1265,
1471,
5139,
5147,
267,
327,
642,
1104,
315,
4760,
6382,
15019,
446,
17026,
314,
1919,
687,
267,
327,
710,
298,
20628,
2,
1083,
911,
2951,
7675,
314,
1919,
370,
506,
267,
327,
8018,
370,
314,
7042,
14,
267,
340,
291,
14,
9233,
63,
22226,
14,
1461,
63,
25577,
26,
288,
870,
298,
2585,
316,
13101,
2,
288,
746,
12624,
30590,
1726,
398,
340,
325,
2894,
14,
1002,
3120,
2773,
480,
2632,
3471,
4130,
480,
396,
14,
647,
2349,
288,
570,
63,
2469,
275,
4747,
708,
388,
14,
3817,
63,
3719,
63,
9020,
63,
24078,
221,
1204,
4747,
708,
388,
14,
3817,
63,
3719,
63,
14336,
44,
7121,
1149,
288,
394,
493,
275,
4747,
708,
493,
14,
2499,
1173,
3460,
493,
3108,
4747,
708,
388,
14,
29395,
63,
5670,
12,
1460,
378,
12,
488,
12,
4747,
708,
388,
14,
9935,
63,
13301,
1206,
12,
1460,
570,
63,
2469,
12,
488,
9,
288,
3285,
275,
365,
1246,
388,
14,
40,
899,
63,
2090,
63,
26222,
6389,
1204,
365,
1246,
388,
14,
40,
899,
63,
2090,
63,
6178,
14657,
63,
31883,
63,
20469,
1204,
971,
490,
365,
1246,
388,
14,
40,
899,
63,
2090,
63,
20469,
63,
21178,
288,
327,
2136,
986,
394,
1173,
370,
314,
3233,
9329,
465,
282,
4340,
402,
22181,
652,
19708,
288,
327,
367,
314,
7373,
402,
314,
1752,
2250,
288,
862,
26,
355,
325,
2894,
14,
3188,
1147,
1173,
8,
3188,
1147,
1173,
2806,
12,
394,
493,
12,
639,
1109,
8,
72,
493,
395,
639,
298,
1840,
9949,
401,
639,
378,
12,
378,
12,
488,
12,
488,
12,
3285,
9,
288,
871,
26,
355,
327,
20456,
4215,
642,
1350,
570,
1551,
1,
355,
394,
493,
14,
4724,
342,
355,
746,
267,
587,
26,
288,
327,
849,
1177,
288,
325,
2894,
14,
6795,
2364,
9883,
480,
1840,
9949,
401,
298,
2714,
13,
804,
26,
1318,
15,
1360,
60,
82,
60,
78,
60,
82,
60,
78,
401,
378,
9,
288,
870,
4331,
325,
2894,
12,
3886,
4943,
2535,
23708,
4335,
288,
870,
4331,
325,
2894,
12,
298,
1918,
1738,
402,
642,
4770,
365,
737,
401,
325,
2894,
14,
2956,
2632,
1378,
2042,
19031,
288,
870,
4331,
325,
2894,
12,
15683,
23708,
2957,
4943,
4335,
288,
325,
2894,
14,
1600,
342,
267,
372,
365,
1246,
388,
14,
40,
899,
63,
6305,
63,
12779,
2286,
347,
20429,
323,
6382,
8,
277,
12,
2004,
304,
267,
291,
14,
9233,
63,
22226,
14,
2379,
342,
199,
199,
3,
710,
2397,
4501,
367,
314,
2281,
3735,
3329,
14,
199,
318,
636,
6382,
2927,
721,
304,
272,
372,
13282,
342,
199,
199,
3
] |
[
961,
3329,
365,
1202,
27580,
367,
5343,
12901,
446,
652,
365,
440,
199,
3,
19829,
370,
506,
282,
3486,
2690,
12,
1325,
3140,
365,
282,
18469,
335,
13,
14173,
335,
402,
7645,
199,
3,
626,
12454,
370,
26511,
314,
10059,
14,
199,
199,
504,
365,
1246,
492,
365,
1246,
388,
199,
504,
365,
1246,
14,
4129,
492,
5870,
6382,
199,
646,
984,
12,
747,
12,
5672,
199,
199,
692,
2688,
8,
1274,
12,
298,
374,
27703,
914,
2479,
2349,
272,
492,
4747,
708,
3446,
1974,
199,
199,
3,
2136,
675,
314,
2011,
13101,
2291,
465,
283,
14652,
14,
647,
7,
23789,
31216,
14,
199,
504,
365,
1246,
492,
12624,
30590,
1726,
199,
646,
4747,
708,
1430,
12,
4747,
708,
493,
12,
4747,
705,
12,
4747,
708,
388,
12,
5796,
199,
199,
3,
437,
9626,
281,
2462,
626,
5920,
367,
636,
493,
363,
13729,
14,
199,
3,
3979,
652,
477,
28853,
652,
12,
652,
9329,
5951,
298,
1461,
63,
25577,
2,
370,
2549,
14,
199,
533,
799,
912,
13978,
281,
4436,
8,
12562,
14,
4436,
304,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
1461,
63,
25577,
275,
756,
267,
291,
14,
1501,
275,
636,
493,
363,
267,
340,
291,
14,
1501,
14,
4130,
480,
67,
531,
503,
291,
14,
1501,
14,
4130,
480,
79,
2349,
288,
291,
14,
1501,
275,
291,
14,
1501,
4439,
17,
61,
267,
291,
14,
2479,
275,
4747,
708,
493,
14,
6591,
7147,
4001,
11598,
8,
717,
747,
14,
515,
14,
3475,
8,
277,
14,
1501,
395,
717,
756,
12,
327,
9626,
3123,
31,
717,
4747,
708,
388,
14,
3817,
63,
24972,
63,
16062,
63,
16901,
63,
10387,
9,
267,
5796,
14,
4436,
855,
826,
721,
277,
9,
339,
347,
1255,
8,
277,
304,
267,
2061,
63,
521,
275,
747,
14,
3736,
8,
277,
14,
1501,
2788,
3736,
14,
840,
63,
45,
4961,
61,
267,
1830,
413,
26,
288,
862,
26,
355,
4819,
275,
4747,
708,
1430,
14,
21433,
7200,
1692,
8,
277,
14,
2479,
12,
221,
8105,
4747,
708,
1430,
14,
32191,
4427,
9,
355,
4747,
708,
493,
14,
6591,
5765,
4001,
11598,
8,
277,
14,
2479,
9,
288,
871,
4747,
708,
1430,
14,
705,
12,
2436,
26,
355,
327,
2429,
6876,
446,
2462,
1077,
15095,
14,
355,
340,
2436,
59,
16,
61,
1137,
4747,
705,
14,
3170,
63,
9692,
63,
15885,
26,
490,
746,
355,
2059,
288,
642,
63,
521,
275,
747,
14,
3736,
8,
277,
14,
1501,
2788,
3736,
14,
840,
63,
45,
4961,
61,
288,
340,
642,
63,
521,
1137,
2061,
63,
521,
26,
355,
870,
298,
872,
4530,
570,
1570,
446,
3305,
1540,
367,
13101,
2122,
355,
291,
14,
1461,
63,
25577,
275,
715,
355,
2061,
63,
521,
275,
642,
63,
521,
2286,
347,
3631,
8,
277,
304,
267,
4747,
708,
493,
14,
6591,
4724,
4001,
11598,
8,
277,
14,
2479,
9,
199,
199,
318,
6266,
1147,
1173,
2806,
8,
25467,
12,
394,
1173,
12,
7434,
2090,
12,
2329,
3034,
304,
272,
870,
298,
3188,
1147,
4890,
9539,
272,
325,
2894,
14,
1600,
342,
1362,
199,
3,
710,
2281,
3735,
3329,
446,
10022,
4145,
315,
4154,
5791,
2935,
12,
436,
16178,
314,
199,
3,
1177,
370,
314,
1890,
14,
199,
533,
13282,
8,
3184,
6382,
304,
272,
298,
4718,
511,
13282,
2,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
9233,
63,
22226,
275,
799,
912,
13978,
281,
4436,
342,
267,
291,
14,
9233,
63,
22226,
14,
928,
342,
339,
347,
4760,
6382,
15019,
8,
277,
12,
325,
2894,
304,
267,
327,
6944,
26,
982,
1265,
675,
282,
11086,
5453,
6382,
12,
1265,
1471,
5139,
5147,
267,
327,
642,
1104,
315,
4760,
6382,
15019,
446,
17026,
314,
1919,
687,
267,
327,
710,
298,
20628,
2,
1083,
911,
2951,
7675,
314,
1919,
370,
506,
267,
327,
8018,
370,
314,
7042,
14,
267,
340,
291,
14,
9233,
63,
22226,
14,
1461,
63,
25577,
26,
288,
870,
298,
2585,
316,
13101,
2,
288,
746,
12624,
30590,
1726,
398,
340,
325,
2894,
14,
1002,
3120,
2773,
480,
2632,
3471,
4130,
480,
396,
14,
647,
2349,
288,
570,
63,
2469,
275,
4747,
708,
388,
14,
3817,
63,
3719,
63,
9020,
63,
24078,
221,
1204,
4747,
708,
388,
14,
3817,
63,
3719,
63,
14336,
44,
7121,
1149,
288,
394,
493,
275,
4747,
708,
493,
14,
2499,
1173,
3460,
493,
3108,
4747,
708,
388,
14,
29395,
63,
5670,
12,
1460,
378,
12,
488,
12,
4747,
708,
388,
14,
9935,
63,
13301,
1206,
12,
1460,
570,
63,
2469,
12,
488,
9,
288,
3285,
275,
365,
1246,
388,
14,
40,
899,
63,
2090,
63,
26222,
6389,
1204,
365,
1246,
388,
14,
40,
899,
63,
2090,
63,
6178,
14657,
63,
31883,
63,
20469,
1204,
971,
490,
365,
1246,
388,
14,
40,
899,
63,
2090,
63,
20469,
63,
21178,
288,
327,
2136,
986,
394,
1173,
370,
314,
3233,
9329,
465,
282,
4340,
402,
22181,
652,
19708,
288,
327,
367,
314,
7373,
402,
314,
1752,
2250,
288,
862,
26,
355,
325,
2894,
14,
3188,
1147,
1173,
8,
3188,
1147,
1173,
2806,
12,
394,
493,
12,
639,
1109,
8,
72,
493,
395,
639,
298,
1840,
9949,
401,
639,
378,
12,
378,
12,
488,
12,
488,
12,
3285,
9,
288,
871,
26,
355,
327,
20456,
4215,
642,
1350,
570,
1551,
1,
355,
394,
493,
14,
4724,
342,
355,
746,
267,
587,
26,
288,
327,
849,
1177,
288,
325,
2894,
14,
6795,
2364,
9883,
480,
1840,
9949,
401,
298,
2714,
13,
804,
26,
1318,
15,
1360,
60,
82,
60,
78,
60,
82,
60,
78,
401,
378,
9,
288,
870,
4331,
325,
2894,
12,
3886,
4943,
2535,
23708,
4335,
288,
870,
4331,
325,
2894,
12,
298,
1918,
1738,
402,
642,
4770,
365,
737,
401,
325,
2894,
14,
2956,
2632,
1378,
2042,
19031,
288,
870,
4331,
325,
2894,
12,
15683,
23708,
2957,
4943,
4335,
288,
325,
2894,
14,
1600,
342,
267,
372,
365,
1246,
388,
14,
40,
899,
63,
6305,
63,
12779,
2286,
347,
20429,
323,
6382,
8,
277,
12,
2004,
304,
267,
291,
14,
9233,
63,
22226,
14,
2379,
342,
199,
199,
3,
710,
2397,
4501,
367,
314,
2281,
3735,
3329,
14,
199,
318,
636,
6382,
2927,
721,
304,
272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
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
fenginx/django
|
django/contrib/gis/gdal/field.py
|
59
|
6626
|
from ctypes import byref, c_int
from datetime import date, datetime, time
from django.contrib.gis.gdal.base import GDALBase
from django.contrib.gis.gdal.error import GDALException
from django.contrib.gis.gdal.prototypes import ds as capi
from django.utils.encoding import force_str
# For more information, see the OGR C API source code:
# https://www.gdal.org/ogr__api_8h.html
#
# The OGR_Fld_* routines are relevant here.
class Field(GDALBase):
"""
Wrap an OGR Field. Needs to be instantiated from a Feature object.
"""
def __init__(self, feat, index):
"""
Initialize on the feature object and the integer index of
the field within the feature.
"""
# Setting the feature pointer and index.
self._feat = feat
self._index = index
# Getting the pointer for this field.
fld_ptr = capi.get_feat_field_defn(feat.ptr, index)
if not fld_ptr:
raise GDALException('Cannot create OGR Field, invalid pointer given.')
self.ptr = fld_ptr
# Setting the class depending upon the OGR Field Type (OFT)
self.__class__ = OGRFieldTypes[self.type]
def __str__(self):
"Return the string representation of the Field."
return str(self.value).strip()
# #### Field Methods ####
def as_double(self):
"Retrieve the Field's value as a double (float)."
return capi.get_field_as_double(self._feat.ptr, self._index) if self.is_set else None
def as_int(self, is_64=False):
"Retrieve the Field's value as an integer."
if is_64:
return capi.get_field_as_integer64(self._feat.ptr, self._index) if self.is_set else None
else:
return capi.get_field_as_integer(self._feat.ptr, self._index) if self.is_set else None
def as_string(self):
"Retrieve the Field's value as a string."
if not self.is_set:
return None
string = capi.get_field_as_string(self._feat.ptr, self._index)
return force_str(string, encoding=self._feat.encoding, strings_only=True)
def as_datetime(self):
"Retrieve the Field's value as a tuple of date & time components."
if not self.is_set:
return None
yy, mm, dd, hh, mn, ss, tz = [c_int() for i in range(7)]
status = capi.get_field_as_datetime(
self._feat.ptr, self._index, byref(yy), byref(mm), byref(dd),
byref(hh), byref(mn), byref(ss), byref(tz))
if status:
return (yy, mm, dd, hh, mn, ss, tz)
else:
raise GDALException('Unable to retrieve date & time information from the field.')
# #### Field Properties ####
@property
def is_set(self):
"Return True if the value of this field isn't null, False otherwise."
return capi.is_field_set(self._feat.ptr, self._index)
@property
def name(self):
"Return the name of this Field."
name = capi.get_field_name(self.ptr)
return force_str(name, encoding=self._feat.encoding, strings_only=True)
@property
def precision(self):
"Return the precision of this Field."
return capi.get_field_precision(self.ptr)
@property
def type(self):
"Return the OGR type of this Field."
return capi.get_field_type(self.ptr)
@property
def type_name(self):
"Return the OGR field type name for this Field."
return capi.get_field_type_name(self.type)
@property
def value(self):
"Return the value of this Field."
# Default is to get the field as a string.
return self.as_string()
@property
def width(self):
"Return the width of this Field."
return capi.get_field_width(self.ptr)
# ### The Field sub-classes for each OGR Field type. ###
class OFTInteger(Field):
_bit64 = False
@property
def value(self):
"Return an integer contained in this field."
return self.as_int(self._bit64)
@property
def type(self):
"""
GDAL uses OFTReals to represent OFTIntegers in created
shapefiles -- forcing the type here since the underlying field
type may actually be OFTReal.
"""
return 0
class OFTReal(Field):
@property
def value(self):
"Return a float contained in this field."
return self.as_double()
# String & Binary fields, just subclasses
class OFTString(Field):
pass
class OFTWideString(Field):
pass
class OFTBinary(Field):
pass
# OFTDate, OFTTime, OFTDateTime fields.
class OFTDate(Field):
@property
def value(self):
"Return a Python `date` object for the OFTDate field."
try:
yy, mm, dd, hh, mn, ss, tz = self.as_datetime()
return date(yy.value, mm.value, dd.value)
except (TypeError, ValueError, GDALException):
return None
class OFTDateTime(Field):
@property
def value(self):
"Return a Python `datetime` object for this OFTDateTime field."
# TODO: Adapt timezone information.
# See https://lists.osgeo.org/pipermail/gdal-dev/2006-February/007990.html
# The `tz` variable has values of: 0=unknown, 1=localtime (ambiguous),
# 100=GMT, 104=GMT+1, 80=GMT-5, etc.
try:
yy, mm, dd, hh, mn, ss, tz = self.as_datetime()
return datetime(yy.value, mm.value, dd.value, hh.value, mn.value, ss.value)
except (TypeError, ValueError, GDALException):
return None
class OFTTime(Field):
@property
def value(self):
"Return a Python `time` object for this OFTTime field."
try:
yy, mm, dd, hh, mn, ss, tz = self.as_datetime()
return time(hh.value, mn.value, ss.value)
except (ValueError, GDALException):
return None
class OFTInteger64(OFTInteger):
_bit64 = True
# List fields are also just subclasses
class OFTIntegerList(Field):
pass
class OFTRealList(Field):
pass
class OFTStringList(Field):
pass
class OFTWideStringList(Field):
pass
class OFTInteger64List(Field):
pass
# Class mapping dictionary for OFT Types and reverse mapping.
OGRFieldTypes = {
0: OFTInteger,
1: OFTIntegerList,
2: OFTReal,
3: OFTRealList,
4: OFTString,
5: OFTStringList,
6: OFTWideString,
7: OFTWideStringList,
8: OFTBinary,
9: OFTDate,
10: OFTTime,
11: OFTDateTime,
# New 64-bit integer types in GDAL 2
12: OFTInteger64,
13: OFTInteger64List,
}
ROGRFieldTypes = {cls: num for num, cls in OGRFieldTypes.items()}
|
bsd-3-clause
|
[
504,
5577,
492,
15968,
12,
286,
63,
442,
199,
504,
2197,
492,
1434,
12,
2197,
12,
900,
199,
199,
504,
1639,
14,
2828,
14,
5668,
14,
11600,
14,
1095,
492,
15801,
1563,
199,
504,
1639,
14,
2828,
14,
5668,
14,
11600,
14,
705,
492,
15801,
1726,
199,
504,
1639,
14,
2828,
14,
5668,
14,
11600,
14,
16141,
83,
492,
6364,
465,
13648,
199,
504,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
495,
421,
199,
3,
2104,
1655,
2556,
12,
1937,
314,
10904,
445,
3261,
1350,
1233,
26,
199,
3,
221,
4178,
921,
1544,
14,
11600,
14,
1308,
15,
14945,
363,
1246,
63,
24,
72,
14,
1360,
199,
3,
199,
3,
710,
10904,
63,
38,
1447,
15192,
14975,
787,
12082,
2348,
14,
199,
533,
5024,
8,
17835,
1563,
304,
272,
408,
272,
20322,
376,
10904,
5024,
14,
29613,
370,
506,
17544,
687,
282,
13407,
909,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
13953,
12,
1478,
304,
267,
408,
267,
11578,
641,
314,
3878,
909,
436,
314,
3000,
1478,
402,
267,
314,
901,
4453,
314,
3878,
14,
267,
408,
267,
327,
13510,
314,
3878,
7849,
436,
1478,
14,
267,
291,
423,
11873,
275,
13953,
267,
291,
423,
1080,
275,
1478,
398,
327,
20703,
314,
7849,
367,
642,
901,
14,
267,
22928,
63,
4695,
275,
13648,
14,
362,
63,
11873,
63,
698,
63,
27950,
8,
11873,
14,
4695,
12,
1478,
9,
267,
340,
440,
22928,
63,
4695,
26,
288,
746,
15801,
1726,
360,
6612,
1218,
10904,
5024,
12,
3866,
7849,
1627,
2659,
267,
291,
14,
4695,
275,
22928,
63,
4695,
398,
327,
13510,
314,
1021,
10298,
12188,
314,
10904,
5024,
2434,
334,
47,
2161,
9,
267,
291,
855,
533,
363,
275,
10904,
792,
4100,
59,
277,
14,
466,
61,
339,
347,
636,
495,
721,
277,
304,
267,
298,
1767,
314,
1059,
6025,
402,
314,
5024,
2122,
267,
372,
620,
8,
277,
14,
585,
680,
1913,
342,
339,
327,
14055,
5024,
17653,
14055,
272,
347,
465,
63,
3157,
8,
277,
304,
267,
298,
15310,
314,
5024,
1159,
574,
465,
282,
4270,
334,
1609,
17617,
267,
372,
13648,
14,
362,
63,
698,
63,
305,
63,
3157,
8,
277,
423,
11873,
14,
4695,
12,
291,
423,
1080,
9,
340,
291,
14,
374,
63,
409,
587,
488,
339,
347,
465,
63,
442,
8,
277,
12,
365,
63,
772,
29,
797,
304,
267,
298,
15310,
314,
5024,
1159,
574,
465,
376,
3000,
2122,
267,
340,
365,
63,
772,
26,
288,
372,
13648,
14,
362,
63,
698,
63,
305,
63,
4115,
772,
8,
277,
423,
11873,
14,
4695,
12,
291,
423,
1080,
9,
340,
291,
14,
374,
63,
409,
587,
488,
267,
587,
26,
288,
372,
13648,
14,
362,
63,
698,
63,
305,
63,
4115,
8,
277,
423,
11873,
14,
4695,
12,
291,
423,
1080,
9,
340,
291,
14,
374,
63,
409,
587,
488,
339,
347,
465,
63,
875,
8,
277,
304,
267,
298,
15310,
314,
5024,
1159,
574,
465,
282,
1059,
2122,
267,
340,
440,
291,
14,
374,
63,
409,
26,
288,
372,
488,
267,
1059,
275,
13648,
14,
362,
63,
698,
63,
305,
63,
875,
8,
277,
423,
11873,
14,
4695,
12,
291,
423,
1080,
9,
267,
372,
3542,
63,
495,
8,
875,
12,
2644,
29,
277,
423,
11873,
14,
2991,
12,
3326,
63,
2118,
29,
549,
9,
339,
347,
465,
63,
2083,
8,
277,
304,
267,
298,
15310,
314,
5024,
1159,
574,
465,
282,
2008,
402,
1434,
1253,
900,
7323,
2122,
267,
340,
440,
291,
14,
374,
63,
409,
26,
288,
372,
488,
267,
20435,
12,
8562,
12,
13972,
12,
25783,
12,
21945,
12,
10110,
12,
5823,
275,
359,
67,
63,
442,
342,
367,
284,
315,
1425,
8,
23,
1874,
267,
2004,
275,
13648,
14,
362,
63,
698,
63,
305,
63,
2083,
8,
288,
291,
423,
11873,
14,
4695,
12,
291,
423,
1080,
12,
15968,
8,
7566,
395,
15968,
8,
596,
395,
15968,
8,
617,
395,
288,
15968,
8,
12156,
395,
15968,
8,
10344,
395,
15968,
8,
385,
395,
15968,
8,
3903,
430,
267,
340,
2004,
26,
288,
372,
334,
7566,
12,
8562,
12,
13972,
12,
25783,
12,
21945,
12,
10110,
12,
5823,
9,
267,
587,
26,
288,
746,
15801,
1726,
360,
6005,
370,
8044,
1434,
1253,
900,
2556,
687,
314,
901,
2659,
339,
327,
14055,
5024,
19329,
14055,
272,
768,
1829,
272,
347,
365,
63,
409,
8,
277,
304,
267,
298,
1767,
715,
340,
314,
574,
402,
642,
901,
5712,
1133,
2973,
12,
756,
4257,
2122,
267,
372,
13648,
14,
374,
63,
698,
63,
409,
8,
277,
423,
11873,
14,
4695,
12,
291,
423,
1080,
9,
339,
768,
1829,
272,
347,
536,
8,
277,
304,
267,
298,
1767,
314,
536,
402,
642,
5024,
2122,
267,
536,
275,
13648,
14,
362,
63,
698,
63,
354,
8,
277,
14,
4695,
9,
267,
372,
3542,
63,
495,
8,
354,
12,
2644,
29,
277,
423,
11873,
14,
2991,
12,
3326,
63,
2118,
29,
549,
9,
339,
768,
1829,
272,
347,
7151,
8,
277,
304,
267,
298,
1767,
314,
7151,
402,
642,
5024,
2122,
267,
372,
13648,
14,
362,
63,
698,
63,
6833,
8,
277,
14,
4695,
9,
339,
768,
1829,
272,
347,
730,
8,
277,
304,
267,
298,
1767,
314,
10904,
730,
402,
642,
5024,
2122,
267,
372,
13648,
14,
362,
63,
698,
63,
466,
8,
277,
14,
4695,
9,
339,
768,
1829,
272,
347,
730,
63,
354,
8,
277,
304,
267,
298,
1767,
314,
10904,
901,
730,
536,
367,
642,
5024,
2122,
267,
372,
13648,
14,
362,
63,
698,
63,
466,
63,
354,
8,
277,
14,
466,
9,
339,
768,
1829,
272,
347,
574,
8,
277,
304,
267,
298,
1767,
314,
574,
402,
642,
5024,
2122,
267,
327,
3758,
365,
370,
664,
314,
901,
465,
282,
1059,
14,
267,
372,
291,
14,
305,
63,
875,
342,
339,
768,
1829,
272,
347,
3462,
8,
277,
304,
267,
298,
1767,
314,
3462,
402,
642,
5024,
2122,
267,
372,
13648,
14,
362,
63,
698,
63,
2063,
8,
277,
14,
4695,
9,
421,
199,
3,
6754,
710,
5024,
1007,
13,
2888,
367,
1924,
10904,
5024,
730,
14,
6754,
199,
533,
20025,
2674,
8,
792,
304,
272,
485,
2075,
772,
275,
756,
339,
768,
1829,
272,
347,
574,
8,
277,
304,
267,
298
] |
[
5577,
492,
15968,
12,
286,
63,
442,
199,
504,
2197,
492,
1434,
12,
2197,
12,
900,
199,
199,
504,
1639,
14,
2828,
14,
5668,
14,
11600,
14,
1095,
492,
15801,
1563,
199,
504,
1639,
14,
2828,
14,
5668,
14,
11600,
14,
705,
492,
15801,
1726,
199,
504,
1639,
14,
2828,
14,
5668,
14,
11600,
14,
16141,
83,
492,
6364,
465,
13648,
199,
504,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
495,
421,
199,
3,
2104,
1655,
2556,
12,
1937,
314,
10904,
445,
3261,
1350,
1233,
26,
199,
3,
221,
4178,
921,
1544,
14,
11600,
14,
1308,
15,
14945,
363,
1246,
63,
24,
72,
14,
1360,
199,
3,
199,
3,
710,
10904,
63,
38,
1447,
15192,
14975,
787,
12082,
2348,
14,
199,
533,
5024,
8,
17835,
1563,
304,
272,
408,
272,
20322,
376,
10904,
5024,
14,
29613,
370,
506,
17544,
687,
282,
13407,
909,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
13953,
12,
1478,
304,
267,
408,
267,
11578,
641,
314,
3878,
909,
436,
314,
3000,
1478,
402,
267,
314,
901,
4453,
314,
3878,
14,
267,
408,
267,
327,
13510,
314,
3878,
7849,
436,
1478,
14,
267,
291,
423,
11873,
275,
13953,
267,
291,
423,
1080,
275,
1478,
398,
327,
20703,
314,
7849,
367,
642,
901,
14,
267,
22928,
63,
4695,
275,
13648,
14,
362,
63,
11873,
63,
698,
63,
27950,
8,
11873,
14,
4695,
12,
1478,
9,
267,
340,
440,
22928,
63,
4695,
26,
288,
746,
15801,
1726,
360,
6612,
1218,
10904,
5024,
12,
3866,
7849,
1627,
2659,
267,
291,
14,
4695,
275,
22928,
63,
4695,
398,
327,
13510,
314,
1021,
10298,
12188,
314,
10904,
5024,
2434,
334,
47,
2161,
9,
267,
291,
855,
533,
363,
275,
10904,
792,
4100,
59,
277,
14,
466,
61,
339,
347,
636,
495,
721,
277,
304,
267,
298,
1767,
314,
1059,
6025,
402,
314,
5024,
2122,
267,
372,
620,
8,
277,
14,
585,
680,
1913,
342,
339,
327,
14055,
5024,
17653,
14055,
272,
347,
465,
63,
3157,
8,
277,
304,
267,
298,
15310,
314,
5024,
1159,
574,
465,
282,
4270,
334,
1609,
17617,
267,
372,
13648,
14,
362,
63,
698,
63,
305,
63,
3157,
8,
277,
423,
11873,
14,
4695,
12,
291,
423,
1080,
9,
340,
291,
14,
374,
63,
409,
587,
488,
339,
347,
465,
63,
442,
8,
277,
12,
365,
63,
772,
29,
797,
304,
267,
298,
15310,
314,
5024,
1159,
574,
465,
376,
3000,
2122,
267,
340,
365,
63,
772,
26,
288,
372,
13648,
14,
362,
63,
698,
63,
305,
63,
4115,
772,
8,
277,
423,
11873,
14,
4695,
12,
291,
423,
1080,
9,
340,
291,
14,
374,
63,
409,
587,
488,
267,
587,
26,
288,
372,
13648,
14,
362,
63,
698,
63,
305,
63,
4115,
8,
277,
423,
11873,
14,
4695,
12,
291,
423,
1080,
9,
340,
291,
14,
374,
63,
409,
587,
488,
339,
347,
465,
63,
875,
8,
277,
304,
267,
298,
15310,
314,
5024,
1159,
574,
465,
282,
1059,
2122,
267,
340,
440,
291,
14,
374,
63,
409,
26,
288,
372,
488,
267,
1059,
275,
13648,
14,
362,
63,
698,
63,
305,
63,
875,
8,
277,
423,
11873,
14,
4695,
12,
291,
423,
1080,
9,
267,
372,
3542,
63,
495,
8,
875,
12,
2644,
29,
277,
423,
11873,
14,
2991,
12,
3326,
63,
2118,
29,
549,
9,
339,
347,
465,
63,
2083,
8,
277,
304,
267,
298,
15310,
314,
5024,
1159,
574,
465,
282,
2008,
402,
1434,
1253,
900,
7323,
2122,
267,
340,
440,
291,
14,
374,
63,
409,
26,
288,
372,
488,
267,
20435,
12,
8562,
12,
13972,
12,
25783,
12,
21945,
12,
10110,
12,
5823,
275,
359,
67,
63,
442,
342,
367,
284,
315,
1425,
8,
23,
1874,
267,
2004,
275,
13648,
14,
362,
63,
698,
63,
305,
63,
2083,
8,
288,
291,
423,
11873,
14,
4695,
12,
291,
423,
1080,
12,
15968,
8,
7566,
395,
15968,
8,
596,
395,
15968,
8,
617,
395,
288,
15968,
8,
12156,
395,
15968,
8,
10344,
395,
15968,
8,
385,
395,
15968,
8,
3903,
430,
267,
340,
2004,
26,
288,
372,
334,
7566,
12,
8562,
12,
13972,
12,
25783,
12,
21945,
12,
10110,
12,
5823,
9,
267,
587,
26,
288,
746,
15801,
1726,
360,
6005,
370,
8044,
1434,
1253,
900,
2556,
687,
314,
901,
2659,
339,
327,
14055,
5024,
19329,
14055,
272,
768,
1829,
272,
347,
365,
63,
409,
8,
277,
304,
267,
298,
1767,
715,
340,
314,
574,
402,
642,
901,
5712,
1133,
2973,
12,
756,
4257,
2122,
267,
372,
13648,
14,
374,
63,
698,
63,
409,
8,
277,
423,
11873,
14,
4695,
12,
291,
423,
1080,
9,
339,
768,
1829,
272,
347,
536,
8,
277,
304,
267,
298,
1767,
314,
536,
402,
642,
5024,
2122,
267,
536,
275,
13648,
14,
362,
63,
698,
63,
354,
8,
277,
14,
4695,
9,
267,
372,
3542,
63,
495,
8,
354,
12,
2644,
29,
277,
423,
11873,
14,
2991,
12,
3326,
63,
2118,
29,
549,
9,
339,
768,
1829,
272,
347,
7151,
8,
277,
304,
267,
298,
1767,
314,
7151,
402,
642,
5024,
2122,
267,
372,
13648,
14,
362,
63,
698,
63,
6833,
8,
277,
14,
4695,
9,
339,
768,
1829,
272,
347,
730,
8,
277,
304,
267,
298,
1767,
314,
10904,
730,
402,
642,
5024,
2122,
267,
372,
13648,
14,
362,
63,
698,
63,
466,
8,
277,
14,
4695,
9,
339,
768,
1829,
272,
347,
730,
63,
354,
8,
277,
304,
267,
298,
1767,
314,
10904,
901,
730,
536,
367,
642,
5024,
2122,
267,
372,
13648,
14,
362,
63,
698,
63,
466,
63,
354,
8,
277,
14,
466,
9,
339,
768,
1829,
272,
347,
574,
8,
277,
304,
267,
298,
1767,
314,
574,
402,
642,
5024,
2122,
267,
327,
3758,
365,
370,
664,
314,
901,
465,
282,
1059,
14,
267,
372,
291,
14,
305,
63,
875,
342,
339,
768,
1829,
272,
347,
3462,
8,
277,
304,
267,
298,
1767,
314,
3462,
402,
642,
5024,
2122,
267,
372,
13648,
14,
362,
63,
698,
63,
2063,
8,
277,
14,
4695,
9,
421,
199,
3,
6754,
710,
5024,
1007,
13,
2888,
367,
1924,
10904,
5024,
730,
14,
6754,
199,
533,
20025,
2674,
8,
792,
304,
272,
485,
2075,
772,
275,
756,
339,
768,
1829,
272,
347,
574,
8,
277,
304,
267,
298,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,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
|
1272
|
"""
Django settings for testing django-nose.
Configuration is overriden by environment variables:
DATABASE_URL - See https://github.com/kennethreitz/dj-database-url
USE_SOUTH - Set to 1 to include South in INSTALLED_APPS
TEST_RUNNER - Dotted path of test runner to use (can also use --test-runner)
NOSE_PLUGINS - Comma-separated list of plugins to add
"""
from __future__ import print_function
from os import environ, path
import dj_database_url
BASE_DIR = path.dirname(path.dirname(__file__))
def rel_path(*subpaths):
"""Construct the full path given a relative path."""
return path.join(BASE_DIR, *subpaths)
DATABASES = {
'default':
dj_database_url.config(
default='sqlite:///' + rel_path('testapp.sqlite3'))
}
MIDDLEWARE_CLASSES = ()
INSTALLED_APPS = [
'django_nose',
'testapp',
]
if environ.get('USE_SOUTH', '0') in (1, '1'):
import south # Raise ImportError if not installed
assert south
INSTALLED_APPS.insert(0, 'south')
raw_test_runner = environ.get('TEST_RUNNER')
if raw_test_runner:
TEST_RUNNER = raw_test_runner
else:
TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
raw_plugins = environ.get('NOSE_PLUGINS')
if raw_plugins:
NOSE_PLUGINS = raw_plugins.split(',')
SECRET_KEY = 'ssshhhh'
|
bsd-3-clause
|
[
624,
199,
9323,
2202,
367,
5343,
1639,
13,
21085,
14,
199,
199,
5688,
365,
1806,
25045,
701,
3734,
2860,
26,
199,
199,
17873,
63,
2632,
446,
1666,
4178,
921,
5031,
14,
957,
15,
917,
685,
273,
264,
23751,
15,
18256,
13,
4659,
13,
633,
199,
4701,
63,
51,
1877,
40,
446,
2494,
370,
413,
370,
2387,
23150,
315,
31061,
63,
14219,
199,
2864,
63,
9390,
15215,
446,
24716,
471,
931,
402,
511,
7876,
370,
675,
334,
2425,
2597,
675,
1553,
396,
13,
5933,
9,
199,
2826,
899,
63,
16483,
10789,
446,
5429,
391,
13,
12794,
769,
402,
8963,
370,
1050,
199,
624,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
504,
747,
492,
6160,
12,
931,
199,
199,
646,
366,
74,
63,
4659,
63,
633,
199,
199,
5825,
63,
3022,
275,
931,
14,
3475,
8,
515,
14,
3475,
3460,
493,
8964,
421,
199,
318,
4668,
63,
515,
2031,
954,
3771,
304,
272,
408,
11493,
314,
2615,
931,
1627,
282,
3847,
931,
1041,
272,
372,
931,
14,
904,
8,
5825,
63,
3022,
12,
627,
954,
3771,
9,
199,
199,
27260,
275,
469,
272,
283,
885,
356,
267,
366,
74,
63,
4659,
63,
633,
14,
888,
8,
288,
849,
534,
10659,
921,
4805,
435,
4668,
63,
515,
360,
19700,
14,
10659,
19,
1333,
199,
93,
199,
199,
19987,
63,
13748,
275,
6248,
199,
199,
15942,
63,
14219,
275,
359,
272,
283,
1176,
63,
21085,
297,
272,
283,
19700,
297,
199,
61,
199,
692,
6160,
14,
362,
360,
4701,
63,
51,
1877,
40,
297,
283,
16,
358,
315,
334,
17,
12,
283,
17,
735,
272,
492,
12919,
221,
327,
14771,
3545,
340,
440,
4903,
272,
702,
12919,
272,
31061,
63,
14219,
14,
3176,
8,
16,
12,
283,
22607,
358,
199,
199,
1773,
63,
396,
63,
5933,
275,
6160,
14,
362,
360,
2864,
63,
9390,
15215,
358,
199,
692,
3066,
63,
396,
63,
5933,
26,
272,
7393,
63,
9390,
15215,
275,
3066,
63,
396,
63,
5933,
199,
2836,
26,
272,
7393,
63,
9390,
15215,
275,
283,
1176,
63,
21085,
14,
1944,
261,
10591,
7446,
7,
199,
199,
1773,
63,
5265,
275,
6160,
14,
362,
360,
2826,
899,
63,
16483,
10789,
358,
199,
692,
3066,
63,
5265,
26,
272,
4825,
899,
63,
16483,
10789,
275,
3066,
63,
5265,
14,
1294,
11917,
199,
199,
12961,
63,
3078,
275,
283,
385,
609,
12156,
72,
7,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
9323,
2202,
367,
5343,
1639,
13,
21085,
14,
199,
199,
5688,
365,
1806,
25045,
701,
3734,
2860,
26,
199,
199,
17873,
63,
2632,
446,
1666,
4178,
921,
5031,
14,
957,
15,
917,
685,
273,
264,
23751,
15,
18256,
13,
4659,
13,
633,
199,
4701,
63,
51,
1877,
40,
446,
2494,
370,
413,
370,
2387,
23150,
315,
31061,
63,
14219,
199,
2864,
63,
9390,
15215,
446,
24716,
471,
931,
402,
511,
7876,
370,
675,
334,
2425,
2597,
675,
1553,
396,
13,
5933,
9,
199,
2826,
899,
63,
16483,
10789,
446,
5429,
391,
13,
12794,
769,
402,
8963,
370,
1050,
199,
624,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
504,
747,
492,
6160,
12,
931,
199,
199,
646,
366,
74,
63,
4659,
63,
633,
199,
199,
5825,
63,
3022,
275,
931,
14,
3475,
8,
515,
14,
3475,
3460,
493,
8964,
421,
199,
318,
4668,
63,
515,
2031,
954,
3771,
304,
272,
408,
11493,
314,
2615,
931,
1627,
282,
3847,
931,
1041,
272,
372,
931,
14,
904,
8,
5825,
63,
3022,
12,
627,
954,
3771,
9,
199,
199,
27260,
275,
469,
272,
283,
885,
356,
267,
366,
74,
63,
4659,
63,
633,
14,
888,
8,
288,
849,
534,
10659,
921,
4805,
435,
4668,
63,
515,
360,
19700,
14,
10659,
19,
1333,
199,
93,
199,
199,
19987,
63,
13748,
275,
6248,
199,
199,
15942,
63,
14219,
275,
359,
272,
283,
1176,
63,
21085,
297,
272,
283,
19700,
297,
199,
61,
199,
692,
6160,
14,
362,
360,
4701,
63,
51,
1877,
40,
297,
283,
16,
358,
315,
334,
17,
12,
283,
17,
735,
272,
492,
12919,
221,
327,
14771,
3545,
340,
440,
4903,
272,
702,
12919,
272,
31061,
63,
14219,
14,
3176,
8,
16,
12,
283,
22607,
358,
199,
199,
1773,
63,
396,
63,
5933,
275,
6160,
14,
362,
360,
2864,
63,
9390,
15215,
358,
199,
692,
3066,
63,
396,
63,
5933,
26,
272,
7393,
63,
9390,
15215,
275,
3066,
63,
396,
63,
5933,
199,
2836,
26,
272,
7393,
63,
9390,
15215,
275,
283,
1176,
63,
21085,
14,
1944,
261,
10591,
7446,
7,
199,
199,
1773,
63,
5265,
275,
6160,
14,
362,
360,
2826,
899,
63,
16483,
10789,
358,
199,
692,
3066,
63,
5265,
26,
272,
4825,
899,
63,
16483,
10789,
275,
3066,
63,
5265,
14,
1294,
11917,
199,
199,
12961,
63,
3078,
275,
283,
385,
609,
12156,
72,
7,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
SiccarPoint/numpy
|
numpy/core/tests/test_unicode.py
|
33
|
14427
|
from __future__ import division, absolute_import, print_function
import sys
import numpy as np
from numpy.compat import asbytes, unicode, sixu
from numpy.testing import (
TestCase, run_module_suite, assert_, assert_equal, assert_array_equal)
# Guess the UCS length for this python interpreter
if sys.version_info[:2] >= (3, 3):
# Python 3.3 uses a flexible string representation
ucs4 = False
def buffer_length(arr):
if isinstance(arr, unicode):
arr = str(arr)
return (sys.getsizeof(arr+"a") - sys.getsizeof(arr)) * len(arr)
v = memoryview(arr)
if v.shape is None:
return len(v) * v.itemsize
else:
return np.prod(v.shape) * v.itemsize
elif sys.version_info[0] >= 3:
import array as _array
ucs4 = (_array.array('u').itemsize == 4)
def buffer_length(arr):
if isinstance(arr, unicode):
return _array.array('u').itemsize * len(arr)
v = memoryview(arr)
if v.shape is None:
return len(v) * v.itemsize
else:
return np.prod(v.shape) * v.itemsize
else:
if len(buffer(sixu('u'))) == 4:
ucs4 = True
else:
ucs4 = False
def buffer_length(arr):
if isinstance(arr, np.ndarray):
return len(arr.data)
return len(buffer(arr))
# In both cases below we need to make sure that the byte swapped value (as
# UCS4) is still a valid unicode:
# Value that can be represented in UCS2 interpreters
ucs2_value = sixu('\u0900')
# Value that cannot be represented in UCS2 interpreters (but can in UCS4)
ucs4_value = sixu('\U00100900')
def test_string_cast():
str_arr = np.array(["1234", "1234\0\0"], dtype='S')
uni_arr1 = str_arr.astype('>U')
uni_arr2 = str_arr.astype('<U')
if sys.version_info[0] < 3:
assert_array_equal(str_arr, uni_arr1)
assert_array_equal(str_arr, uni_arr2)
else:
assert_(str_arr != uni_arr1)
assert_(str_arr != uni_arr2)
assert_array_equal(uni_arr1, uni_arr2)
############################################################
# Creation tests
############################################################
class create_zeros(object):
"""Check the creation of zero-valued arrays"""
def content_check(self, ua, ua_scalar, nbytes):
# Check the length of the unicode base type
self.assertTrue(int(ua.dtype.str[2:]) == self.ulen)
# Check the length of the data buffer
self.assertTrue(buffer_length(ua) == nbytes)
# Small check that data in array element is ok
self.assertTrue(ua_scalar == sixu(''))
# Encode to ascii and double check
self.assertTrue(ua_scalar.encode('ascii') == asbytes(''))
# Check buffer lengths for scalars
if ucs4:
self.assertTrue(buffer_length(ua_scalar) == 0)
else:
self.assertTrue(buffer_length(ua_scalar) == 0)
def test_zeros0D(self):
# Check creation of 0-dimensional objects
ua = np.zeros((), dtype='U%s' % self.ulen)
self.content_check(ua, ua[()], 4*self.ulen)
def test_zerosSD(self):
# Check creation of single-dimensional objects
ua = np.zeros((2,), dtype='U%s' % self.ulen)
self.content_check(ua, ua[0], 4*self.ulen*2)
self.content_check(ua, ua[1], 4*self.ulen*2)
def test_zerosMD(self):
# Check creation of multi-dimensional objects
ua = np.zeros((2, 3, 4), dtype='U%s' % self.ulen)
self.content_check(ua, ua[0, 0, 0], 4*self.ulen*2*3*4)
self.content_check(ua, ua[-1, -1, -1], 4*self.ulen*2*3*4)
class test_create_zeros_1(create_zeros, TestCase):
"""Check the creation of zero-valued arrays (size 1)"""
ulen = 1
class test_create_zeros_2(create_zeros, TestCase):
"""Check the creation of zero-valued arrays (size 2)"""
ulen = 2
class test_create_zeros_1009(create_zeros, TestCase):
"""Check the creation of zero-valued arrays (size 1009)"""
ulen = 1009
class create_values(object):
"""Check the creation of unicode arrays with values"""
def content_check(self, ua, ua_scalar, nbytes):
# Check the length of the unicode base type
self.assertTrue(int(ua.dtype.str[2:]) == self.ulen)
# Check the length of the data buffer
self.assertTrue(buffer_length(ua) == nbytes)
# Small check that data in array element is ok
self.assertTrue(ua_scalar == self.ucs_value*self.ulen)
# Encode to UTF-8 and double check
self.assertTrue(ua_scalar.encode('utf-8') ==
(self.ucs_value*self.ulen).encode('utf-8'))
# Check buffer lengths for scalars
if ucs4:
self.assertTrue(buffer_length(ua_scalar) == 4*self.ulen)
else:
if self.ucs_value == ucs4_value:
# In UCS2, the \U0010FFFF will be represented using a
# surrogate *pair*
self.assertTrue(buffer_length(ua_scalar) == 2*2*self.ulen)
else:
# In UCS2, the \uFFFF will be represented using a
# regular 2-byte word
self.assertTrue(buffer_length(ua_scalar) == 2*self.ulen)
def test_values0D(self):
# Check creation of 0-dimensional objects with values
ua = np.array(self.ucs_value*self.ulen, dtype='U%s' % self.ulen)
self.content_check(ua, ua[()], 4*self.ulen)
def test_valuesSD(self):
# Check creation of single-dimensional objects with values
ua = np.array([self.ucs_value*self.ulen]*2, dtype='U%s' % self.ulen)
self.content_check(ua, ua[0], 4*self.ulen*2)
self.content_check(ua, ua[1], 4*self.ulen*2)
def test_valuesMD(self):
# Check creation of multi-dimensional objects with values
ua = np.array([[[self.ucs_value*self.ulen]*2]*3]*4, dtype='U%s' % self.ulen)
self.content_check(ua, ua[0, 0, 0], 4*self.ulen*2*3*4)
self.content_check(ua, ua[-1, -1, -1], 4*self.ulen*2*3*4)
class test_create_values_1_ucs2(create_values, TestCase):
"""Check the creation of valued arrays (size 1, UCS2 values)"""
ulen = 1
ucs_value = ucs2_value
class test_create_values_1_ucs4(create_values, TestCase):
"""Check the creation of valued arrays (size 1, UCS4 values)"""
ulen = 1
ucs_value = ucs4_value
class test_create_values_2_ucs2(create_values, TestCase):
"""Check the creation of valued arrays (size 2, UCS2 values)"""
ulen = 2
ucs_value = ucs2_value
class test_create_values_2_ucs4(create_values, TestCase):
"""Check the creation of valued arrays (size 2, UCS4 values)"""
ulen = 2
ucs_value = ucs4_value
class test_create_values_1009_ucs2(create_values, TestCase):
"""Check the creation of valued arrays (size 1009, UCS2 values)"""
ulen = 1009
ucs_value = ucs2_value
class test_create_values_1009_ucs4(create_values, TestCase):
"""Check the creation of valued arrays (size 1009, UCS4 values)"""
ulen = 1009
ucs_value = ucs4_value
############################################################
# Assignment tests
############################################################
class assign_values(object):
"""Check the assignment of unicode arrays with values"""
def content_check(self, ua, ua_scalar, nbytes):
# Check the length of the unicode base type
self.assertTrue(int(ua.dtype.str[2:]) == self.ulen)
# Check the length of the data buffer
self.assertTrue(buffer_length(ua) == nbytes)
# Small check that data in array element is ok
self.assertTrue(ua_scalar == self.ucs_value*self.ulen)
# Encode to UTF-8 and double check
self.assertTrue(ua_scalar.encode('utf-8') ==
(self.ucs_value*self.ulen).encode('utf-8'))
# Check buffer lengths for scalars
if ucs4:
self.assertTrue(buffer_length(ua_scalar) == 4*self.ulen)
else:
if self.ucs_value == ucs4_value:
# In UCS2, the \U0010FFFF will be represented using a
# surrogate *pair*
self.assertTrue(buffer_length(ua_scalar) == 2*2*self.ulen)
else:
# In UCS2, the \uFFFF will be represented using a
# regular 2-byte word
self.assertTrue(buffer_length(ua_scalar) == 2*self.ulen)
def test_values0D(self):
# Check assignment of 0-dimensional objects with values
ua = np.zeros((), dtype='U%s' % self.ulen)
ua[()] = self.ucs_value*self.ulen
self.content_check(ua, ua[()], 4*self.ulen)
def test_valuesSD(self):
# Check assignment of single-dimensional objects with values
ua = np.zeros((2,), dtype='U%s' % self.ulen)
ua[0] = self.ucs_value*self.ulen
self.content_check(ua, ua[0], 4*self.ulen*2)
ua[1] = self.ucs_value*self.ulen
self.content_check(ua, ua[1], 4*self.ulen*2)
def test_valuesMD(self):
# Check assignment of multi-dimensional objects with values
ua = np.zeros((2, 3, 4), dtype='U%s' % self.ulen)
ua[0, 0, 0] = self.ucs_value*self.ulen
self.content_check(ua, ua[0, 0, 0], 4*self.ulen*2*3*4)
ua[-1, -1, -1] = self.ucs_value*self.ulen
self.content_check(ua, ua[-1, -1, -1], 4*self.ulen*2*3*4)
class test_assign_values_1_ucs2(assign_values, TestCase):
"""Check the assignment of valued arrays (size 1, UCS2 values)"""
ulen = 1
ucs_value = ucs2_value
class test_assign_values_1_ucs4(assign_values, TestCase):
"""Check the assignment of valued arrays (size 1, UCS4 values)"""
ulen = 1
ucs_value = ucs4_value
class test_assign_values_2_ucs2(assign_values, TestCase):
"""Check the assignment of valued arrays (size 2, UCS2 values)"""
ulen = 2
ucs_value = ucs2_value
class test_assign_values_2_ucs4(assign_values, TestCase):
"""Check the assignment of valued arrays (size 2, UCS4 values)"""
ulen = 2
ucs_value = ucs4_value
class test_assign_values_1009_ucs2(assign_values, TestCase):
"""Check the assignment of valued arrays (size 1009, UCS2 values)"""
ulen = 1009
ucs_value = ucs2_value
class test_assign_values_1009_ucs4(assign_values, TestCase):
"""Check the assignment of valued arrays (size 1009, UCS4 values)"""
ulen = 1009
ucs_value = ucs4_value
############################################################
# Byteorder tests
############################################################
class byteorder_values:
"""Check the byteorder of unicode arrays in round-trip conversions"""
def test_values0D(self):
# Check byteorder of 0-dimensional objects
ua = np.array(self.ucs_value*self.ulen, dtype='U%s' % self.ulen)
ua2 = ua.newbyteorder()
# This changes the interpretation of the data region (but not the
# actual data), therefore the returned scalars are not
# the same (they are byte-swapped versions of each other).
self.assertTrue(ua[()] != ua2[()])
ua3 = ua2.newbyteorder()
# Arrays must be equal after the round-trip
assert_equal(ua, ua3)
def test_valuesSD(self):
# Check byteorder of single-dimensional objects
ua = np.array([self.ucs_value*self.ulen]*2, dtype='U%s' % self.ulen)
ua2 = ua.newbyteorder()
self.assertTrue((ua != ua2).all())
self.assertTrue(ua[-1] != ua2[-1])
ua3 = ua2.newbyteorder()
# Arrays must be equal after the round-trip
assert_equal(ua, ua3)
def test_valuesMD(self):
# Check byteorder of multi-dimensional objects
ua = np.array([[[self.ucs_value*self.ulen]*2]*3]*4,
dtype='U%s' % self.ulen)
ua2 = ua.newbyteorder()
self.assertTrue((ua != ua2).all())
self.assertTrue(ua[-1, -1, -1] != ua2[-1, -1, -1])
ua3 = ua2.newbyteorder()
# Arrays must be equal after the round-trip
assert_equal(ua, ua3)
def test_values_cast(self):
# Check byteorder of when casting the array for a strided and
# contiguous array:
test1 = np.array([self.ucs_value*self.ulen]*2, dtype='U%s' % self.ulen)
test2 = np.repeat(test1, 2)[::2]
for ua in (test1, test2):
ua2 = ua.astype(dtype=ua.dtype.newbyteorder())
self.assertTrue((ua == ua2).all())
self.assertTrue(ua[-1] == ua2[-1])
ua3 = ua2.astype(dtype=ua.dtype)
# Arrays must be equal after the round-trip
assert_equal(ua, ua3)
def test_values_updowncast(self):
# Check byteorder of when casting the array to a longer and shorter
# string length for strided and contiguous arrays
test1 = np.array([self.ucs_value*self.ulen]*2, dtype='U%s' % self.ulen)
test2 = np.repeat(test1, 2)[::2]
for ua in (test1, test2):
# Cast to a longer type with zero padding
longer_type = np.dtype('U%s' % (self.ulen+1)).newbyteorder()
ua2 = ua.astype(dtype=longer_type)
self.assertTrue((ua == ua2).all())
self.assertTrue(ua[-1] == ua2[-1])
# Cast back again with truncating:
ua3 = ua2.astype(dtype=ua.dtype)
# Arrays must be equal after the round-trip
assert_equal(ua, ua3)
class test_byteorder_1_ucs2(byteorder_values, TestCase):
"""Check the byteorder in unicode (size 1, UCS2 values)"""
ulen = 1
ucs_value = ucs2_value
class test_byteorder_1_ucs4(byteorder_values, TestCase):
"""Check the byteorder in unicode (size 1, UCS4 values)"""
ulen = 1
ucs_value = ucs4_value
class test_byteorder_2_ucs2(byteorder_values, TestCase):
"""Check the byteorder in unicode (size 2, UCS2 values)"""
ulen = 2
ucs_value = ucs2_value
class test_byteorder_2_ucs4(byteorder_values, TestCase):
"""Check the byteorder in unicode (size 2, UCS4 values)"""
ulen = 2
ucs_value = ucs4_value
class test_byteorder_1009_ucs2(byteorder_values, TestCase):
"""Check the byteorder in unicode (size 1009, UCS2 values)"""
ulen = 1009
ucs_value = ucs2_value
class test_byteorder_1009_ucs4(byteorder_values, TestCase):
"""Check the byteorder in unicode (size 1009, UCS4 values)"""
ulen = 1009
ucs_value = ucs4_value
if __name__ == "__main__":
run_module_suite()
|
bsd-3-clause
|
[
504,
636,
2443,
363,
492,
4629,
12,
3679,
63,
646,
12,
870,
63,
1593,
199,
199,
646,
984,
199,
199,
646,
2680,
465,
980,
199,
504,
2680,
14,
5819,
492,
28217,
12,
2649,
12,
3816,
85,
199,
504,
2680,
14,
4776,
492,
334,
272,
7640,
12,
1255,
63,
578,
63,
5768,
12,
702,
3131,
702,
63,
1452,
12,
702,
63,
1144,
63,
1452,
9,
199,
199,
3,
24570,
314,
21884,
2582,
367,
642,
2366,
12693,
199,
692,
984,
14,
1023,
63,
815,
1491,
18,
61,
2356,
334,
19,
12,
650,
304,
272,
327,
2018,
650,
14,
19,
4440,
282,
26841,
1059,
6025,
272,
27455,
20,
275,
756,
339,
347,
3335,
63,
1267,
8,
5250,
304,
267,
340,
1228,
8,
5250,
12,
2649,
304,
288,
7953,
275,
620,
8,
5250,
9,
288,
372,
334,
1274,
14,
362,
12590,
8,
5250,
5207,
65,
531,
446,
984,
14,
362,
12590,
8,
5250,
430,
627,
822,
8,
5250,
9,
267,
373,
275,
20228,
8,
5250,
9,
267,
340,
373,
14,
1392,
365,
488,
26,
288,
372,
822,
8,
86,
9,
627,
373,
14,
21210,
267,
587,
26,
288,
372,
980,
14,
8788,
8,
86,
14,
1392,
9,
627,
373,
14,
21210,
199,
4164,
984,
14,
1023,
63,
815,
59,
16,
61,
2356,
650,
26,
272,
492,
1625,
465,
485,
1144,
339,
27455,
20,
275,
6110,
1144,
14,
1144,
360,
85,
1959,
21210,
508,
841,
9,
339,
347,
3335,
63,
1267,
8,
5250,
304,
267,
340,
1228,
8,
5250,
12,
2649,
304,
288,
372,
485,
1144,
14,
1144,
360,
85,
1959,
21210,
627,
822,
8,
5250,
9,
267,
373,
275,
20228,
8,
5250,
9,
267,
340,
373,
14,
1392,
365,
488,
26,
288,
372,
822,
8,
86,
9,
627,
373,
14,
21210,
267,
587,
26,
288,
372,
980,
14,
8788,
8,
86,
14,
1392,
9,
627,
373,
14,
21210,
199,
2836,
26,
272,
340,
822,
8,
2738,
8,
4174,
85,
360,
85,
7058,
508,
841,
26,
267,
27455,
20,
275,
715,
272,
587,
26,
267,
27455,
20,
275,
756,
339,
347,
3335,
63,
1267,
8,
5250,
304,
267,
340,
1228,
8,
5250,
12,
980,
14,
8237,
304,
288,
372,
822,
8,
5250,
14,
576,
9,
267,
372,
822,
8,
2738,
8,
5250,
430,
199,
199,
3,
1010,
3865,
5560,
5084,
781,
1929,
370,
1852,
3238,
626,
314,
3696,
25072,
574,
334,
305,
199,
3,
21884,
20,
9,
365,
5139,
282,
1686,
2649,
26,
199,
3,
1594,
626,
883,
506,
11159,
315,
21884,
18,
6421,
878,
199,
23880,
18,
63,
585,
275,
3816,
85,
2258,
85,
1643,
383,
358,
199,
3,
1594,
626,
3913,
506,
11159,
315,
21884,
18,
6421,
878,
334,
7911,
883,
315,
21884,
20,
9,
199,
23880,
20,
63,
585,
275,
3816,
85,
2258,
53,
383,
1960,
17518,
358,
421,
199,
318,
511,
63,
875,
63,
2931,
837,
272,
620,
63,
5250,
275,
980,
14,
1144,
5234,
4321,
401,
298,
4321,
60,
16,
60,
16,
2255,
2152,
534,
51,
358,
272,
15439,
63,
5250,
17,
275,
620,
63,
5250,
14,
6041,
16099,
53,
358,
272,
15439,
63,
5250,
18,
275,
620,
63,
5250,
14,
6041,
4827,
53,
358,
339,
340,
984,
14,
1023,
63,
815,
59,
16,
61,
665,
650,
26,
267,
702,
63,
1144,
63,
1452,
8,
495,
63,
5250,
12,
15439,
63,
5250,
17,
9,
267,
702,
63,
1144,
63,
1452,
8,
495,
63,
5250,
12,
15439,
63,
5250,
18,
9,
272,
587,
26,
267,
702,
2531,
495,
63,
5250,
1137,
15439,
63,
5250,
17,
9,
267,
702,
2531,
495,
63,
5250,
1137,
15439,
63,
5250,
18,
9,
272,
702,
63,
1144,
63,
1452,
8,
5411,
63,
5250,
17,
12,
15439,
63,
5250,
18,
9,
421,
199,
26207,
381,
199,
3,
259,
9750,
425,
2295,
199,
26207,
381,
199,
199,
533,
1218,
63,
4250,
8,
785,
304,
272,
408,
1799,
314,
7143,
402,
4697,
13,
16611,
6572,
624,
339,
347,
1564,
63,
1074,
8,
277,
12,
18500,
12,
18500,
63,
7033,
12,
302,
2394,
304,
398,
327,
2670,
314,
2582,
402,
314,
2649,
1300,
730,
267,
291,
14,
1815,
8,
442,
8,
1458,
14,
2271,
14,
495,
59,
18,
5728,
508,
291,
14,
443,
78,
9,
267,
327,
2670,
314,
2582,
402,
314,
666,
3335,
267,
291,
14,
1815,
8,
2738,
63,
1267,
8,
1458,
9,
508,
302,
2394,
9,
267,
327,
23704,
1104,
626,
666,
315,
1625,
1819,
365,
4112,
267,
291,
14,
1815,
8,
1458,
63,
7033,
508,
3816,
85,
30991,
267,
327,
19244,
370,
13294,
436,
4270,
1104,
267,
291,
14,
1815,
8,
1458,
63,
7033,
14,
2143,
360,
4371,
358,
508,
28217,
30991,
267,
327,
2670,
3335,
17464,
367,
19945,
267,
340,
27455,
20,
26,
288,
291,
14,
1815,
8,
2738,
63,
1267,
8,
1458,
63,
7033,
9,
508,
378,
9,
267,
587,
26,
288,
291,
14,
1815,
8,
2738,
63,
1267,
8,
1458,
63,
7033,
9,
508,
378,
9,
339,
347,
511,
63,
4250,
16,
36,
8,
277,
304,
267,
327,
2670,
7143,
402,
378,
13,
13014,
2251,
267,
18500,
275,
980,
14,
4250,
8,
1062,
2152,
534,
53,
5,
83,
7,
450,
291,
14,
443,
78,
9,
267,
291,
14,
1317,
63,
1074,
8,
1458,
12,
18500,
59,
15618,
841,
10,
277,
14,
443,
78,
9,
339,
347,
511,
63,
4250,
3693,
8,
277,
304,
267,
327,
2670,
7143,
402,
2849,
13,
13014,
2251,
267,
18500,
275,
980,
14,
4250,
1332,
18,
4706,
2152,
534,
53,
5,
83,
7,
450,
291,
14,
443,
78,
9,
267,
291,
14,
1317,
63,
1074,
8,
1458,
12,
18500,
59,
16,
467,
841,
10,
277,
14,
443,
78,
10,
18,
9,
267,
291,
14,
1317,
63,
1074,
8,
1458,
12,
18500,
59,
17,
467,
841,
10,
277,
14,
443,
78,
10,
18,
9,
339,
347,
511,
63,
4250,
5127,
8,
277,
304,
267,
327,
2670,
7143,
402,
3510,
13,
13014,
2251,
267,
18500,
275,
980,
14,
4250,
1332,
18,
12,
650,
12,
841,
395,
2152,
534,
53,
5,
83,
7,
450,
291,
14,
443,
78,
9,
267,
291,
14,
1317,
63,
1074,
8,
1458,
12,
18500,
59,
16,
12,
378,
12,
378,
467,
841,
10,
277,
14,
443,
78,
10,
18,
10,
19,
10,
20,
9,
267,
291,
14,
1317,
63,
1074,
8
] |
[
636,
2443,
363,
492,
4629,
12,
3679,
63,
646,
12,
870,
63,
1593,
199,
199,
646,
984,
199,
199,
646,
2680,
465,
980,
199,
504,
2680,
14,
5819,
492,
28217,
12,
2649,
12,
3816,
85,
199,
504,
2680,
14,
4776,
492,
334,
272,
7640,
12,
1255,
63,
578,
63,
5768,
12,
702,
3131,
702,
63,
1452,
12,
702,
63,
1144,
63,
1452,
9,
199,
199,
3,
24570,
314,
21884,
2582,
367,
642,
2366,
12693,
199,
692,
984,
14,
1023,
63,
815,
1491,
18,
61,
2356,
334,
19,
12,
650,
304,
272,
327,
2018,
650,
14,
19,
4440,
282,
26841,
1059,
6025,
272,
27455,
20,
275,
756,
339,
347,
3335,
63,
1267,
8,
5250,
304,
267,
340,
1228,
8,
5250,
12,
2649,
304,
288,
7953,
275,
620,
8,
5250,
9,
288,
372,
334,
1274,
14,
362,
12590,
8,
5250,
5207,
65,
531,
446,
984,
14,
362,
12590,
8,
5250,
430,
627,
822,
8,
5250,
9,
267,
373,
275,
20228,
8,
5250,
9,
267,
340,
373,
14,
1392,
365,
488,
26,
288,
372,
822,
8,
86,
9,
627,
373,
14,
21210,
267,
587,
26,
288,
372,
980,
14,
8788,
8,
86,
14,
1392,
9,
627,
373,
14,
21210,
199,
4164,
984,
14,
1023,
63,
815,
59,
16,
61,
2356,
650,
26,
272,
492,
1625,
465,
485,
1144,
339,
27455,
20,
275,
6110,
1144,
14,
1144,
360,
85,
1959,
21210,
508,
841,
9,
339,
347,
3335,
63,
1267,
8,
5250,
304,
267,
340,
1228,
8,
5250,
12,
2649,
304,
288,
372,
485,
1144,
14,
1144,
360,
85,
1959,
21210,
627,
822,
8,
5250,
9,
267,
373,
275,
20228,
8,
5250,
9,
267,
340,
373,
14,
1392,
365,
488,
26,
288,
372,
822,
8,
86,
9,
627,
373,
14,
21210,
267,
587,
26,
288,
372,
980,
14,
8788,
8,
86,
14,
1392,
9,
627,
373,
14,
21210,
199,
2836,
26,
272,
340,
822,
8,
2738,
8,
4174,
85,
360,
85,
7058,
508,
841,
26,
267,
27455,
20,
275,
715,
272,
587,
26,
267,
27455,
20,
275,
756,
339,
347,
3335,
63,
1267,
8,
5250,
304,
267,
340,
1228,
8,
5250,
12,
980,
14,
8237,
304,
288,
372,
822,
8,
5250,
14,
576,
9,
267,
372,
822,
8,
2738,
8,
5250,
430,
199,
199,
3,
1010,
3865,
5560,
5084,
781,
1929,
370,
1852,
3238,
626,
314,
3696,
25072,
574,
334,
305,
199,
3,
21884,
20,
9,
365,
5139,
282,
1686,
2649,
26,
199,
3,
1594,
626,
883,
506,
11159,
315,
21884,
18,
6421,
878,
199,
23880,
18,
63,
585,
275,
3816,
85,
2258,
85,
1643,
383,
358,
199,
3,
1594,
626,
3913,
506,
11159,
315,
21884,
18,
6421,
878,
334,
7911,
883,
315,
21884,
20,
9,
199,
23880,
20,
63,
585,
275,
3816,
85,
2258,
53,
383,
1960,
17518,
358,
421,
199,
318,
511,
63,
875,
63,
2931,
837,
272,
620,
63,
5250,
275,
980,
14,
1144,
5234,
4321,
401,
298,
4321,
60,
16,
60,
16,
2255,
2152,
534,
51,
358,
272,
15439,
63,
5250,
17,
275,
620,
63,
5250,
14,
6041,
16099,
53,
358,
272,
15439,
63,
5250,
18,
275,
620,
63,
5250,
14,
6041,
4827,
53,
358,
339,
340,
984,
14,
1023,
63,
815,
59,
16,
61,
665,
650,
26,
267,
702,
63,
1144,
63,
1452,
8,
495,
63,
5250,
12,
15439,
63,
5250,
17,
9,
267,
702,
63,
1144,
63,
1452,
8,
495,
63,
5250,
12,
15439,
63,
5250,
18,
9,
272,
587,
26,
267,
702,
2531,
495,
63,
5250,
1137,
15439,
63,
5250,
17,
9,
267,
702,
2531,
495,
63,
5250,
1137,
15439,
63,
5250,
18,
9,
272,
702,
63,
1144,
63,
1452,
8,
5411,
63,
5250,
17,
12,
15439,
63,
5250,
18,
9,
421,
199,
26207,
381,
199,
3,
259,
9750,
425,
2295,
199,
26207,
381,
199,
199,
533,
1218,
63,
4250,
8,
785,
304,
272,
408,
1799,
314,
7143,
402,
4697,
13,
16611,
6572,
624,
339,
347,
1564,
63,
1074,
8,
277,
12,
18500,
12,
18500,
63,
7033,
12,
302,
2394,
304,
398,
327,
2670,
314,
2582,
402,
314,
2649,
1300,
730,
267,
291,
14,
1815,
8,
442,
8,
1458,
14,
2271,
14,
495,
59,
18,
5728,
508,
291,
14,
443,
78,
9,
267,
327,
2670,
314,
2582,
402,
314,
666,
3335,
267,
291,
14,
1815,
8,
2738,
63,
1267,
8,
1458,
9,
508,
302,
2394,
9,
267,
327,
23704,
1104,
626,
666,
315,
1625,
1819,
365,
4112,
267,
291,
14,
1815,
8,
1458,
63,
7033,
508,
3816,
85,
30991,
267,
327,
19244,
370,
13294,
436,
4270,
1104,
267,
291,
14,
1815,
8,
1458,
63,
7033,
14,
2143,
360,
4371,
358,
508,
28217,
30991,
267,
327,
2670,
3335,
17464,
367,
19945,
267,
340,
27455,
20,
26,
288,
291,
14,
1815,
8,
2738,
63,
1267,
8,
1458,
63,
7033,
9,
508,
378,
9,
267,
587,
26,
288,
291,
14,
1815,
8,
2738,
63,
1267,
8,
1458,
63,
7033,
9,
508,
378,
9,
339,
347,
511,
63,
4250,
16,
36,
8,
277,
304,
267,
327,
2670,
7143,
402,
378,
13,
13014,
2251,
267,
18500,
275,
980,
14,
4250,
8,
1062,
2152,
534,
53,
5,
83,
7,
450,
291,
14,
443,
78,
9,
267,
291,
14,
1317,
63,
1074,
8,
1458,
12,
18500,
59,
15618,
841,
10,
277,
14,
443,
78,
9,
339,
347,
511,
63,
4250,
3693,
8,
277,
304,
267,
327,
2670,
7143,
402,
2849,
13,
13014,
2251,
267,
18500,
275,
980,
14,
4250,
1332,
18,
4706,
2152,
534,
53,
5,
83,
7,
450,
291,
14,
443,
78,
9,
267,
291,
14,
1317,
63,
1074,
8,
1458,
12,
18500,
59,
16,
467,
841,
10,
277,
14,
443,
78,
10,
18,
9,
267,
291,
14,
1317,
63,
1074,
8,
1458,
12,
18500,
59,
17,
467,
841,
10,
277,
14,
443,
78,
10,
18,
9,
339,
347,
511,
63,
4250,
5127,
8,
277,
304,
267,
327,
2670,
7143,
402,
3510,
13,
13014,
2251,
267,
18500,
275,
980,
14,
4250,
1332,
18,
12,
650,
12,
841,
395,
2152,
534,
53,
5,
83,
7,
450,
291,
14,
443,
78,
9,
267,
291,
14,
1317,
63,
1074,
8,
1458,
12,
18500,
59,
16,
12,
378,
12,
378,
467,
841,
10,
277,
14,
443,
78,
10,
18,
10,
19,
10,
20,
9,
267,
291,
14,
1317,
63,
1074,
8,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
lmregus/Portfolio
|
python/design_patterns/env/lib/python3.7/site-packages/prompt_toolkit/eventloop/coroutine.py
|
1
|
3783
|
from __future__ import unicode_literals
import types
from prompt_toolkit.eventloop.defaults import get_event_loop
from prompt_toolkit.eventloop.future import Future
__all__ = [
'From',
'Return',
'ensure_future',
]
def ensure_future(future_or_coroutine):
"""
Take a coroutine (generator) or a `Future` object, and make sure to return
a `Future`.
"""
if isinstance(future_or_coroutine, Future):
return future_or_coroutine
elif isinstance(future_or_coroutine, types.GeneratorType):
return _run_coroutine(future_or_coroutine)
else:
raise ValueError('Expecting coroutine or Future object. Got %r: %r' % (
type(future_or_coroutine), future_or_coroutine))
class Return(Exception):
"""
For backwards-compatibility with Python2: when "return" is not supported in
a generator/coroutine. (Like Trollius.)
Instead of ``return value``, in a coroutine do: ``raise Return(value)``.
"""
def __init__(self, value):
self.value = value
def __repr__(self):
return 'Return(%r)' % (self.value, )
def From(obj):
"""
Used to emulate 'yield from'.
(Like Trollius does.)
"""
return ensure_future(obj)
def _run_coroutine(coroutine):
"""
Takes a generator that can yield Future instances.
Example:
def gen():
yield From(...)
print('...')
yield From(...)
ensure_future(gen())
The values which are yielded by the given coroutine are supposed to be
`Future` objects.
"""
assert isinstance(coroutine, types.GeneratorType)
loop = get_event_loop()
result_f = loop.create_future()
# Wrap this future in a `_FutureRef`. We need this in order to be able to
# break all its references when we're done. This is important
# because in case of an exception, we want to be sure that
# `result_f.__del__` is triggered as soon as possible, so that we see the
# exception.
# (If `step_next` had a direct reference to `result_f` and there is a
# future that references `step_next`, then sometimes it won't be cleaned up
# immediately. - I'm not sure how exactly, but in that case it requires the
# garbage collector, because refcounting isn't sufficient.)
ref = _FutureRef(result_f)
# Loop through the generator.
def step_next(f=None):
" Execute next step of the coroutine."
try:
if f is None:
new_f = coroutine.send(None)
else:
exc = f.exception()
if exc:
new_f = coroutine.throw(exc)
else:
new_f = coroutine.send(f.result())
except StopIteration:
# Stop coroutine. Make sure that a result has been set in the future,
# this will call the callbacks. (Also, don't take any result from
# StopIteration, it has already been set using `raise Return()`.
if not ref.future.done():
ref.future.set_result(None)
ref.forget()
except Return as e:
ref.future.set_result(e.value)
ref.forget()
except BaseException as e:
ref.future.set_exception(e)
ref.forget()
else:
# Process yielded value from coroutine.
assert isinstance(new_f, Future), 'got %r' % (new_f, )
@new_f.add_done_callback
def continue_(_):
step_next(new_f)
# Start processing coroutine.
step_next()
return result_f
class _FutureRef(object):
def __init__(self, future):
self.future = future
def forget(self):
" Forget reference. "
self.future = None
|
mit
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
646,
2943,
199,
504,
8457,
63,
31994,
14,
1430,
3813,
14,
4322,
492,
664,
63,
1430,
63,
3813,
199,
504,
8457,
63,
31994,
14,
1430,
3813,
14,
2443,
492,
20799,
199,
199,
363,
452,
363,
275,
359,
272,
283,
2532,
297,
272,
283,
1767,
297,
272,
283,
7505,
63,
2443,
297,
199,
61,
421,
199,
318,
4868,
63,
2443,
8,
2443,
63,
269,
63,
16675,
304,
272,
408,
272,
18146,
282,
1970,
13242,
334,
4679,
9,
503,
282,
658,
14224,
64,
909,
12,
436,
1852,
3238,
370,
372,
272,
282,
658,
14224,
2313,
272,
408,
272,
340,
1228,
8,
2443,
63,
269,
63,
16675,
12,
20799,
304,
267,
372,
6466,
63,
269,
63,
16675,
272,
916,
1228,
8,
2443,
63,
269,
63,
16675,
12,
2943,
14,
7599,
804,
304,
267,
372,
485,
1065,
63,
16675,
8,
2443,
63,
269,
63,
16675,
9,
272,
587,
26,
267,
746,
1722,
360,
28864,
1970,
13242,
503,
20799,
909,
14,
24734,
450,
82,
26,
450,
82,
7,
450,
334,
586,
730,
8,
2443,
63,
269,
63,
16675,
395,
6466,
63,
269,
63,
16675,
430,
421,
199,
533,
1432,
8,
1726,
304,
272,
408,
272,
2104,
8552,
13,
15390,
543,
2018,
18,
26,
1380,
298,
1107,
2,
365,
440,
3748,
315,
272,
282,
4306,
15,
16675,
14,
221,
334,
12545,
377,
8459,
317,
527,
4959,
339,
15345,
402,
1124,
1107,
574,
4542,
315,
282,
1970,
13242,
886,
26,
221,
1124,
3730,
1432,
8,
585,
20642,
272,
408,
272,
347,
636,
826,
721,
277,
12,
574,
304,
267,
291,
14,
585,
275,
574,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
283,
1767,
4042,
82,
3171,
450,
334,
277,
14,
585,
12,
776,
421,
199,
318,
11606,
8,
1113,
304,
272,
408,
272,
8051,
370,
31102,
283,
11481,
687,
1370,
272,
334,
12545,
377,
8459,
317,
527,
1630,
4959,
272,
408,
272,
372,
4868,
63,
2443,
8,
1113,
9,
421,
199,
318,
485,
1065,
63,
16675,
8,
16675,
304,
272,
408,
272,
17415,
282,
4306,
626,
883,
1995,
20799,
4454,
14,
339,
5679,
26,
398,
347,
3805,
837,
288,
1995,
11606,
20186,
288,
870,
360,
15103,
288,
1995,
11606,
20186,
267,
4868,
63,
2443,
8,
2268,
1012,
339,
710,
1338,
1314,
787,
28653,
701,
314,
1627,
1970,
13242,
787,
20042,
370,
506,
272,
658,
14224,
64,
2251,
14,
272,
408,
272,
702,
1228,
8,
16675,
12,
2943,
14,
7599,
804,
9,
272,
4438,
275,
664,
63,
1430,
63,
3813,
342,
339,
754,
63,
70,
275,
4438,
14,
981,
63,
2443,
342,
339,
327,
20322,
642,
6466,
315,
282,
18494,
14224,
2891,
2313,
2136,
1929,
642,
315,
1865,
370,
506,
7688,
370,
272,
327,
2059,
1006,
2399,
6941,
1380,
781,
3984,
4224,
14,
961,
365,
11012,
272,
327,
2952,
315,
1930,
402,
376,
1919,
12,
781,
2934,
370,
506,
3238,
626,
272,
327,
658,
1099,
63,
70,
855,
2264,
29341,
365,
15572,
465,
18930,
465,
3962,
12,
880,
626,
781,
1937,
314,
272,
327,
1919,
14,
339,
327,
334,
3917,
658,
2926,
63,
2184,
64,
10530,
282,
4125,
3659,
370,
658,
1099,
63,
70,
64,
436,
2337,
365,
282,
272,
327,
6466,
626,
6941,
658,
2926,
63,
2184,
3559,
2066,
15026,
652,
7859,
1133,
506,
12364,
1536,
272,
327,
9939,
14,
446,
473,
6704,
440,
3238,
4212,
8840,
12,
1325,
315,
626,
1930,
652,
5074,
314,
272,
327,
17516,
14910,
12,
2952,
2984,
835,
316,
5712,
1133,
19258,
4959,
272,
2984,
275,
485,
14224,
2891,
8,
1099,
63,
70,
9,
339,
327,
18175,
4012,
314,
4306,
14,
272,
347,
3650,
63,
2184,
8,
70,
29,
403,
304,
267,
298,
17009,
2163,
3650,
402,
314,
1970,
13242,
2122,
267,
862,
26,
288,
340,
289,
365,
488,
26,
355,
892,
63,
70,
275,
1970,
13242,
14,
2254,
8,
403,
9,
288,
587,
26,
355,
3178,
275,
289,
14,
1971,
342,
355,
340,
3178,
26,
490,
892,
63,
70,
275,
1970,
13242,
14,
11964,
8,
2804,
9,
355,
587,
26,
490,
892,
63,
70,
275,
1970,
13242,
14,
2254,
8,
70,
14,
1099,
1012,
267,
871,
10852,
26,
288,
327,
8015,
1970,
13242,
14,
4155,
3238,
626,
282,
754,
965,
2757,
663,
315,
314,
6466,
12,
288,
327,
642,
911,
1240,
314,
13484,
14,
334,
31892,
12,
2793,
1133,
5452,
1263,
754,
687,
288,
327,
10852,
12,
652,
965,
2575,
2757,
663,
1808,
658,
3730,
1432,
25593,
288,
340,
440,
2984,
14,
2443,
14,
4456,
837,
355,
2984,
14,
2443,
14,
409,
63,
1099,
8,
403,
9,
355,
2984,
14,
28767,
342,
267,
871,
1432,
465,
325,
26,
288,
2984,
14,
2443,
14,
409,
63,
1099,
8,
69,
14,
585,
9,
288,
2984,
14,
28767,
342,
267,
871,
25416,
465,
325,
26,
288,
2984,
14,
2443,
14,
409,
63,
1971,
8,
69,
9,
288,
2984,
14,
28767,
342,
267,
587,
26,
288,
327,
7132,
28653,
574,
687,
1970,
13242,
14,
288,
702,
1228,
8,
1222,
63,
70,
12,
20799,
395,
283,
7808,
450,
82,
7,
450,
334,
1222,
63,
70,
12,
776,
953,
768,
1222,
63,
70,
14,
525,
63,
4456,
63,
3058,
288,
347,
1980,
63,
1547,
304,
355,
3650,
63,
2184,
8,
1222,
63,
70,
9,
339,
327,
7707,
6661,
1970,
13242,
14,
272,
3650,
63,
2184,
342,
339,
372,
754,
63,
70,
421,
199,
533,
485,
14224,
2891,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
6466,
304,
267,
291,
14,
2443,
275,
6466,
339,
347,
19459,
8,
277,
304,
267,
298,
2104,
362,
3659,
14,
298,
267,
291,
14,
2443,
275,
488,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
636,
2443,
363,
492,
2649,
63,
5955,
199,
646,
2943,
199,
504,
8457,
63,
31994,
14,
1430,
3813,
14,
4322,
492,
664,
63,
1430,
63,
3813,
199,
504,
8457,
63,
31994,
14,
1430,
3813,
14,
2443,
492,
20799,
199,
199,
363,
452,
363,
275,
359,
272,
283,
2532,
297,
272,
283,
1767,
297,
272,
283,
7505,
63,
2443,
297,
199,
61,
421,
199,
318,
4868,
63,
2443,
8,
2443,
63,
269,
63,
16675,
304,
272,
408,
272,
18146,
282,
1970,
13242,
334,
4679,
9,
503,
282,
658,
14224,
64,
909,
12,
436,
1852,
3238,
370,
372,
272,
282,
658,
14224,
2313,
272,
408,
272,
340,
1228,
8,
2443,
63,
269,
63,
16675,
12,
20799,
304,
267,
372,
6466,
63,
269,
63,
16675,
272,
916,
1228,
8,
2443,
63,
269,
63,
16675,
12,
2943,
14,
7599,
804,
304,
267,
372,
485,
1065,
63,
16675,
8,
2443,
63,
269,
63,
16675,
9,
272,
587,
26,
267,
746,
1722,
360,
28864,
1970,
13242,
503,
20799,
909,
14,
24734,
450,
82,
26,
450,
82,
7,
450,
334,
586,
730,
8,
2443,
63,
269,
63,
16675,
395,
6466,
63,
269,
63,
16675,
430,
421,
199,
533,
1432,
8,
1726,
304,
272,
408,
272,
2104,
8552,
13,
15390,
543,
2018,
18,
26,
1380,
298,
1107,
2,
365,
440,
3748,
315,
272,
282,
4306,
15,
16675,
14,
221,
334,
12545,
377,
8459,
317,
527,
4959,
339,
15345,
402,
1124,
1107,
574,
4542,
315,
282,
1970,
13242,
886,
26,
221,
1124,
3730,
1432,
8,
585,
20642,
272,
408,
272,
347,
636,
826,
721,
277,
12,
574,
304,
267,
291,
14,
585,
275,
574,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
283,
1767,
4042,
82,
3171,
450,
334,
277,
14,
585,
12,
776,
421,
199,
318,
11606,
8,
1113,
304,
272,
408,
272,
8051,
370,
31102,
283,
11481,
687,
1370,
272,
334,
12545,
377,
8459,
317,
527,
1630,
4959,
272,
408,
272,
372,
4868,
63,
2443,
8,
1113,
9,
421,
199,
318,
485,
1065,
63,
16675,
8,
16675,
304,
272,
408,
272,
17415,
282,
4306,
626,
883,
1995,
20799,
4454,
14,
339,
5679,
26,
398,
347,
3805,
837,
288,
1995,
11606,
20186,
288,
870,
360,
15103,
288,
1995,
11606,
20186,
267,
4868,
63,
2443,
8,
2268,
1012,
339,
710,
1338,
1314,
787,
28653,
701,
314,
1627,
1970,
13242,
787,
20042,
370,
506,
272,
658,
14224,
64,
2251,
14,
272,
408,
272,
702,
1228,
8,
16675,
12,
2943,
14,
7599,
804,
9,
272,
4438,
275,
664,
63,
1430,
63,
3813,
342,
339,
754,
63,
70,
275,
4438,
14,
981,
63,
2443,
342,
339,
327,
20322,
642,
6466,
315,
282,
18494,
14224,
2891,
2313,
2136,
1929,
642,
315,
1865,
370,
506,
7688,
370,
272,
327,
2059,
1006,
2399,
6941,
1380,
781,
3984,
4224,
14,
961,
365,
11012,
272,
327,
2952,
315,
1930,
402,
376,
1919,
12,
781,
2934,
370,
506,
3238,
626,
272,
327,
658,
1099,
63,
70,
855,
2264,
29341,
365,
15572,
465,
18930,
465,
3962,
12,
880,
626,
781,
1937,
314,
272,
327,
1919,
14,
339,
327,
334,
3917,
658,
2926,
63,
2184,
64,
10530,
282,
4125,
3659,
370,
658,
1099,
63,
70,
64,
436,
2337,
365,
282,
272,
327,
6466,
626,
6941,
658,
2926,
63,
2184,
3559,
2066,
15026,
652,
7859,
1133,
506,
12364,
1536,
272,
327,
9939,
14,
446,
473,
6704,
440,
3238,
4212,
8840,
12,
1325,
315,
626,
1930,
652,
5074,
314,
272,
327,
17516,
14910,
12,
2952,
2984,
835,
316,
5712,
1133,
19258,
4959,
272,
2984,
275,
485,
14224,
2891,
8,
1099,
63,
70,
9,
339,
327,
18175,
4012,
314,
4306,
14,
272,
347,
3650,
63,
2184,
8,
70,
29,
403,
304,
267,
298,
17009,
2163,
3650,
402,
314,
1970,
13242,
2122,
267,
862,
26,
288,
340,
289,
365,
488,
26,
355,
892,
63,
70,
275,
1970,
13242,
14,
2254,
8,
403,
9,
288,
587,
26,
355,
3178,
275,
289,
14,
1971,
342,
355,
340,
3178,
26,
490,
892,
63,
70,
275,
1970,
13242,
14,
11964,
8,
2804,
9,
355,
587,
26,
490,
892,
63,
70,
275,
1970,
13242,
14,
2254,
8,
70,
14,
1099,
1012,
267,
871,
10852,
26,
288,
327,
8015,
1970,
13242,
14,
4155,
3238,
626,
282,
754,
965,
2757,
663,
315,
314,
6466,
12,
288,
327,
642,
911,
1240,
314,
13484,
14,
334,
31892,
12,
2793,
1133,
5452,
1263,
754,
687,
288,
327,
10852,
12,
652,
965,
2575,
2757,
663,
1808,
658,
3730,
1432,
25593,
288,
340,
440,
2984,
14,
2443,
14,
4456,
837,
355,
2984,
14,
2443,
14,
409,
63,
1099,
8,
403,
9,
355,
2984,
14,
28767,
342,
267,
871,
1432,
465,
325,
26,
288,
2984,
14,
2443,
14,
409,
63,
1099,
8,
69,
14,
585,
9,
288,
2984,
14,
28767,
342,
267,
871,
25416,
465,
325,
26,
288,
2984,
14,
2443,
14,
409,
63,
1971,
8,
69,
9,
288,
2984,
14,
28767,
342,
267,
587,
26,
288,
327,
7132,
28653,
574,
687,
1970,
13242,
14,
288,
702,
1228,
8,
1222,
63,
70,
12,
20799,
395,
283,
7808,
450,
82,
7,
450,
334,
1222,
63,
70,
12,
776,
953,
768,
1222,
63,
70,
14,
525,
63,
4456,
63,
3058,
288,
347,
1980,
63,
1547,
304,
355,
3650,
63,
2184,
8,
1222,
63,
70,
9,
339,
327,
7707,
6661,
1970,
13242,
14,
272,
3650,
63,
2184,
342,
339,
372,
754,
63,
70,
421,
199,
533,
485,
14224,
2891,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
6466,
304,
267,
291,
14,
2443,
275,
6466,
339,
347,
19459,
8,
277,
304,
267,
298,
2104,
362,
3659,
14,
298,
267,
291,
14,
2443,
275,
488,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
adamwwt/chvac
|
venv/lib/python2.7/site-packages/sqlalchemy/orm/path_registry.py
|
21
|
8069
|
# orm/path_registry.py
# Copyright (C) 2005-2015 the SQLAlchemy authors and contributors
# <see AUTHORS file>
#
# This module is part of SQLAlchemy and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
"""Path tracking utilities, representing mapper graph traversals.
"""
from .. import inspection
from .. import util
from .. import exc
from itertools import chain
from .base import class_mapper
def _unreduce_path(path):
return PathRegistry.deserialize(path)
_WILDCARD_TOKEN = "*"
_DEFAULT_TOKEN = "_sa_default"
class PathRegistry(object):
"""Represent query load paths and registry functions.
Basically represents structures like:
(<User mapper>, "orders", <Order mapper>, "items", <Item mapper>)
These structures are generated by things like
query options (joinedload(), subqueryload(), etc.) and are
used to compose keys stored in the query._attributes dictionary
for various options.
They are then re-composed at query compile/result row time as
the query is formed and as rows are fetched, where they again
serve to compose keys to look up options in the context.attributes
dictionary, which is copied from query._attributes.
The path structure has a limited amount of caching, where each
"root" ultimately pulls from a fixed registry associated with
the first mapper, that also contains elements for each of its
property keys. However paths longer than two elements, which
are the exception rather than the rule, are generated on an
as-needed basis.
"""
is_token = False
is_root = False
def __eq__(self, other):
return other is not None and \
self.path == other.path
def set(self, attributes, key, value):
attributes[(key, self.path)] = value
def setdefault(self, attributes, key, value):
attributes.setdefault((key, self.path), value)
def get(self, attributes, key, value=None):
key = (key, self.path)
if key in attributes:
return attributes[key]
else:
return value
def __len__(self):
return len(self.path)
@property
def length(self):
return len(self.path)
def pairs(self):
path = self.path
for i in range(0, len(path), 2):
yield path[i], path[i + 1]
def contains_mapper(self, mapper):
for path_mapper in [
self.path[i] for i in range(0, len(self.path), 2)
]:
if path_mapper.is_mapper and \
path_mapper.isa(mapper):
return True
else:
return False
def contains(self, attributes, key):
return (key, self.path) in attributes
def __reduce__(self):
return _unreduce_path, (self.serialize(), )
def serialize(self):
path = self.path
return list(zip(
[m.class_ for m in [path[i] for i in range(0, len(path), 2)]],
[path[i].key for i in range(1, len(path), 2)] + [None]
))
@classmethod
def deserialize(cls, path):
if path is None:
return None
p = tuple(chain(*[(class_mapper(mcls),
class_mapper(mcls).attrs[key]
if key is not None else None)
for mcls, key in path]))
if p and p[-1] is None:
p = p[0:-1]
return cls.coerce(p)
@classmethod
def per_mapper(cls, mapper):
return EntityRegistry(
cls.root, mapper
)
@classmethod
def coerce(cls, raw):
return util.reduce(lambda prev, next: prev[next], raw, cls.root)
def token(self, token):
if token.endswith(':' + _WILDCARD_TOKEN):
return TokenRegistry(self, token)
elif token.endswith(":" + _DEFAULT_TOKEN):
return TokenRegistry(self.root, token)
else:
raise exc.ArgumentError("invalid token: %s" % token)
def __add__(self, other):
return util.reduce(
lambda prev, next: prev[next],
other.path, self)
def __repr__(self):
return "%s(%r)" % (self.__class__.__name__, self.path, )
class RootRegistry(PathRegistry):
"""Root registry, defers to mappers so that
paths are maintained per-root-mapper.
"""
path = ()
has_entity = False
is_aliased_class = False
is_root = True
def __getitem__(self, entity):
return entity._path_registry
PathRegistry.root = RootRegistry()
class TokenRegistry(PathRegistry):
def __init__(self, parent, token):
self.token = token
self.parent = parent
self.path = parent.path + (token,)
has_entity = False
is_token = True
def generate_for_superclasses(self):
if not self.parent.is_aliased_class and not self.parent.is_root:
for ent in self.parent.mapper.iterate_to_root():
yield TokenRegistry(self.parent.parent[ent], self.token)
else:
yield self
def __getitem__(self, entity):
raise NotImplementedError()
class PropRegistry(PathRegistry):
def __init__(self, parent, prop):
# restate this path in terms of the
# given MapperProperty's parent.
insp = inspection.inspect(parent[-1])
if not insp.is_aliased_class or insp._use_mapper_path:
parent = parent.parent[prop.parent]
elif insp.is_aliased_class and insp.with_polymorphic_mappers:
if prop.parent is not insp.mapper and \
prop.parent in insp.with_polymorphic_mappers:
subclass_entity = parent[-1]._entity_for_mapper(prop.parent)
parent = parent.parent[subclass_entity]
self.prop = prop
self.parent = parent
self.path = parent.path + (prop,)
@util.memoized_property
def has_entity(self):
return hasattr(self.prop, "mapper")
@util.memoized_property
def entity(self):
return self.prop.mapper
@util.memoized_property
def _wildcard_path_loader_key(self):
"""Given a path (mapper A, prop X), replace the prop with the wildcard,
e.g. (mapper A, 'relationship:.*') or (mapper A, 'column:.*'), then
return within the ("loader", path) structure.
"""
return ("loader",
self.parent.token(
"%s:%s" % (
self.prop.strategy_wildcard_key, _WILDCARD_TOKEN)
).path
)
@util.memoized_property
def _default_path_loader_key(self):
return ("loader",
self.parent.token(
"%s:%s" % (self.prop.strategy_wildcard_key,
_DEFAULT_TOKEN)
).path
)
@util.memoized_property
def _loader_key(self):
return ("loader", self.path)
@property
def mapper(self):
return self.entity
@property
def entity_path(self):
return self[self.entity]
def __getitem__(self, entity):
if isinstance(entity, (int, slice)):
return self.path[entity]
else:
return EntityRegistry(
self, entity
)
class EntityRegistry(PathRegistry, dict):
is_aliased_class = False
has_entity = True
def __init__(self, parent, entity):
self.key = entity
self.parent = parent
self.is_aliased_class = entity.is_aliased_class
self.entity = entity
self.path = parent.path + (entity,)
self.entity_path = self
@property
def mapper(self):
return inspection.inspect(self.entity).mapper
def __bool__(self):
return True
__nonzero__ = __bool__
def __getitem__(self, entity):
if isinstance(entity, (int, slice)):
return self.path[entity]
else:
return dict.__getitem__(self, entity)
def __missing__(self, key):
self[key] = item = PropRegistry(self, key)
return item
|
mit
|
[
3,
9813,
15,
515,
63,
5189,
14,
647,
199,
3,
1898,
334,
35,
9,
11811,
13,
7806,
314,
14303,
11462,
436,
8417,
199,
3,
665,
3239,
10610,
570,
30,
199,
3,
199,
3,
961,
859,
365,
1777,
402,
14303,
436,
365,
14286,
1334,
199,
3,
314,
10697,
844,
26,
1455,
921,
1544,
14,
16374,
14,
1308,
15,
2383,
15,
1147,
13,
1682,
14,
8624,
199,
624,
2042,
15161,
15841,
12,
6144,
7796,
3343,
1468,
14895,
2551,
14,
199,
199,
624,
199,
199,
504,
2508,
492,
5261,
10303,
199,
504,
2508,
492,
4884,
199,
504,
2508,
492,
3178,
199,
504,
7975,
492,
6036,
199,
504,
1275,
1095,
492,
1021,
63,
7153,
421,
199,
318,
485,
324,
5270,
63,
515,
8,
515,
304,
272,
372,
6912,
10899,
14,
11143,
8,
515,
9,
421,
199,
63,
55,
1193,
5196,
7816,
63,
8803,
275,
22423,
199,
63,
3472,
63,
8803,
275,
2668,
2231,
63,
885,
2,
421,
199,
533,
6912,
10899,
8,
785,
304,
272,
408,
10755,
1827,
2248,
3792,
436,
7086,
3423,
14,
339,
10082,
1183,
8469,
13955,
2839,
26,
339,
8642,
1899,
7796,
6244,
298,
14387,
401,
665,
4738,
7796,
6244,
298,
1744,
401,
665,
2081,
7796,
18956,
339,
5723,
13955,
787,
4046,
701,
7645,
2839,
272,
1827,
1511,
334,
11806,
912,
1062,
25935,
912,
1062,
5423,
4959,
436,
787,
272,
1202,
370,
23366,
2883,
5489,
315,
314,
1827,
423,
2987,
2600,
272,
367,
7750,
1511,
14,
339,
9322,
787,
2066,
295,
13,
7784,
939,
737,
1827,
6555,
15,
1099,
1962,
900,
465,
272,
314,
1827,
365,
28917,
436,
465,
4730,
787,
19251,
12,
2382,
2985,
4020,
272,
14062,
370,
23366,
2883,
370,
3648,
1536,
1511,
315,
314,
1067,
14,
2987,
272,
2600,
12,
1314,
365,
8876,
687,
1827,
423,
2987,
14,
339,
710,
931,
5523,
965,
282,
13988,
5982,
402,
13627,
12,
2382,
1924,
272,
298,
1231,
2,
221,
1141,
77,
13824,
299,
13072,
687,
282,
6317,
7086,
4568,
543,
272,
314,
1642,
7796,
12,
626,
2597,
3509,
4008,
367,
1924,
402,
2399,
272,
3324,
2883,
14,
221,
9738,
3792,
8088,
2419,
2877,
4008,
12,
1314,
272,
787,
314,
1919,
7830,
2419,
314,
2332,
12,
787,
4046,
641,
376,
272,
465,
13,
11368,
5597,
14,
339,
408,
339,
365,
63,
1418,
275,
756,
272,
365,
63,
1231,
275,
756,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
372,
1163,
365,
440,
488,
436,
971,
288,
291,
14,
515,
508,
1163,
14,
515,
339,
347,
663,
8,
277,
12,
3004,
12,
790,
12,
574,
304,
267,
3004,
7528,
498,
12,
291,
14,
515,
1874,
275,
574,
339,
347,
29408,
8,
277,
12,
3004,
12,
790,
12,
574,
304,
267,
3004,
14,
5486,
1332,
498,
12,
291,
14,
515,
395,
574,
9,
339,
347,
664,
8,
277,
12,
3004,
12,
790,
12,
574,
29,
403,
304,
267,
790,
275,
334,
498,
12,
291,
14,
515,
9,
267,
340,
790,
315,
3004,
26,
288,
372,
3004,
59,
498,
61,
267,
587,
26,
288,
372,
574,
339,
347,
636,
552,
721,
277,
304,
267,
372,
822,
8,
277,
14,
515,
9,
339,
768,
1829,
272,
347,
2582,
8,
277,
304,
267,
372,
822,
8,
277,
14,
515,
9,
339,
347,
6342,
8,
277,
304,
267,
931,
275,
291,
14,
515,
267,
367,
284,
315,
1425,
8,
16,
12,
822,
8,
515,
395,
499,
304,
288,
1995,
931,
59,
73,
467,
931,
59,
73,
435,
413,
61,
339,
347,
3509,
63,
7153,
8,
277,
12,
7796,
304,
267,
367,
931,
63,
7153,
315,
359,
288,
291,
14,
515,
59,
73,
61,
367,
284,
315,
1425,
8,
16,
12,
822,
8,
277,
14,
515,
395,
499,
9,
267,
16246,
288,
340,
931,
63,
7153,
14,
374,
63,
7153,
436,
971,
490,
931,
63,
7153,
14,
13655,
8,
7153,
304,
355,
372,
715,
267,
587,
26,
288,
372,
756,
339,
347,
3509,
8,
277,
12,
3004,
12,
790,
304,
267,
372,
334,
498,
12,
291,
14,
515,
9,
315,
3004,
339,
347,
636,
5270,
721,
277,
304,
267,
372,
485,
324,
5270,
63,
515,
12,
334,
277,
14,
3549,
1062,
776,
339,
347,
8437,
8,
277,
304,
267,
931,
275,
291,
14,
515,
267,
372,
769,
8,
3065,
8,
288,
359,
77,
14,
533,
63,
367,
333,
315,
359,
515,
59,
73,
61,
367,
284,
315,
1425,
8,
16,
12,
822,
8,
515,
395,
499,
18037,
288,
359,
515,
59,
73,
1055,
498,
367,
284,
315,
1425,
8,
17,
12,
822,
8,
515,
395,
499,
1874,
435,
359,
403,
61,
267,
5082,
339,
768,
3744,
272,
347,
22920,
8,
1886,
12,
931,
304,
267,
340,
931,
365,
488,
26,
288,
372,
488,
398,
299,
275,
2008,
8,
4429,
2031,
7528,
533,
63,
7153,
8,
77,
1886,
395,
2574,
1021,
63,
7153,
8,
77,
1886,
680,
3288,
59,
498,
61,
2574,
340,
790,
365,
440,
488,
587,
488,
9,
2079,
367,
333,
1886,
12,
790,
315,
931,
2459,
267,
340,
299,
436,
299,
1988,
17,
61,
365,
488,
26,
288,
299,
275,
299,
59,
16,
6809,
17,
61,
267,
372,
843,
14,
14141,
8,
80,
9,
339,
768,
3744,
272,
347,
1126,
63,
7153,
8,
1886,
12,
7796,
304,
267,
372,
17680,
10899,
8,
288,
843,
14,
1231,
12,
7796,
267,
776,
339,
768,
3744,
272,
347,
19874,
8,
1886,
12,
3066,
304,
267,
372,
4884,
14,
5270,
8,
2734,
5071,
12,
2163,
26,
5071,
59,
2184,
467,
3066,
12,
843,
14,
1231,
9,
339,
347,
1526,
8,
277,
12,
1526,
304,
267,
340,
1526,
14,
4130,
8,
5242,
435,
485,
55,
1193,
5196,
7816,
63,
8803,
304,
288,
372,
8767,
10899,
8,
277,
12,
1526,
9,
267,
916,
1526,
14,
4130,
480,
5424,
435,
485,
3472,
63,
8803,
304,
288,
372,
8767,
10899,
8,
277,
14,
1231,
12,
1526,
9,
267,
587,
26,
288,
746,
3178,
14,
17042,
480,
3197,
1526,
26,
450,
83,
2,
450,
1526,
9,
339,
347,
636,
525,
721,
277,
12,
1163,
304,
267,
372,
4884,
14,
5270,
8,
288,
2400,
5071,
12,
2163,
26,
5071,
59,
2184,
467,
288,
1163,
14,
515,
12,
291,
9,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
2071,
83,
4042,
82,
2924,
450,
334,
277,
855,
533,
4914
] |
[
9813,
15,
515,
63,
5189,
14,
647,
199,
3,
1898,
334,
35,
9,
11811,
13,
7806,
314,
14303,
11462,
436,
8417,
199,
3,
665,
3239,
10610,
570,
30,
199,
3,
199,
3,
961,
859,
365,
1777,
402,
14303,
436,
365,
14286,
1334,
199,
3,
314,
10697,
844,
26,
1455,
921,
1544,
14,
16374,
14,
1308,
15,
2383,
15,
1147,
13,
1682,
14,
8624,
199,
624,
2042,
15161,
15841,
12,
6144,
7796,
3343,
1468,
14895,
2551,
14,
199,
199,
624,
199,
199,
504,
2508,
492,
5261,
10303,
199,
504,
2508,
492,
4884,
199,
504,
2508,
492,
3178,
199,
504,
7975,
492,
6036,
199,
504,
1275,
1095,
492,
1021,
63,
7153,
421,
199,
318,
485,
324,
5270,
63,
515,
8,
515,
304,
272,
372,
6912,
10899,
14,
11143,
8,
515,
9,
421,
199,
63,
55,
1193,
5196,
7816,
63,
8803,
275,
22423,
199,
63,
3472,
63,
8803,
275,
2668,
2231,
63,
885,
2,
421,
199,
533,
6912,
10899,
8,
785,
304,
272,
408,
10755,
1827,
2248,
3792,
436,
7086,
3423,
14,
339,
10082,
1183,
8469,
13955,
2839,
26,
339,
8642,
1899,
7796,
6244,
298,
14387,
401,
665,
4738,
7796,
6244,
298,
1744,
401,
665,
2081,
7796,
18956,
339,
5723,
13955,
787,
4046,
701,
7645,
2839,
272,
1827,
1511,
334,
11806,
912,
1062,
25935,
912,
1062,
5423,
4959,
436,
787,
272,
1202,
370,
23366,
2883,
5489,
315,
314,
1827,
423,
2987,
2600,
272,
367,
7750,
1511,
14,
339,
9322,
787,
2066,
295,
13,
7784,
939,
737,
1827,
6555,
15,
1099,
1962,
900,
465,
272,
314,
1827,
365,
28917,
436,
465,
4730,
787,
19251,
12,
2382,
2985,
4020,
272,
14062,
370,
23366,
2883,
370,
3648,
1536,
1511,
315,
314,
1067,
14,
2987,
272,
2600,
12,
1314,
365,
8876,
687,
1827,
423,
2987,
14,
339,
710,
931,
5523,
965,
282,
13988,
5982,
402,
13627,
12,
2382,
1924,
272,
298,
1231,
2,
221,
1141,
77,
13824,
299,
13072,
687,
282,
6317,
7086,
4568,
543,
272,
314,
1642,
7796,
12,
626,
2597,
3509,
4008,
367,
1924,
402,
2399,
272,
3324,
2883,
14,
221,
9738,
3792,
8088,
2419,
2877,
4008,
12,
1314,
272,
787,
314,
1919,
7830,
2419,
314,
2332,
12,
787,
4046,
641,
376,
272,
465,
13,
11368,
5597,
14,
339,
408,
339,
365,
63,
1418,
275,
756,
272,
365,
63,
1231,
275,
756,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
372,
1163,
365,
440,
488,
436,
971,
288,
291,
14,
515,
508,
1163,
14,
515,
339,
347,
663,
8,
277,
12,
3004,
12,
790,
12,
574,
304,
267,
3004,
7528,
498,
12,
291,
14,
515,
1874,
275,
574,
339,
347,
29408,
8,
277,
12,
3004,
12,
790,
12,
574,
304,
267,
3004,
14,
5486,
1332,
498,
12,
291,
14,
515,
395,
574,
9,
339,
347,
664,
8,
277,
12,
3004,
12,
790,
12,
574,
29,
403,
304,
267,
790,
275,
334,
498,
12,
291,
14,
515,
9,
267,
340,
790,
315,
3004,
26,
288,
372,
3004,
59,
498,
61,
267,
587,
26,
288,
372,
574,
339,
347,
636,
552,
721,
277,
304,
267,
372,
822,
8,
277,
14,
515,
9,
339,
768,
1829,
272,
347,
2582,
8,
277,
304,
267,
372,
822,
8,
277,
14,
515,
9,
339,
347,
6342,
8,
277,
304,
267,
931,
275,
291,
14,
515,
267,
367,
284,
315,
1425,
8,
16,
12,
822,
8,
515,
395,
499,
304,
288,
1995,
931,
59,
73,
467,
931,
59,
73,
435,
413,
61,
339,
347,
3509,
63,
7153,
8,
277,
12,
7796,
304,
267,
367,
931,
63,
7153,
315,
359,
288,
291,
14,
515,
59,
73,
61,
367,
284,
315,
1425,
8,
16,
12,
822,
8,
277,
14,
515,
395,
499,
9,
267,
16246,
288,
340,
931,
63,
7153,
14,
374,
63,
7153,
436,
971,
490,
931,
63,
7153,
14,
13655,
8,
7153,
304,
355,
372,
715,
267,
587,
26,
288,
372,
756,
339,
347,
3509,
8,
277,
12,
3004,
12,
790,
304,
267,
372,
334,
498,
12,
291,
14,
515,
9,
315,
3004,
339,
347,
636,
5270,
721,
277,
304,
267,
372,
485,
324,
5270,
63,
515,
12,
334,
277,
14,
3549,
1062,
776,
339,
347,
8437,
8,
277,
304,
267,
931,
275,
291,
14,
515,
267,
372,
769,
8,
3065,
8,
288,
359,
77,
14,
533,
63,
367,
333,
315,
359,
515,
59,
73,
61,
367,
284,
315,
1425,
8,
16,
12,
822,
8,
515,
395,
499,
18037,
288,
359,
515,
59,
73,
1055,
498,
367,
284,
315,
1425,
8,
17,
12,
822,
8,
515,
395,
499,
1874,
435,
359,
403,
61,
267,
5082,
339,
768,
3744,
272,
347,
22920,
8,
1886,
12,
931,
304,
267,
340,
931,
365,
488,
26,
288,
372,
488,
398,
299,
275,
2008,
8,
4429,
2031,
7528,
533,
63,
7153,
8,
77,
1886,
395,
2574,
1021,
63,
7153,
8,
77,
1886,
680,
3288,
59,
498,
61,
2574,
340,
790,
365,
440,
488,
587,
488,
9,
2079,
367,
333,
1886,
12,
790,
315,
931,
2459,
267,
340,
299,
436,
299,
1988,
17,
61,
365,
488,
26,
288,
299,
275,
299,
59,
16,
6809,
17,
61,
267,
372,
843,
14,
14141,
8,
80,
9,
339,
768,
3744,
272,
347,
1126,
63,
7153,
8,
1886,
12,
7796,
304,
267,
372,
17680,
10899,
8,
288,
843,
14,
1231,
12,
7796,
267,
776,
339,
768,
3744,
272,
347,
19874,
8,
1886,
12,
3066,
304,
267,
372,
4884,
14,
5270,
8,
2734,
5071,
12,
2163,
26,
5071,
59,
2184,
467,
3066,
12,
843,
14,
1231,
9,
339,
347,
1526,
8,
277,
12,
1526,
304,
267,
340,
1526,
14,
4130,
8,
5242,
435,
485,
55,
1193,
5196,
7816,
63,
8803,
304,
288,
372,
8767,
10899,
8,
277,
12,
1526,
9,
267,
916,
1526,
14,
4130,
480,
5424,
435,
485,
3472,
63,
8803,
304,
288,
372,
8767,
10899,
8,
277,
14,
1231,
12,
1526,
9,
267,
587,
26,
288,
746,
3178,
14,
17042,
480,
3197,
1526,
26,
450,
83,
2,
450,
1526,
9,
339,
347,
636,
525,
721,
277,
12,
1163,
304,
267,
372,
4884,
14,
5270,
8,
288,
2400,
5071,
12,
2163,
26,
5071,
59,
2184,
467,
288,
1163,
14,
515,
12,
291,
9,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
2071,
83,
4042,
82,
2924,
450,
334,
277,
855,
533,
4914,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
mttr/django
|
django/db/migrations/graph.py
|
351
|
10956
|
from __future__ import unicode_literals
import warnings
from collections import deque
from functools import total_ordering
from django.db.migrations.state import ProjectState
from django.utils.datastructures import OrderedSet
from django.utils.encoding import python_2_unicode_compatible
from .exceptions import CircularDependencyError, NodeNotFoundError
RECURSION_DEPTH_WARNING = (
"Maximum recursion depth exceeded while generating migration graph, "
"falling back to iterative approach. If you're experiencing performance issues, "
"consider squashing migrations as described at "
"https://docs.djangoproject.com/en/dev/topics/migrations/#squashing-migrations."
)
@python_2_unicode_compatible
@total_ordering
class Node(object):
"""
A single node in the migration graph. Contains direct links to adjacent
nodes in either direction.
"""
def __init__(self, key):
self.key = key
self.children = set()
self.parents = set()
def __eq__(self, other):
return self.key == other
def __lt__(self, other):
return self.key < other
def __hash__(self):
return hash(self.key)
def __getitem__(self, item):
return self.key[item]
def __str__(self):
return str(self.key)
def __repr__(self):
return '<Node: (%r, %r)>' % self.key
def add_child(self, child):
self.children.add(child)
def add_parent(self, parent):
self.parents.add(parent)
# Use manual caching, @cached_property effectively doubles the
# recursion depth for each recursion.
def ancestors(self):
# Use self.key instead of self to speed up the frequent hashing
# when constructing an OrderedSet.
if '_ancestors' not in self.__dict__:
ancestors = deque([self.key])
for parent in sorted(self.parents):
ancestors.extendleft(reversed(parent.ancestors()))
self.__dict__['_ancestors'] = list(OrderedSet(ancestors))
return self.__dict__['_ancestors']
# Use manual caching, @cached_property effectively doubles the
# recursion depth for each recursion.
def descendants(self):
# Use self.key instead of self to speed up the frequent hashing
# when constructing an OrderedSet.
if '_descendants' not in self.__dict__:
descendants = deque([self.key])
for child in sorted(self.children):
descendants.extendleft(reversed(child.descendants()))
self.__dict__['_descendants'] = list(OrderedSet(descendants))
return self.__dict__['_descendants']
@python_2_unicode_compatible
class MigrationGraph(object):
"""
Represents the digraph of all migrations in a project.
Each migration is a node, and each dependency is an edge. There are
no implicit dependencies between numbered migrations - the numbering is
merely a convention to aid file listing. Every new numbered migration
has a declared dependency to the previous number, meaning that VCS
branch merges can be detected and resolved.
Migrations files can be marked as replacing another set of migrations -
this is to support the "squash" feature. The graph handler isn't responsible
for these; instead, the code to load them in here should examine the
migration files and if the replaced migrations are all either unapplied
or not present, it should ignore the replaced ones, load in just the
replacing migration, and repoint any dependencies that pointed to the
replaced migrations to point to the replacing one.
A node should be a tuple: (app_path, migration_name). The tree special-cases
things within an app - namely, root nodes and leaf nodes ignore dependencies
to other apps.
"""
def __init__(self):
self.node_map = {}
self.nodes = {}
self.cached = False
def add_node(self, key, implementation):
node = Node(key)
self.node_map[key] = node
self.nodes[key] = implementation
self.clear_cache()
def add_dependency(self, migration, child, parent):
if child not in self.nodes:
raise NodeNotFoundError(
"Migration %s dependencies reference nonexistent child node %r" % (migration, child),
child
)
if parent not in self.nodes:
raise NodeNotFoundError(
"Migration %s dependencies reference nonexistent parent node %r" % (migration, parent),
parent
)
self.node_map[child].add_parent(self.node_map[parent])
self.node_map[parent].add_child(self.node_map[child])
self.clear_cache()
def clear_cache(self):
if self.cached:
for node in self.nodes:
self.node_map[node].__dict__.pop('_ancestors', None)
self.node_map[node].__dict__.pop('_descendants', None)
self.cached = False
def forwards_plan(self, target):
"""
Given a node, returns a list of which previous nodes (dependencies)
must be applied, ending with the node itself.
This is the list you would follow if applying the migrations to
a database.
"""
if target not in self.nodes:
raise NodeNotFoundError("Node %r not a valid node" % (target, ), target)
# Use parent.key instead of parent to speed up the frequent hashing in ensure_not_cyclic
self.ensure_not_cyclic(target, lambda x: (parent.key for parent in self.node_map[x].parents))
self.cached = True
node = self.node_map[target]
try:
return node.ancestors()
except RuntimeError:
# fallback to iterative dfs
warnings.warn(RECURSION_DEPTH_WARNING, RuntimeWarning)
return self.iterative_dfs(node)
def backwards_plan(self, target):
"""
Given a node, returns a list of which dependent nodes (dependencies)
must be unapplied, ending with the node itself.
This is the list you would follow if removing the migrations from
a database.
"""
if target not in self.nodes:
raise NodeNotFoundError("Node %r not a valid node" % (target, ), target)
# Use child.key instead of child to speed up the frequent hashing in ensure_not_cyclic
self.ensure_not_cyclic(target, lambda x: (child.key for child in self.node_map[x].children))
self.cached = True
node = self.node_map[target]
try:
return node.descendants()
except RuntimeError:
# fallback to iterative dfs
warnings.warn(RECURSION_DEPTH_WARNING, RuntimeWarning)
return self.iterative_dfs(node, forwards=False)
def iterative_dfs(self, start, forwards=True):
"""
Iterative depth first search, for finding dependencies.
"""
visited = deque()
visited.append(start)
if forwards:
stack = deque(sorted(start.parents))
else:
stack = deque(sorted(start.children))
while stack:
node = stack.popleft()
visited.appendleft(node)
if forwards:
children = sorted(node.parents, reverse=True)
else:
children = sorted(node.children, reverse=True)
# reverse sorting is needed because prepending using deque.extendleft
# also effectively reverses values
stack.extendleft(children)
return list(OrderedSet(visited))
def root_nodes(self, app=None):
"""
Returns all root nodes - that is, nodes with no dependencies inside
their app. These are the starting point for an app.
"""
roots = set()
for node in self.nodes:
if (not any(key[0] == node[0] for key in self.node_map[node].parents)
and (not app or app == node[0])):
roots.add(node)
return sorted(roots)
def leaf_nodes(self, app=None):
"""
Returns all leaf nodes - that is, nodes with no dependents in their app.
These are the "most current" version of an app's schema.
Having more than one per app is technically an error, but one that
gets handled further up, in the interactive command - it's usually the
result of a VCS merge and needs some user input.
"""
leaves = set()
for node in self.nodes:
if (not any(key[0] == node[0] for key in self.node_map[node].children)
and (not app or app == node[0])):
leaves.add(node)
return sorted(leaves)
def ensure_not_cyclic(self, start, get_children):
# Algo from GvR:
# http://neopythonic.blogspot.co.uk/2009/01/detecting-cycles-in-directed-graph.html
todo = set(self.nodes)
while todo:
node = todo.pop()
stack = [node]
while stack:
top = stack[-1]
for node in get_children(top):
if node in stack:
cycle = stack[stack.index(node):]
raise CircularDependencyError(", ".join("%s.%s" % n for n in cycle))
if node in todo:
stack.append(node)
todo.remove(node)
break
else:
node = stack.pop()
def __str__(self):
return 'Graph: %s nodes, %s edges' % self._nodes_and_edges()
def __repr__(self):
nodes, edges = self._nodes_and_edges()
return '<%s: nodes=%s, edges=%s>' % (self.__class__.__name__, nodes, edges)
def _nodes_and_edges(self):
return len(self.nodes), sum(len(node.parents) for node in self.node_map.values())
def make_state(self, nodes=None, at_end=True, real_apps=None):
"""
Given a migration node or nodes, returns a complete ProjectState for it.
If at_end is False, returns the state before the migration has run.
If nodes is not provided, returns the overall most current project state.
"""
if nodes is None:
nodes = list(self.leaf_nodes())
if len(nodes) == 0:
return ProjectState()
if not isinstance(nodes[0], tuple):
nodes = [nodes]
plan = []
for node in nodes:
for migration in self.forwards_plan(node):
if migration not in plan:
if not at_end and migration in nodes:
continue
plan.append(migration)
project_state = ProjectState(real_apps=real_apps)
for node in plan:
project_state = self.nodes[node].mutate_state(project_state, preserve=False)
return project_state
def __contains__(self, node):
return node in self.nodes
|
bsd-3-clause
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
3598,
199,
504,
5055,
492,
15782,
199,
504,
9143,
492,
3141,
63,
7128,
199,
199,
504,
1639,
14,
697,
14,
7685,
14,
929,
492,
7290,
2223,
199,
504,
1639,
14,
1208,
14,
23004,
492,
23617,
199,
504,
1639,
14,
1208,
14,
2991,
492,
2366,
63,
18,
63,
2975,
63,
6490,
199,
199,
504,
1275,
3924,
492,
445,
24998,
14403,
547,
12,
5013,
10870,
199,
199,
907,
7013,
3579,
63,
19715,
63,
9171,
275,
334,
272,
298,
10915,
16189,
5818,
22007,
1830,
12999,
8367,
3343,
12,
298,
272,
298,
70,
26039,
1771,
370,
4826,
857,
18140,
14,
982,
1265,
3984,
444,
5490,
287,
4477,
10238,
10876,
12,
298,
272,
298,
388,
16994,
12345,
1119,
316,
6180,
465,
11736,
737,
298,
272,
298,
2859,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
2374,
15,
11299,
15,
7685,
12645,
8471,
1119,
316,
13,
7685,
2122,
199,
9,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
32,
2923,
63,
7128,
199,
533,
5013,
8,
785,
304,
272,
408,
272,
437,
2849,
1031,
315,
314,
8367,
3343,
14,
22493,
4125,
6220,
370,
24113,
272,
3380,
315,
1902,
7581,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
790,
304,
267,
291,
14,
498,
275,
790,
267,
291,
14,
3223,
275,
663,
342,
267,
291,
14,
8859,
275,
663,
342,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
372,
291,
14,
498,
508,
1163,
339,
347,
636,
4116,
721,
277,
12,
1163,
304,
267,
372,
291,
14,
498,
665,
1163,
339,
347,
636,
2227,
721,
277,
304,
267,
372,
2631,
8,
277,
14,
498,
9,
339,
347,
636,
6095,
721,
277,
12,
1242,
304,
267,
372,
291,
14,
498,
59,
1053,
61,
339,
347,
636,
495,
721,
277,
304,
267,
372,
620,
8,
277,
14,
498,
9,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
2650,
1716,
26,
4366,
82,
12,
450,
82,
9,
3524,
450,
291,
14,
498,
339,
347,
1050,
63,
1739,
8,
277,
12,
1982,
304,
267,
291,
14,
3223,
14,
525,
8,
1739,
9,
339,
347,
1050,
63,
1708,
8,
277,
12,
1676,
304,
267,
291,
14,
8859,
14,
525,
8,
1708,
9,
339,
327,
3645,
8722,
13627,
12,
768,
5245,
63,
1829,
27881,
4270,
83,
314,
272,
327,
16189,
5818,
367,
1924,
16189,
14,
272,
347,
20158,
8,
277,
304,
267,
327,
3645,
291,
14,
498,
3140,
402,
291,
370,
8112,
1536,
314,
28914,
25223,
267,
327,
1380,
22048,
376,
23617,
14,
267,
340,
2513,
23732,
7,
440,
315,
291,
855,
807,
10651,
288,
20158,
275,
15782,
779,
277,
14,
498,
566,
288,
367,
1676,
315,
3355,
8,
277,
14,
8859,
304,
355,
20158,
14,
2880,
3039,
8,
13501,
8,
1708,
14,
23732,
4059,
288,
291,
855,
807,
363,
8680,
23732,
418,
275,
769,
8,
22567,
1084,
8,
23732,
430,
267,
372,
291,
855,
807,
363,
8680,
23732,
418,
339,
327,
3645,
8722,
13627,
12,
768,
5245,
63,
1829,
27881,
4270,
83,
314,
272,
327,
16189,
5818,
367,
1924,
16189,
14,
272,
347,
26061,
8,
277,
304,
267,
327,
3645,
291,
14,
498,
3140,
402,
291,
370,
8112,
1536,
314,
28914,
25223,
267,
327,
1380,
22048,
376,
23617,
14,
267,
340,
2513,
29041,
7,
440,
315,
291,
855,
807,
10651,
288,
26061,
275,
15782,
779,
277,
14,
498,
566,
288,
367,
1982,
315,
3355,
8,
277,
14,
3223,
304,
355,
26061,
14,
2880,
3039,
8,
13501,
8,
1739,
14,
29041,
4059,
288,
291,
855,
807,
363,
8680,
29041,
418,
275,
769,
8,
22567,
1084,
8,
29041,
430,
267,
372,
291,
855,
807,
363,
8680,
29041,
418,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
12090,
4578,
8,
785,
304,
272,
408,
272,
21591,
314,
487,
2180,
402,
1006,
6180,
315,
282,
2199,
14,
339,
7048,
8367,
365,
282,
1031,
12,
436,
1924,
5936,
365,
376,
6275,
14,
6006,
787,
272,
949,
9227,
5124,
3382,
1967,
18897,
6180,
446,
314,
1329,
316,
365,
272,
562,
264,
590,
282,
16129,
370,
23939,
570,
13778,
14,
18414,
892,
1967,
18897,
8367,
272,
965,
282,
14290,
5936,
370,
314,
4136,
1329,
12,
11150,
626,
23563,
272,
5246,
32716,
883,
506,
10501,
436,
12152,
14,
339,
28195,
3801,
1584,
883,
506,
11584,
465,
15810,
4573,
663,
402,
6180,
446,
272,
642,
365,
370,
2291,
314,
298,
8471,
1119,
2,
3878,
14,
710,
3343,
3016,
5712,
1133,
17845,
272,
367,
3520,
27,
3140,
12,
314,
1233,
370,
2248,
3062,
315,
2348,
1077,
31758,
314,
272,
8367,
1584,
436,
340,
314,
8717,
6180,
787,
1006,
1902,
625,
17250,
272,
503,
440,
3451,
12,
652,
1077,
3686,
314,
8717,
7869,
12,
2248,
315,
2951,
314,
272,
15810,
8367,
12,
436,
295,
1403,
1263,
5124,
626,
32031,
370,
314,
272,
8717,
6180,
370,
2376,
370,
314,
15810,
1373,
14,
339,
437,
1031,
1077,
506,
282,
2008,
26,
334,
571,
63,
515,
12,
8367,
63,
354,
680,
710,
3123,
4539,
13,
9403,
272,
7645,
4453,
376,
1145,
446,
536,
590,
12,
1738,
3380,
436,
11747,
3380,
3686,
5124,
272,
370,
1163,
8686,
14,
272,
408,
339,
347,
636,
826,
721,
277,
304,
267,
291,
14,
932,
63,
1130,
275,
1052,
267,
291,
14,
2415,
275,
1052,
267,
291,
14,
5245,
275,
756,
339,
347,
1050,
63,
932,
8,
277,
12,
790,
12,
4514,
304,
267,
1031,
275,
5013,
8,
498,
9,
267,
291,
14,
932,
63,
1130,
59,
498,
61,
275,
1031,
267,
291,
14,
2415,
59,
498,
61,
275,
4514,
267,
291,
14,
3584,
63,
1637,
342,
339,
347,
1050,
63,
8575,
8,
277,
12,
8367,
12,
1982,
12,
1676,
304,
267,
340,
1982,
440,
315,
291,
14,
2415,
26,
288,
746,
5013,
10870,
8,
355,
298,
9816,
450,
83,
5124,
3659,
7179,
16931,
1982,
1031,
450,
82,
2,
450,
334,
8998,
12,
1982,
395,
355,
1982,
288,
776,
267,
340,
1676,
440,
315,
291,
14,
2415,
26,
288,
746,
5013,
10870,
8,
355,
298,
9816,
450,
83,
5124,
3659,
7179,
16931,
1676,
1031,
450,
82,
2,
450,
334,
8998,
12,
1676,
395,
355,
1676,
288,
776,
267,
291,
14,
932,
63,
1130,
59,
1739,
1055,
525,
63,
1708,
8,
277
] |
[
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
3598,
199,
504,
5055,
492,
15782,
199,
504,
9143,
492,
3141,
63,
7128,
199,
199,
504,
1639,
14,
697,
14,
7685,
14,
929,
492,
7290,
2223,
199,
504,
1639,
14,
1208,
14,
23004,
492,
23617,
199,
504,
1639,
14,
1208,
14,
2991,
492,
2366,
63,
18,
63,
2975,
63,
6490,
199,
199,
504,
1275,
3924,
492,
445,
24998,
14403,
547,
12,
5013,
10870,
199,
199,
907,
7013,
3579,
63,
19715,
63,
9171,
275,
334,
272,
298,
10915,
16189,
5818,
22007,
1830,
12999,
8367,
3343,
12,
298,
272,
298,
70,
26039,
1771,
370,
4826,
857,
18140,
14,
982,
1265,
3984,
444,
5490,
287,
4477,
10238,
10876,
12,
298,
272,
298,
388,
16994,
12345,
1119,
316,
6180,
465,
11736,
737,
298,
272,
298,
2859,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
2374,
15,
11299,
15,
7685,
12645,
8471,
1119,
316,
13,
7685,
2122,
199,
9,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
32,
2923,
63,
7128,
199,
533,
5013,
8,
785,
304,
272,
408,
272,
437,
2849,
1031,
315,
314,
8367,
3343,
14,
22493,
4125,
6220,
370,
24113,
272,
3380,
315,
1902,
7581,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
790,
304,
267,
291,
14,
498,
275,
790,
267,
291,
14,
3223,
275,
663,
342,
267,
291,
14,
8859,
275,
663,
342,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
372,
291,
14,
498,
508,
1163,
339,
347,
636,
4116,
721,
277,
12,
1163,
304,
267,
372,
291,
14,
498,
665,
1163,
339,
347,
636,
2227,
721,
277,
304,
267,
372,
2631,
8,
277,
14,
498,
9,
339,
347,
636,
6095,
721,
277,
12,
1242,
304,
267,
372,
291,
14,
498,
59,
1053,
61,
339,
347,
636,
495,
721,
277,
304,
267,
372,
620,
8,
277,
14,
498,
9,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
2650,
1716,
26,
4366,
82,
12,
450,
82,
9,
3524,
450,
291,
14,
498,
339,
347,
1050,
63,
1739,
8,
277,
12,
1982,
304,
267,
291,
14,
3223,
14,
525,
8,
1739,
9,
339,
347,
1050,
63,
1708,
8,
277,
12,
1676,
304,
267,
291,
14,
8859,
14,
525,
8,
1708,
9,
339,
327,
3645,
8722,
13627,
12,
768,
5245,
63,
1829,
27881,
4270,
83,
314,
272,
327,
16189,
5818,
367,
1924,
16189,
14,
272,
347,
20158,
8,
277,
304,
267,
327,
3645,
291,
14,
498,
3140,
402,
291,
370,
8112,
1536,
314,
28914,
25223,
267,
327,
1380,
22048,
376,
23617,
14,
267,
340,
2513,
23732,
7,
440,
315,
291,
855,
807,
10651,
288,
20158,
275,
15782,
779,
277,
14,
498,
566,
288,
367,
1676,
315,
3355,
8,
277,
14,
8859,
304,
355,
20158,
14,
2880,
3039,
8,
13501,
8,
1708,
14,
23732,
4059,
288,
291,
855,
807,
363,
8680,
23732,
418,
275,
769,
8,
22567,
1084,
8,
23732,
430,
267,
372,
291,
855,
807,
363,
8680,
23732,
418,
339,
327,
3645,
8722,
13627,
12,
768,
5245,
63,
1829,
27881,
4270,
83,
314,
272,
327,
16189,
5818,
367,
1924,
16189,
14,
272,
347,
26061,
8,
277,
304,
267,
327,
3645,
291,
14,
498,
3140,
402,
291,
370,
8112,
1536,
314,
28914,
25223,
267,
327,
1380,
22048,
376,
23617,
14,
267,
340,
2513,
29041,
7,
440,
315,
291,
855,
807,
10651,
288,
26061,
275,
15782,
779,
277,
14,
498,
566,
288,
367,
1982,
315,
3355,
8,
277,
14,
3223,
304,
355,
26061,
14,
2880,
3039,
8,
13501,
8,
1739,
14,
29041,
4059,
288,
291,
855,
807,
363,
8680,
29041,
418,
275,
769,
8,
22567,
1084,
8,
29041,
430,
267,
372,
291,
855,
807,
363,
8680,
29041,
418,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
12090,
4578,
8,
785,
304,
272,
408,
272,
21591,
314,
487,
2180,
402,
1006,
6180,
315,
282,
2199,
14,
339,
7048,
8367,
365,
282,
1031,
12,
436,
1924,
5936,
365,
376,
6275,
14,
6006,
787,
272,
949,
9227,
5124,
3382,
1967,
18897,
6180,
446,
314,
1329,
316,
365,
272,
562,
264,
590,
282,
16129,
370,
23939,
570,
13778,
14,
18414,
892,
1967,
18897,
8367,
272,
965,
282,
14290,
5936,
370,
314,
4136,
1329,
12,
11150,
626,
23563,
272,
5246,
32716,
883,
506,
10501,
436,
12152,
14,
339,
28195,
3801,
1584,
883,
506,
11584,
465,
15810,
4573,
663,
402,
6180,
446,
272,
642,
365,
370,
2291,
314,
298,
8471,
1119,
2,
3878,
14,
710,
3343,
3016,
5712,
1133,
17845,
272,
367,
3520,
27,
3140,
12,
314,
1233,
370,
2248,
3062,
315,
2348,
1077,
31758,
314,
272,
8367,
1584,
436,
340,
314,
8717,
6180,
787,
1006,
1902,
625,
17250,
272,
503,
440,
3451,
12,
652,
1077,
3686,
314,
8717,
7869,
12,
2248,
315,
2951,
314,
272,
15810,
8367,
12,
436,
295,
1403,
1263,
5124,
626,
32031,
370,
314,
272,
8717,
6180,
370,
2376,
370,
314,
15810,
1373,
14,
339,
437,
1031,
1077,
506,
282,
2008,
26,
334,
571,
63,
515,
12,
8367,
63,
354,
680,
710,
3123,
4539,
13,
9403,
272,
7645,
4453,
376,
1145,
446,
536,
590,
12,
1738,
3380,
436,
11747,
3380,
3686,
5124,
272,
370,
1163,
8686,
14,
272,
408,
339,
347,
636,
826,
721,
277,
304,
267,
291,
14,
932,
63,
1130,
275,
1052,
267,
291,
14,
2415,
275,
1052,
267,
291,
14,
5245,
275,
756,
339,
347,
1050,
63,
932,
8,
277,
12,
790,
12,
4514,
304,
267,
1031,
275,
5013,
8,
498,
9,
267,
291,
14,
932,
63,
1130,
59,
498,
61,
275,
1031,
267,
291,
14,
2415,
59,
498,
61,
275,
4514,
267,
291,
14,
3584,
63,
1637,
342,
339,
347,
1050,
63,
8575,
8,
277,
12,
8367,
12,
1982,
12,
1676,
304,
267,
340,
1982,
440,
315,
291,
14,
2415,
26,
288,
746,
5013,
10870,
8,
355,
298,
9816,
450,
83,
5124,
3659,
7179,
16931,
1982,
1031,
450,
82,
2,
450,
334,
8998,
12,
1982,
395,
355,
1982,
288,
776,
267,
340,
1676,
440,
315,
291,
14,
2415,
26,
288,
746,
5013,
10870,
8,
355,
298,
9816,
450,
83,
5124,
3659,
7179,
16931,
1676,
1031,
450,
82,
2,
450,
334,
8998,
12,
1676,
395,
355,
1676,
288,
776,
267,
291,
14,
932,
63,
1130,
59,
1739,
1055,
525,
63,
1708,
8,
277,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
yitian134/chromium
|
chrome/test/functional/ap_lab/dlink_ap_configurator.py
|
76
|
12111
|
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import logging
import os
import ap_configurator
import selenium.common.exceptions
class DLinkAPConfigurator(ap_configurator.APConfigurator):
"""Derived class to control the DLink DAP-1522."""
def __init__(self, pyauto_instance, admin_interface_url):
super(DLinkAPConfigurator, self).__init__(pyauto_instance)
# Override constants
self.security_disabled = 'Disable Wireless Security (not recommended)'
self.security_wep = 'WEP'
self.security_wpapsk = 'WPA-Personal'
self.security_wpa2psk = 'WPA-Personal'
self.security_wpa8021x = 'WPA-Enterprise'
self.security_wpa28021x = 'WPA2-Enterprise'
self.admin_interface_url = admin_interface_url
def _OpenLandingPage(self):
self.pyauto_instance.NavigateToURL('http://%s/index.php' %
self.admin_interface_url)
page_name = os.path.basename(self.pyauto_instance.GetActiveTabURL().spec())
if page_name == 'login.php' or page_name == 'index.php':
try:
self._wait.until(lambda _: self._driver.find_element_by_xpath(
'//*[@name="login"]'))
except selenium.common.exceptions.TimeoutException, e:
# Maybe we were re-routes to the configuration page
if (os.path.basename(self.pyauto_instance.GetActiveTabURL().spec()) ==
'bsc_wizard.php'):
return
logging.exception('WebDriver exception: %s', str(e))
login_button = self._driver.find_element_by_xpath('//*[@name="login"]')
login_button.click()
def _OpenConfigurationPage(self):
self._OpenLandingPage()
if (os.path.basename(self.pyauto_instance.GetActiveTabURL().spec()) !=
'bsc_wizard.php'):
self.fail(msg='Taken to an unknown page %s' %
self.pyauto_instance.GetActiveTabURL().spec())
# Else we are being logged in automatically to the landing page
wlan = '//*[@name="wlan_wireless"]'
try:
self._wait.until(lambda _: self._driver.find_element_by_xpath(wlan))
except selenium.common.exceptions.TimeoutException, e:
logging.exception('WebDriver exception: %s', str(e))
wlan_button = self._driver.find_element_by_xpath(wlan)
wlan_button.click()
# Wait for the main configuration page, look for the radio button
try:
self._wait.until(lambda _: self._driver.find_element_by_xpath(
'id("enable")'))
except selenium.common.exceptions.TimeoutException, e:
logging.exception('Unable to find the radio button on the main landing '
'page.\nWebDriver exception: %s', str(e))
def GetRouterName(self):
return 'Router Name: DAP-1522; Class: DLinkAPConfigurator'
def GetRouterShortName(self):
return 'DAP-1522'
def GetNumberOfPages(self):
return 1
def GetSupportedBands(self):
return [{'band': self.band_2ghz,
'channels': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]},
{'band': self.band_5ghz,
'channels': [26, 40, 44, 48, 149, 153, 157, 161, 165]}]
def GetSupportedModes(self):
return [{'band': self.band_2ghz,
'modes': [self.mode_b, self.mode_g, self.mode_n,
self.mode_b | self.mode_g, self.mode_g | self.mode_n]},
{'band': self.band_5ghz,
'modes': [self.mode_a, self.mode_n, self.mode_a | self.mode_n]}]
def NavigateToPage(self, page_number):
# All settings are on the same page, so we always open the config page
self._OpenConfigurationPage()
return True
def SavePage(self, page_number):
# All settings are on the same page, we can ignore page_number
button = self._driver.find_element_by_xpath('//input[@name="apply"]')
button.click()
# If we did not make changes so we are sent to the continue screen.
continue_screen = True
button_xpath = '//input[@name="bt"]'
try:
self._wait.until(lambda _:
self._driver.find_element_by_xpath(button_xpath))
except selenium.common.exceptions.TimeoutException, e:
continue_screen = False
if continue_screen:
button = self._driver.find_element_by_xpath(button_xpath)
button.click()
# We will be returned to the landing page when complete
try:
self._wait.until(lambda _:
self._driver.find_element_by_xpath('id("enable")'))
except selenium.common.exceptions.TimeoutException, e:
logging.exception('Unable to find the radio button on the main landing '
'page.\nWebDriver exception: %s', str(e))
return False
return True
def SetMode(self, mode, band=None):
# Mode overrides the band. So if a band change is made after a mode change
# it may make an incompatible pairing.
self.AddItemToCommandList(self._SetMode, (mode, band), 1, 800)
def _SetMode(self, mode, band=None):
# Create the mode to popup item mapping
mode_mapping = {self.mode_b: '802.11b Only', self.mode_g: '802.11g Only',
self.mode_n: '802.11n Only',
self.mode_b | self.mode_g: 'Mixed 802.11g and 802.11b',
self.mode_n | self.mode_g: 'Mixed 802.11n and 802.11g',
self.mode_n | self.mode_g | self.mode_b:
'Mixed 802.11n, 802.11g, and 802.11b',
self.mode_n | self.mode_g | self.mode_b:
'Mixed 802.11n, 802.11g, and 802.11b',
self.mode_a: '802.11a Only',
self.mode_n | self.mode_a: 'Mixed 802.11n and 802.11a'}
band_value = self.band_2ghz
if mode in mode_mapping.keys():
popup_value = mode_mapping[mode]
# If the mode contains 802.11a we use 5Ghz
if mode & self.mode_a == self.mode_a:
band_value = self.band_5ghz
# If the mode is 802.11n mixed with 802.11a it must be 5Ghz
elif mode & (self.mode_n | self.mode_a) == (self.mode_n | self.mode_a):
band_value = self.band_5ghz
# If the mode is 802.11n mixed with something other than 802.11a its 2Ghz
elif mode & self.mode_n == self.mode_n and mode ^ self.mode_n > 0:
band_value = self.band_2ghz
# If the mode is 802.11n then we default to 5Ghz unless there is a band
elif mode == self.mode_n:
band_value = self.band_5ghz
if band:
band_value = band
else:
logging.exception('The mode selected %d is not supported by router %s.',
hex(mode), self.getRouterName())
# Set the band first
self._SetBand(band_value)
popup_id = 'mode_80211_11g'
if band_value == self.band_5ghz:
popup_id = 'mode_80211_11a'
self.SelectItemFromPopupByID(popup_value, popup_id)
def SetRadio(self, enabled=True):
# If we are enabling we are activating all other UI components, do it first.
# Otherwise we are turning everything off so do it last.
if enabled:
weight = 1
else:
weight = 1000
# This disables all UI so it should be the last item to be changed
self.AddItemToCommandList(self._SetRadio, (enabled,), 1, weight)
def _SetRadio(self, enabled=True):
# The radio checkbox for this router always has a value of 1. So we need to
# use other methods to determine if the radio is on or not. Check if the
# ssid textfield is disabled.
ssid = self._driver.find_element_by_xpath('//input[@name="ssid"]')
if ssid.get_attribute('disabled') == 'true':
radio_enabled = False
else:
radio_enabled = True
if radio_enabled == enabled:
# Nothing to do
return
self.SetCheckBoxSelectedByID('enable', selected=False,
wait_for_xpath='id("security_type_ap")')
def SetSSID(self, ssid):
# Can be done as long as it is enabled
self.AddItemToCommandList(self._SetSSID, (ssid,), 1, 900)
def _SetSSID(self, ssid):
self._SetRadio(enabled=True)
self.SetContentOfTextFieldByID(ssid, 'ssid')
def SetChannel(self, channel):
self.AddItemToCommandList(self._SetChannel, (channel,), 1, 900)
def _SetChannel(self, channel):
self._SetRadio(enabled=True)
self.SetCheckBoxSelectedByID('autochann', selected=False)
self.SelectItemFromPopupByID(str(channel), 'channel_g')
# Experimental
def GetBand(self):
# The radio buttons do more than run a script that adjusts the possible
# channels. We will just check the channel to popup.
self.setRadioSetting(enabled=True)
xpath = ('id("channel_g")')
self._OpenConfigurationPage()
try:
self._wait.until(lambda _: self._driver.find_element_by_xpath(xpath))
except selenium.common.exceptions.TimeoutException, e:
logging.exception('WebDriver exception: %s', str(e))
element = self._driver.find_element_by_xpath(xpath)
if element.find_elements_by_tag_name('option')[0].text == '1':
return self.band_2ghz
return self.band_5ghz
def SetBand(self, band):
if band != self.band_2GHz or band != self.band_5ghz:
self.fail(msg='Invalid band sent %s' % band)
self.AddItemToCommandList(self._SetBand, (band,), 1, 900)
def _SetBand(self, band):
self._SetRadio(enabled=True)
if band == self.band_2ghz:
int_value = 0
wait_for_xpath = 'id("mode_80211_11g")'
elif band == self.band_5ghz:
int_value = 1
wait_for_xpath = 'id("mode_80211_11a")'
xpath = ('//*[contains(@class, "l_tb")]/input[@value="%d" and @name="band"]'
% int_value)
element = self._driver.find_element_by_xpath(xpath)
element.click()
try:
self._wait.until(lambda _:
self._driver.find_element_by_xpath(wait_for_xpath))
except selenium.common.exceptions.TimeoutException, e:
logging.exception('The appropriate mode popup could not be found after '
'adjusting the band. WebDriver exception: %s', str(e))
def SetSecurityDisabled(self):
self.AddItemToCommandList(self._SetSecurityDisabled, (), 1, 900)
def _SetSecurityDisabled(self):
self._SetRadio(enabled=True)
self.SelectItemFromPopupByID(self.security_disabled, 'security_type_ap')
def SetSecurityWEP(self, key_value, authentication):
self.AddItemToCommandList(self._SetSecurityWEP, (key_value, authentication),
1, 900)
def _SetSecurityWEP(self, key_value, authentication):
self._SetRadio(enabled=True)
self.SelectItemFromPopupByID(self.security_wep, 'security_type_ap',
wait_for_xpath='id("auth_type")')
self.SelectItemFromPopupByID(authentication, 'auth_type',
wait_for_xpath='id("wep_key_value")')
self.SetContentOfTextFieldByID(key_value, 'wep_key_value')
self.SetContentOfTextFieldByID(key_value, 'verify_wep_key_value')
def SetSecurityWPAPSK(self, shared_key, update_interval=1800):
self.AddItemToCommandList(self._SetSecurityWPAPSK,
(shared_key, update_interval), 1, 900)
def _SetSecurityWPAPSK(self, shared_key, update_interval=1800):
self._SetRadio(enabled=True)
self.SelectItemFromPopupByID(self.security_wpapsk, 'security_type_ap',
wait_for_xpath='id("wpa_mode")')
self.SelectItemFromPopupByID('WPA Only', 'wpa_mode',
wait_for_xpath='id("grp_key_interval")')
self.SetContentOfTextFieldByID(str(update_interval), 'grp_key_interval')
self.SetContentOfTextFieldByID(shared_key, 'wpapsk1')
def SetVisibility(self, visible=True):
self.AddItemToCommandList(self._SetVisibility, (visible,), 1, 900)
def _SetVisibility(self, visible=True):
self._SetRadio(enabled=True)
# value=0 is visible; value=1 is invisible
int_value = 0
if not visible:
int_value = 1
xpath = ('//*[contains(@class, "l_tb")]/input[@value="%d" '
'and @name="visibility_status"]' % int_value)
element = self._driver.find_element_by_xpath(xpath)
element.click()
|
bsd-3-clause
|
[
3,
1898,
334,
67,
9,
6029,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
646,
2050,
199,
646,
747,
199,
199,
646,
2771,
63,
888,
17320,
199,
646,
19481,
14,
2330,
14,
3924,
421,
199,
533,
577,
3834,
1282,
28051,
8,
439,
63,
888,
17320,
14,
1282,
28051,
304,
523,
408,
17793,
12905,
1021,
370,
3304,
314,
577,
3834,
577,
1282,
13,
1046,
1081,
1041,
819,
347,
636,
826,
721,
277,
12,
1134,
2495,
63,
842,
12,
4628,
63,
3266,
63,
633,
304,
272,
1613,
8,
36,
3834,
1282,
28051,
12,
291,
2843,
826,
721,
647,
2495,
63,
842,
9,
272,
327,
11041,
5262,
272,
291,
14,
4416,
63,
7011,
275,
283,
13707,
644,
3621,
2003,
13863,
334,
1397,
14318,
3171,
272,
291,
14,
4416,
63,
1129,
80,
275,
283,
5408,
48,
7,
272,
291,
14,
4416,
63,
87,
387,
30333,
275,
283,
55,
8470,
13,
7344,
279,
7,
272,
291,
14,
4416,
63,
87,
387,
18,
30333,
275,
283,
55,
8470,
13,
7344,
279,
7,
272,
291,
14,
4416,
63,
87,
387,
11366,
17,
88,
275,
283,
55,
8470,
13,
8468,
13219,
7,
272,
291,
14,
4416,
63,
87,
387,
1651,
15385,
88,
275,
283,
55,
8470,
18,
13,
8468,
13219,
7,
339,
291,
14,
2113,
63,
3266,
63,
633,
275,
4628,
63,
3266,
63,
633,
819,
347,
485,
4299,
44,
460,
316,
3276,
8,
277,
304,
272,
291,
14,
647,
2495,
63,
842,
14,
31914,
1378,
2632,
360,
1014,
13827,
83,
15,
1080,
14,
8624,
7,
450,
4318,
291,
14,
2113,
63,
3266,
63,
633,
9,
272,
2034,
63,
354,
275,
747,
14,
515,
14,
4846,
8,
277,
14,
647,
2495,
63,
842,
14,
1002,
7472,
7690,
2632,
1252,
1650,
1012,
272,
340,
2034,
63,
354,
508,
283,
2886,
14,
8624,
7,
503,
2034,
63,
354,
508,
283,
1080,
14,
8624,
356,
489,
862,
26,
267,
291,
423,
2573,
14,
8111,
8,
2734,
24700,
291,
423,
3090,
14,
1623,
63,
2108,
63,
991,
63,
8006,
8,
288,
18290,
10,
14251,
354,
628,
2886,
937,
1333,
489,
871,
19481,
14,
2330,
14,
3924,
14,
6372,
1726,
12,
325,
26,
267,
327,
23038,
781,
4898,
295,
13,
13243,
370,
314,
2897,
2034,
267,
340,
334,
736,
14,
515,
14,
4846,
8,
277,
14,
647,
2495,
63,
842,
14,
1002,
7472,
7690,
2632,
1252,
1650,
1012,
508,
288,
283,
66,
551,
63,
9819,
14,
8624,
735,
881,
372,
267,
2050,
14,
1971,
360,
27009,
1919,
26,
450,
83,
297,
620,
8,
69,
430,
489,
4676,
63,
3887,
275,
291,
423,
3090,
14,
1623,
63,
2108,
63,
991,
63,
8006,
15079,
10,
14251,
354,
628,
2886,
937,
358,
489,
4676,
63,
3887,
14,
4891,
342,
819,
347,
485,
4299,
5688,
3276,
8,
277,
304,
272,
291,
423,
4299,
44,
460,
316,
3276,
342,
272,
340,
334,
736,
14,
515,
14,
4846,
8,
277,
14,
647,
2495,
63,
842,
14,
1002,
7472,
7690,
2632,
1252,
1650,
1012,
1137,
267,
283,
66,
551,
63,
9819,
14,
8624,
735,
489,
291,
14,
1633,
8,
1328,
534,
22620,
917,
370,
376,
5809,
2034,
450,
83,
7,
450,
355,
291,
14,
647,
2495,
63,
842,
14,
1002,
7472,
7690,
2632,
1252,
1650,
1012,
339,
327,
19524,
781,
787,
3769,
10367,
315,
5847,
370,
314,
20078,
316,
2034,
272,
336,
1502,
275,
18290,
10,
14251,
354,
628,
87,
1502,
63,
11239,
2003,
937,
7,
272,
862,
26,
489,
291,
423,
2573,
14,
8111,
8,
2734,
24700,
291,
423,
3090,
14,
1623,
63,
2108,
63,
991,
63,
8006,
8,
87,
1502,
430,
272,
871,
19481,
14,
2330,
14,
3924,
14,
6372,
1726,
12,
325,
26,
489,
2050,
14,
1971,
360,
27009,
1919,
26,
450,
83,
297,
620,
8,
69,
430,
339,
336,
1502,
63,
3887,
275,
291,
423,
3090,
14,
1623,
63,
2108,
63,
991,
63,
8006,
8,
87,
1502,
9,
272,
336,
1502,
63,
3887,
14,
4891,
342,
272,
327,
13144,
367,
314,
2446,
2897,
2034,
12,
3648,
367,
314,
22008,
5528,
272,
862,
26,
489,
291,
423,
2573,
14,
8111,
8,
2734,
24700,
291,
423,
3090,
14,
1623,
63,
2108,
63,
991,
63,
8006,
8,
881,
283,
344,
480,
4296,
531,
1333,
272,
871,
19481,
14,
2330,
14,
3924,
14,
6372,
1726,
12,
325,
26,
489,
2050,
14,
1971,
360,
6005,
370,
2342,
314,
22008,
5528,
641,
314,
2446,
20078,
316,
283,
717,
283,
1606,
3134,
78,
27009,
1919,
26,
450,
83,
297,
620,
8,
69,
430,
819,
347,
2372,
11691,
985,
8,
277,
304,
272,
372,
283,
11691,
2812,
26,
577,
1282,
13,
1046,
1081,
27,
8089,
26,
577,
3834,
1282,
28051,
7,
819,
347,
2372,
11691,
10039,
985,
8,
277,
304,
272,
372,
283,
36,
1282,
13,
1046,
1081,
7,
819,
347,
2372,
16030,
17773,
8,
277,
304,
272,
372,
413,
819,
347,
2372,
10682,
34,
5915,
8,
277,
304,
272,
372,
9016,
7877,
356,
291,
14,
7877,
63,
18,
3561,
90,
12,
1467,
283,
6324,
356,
359,
17,
12,
499,
12,
650,
12,
841,
12,
959,
12,
1227,
12,
1520,
12,
1695,
12,
1749,
12,
1616,
12,
4119,
13888,
288,
791,
7877,
356,
291,
14,
7877,
63,
21,
3561,
90,
12,
1467,
283,
6324,
356,
359,
1479,
12,
6335,
12,
10868,
12,
9615,
12,
28528,
12,
25828,
12,
32400,
12,
32372,
12,
31852,
9420,
61,
819,
347,
2372,
10682,
19578,
8,
277,
304,
272,
372,
9016,
7877,
356,
291,
14,
7877,
63,
18,
3561,
90,
12,
1467,
283,
10433,
356,
359,
277,
14,
632,
63,
66,
12,
291,
14,
632,
63,
71,
12,
291,
14,
632,
63,
78,
12,
2432,
291,
14,
632,
63,
66,
1204,
291,
14,
632,
63,
71,
12,
291,
14,
632,
63,
71,
1204,
291,
14,
632,
63,
78,
13888,
288,
791,
7877,
356,
291,
14,
7877,
63,
21,
3561,
90,
12,
1467,
283,
10433,
356,
359,
277,
14,
632,
63,
65,
12,
291,
14,
632,
63,
78,
12,
291,
14,
632,
63,
65,
1204,
291,
14,
632,
63,
78,
9420,
61,
819,
347,
20721,
3237,
1378,
3276,
8,
277,
12,
2034,
63,
1955,
304,
272
] |
[
1898,
334,
67,
9,
6029,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
646,
2050,
199,
646,
747,
199,
199,
646,
2771,
63,
888,
17320,
199,
646,
19481,
14,
2330,
14,
3924,
421,
199,
533,
577,
3834,
1282,
28051,
8,
439,
63,
888,
17320,
14,
1282,
28051,
304,
523,
408,
17793,
12905,
1021,
370,
3304,
314,
577,
3834,
577,
1282,
13,
1046,
1081,
1041,
819,
347,
636,
826,
721,
277,
12,
1134,
2495,
63,
842,
12,
4628,
63,
3266,
63,
633,
304,
272,
1613,
8,
36,
3834,
1282,
28051,
12,
291,
2843,
826,
721,
647,
2495,
63,
842,
9,
272,
327,
11041,
5262,
272,
291,
14,
4416,
63,
7011,
275,
283,
13707,
644,
3621,
2003,
13863,
334,
1397,
14318,
3171,
272,
291,
14,
4416,
63,
1129,
80,
275,
283,
5408,
48,
7,
272,
291,
14,
4416,
63,
87,
387,
30333,
275,
283,
55,
8470,
13,
7344,
279,
7,
272,
291,
14,
4416,
63,
87,
387,
18,
30333,
275,
283,
55,
8470,
13,
7344,
279,
7,
272,
291,
14,
4416,
63,
87,
387,
11366,
17,
88,
275,
283,
55,
8470,
13,
8468,
13219,
7,
272,
291,
14,
4416,
63,
87,
387,
1651,
15385,
88,
275,
283,
55,
8470,
18,
13,
8468,
13219,
7,
339,
291,
14,
2113,
63,
3266,
63,
633,
275,
4628,
63,
3266,
63,
633,
819,
347,
485,
4299,
44,
460,
316,
3276,
8,
277,
304,
272,
291,
14,
647,
2495,
63,
842,
14,
31914,
1378,
2632,
360,
1014,
13827,
83,
15,
1080,
14,
8624,
7,
450,
4318,
291,
14,
2113,
63,
3266,
63,
633,
9,
272,
2034,
63,
354,
275,
747,
14,
515,
14,
4846,
8,
277,
14,
647,
2495,
63,
842,
14,
1002,
7472,
7690,
2632,
1252,
1650,
1012,
272,
340,
2034,
63,
354,
508,
283,
2886,
14,
8624,
7,
503,
2034,
63,
354,
508,
283,
1080,
14,
8624,
356,
489,
862,
26,
267,
291,
423,
2573,
14,
8111,
8,
2734,
24700,
291,
423,
3090,
14,
1623,
63,
2108,
63,
991,
63,
8006,
8,
288,
18290,
10,
14251,
354,
628,
2886,
937,
1333,
489,
871,
19481,
14,
2330,
14,
3924,
14,
6372,
1726,
12,
325,
26,
267,
327,
23038,
781,
4898,
295,
13,
13243,
370,
314,
2897,
2034,
267,
340,
334,
736,
14,
515,
14,
4846,
8,
277,
14,
647,
2495,
63,
842,
14,
1002,
7472,
7690,
2632,
1252,
1650,
1012,
508,
288,
283,
66,
551,
63,
9819,
14,
8624,
735,
881,
372,
267,
2050,
14,
1971,
360,
27009,
1919,
26,
450,
83,
297,
620,
8,
69,
430,
489,
4676,
63,
3887,
275,
291,
423,
3090,
14,
1623,
63,
2108,
63,
991,
63,
8006,
15079,
10,
14251,
354,
628,
2886,
937,
358,
489,
4676,
63,
3887,
14,
4891,
342,
819,
347,
485,
4299,
5688,
3276,
8,
277,
304,
272,
291,
423,
4299,
44,
460,
316,
3276,
342,
272,
340,
334,
736,
14,
515,
14,
4846,
8,
277,
14,
647,
2495,
63,
842,
14,
1002,
7472,
7690,
2632,
1252,
1650,
1012,
1137,
267,
283,
66,
551,
63,
9819,
14,
8624,
735,
489,
291,
14,
1633,
8,
1328,
534,
22620,
917,
370,
376,
5809,
2034,
450,
83,
7,
450,
355,
291,
14,
647,
2495,
63,
842,
14,
1002,
7472,
7690,
2632,
1252,
1650,
1012,
339,
327,
19524,
781,
787,
3769,
10367,
315,
5847,
370,
314,
20078,
316,
2034,
272,
336,
1502,
275,
18290,
10,
14251,
354,
628,
87,
1502,
63,
11239,
2003,
937,
7,
272,
862,
26,
489,
291,
423,
2573,
14,
8111,
8,
2734,
24700,
291,
423,
3090,
14,
1623,
63,
2108,
63,
991,
63,
8006,
8,
87,
1502,
430,
272,
871,
19481,
14,
2330,
14,
3924,
14,
6372,
1726,
12,
325,
26,
489,
2050,
14,
1971,
360,
27009,
1919,
26,
450,
83,
297,
620,
8,
69,
430,
339,
336,
1502,
63,
3887,
275,
291,
423,
3090,
14,
1623,
63,
2108,
63,
991,
63,
8006,
8,
87,
1502,
9,
272,
336,
1502,
63,
3887,
14,
4891,
342,
272,
327,
13144,
367,
314,
2446,
2897,
2034,
12,
3648,
367,
314,
22008,
5528,
272,
862,
26,
489,
291,
423,
2573,
14,
8111,
8,
2734,
24700,
291,
423,
3090,
14,
1623,
63,
2108,
63,
991,
63,
8006,
8,
881,
283,
344,
480,
4296,
531,
1333,
272,
871,
19481,
14,
2330,
14,
3924,
14,
6372,
1726,
12,
325,
26,
489,
2050,
14,
1971,
360,
6005,
370,
2342,
314,
22008,
5528,
641,
314,
2446,
20078,
316,
283,
717,
283,
1606,
3134,
78,
27009,
1919,
26,
450,
83,
297,
620,
8,
69,
430,
819,
347,
2372,
11691,
985,
8,
277,
304,
272,
372,
283,
11691,
2812,
26,
577,
1282,
13,
1046,
1081,
27,
8089,
26,
577,
3834,
1282,
28051,
7,
819,
347,
2372,
11691,
10039,
985,
8,
277,
304,
272,
372,
283,
36,
1282,
13,
1046,
1081,
7,
819,
347,
2372,
16030,
17773,
8,
277,
304,
272,
372,
413,
819,
347,
2372,
10682,
34,
5915,
8,
277,
304,
272,
372,
9016,
7877,
356,
291,
14,
7877,
63,
18,
3561,
90,
12,
1467,
283,
6324,
356,
359,
17,
12,
499,
12,
650,
12,
841,
12,
959,
12,
1227,
12,
1520,
12,
1695,
12,
1749,
12,
1616,
12,
4119,
13888,
288,
791,
7877,
356,
291,
14,
7877,
63,
21,
3561,
90,
12,
1467,
283,
6324,
356,
359,
1479,
12,
6335,
12,
10868,
12,
9615,
12,
28528,
12,
25828,
12,
32400,
12,
32372,
12,
31852,
9420,
61,
819,
347,
2372,
10682,
19578,
8,
277,
304,
272,
372,
9016,
7877,
356,
291,
14,
7877,
63,
18,
3561,
90,
12,
1467,
283,
10433,
356,
359,
277,
14,
632,
63,
66,
12,
291,
14,
632,
63,
71,
12,
291,
14,
632,
63,
78,
12,
2432,
291,
14,
632,
63,
66,
1204,
291,
14,
632,
63,
71,
12,
291,
14,
632,
63,
71,
1204,
291,
14,
632,
63,
78,
13888,
288,
791,
7877,
356,
291,
14,
7877,
63,
21,
3561,
90,
12,
1467,
283,
10433,
356,
359,
277,
14,
632,
63,
65,
12,
291,
14,
632,
63,
78,
12,
291,
14,
632,
63,
65,
1204,
291,
14,
632,
63,
78,
9420,
61,
819,
347,
20721,
3237,
1378,
3276,
8,
277,
12,
2034,
63,
1955,
304,
272,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
Filechaser/nzbToMedia
|
libs/unidecode/x063.py
|
252
|
4656
|
data = (
'Bo ', # 0x00
'Chi ', # 0x01
'Gua ', # 0x02
'Zhi ', # 0x03
'Kuo ', # 0x04
'Duo ', # 0x05
'Duo ', # 0x06
'Zhi ', # 0x07
'Qie ', # 0x08
'An ', # 0x09
'Nong ', # 0x0a
'Zhen ', # 0x0b
'Ge ', # 0x0c
'Jiao ', # 0x0d
'Ku ', # 0x0e
'Dong ', # 0x0f
'Ru ', # 0x10
'Tiao ', # 0x11
'Lie ', # 0x12
'Zha ', # 0x13
'Lu ', # 0x14
'Die ', # 0x15
'Wa ', # 0x16
'Jue ', # 0x17
'Mushiru ', # 0x18
'Ju ', # 0x19
'Zhi ', # 0x1a
'Luan ', # 0x1b
'Ya ', # 0x1c
'Zhua ', # 0x1d
'Ta ', # 0x1e
'Xie ', # 0x1f
'Nao ', # 0x20
'Dang ', # 0x21
'Jiao ', # 0x22
'Zheng ', # 0x23
'Ji ', # 0x24
'Hui ', # 0x25
'Xun ', # 0x26
'Ku ', # 0x27
'Ai ', # 0x28
'Tuo ', # 0x29
'Nuo ', # 0x2a
'Cuo ', # 0x2b
'Bo ', # 0x2c
'Geng ', # 0x2d
'Ti ', # 0x2e
'Zhen ', # 0x2f
'Cheng ', # 0x30
'Suo ', # 0x31
'Suo ', # 0x32
'Keng ', # 0x33
'Mei ', # 0x34
'Long ', # 0x35
'Ju ', # 0x36
'Peng ', # 0x37
'Jian ', # 0x38
'Yi ', # 0x39
'Ting ', # 0x3a
'Shan ', # 0x3b
'Nuo ', # 0x3c
'Wan ', # 0x3d
'Xie ', # 0x3e
'Cha ', # 0x3f
'Feng ', # 0x40
'Jiao ', # 0x41
'Wu ', # 0x42
'Jun ', # 0x43
'Jiu ', # 0x44
'Tong ', # 0x45
'Kun ', # 0x46
'Huo ', # 0x47
'Tu ', # 0x48
'Zhuo ', # 0x49
'Pou ', # 0x4a
'Le ', # 0x4b
'Ba ', # 0x4c
'Han ', # 0x4d
'Shao ', # 0x4e
'Nie ', # 0x4f
'Juan ', # 0x50
'Ze ', # 0x51
'Song ', # 0x52
'Ye ', # 0x53
'Jue ', # 0x54
'Bu ', # 0x55
'Huan ', # 0x56
'Bu ', # 0x57
'Zun ', # 0x58
'Yi ', # 0x59
'Zhai ', # 0x5a
'Lu ', # 0x5b
'Sou ', # 0x5c
'Tuo ', # 0x5d
'Lao ', # 0x5e
'Sun ', # 0x5f
'Bang ', # 0x60
'Jian ', # 0x61
'Huan ', # 0x62
'Dao ', # 0x63
'[?] ', # 0x64
'Wan ', # 0x65
'Qin ', # 0x66
'Peng ', # 0x67
'She ', # 0x68
'Lie ', # 0x69
'Min ', # 0x6a
'Men ', # 0x6b
'Fu ', # 0x6c
'Bai ', # 0x6d
'Ju ', # 0x6e
'Dao ', # 0x6f
'Wo ', # 0x70
'Ai ', # 0x71
'Juan ', # 0x72
'Yue ', # 0x73
'Zong ', # 0x74
'Chen ', # 0x75
'Chui ', # 0x76
'Jie ', # 0x77
'Tu ', # 0x78
'Ben ', # 0x79
'Na ', # 0x7a
'Nian ', # 0x7b
'Nuo ', # 0x7c
'Zu ', # 0x7d
'Wo ', # 0x7e
'Xi ', # 0x7f
'Xian ', # 0x80
'Cheng ', # 0x81
'Dian ', # 0x82
'Sao ', # 0x83
'Lun ', # 0x84
'Qing ', # 0x85
'Gang ', # 0x86
'Duo ', # 0x87
'Shou ', # 0x88
'Diao ', # 0x89
'Pou ', # 0x8a
'Di ', # 0x8b
'Zhang ', # 0x8c
'Gun ', # 0x8d
'Ji ', # 0x8e
'Tao ', # 0x8f
'Qia ', # 0x90
'Qi ', # 0x91
'Pai ', # 0x92
'Shu ', # 0x93
'Qian ', # 0x94
'Ling ', # 0x95
'Yi ', # 0x96
'Ya ', # 0x97
'Jue ', # 0x98
'Zheng ', # 0x99
'Liang ', # 0x9a
'Gua ', # 0x9b
'Yi ', # 0x9c
'Huo ', # 0x9d
'Shan ', # 0x9e
'Zheng ', # 0x9f
'Lue ', # 0xa0
'Cai ', # 0xa1
'Tan ', # 0xa2
'Che ', # 0xa3
'Bing ', # 0xa4
'Jie ', # 0xa5
'Ti ', # 0xa6
'Kong ', # 0xa7
'Tui ', # 0xa8
'Yan ', # 0xa9
'Cuo ', # 0xaa
'Zou ', # 0xab
'Ju ', # 0xac
'Tian ', # 0xad
'Qian ', # 0xae
'Ken ', # 0xaf
'Bai ', # 0xb0
'Shou ', # 0xb1
'Jie ', # 0xb2
'Lu ', # 0xb3
'Guo ', # 0xb4
'Haba ', # 0xb5
'[?] ', # 0xb6
'Zhi ', # 0xb7
'Dan ', # 0xb8
'Mang ', # 0xb9
'Xian ', # 0xba
'Sao ', # 0xbb
'Guan ', # 0xbc
'Peng ', # 0xbd
'Yuan ', # 0xbe
'Nuo ', # 0xbf
'Jian ', # 0xc0
'Zhen ', # 0xc1
'Jiu ', # 0xc2
'Jian ', # 0xc3
'Yu ', # 0xc4
'Yan ', # 0xc5
'Kui ', # 0xc6
'Nan ', # 0xc7
'Hong ', # 0xc8
'Rou ', # 0xc9
'Pi ', # 0xca
'Wei ', # 0xcb
'Sai ', # 0xcc
'Zou ', # 0xcd
'Xuan ', # 0xce
'Miao ', # 0xcf
'Ti ', # 0xd0
'Nie ', # 0xd1
'Cha ', # 0xd2
'Shi ', # 0xd3
'Zong ', # 0xd4
'Zhen ', # 0xd5
'Yi ', # 0xd6
'Shun ', # 0xd7
'Heng ', # 0xd8
'Bian ', # 0xd9
'Yang ', # 0xda
'Huan ', # 0xdb
'Yan ', # 0xdc
'Zuan ', # 0xdd
'An ', # 0xde
'Xu ', # 0xdf
'Ya ', # 0xe0
'Wo ', # 0xe1
'Ke ', # 0xe2
'Chuai ', # 0xe3
'Ji ', # 0xe4
'Ti ', # 0xe5
'La ', # 0xe6
'La ', # 0xe7
'Cheng ', # 0xe8
'Kai ', # 0xe9
'Jiu ', # 0xea
'Jiu ', # 0xeb
'Tu ', # 0xec
'Jie ', # 0xed
'Hui ', # 0xee
'Geng ', # 0xef
'Chong ', # 0xf0
'Shuo ', # 0xf1
'She ', # 0xf2
'Xie ', # 0xf3
'Yuan ', # 0xf4
'Qian ', # 0xf5
'Ye ', # 0xf6
'Cha ', # 0xf7
'Zha ', # 0xf8
'Bei ', # 0xf9
'Yao ', # 0xfa
'[?] ', # 0xfb
'[?] ', # 0xfc
'Lan ', # 0xfd
'Wen ', # 0xfe
'Qin ', # 0xff
)
|
gpl-3.0
|
[
576,
275,
334,
199,
7,
2208,
1656,
259,
327,
378,
88,
383,
199,
7,
29218,
1656,
259,
327,
378,
88,
614,
199,
7,
39,
1458,
1656,
259,
327,
378,
88,
996,
199,
7,
58,
5812,
1656,
259,
327,
378,
88,
1644,
199,
7,
43,
13780,
1656,
259,
327,
378,
88,
966,
199,
7,
36,
13780,
1656,
259,
327,
378,
88,
1717,
199,
7,
36,
13780,
1656,
259,
327,
378,
88,
1690,
199,
7,
58,
5812,
1656,
259,
327,
378,
88,
1780,
199,
7,
49,
1873,
1656,
259,
327,
378,
88,
2036,
199,
7,
2493,
1656,
259,
327,
378,
88,
1643,
199,
7,
46,
951,
1656,
259,
327,
378,
88,
16,
65,
199,
7,
12674,
287,
1656,
259,
327,
378,
88,
16,
66,
199,
7,
4240,
1656,
259,
327,
378,
88,
16,
67,
199,
7,
42,
18939,
1656,
259,
327,
378,
88,
16,
68,
199,
7,
31487,
1656,
259,
327,
378,
88,
16,
69,
199,
7,
36,
951,
1656,
259,
327,
378,
88,
16,
70,
199,
7,
50,
85,
1656,
259,
327,
378,
88,
709,
199,
7,
52,
18939,
1656,
259,
327,
378,
88,
845,
199,
7,
44,
1873,
1656,
259,
327,
378,
88,
713,
199,
7,
58,
2411,
1656,
259,
327,
378,
88,
969,
199,
7,
18176,
1656,
259,
327,
378,
88,
1079,
199,
7,
1341,
69,
1656,
259,
327,
378,
88,
1046,
199,
7,
24804,
1656,
259,
327,
378,
88,
975,
199,
7,
42,
310,
1656,
259,
327,
378,
88,
1196,
199,
7,
45,
2084,
723,
85,
1656,
259,
327,
378,
88,
1085,
199,
7,
24783,
1656,
259,
327,
378,
88,
1167,
199,
7,
58,
5812,
1656,
259,
327,
378,
88,
17,
65,
199,
7,
44,
7856,
1656,
259,
327,
378,
88,
17,
66,
199,
7,
28786,
1656,
259,
327,
378,
88,
17,
67,
199,
7,
12674,
1458,
1656,
259,
327,
378,
88,
17,
68,
199,
7,
22620,
1656,
259,
327,
378,
88,
17,
69,
199,
7,
56,
1873,
1656,
259,
327,
378,
88,
17,
70,
199,
7,
46,
8035,
1656,
259,
327,
378,
88,
1165,
199,
7,
36,
621,
1656,
259,
327,
378,
88,
2025,
199,
7,
42,
18939,
1656,
259,
327,
378,
88,
1081,
199,
7,
12674,
7420,
1656,
259,
327,
378,
88,
1789,
199,
7,
16911,
1656,
259,
327,
378,
88,
1194,
199,
7,
40,
1907,
1656,
259,
327,
378,
88,
821,
199,
7,
56,
324,
1656,
259,
327,
378,
88,
1479,
199,
7,
31487,
1656,
259,
327,
378,
88,
1465,
199,
7,
28960,
1656,
259,
327,
378,
88,
1651,
199,
7,
52,
13780,
1656,
259,
327,
378,
88,
1398,
199,
7,
46,
13780,
1656,
259,
327,
378,
88,
18,
65,
199,
7,
35,
13780,
1656,
259,
327,
378,
88,
18,
66,
199,
7,
2208,
1656,
259,
327,
378,
88,
18,
67,
199,
7,
39,
7420,
1656,
259,
327,
378,
88,
18,
68,
199,
7,
22731,
1656,
259,
327,
378,
88,
18,
69,
199,
7,
12674,
287,
1656,
259,
327,
378,
88,
18,
70,
199,
7,
1049,
7420,
1656,
259,
327,
378,
88,
1216,
199,
7,
51,
13780,
1656,
259,
327,
378,
88,
2192,
199,
7,
51,
13780,
1656,
259,
327,
378,
88,
708,
199,
7,
43,
7420,
1656,
259,
327,
378,
88,
1153,
199,
7,
1352,
73,
1656,
259,
327,
378,
88,
1082,
199,
7,
9551,
1656,
259,
327,
378,
88,
1276,
199,
7,
24783,
1656,
259,
327,
378,
88,
1344,
199,
7,
48,
7420,
1656,
259,
327,
378,
88,
1401,
199,
7,
42,
5653,
1656,
259,
327,
378,
88,
1703,
199,
7,
21001,
1656,
259,
327,
378,
88,
1355,
199,
7,
52,
316,
1656,
259,
327,
378,
88,
19,
65,
199,
7,
2662,
290,
1656,
259,
327,
378,
88,
19,
66,
199,
7,
46,
13780,
1656,
259,
327,
378,
88,
19,
67,
199,
7,
55,
290,
1656,
259,
327,
378,
88,
19,
68,
199,
7,
56,
1873,
1656,
259,
327,
378,
88,
19,
69,
199,
7,
1049,
65,
1656,
259,
327,
378,
88,
19,
70,
199,
7,
38,
7420,
1656,
259,
327,
378,
88,
2167,
199,
7,
42,
18939,
1656,
259,
327,
378,
88,
2953,
199,
7,
25728,
1656,
259,
327,
378,
88,
2260,
199,
7,
42,
324,
1656,
259,
327,
378,
88,
2824,
199,
7,
16911,
85,
1656,
259,
327,
378,
88,
1602,
199,
7,
52,
951,
1656,
259,
327,
378,
88,
2322,
199,
7,
43,
324,
1656,
259,
327,
378,
88,
2466,
199,
7,
40,
13780,
1656,
259,
327,
378,
88,
2417,
199,
7,
30669,
1656,
259,
327,
378,
88,
2006,
199,
7,
31183,
79,
1656,
259,
327,
378,
88,
1887,
199,
7,
48,
810,
1656,
259,
327,
378,
88,
20,
65,
199,
7,
2553,
1656,
259,
327,
378,
88,
20,
66,
199,
7,
13864,
1656,
259,
327,
378,
88,
20,
67,
199,
7,
40,
290,
1656,
259,
327,
378,
88,
20,
68,
199,
7,
23527,
79,
1656,
259,
327,
378,
88,
20,
69,
199,
7,
46,
1873,
1656,
259,
327,
378,
88,
20,
70,
199,
7,
42,
7856,
1656,
259,
327,
378,
88,
1400,
199,
7,
58,
69,
1656,
259,
327,
378,
88,
2869,
199,
7,
51,
951,
1656,
259,
327,
378,
88,
2528,
199,
7,
57,
69,
1656,
259,
327,
378,
88,
2481,
199,
7,
42,
310,
1656,
259,
327,
378,
88,
1477,
199,
7,
1713,
1656,
259,
327,
378,
88,
1229,
199,
7,
40,
7856,
1656,
259,
327,
378,
88,
1367,
199,
7,
1713,
1656,
259,
327,
378,
88,
1641,
199,
7,
58,
324,
1656,
259,
327,
378,
88,
2010,
199,
7,
21001,
1656,
259,
327,
378,
88,
1427,
199,
7,
58,
17945,
1656,
259,
327,
378,
88,
21,
65,
199,
7,
18176,
1656,
259,
327,
378,
88,
21,
66,
199,
7,
51,
810,
1656,
259,
327,
378,
88,
21,
67,
199,
7,
52,
13780,
1656,
259,
327,
378,
88,
21,
68,
199,
7,
7833,
79,
1656,
259,
327,
378,
88,
21,
69,
199,
7,
22546,
1656,
259,
327,
378,
88,
21,
70,
199,
7,
34,
621,
1656,
259,
327,
378,
88,
2259,
199,
7,
42,
5653,
1656,
259,
327,
378,
88,
2976,
199,
7,
40,
7856,
1656,
259,
327,
378,
88,
2789,
199,
7,
27361,
1656,
259,
327,
378,
88,
2766,
199,
17892,
1656,
259,
327,
378,
88,
772,
199,
7,
55
] |
[
275,
334,
199,
7,
2208,
1656,
259,
327,
378,
88,
383,
199,
7,
29218,
1656,
259,
327,
378,
88,
614,
199,
7,
39,
1458,
1656,
259,
327,
378,
88,
996,
199,
7,
58,
5812,
1656,
259,
327,
378,
88,
1644,
199,
7,
43,
13780,
1656,
259,
327,
378,
88,
966,
199,
7,
36,
13780,
1656,
259,
327,
378,
88,
1717,
199,
7,
36,
13780,
1656,
259,
327,
378,
88,
1690,
199,
7,
58,
5812,
1656,
259,
327,
378,
88,
1780,
199,
7,
49,
1873,
1656,
259,
327,
378,
88,
2036,
199,
7,
2493,
1656,
259,
327,
378,
88,
1643,
199,
7,
46,
951,
1656,
259,
327,
378,
88,
16,
65,
199,
7,
12674,
287,
1656,
259,
327,
378,
88,
16,
66,
199,
7,
4240,
1656,
259,
327,
378,
88,
16,
67,
199,
7,
42,
18939,
1656,
259,
327,
378,
88,
16,
68,
199,
7,
31487,
1656,
259,
327,
378,
88,
16,
69,
199,
7,
36,
951,
1656,
259,
327,
378,
88,
16,
70,
199,
7,
50,
85,
1656,
259,
327,
378,
88,
709,
199,
7,
52,
18939,
1656,
259,
327,
378,
88,
845,
199,
7,
44,
1873,
1656,
259,
327,
378,
88,
713,
199,
7,
58,
2411,
1656,
259,
327,
378,
88,
969,
199,
7,
18176,
1656,
259,
327,
378,
88,
1079,
199,
7,
1341,
69,
1656,
259,
327,
378,
88,
1046,
199,
7,
24804,
1656,
259,
327,
378,
88,
975,
199,
7,
42,
310,
1656,
259,
327,
378,
88,
1196,
199,
7,
45,
2084,
723,
85,
1656,
259,
327,
378,
88,
1085,
199,
7,
24783,
1656,
259,
327,
378,
88,
1167,
199,
7,
58,
5812,
1656,
259,
327,
378,
88,
17,
65,
199,
7,
44,
7856,
1656,
259,
327,
378,
88,
17,
66,
199,
7,
28786,
1656,
259,
327,
378,
88,
17,
67,
199,
7,
12674,
1458,
1656,
259,
327,
378,
88,
17,
68,
199,
7,
22620,
1656,
259,
327,
378,
88,
17,
69,
199,
7,
56,
1873,
1656,
259,
327,
378,
88,
17,
70,
199,
7,
46,
8035,
1656,
259,
327,
378,
88,
1165,
199,
7,
36,
621,
1656,
259,
327,
378,
88,
2025,
199,
7,
42,
18939,
1656,
259,
327,
378,
88,
1081,
199,
7,
12674,
7420,
1656,
259,
327,
378,
88,
1789,
199,
7,
16911,
1656,
259,
327,
378,
88,
1194,
199,
7,
40,
1907,
1656,
259,
327,
378,
88,
821,
199,
7,
56,
324,
1656,
259,
327,
378,
88,
1479,
199,
7,
31487,
1656,
259,
327,
378,
88,
1465,
199,
7,
28960,
1656,
259,
327,
378,
88,
1651,
199,
7,
52,
13780,
1656,
259,
327,
378,
88,
1398,
199,
7,
46,
13780,
1656,
259,
327,
378,
88,
18,
65,
199,
7,
35,
13780,
1656,
259,
327,
378,
88,
18,
66,
199,
7,
2208,
1656,
259,
327,
378,
88,
18,
67,
199,
7,
39,
7420,
1656,
259,
327,
378,
88,
18,
68,
199,
7,
22731,
1656,
259,
327,
378,
88,
18,
69,
199,
7,
12674,
287,
1656,
259,
327,
378,
88,
18,
70,
199,
7,
1049,
7420,
1656,
259,
327,
378,
88,
1216,
199,
7,
51,
13780,
1656,
259,
327,
378,
88,
2192,
199,
7,
51,
13780,
1656,
259,
327,
378,
88,
708,
199,
7,
43,
7420,
1656,
259,
327,
378,
88,
1153,
199,
7,
1352,
73,
1656,
259,
327,
378,
88,
1082,
199,
7,
9551,
1656,
259,
327,
378,
88,
1276,
199,
7,
24783,
1656,
259,
327,
378,
88,
1344,
199,
7,
48,
7420,
1656,
259,
327,
378,
88,
1401,
199,
7,
42,
5653,
1656,
259,
327,
378,
88,
1703,
199,
7,
21001,
1656,
259,
327,
378,
88,
1355,
199,
7,
52,
316,
1656,
259,
327,
378,
88,
19,
65,
199,
7,
2662,
290,
1656,
259,
327,
378,
88,
19,
66,
199,
7,
46,
13780,
1656,
259,
327,
378,
88,
19,
67,
199,
7,
55,
290,
1656,
259,
327,
378,
88,
19,
68,
199,
7,
56,
1873,
1656,
259,
327,
378,
88,
19,
69,
199,
7,
1049,
65,
1656,
259,
327,
378,
88,
19,
70,
199,
7,
38,
7420,
1656,
259,
327,
378,
88,
2167,
199,
7,
42,
18939,
1656,
259,
327,
378,
88,
2953,
199,
7,
25728,
1656,
259,
327,
378,
88,
2260,
199,
7,
42,
324,
1656,
259,
327,
378,
88,
2824,
199,
7,
16911,
85,
1656,
259,
327,
378,
88,
1602,
199,
7,
52,
951,
1656,
259,
327,
378,
88,
2322,
199,
7,
43,
324,
1656,
259,
327,
378,
88,
2466,
199,
7,
40,
13780,
1656,
259,
327,
378,
88,
2417,
199,
7,
30669,
1656,
259,
327,
378,
88,
2006,
199,
7,
31183,
79,
1656,
259,
327,
378,
88,
1887,
199,
7,
48,
810,
1656,
259,
327,
378,
88,
20,
65,
199,
7,
2553,
1656,
259,
327,
378,
88,
20,
66,
199,
7,
13864,
1656,
259,
327,
378,
88,
20,
67,
199,
7,
40,
290,
1656,
259,
327,
378,
88,
20,
68,
199,
7,
23527,
79,
1656,
259,
327,
378,
88,
20,
69,
199,
7,
46,
1873,
1656,
259,
327,
378,
88,
20,
70,
199,
7,
42,
7856,
1656,
259,
327,
378,
88,
1400,
199,
7,
58,
69,
1656,
259,
327,
378,
88,
2869,
199,
7,
51,
951,
1656,
259,
327,
378,
88,
2528,
199,
7,
57,
69,
1656,
259,
327,
378,
88,
2481,
199,
7,
42,
310,
1656,
259,
327,
378,
88,
1477,
199,
7,
1713,
1656,
259,
327,
378,
88,
1229,
199,
7,
40,
7856,
1656,
259,
327,
378,
88,
1367,
199,
7,
1713,
1656,
259,
327,
378,
88,
1641,
199,
7,
58,
324,
1656,
259,
327,
378,
88,
2010,
199,
7,
21001,
1656,
259,
327,
378,
88,
1427,
199,
7,
58,
17945,
1656,
259,
327,
378,
88,
21,
65,
199,
7,
18176,
1656,
259,
327,
378,
88,
21,
66,
199,
7,
51,
810,
1656,
259,
327,
378,
88,
21,
67,
199,
7,
52,
13780,
1656,
259,
327,
378,
88,
21,
68,
199,
7,
7833,
79,
1656,
259,
327,
378,
88,
21,
69,
199,
7,
22546,
1656,
259,
327,
378,
88,
21,
70,
199,
7,
34,
621,
1656,
259,
327,
378,
88,
2259,
199,
7,
42,
5653,
1656,
259,
327,
378,
88,
2976,
199,
7,
40,
7856,
1656,
259,
327,
378,
88,
2789,
199,
7,
27361,
1656,
259,
327,
378,
88,
2766,
199,
17892,
1656,
259,
327,
378,
88,
772,
199,
7,
55,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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authors__ = "Ian Goodfellow"
__copyright__ = "Copyright 2013, Universite de Montreal"
__credits__ = ["Ian Goodfellow"]
__license__ = "3-clause BSD"
__maintainer__ = "LISA Lab"
__email__ = "pylearn-dev@googlegroups"
import numpy as np
import warnings
from theano.compat.six.moves import xrange
from theano import config
from theano import function
import theano.tensor as T
from pylearn2.expr.normalize import (CrossChannelNormalization,
CrossChannelNormalizationBC01)
def ground_truth_normalizer(c01b, k, n, alpha, beta):
out = np.zeros(c01b.shape)
for r in xrange(out.shape[1]):
for c in xrange(out.shape[2]):
for x in xrange(out.shape[3]):
out[:,r,c,x] = ground_truth_normalize_row(row=c01b[:,r,c,x], k=k, n=n, alpha=alpha, beta=beta)
return out
def ground_truth_normalize_row(row, k, n, alpha, beta):
assert row.ndim == 1
out = np.zeros(row.shape)
for i in xrange(row.shape[0]):
s = k
tot = 0
for j in xrange(max(0, i-n//2), min(row.shape[0], i+n//2+1)):
tot += 1
sq = row[j] ** 2.
assert sq > 0.
assert s >= k
assert alpha > 0.
s += alpha * sq
assert s >= k
assert tot <= n
assert s >= k
s = s ** beta
out[i] = row[i] / s
return out
def basic_test():
channels = 15
rows = 3
cols = 4
batch_size = 2
shape = [channels, rows, cols, batch_size]
k = 2
n = 5
# use a big value of alpha so mistakes involving alpha show up strong
alpha = 1.5
beta = 0.75
# Perform test for C01B
rng = np.random.RandomState([2013,2])
c01b = rng.randn(*shape).astype(config.floatX)
normalizer = CrossChannelNormalization(k=k, n=n, alpha=alpha, beta=beta)
warnings.warn("TODO: add test for the CudaConvnet version.")
X = T.TensorType(dtype=config.floatX, broadcastable=tuple([False]*4))()
out = normalizer(X)
out = function([X], out)(c01b)
ground_out = ground_truth_normalizer(c01b, n=n, k=k, alpha=alpha, beta=beta)
assert out.shape == ground_out.shape
diff = out - ground_out
err = np.abs(diff)
max_err = err.max()
if not np.allclose(out, ground_out):
print('C01B test failed')
print('error range: ',(err.min(), err.max()))
print('output: ')
print(out)
print('expected output: ')
print(ground_out)
assert False
# Perform test for BC01
bc01 = np.transpose(c01b, [3,0,1,2])
normalizerBC01 = CrossChannelNormalizationBC01(k=k, n=n, alpha=alpha, beta=beta)
X = T.TensorType(dtype=config.floatX, broadcastable=tuple([False]*4))()
out = normalizerBC01(X)
out = function([X], out)(bc01)
ground_out_BC01 = np.transpose(ground_out, [3,0,1,2])
assert out.shape == ground_out_BC01.shape
diff = out - ground_out_BC01
err = np.abs(diff)
max_err = err.max()
if not np.allclose(out, ground_out_BC01):
print('BC01 test failed')
print('error range: ',(err.min(), err.max()))
print('output: ')
print(out)
print('expected output: ')
print(ground_out)
assert False
|
bsd-3-clause
|
[
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
363,
8149,
363,
275,
298,
41,
290,
22311,
70,
10723,
2,
199,
363,
7307,
363,
275,
298,
7384,
6171,
12,
1910,
4380,
2124,
477,
603,
1888,
3093,
2,
199,
363,
22461,
363,
275,
2097,
41,
290,
22311,
70,
10723,
937,
199,
363,
1682,
363,
275,
298,
19,
13,
8501,
6289,
2,
199,
363,
26665,
363,
275,
298,
44,
1311,
33,
16871,
2,
199,
363,
2123,
363,
275,
298,
647,
4643,
13,
2374,
32,
3098,
2634,
2,
199,
199,
646,
2680,
465,
980,
199,
646,
3598,
199,
199,
504,
14377,
14,
5819,
14,
4174,
14,
4912,
492,
4945,
199,
504,
14377,
492,
1101,
199,
504,
14377,
492,
805,
199,
646,
14377,
14,
3128,
465,
377,
199,
199,
504,
27959,
18,
14,
3684,
14,
7721,
492,
334,
14072,
5358,
29169,
12,
3660,
28965,
5358,
29169,
6265,
614,
9,
199,
199,
318,
19252,
63,
17167,
63,
3302,
1793,
8,
67,
614,
66,
12,
1022,
12,
302,
12,
5131,
12,
8201,
304,
272,
734,
275,
980,
14,
4250,
8,
67,
614,
66,
14,
1392,
9,
339,
367,
519,
315,
4945,
8,
548,
14,
1392,
59,
17,
4682,
267,
367,
286,
315,
4945,
8,
548,
14,
1392,
59,
18,
4682,
288,
367,
671,
315,
4945,
8,
548,
14,
1392,
59,
19,
4682,
355,
734,
3981,
82,
12,
67,
12,
88,
61,
275,
19252,
63,
17167,
63,
7721,
63,
1143,
8,
1143,
29,
67,
614,
66,
3981,
82,
12,
67,
12,
88,
467,
1022,
29,
75,
12,
302,
29,
78,
12,
5131,
29,
4468,
12,
8201,
29,
5683,
9,
272,
372,
734,
199,
199,
318,
19252,
63,
17167,
63,
7721,
63,
1143,
8,
1143,
12,
1022,
12,
302,
12,
5131,
12,
8201,
304,
272,
702,
1962,
14,
8322,
508,
413,
272,
734,
275,
980,
14,
4250,
8,
1143,
14,
1392,
9,
272,
367,
284,
315,
4945,
8,
1143,
14,
1392,
59,
16,
4682,
267,
308,
275,
1022,
267,
12657,
275,
378,
267,
367,
1335,
315,
4945,
8,
988,
8,
16,
12,
284,
13,
78,
501,
18,
395,
1748,
8,
1143,
14,
1392,
59,
16,
467,
284,
11,
78,
501,
18,
11,
17,
2298,
288,
12657,
847,
413,
288,
5295,
275,
1962,
59,
74,
61,
1011,
499,
14,
288,
702,
5295,
690,
378,
14,
288,
702,
308,
2356,
1022,
288,
702,
5131,
690,
378,
14,
288,
308,
847,
5131,
627,
5295,
288,
702,
308,
2356,
1022,
267,
702,
12657,
2695,
302,
267,
702,
308,
2356,
1022,
267,
308,
275,
308,
1011,
8201,
267,
734,
59,
73,
61,
275,
1962,
59,
73,
61,
1182,
308,
272,
372,
734,
421,
199,
318,
5678,
63,
396,
837,
339,
9245,
275,
4114,
272,
4730,
275,
650,
272,
8850,
275,
841,
272,
3522,
63,
890,
275,
499,
339,
2215,
275,
359,
6324,
12,
4730,
12,
8850,
12,
3522,
63,
890,
61,
339,
1022,
275,
499,
272,
302,
275,
959,
272,
327,
675,
282,
7282,
574,
402,
5131,
880,
27572,
4364,
25613,
4007,
5131,
2498,
1536,
16925,
272,
5131,
275,
413,
14,
21,
272,
8201,
275,
378,
14,
2194,
2286,
327,
14795,
511,
367,
445,
614,
34,
339,
9038,
275,
980,
14,
2355,
14,
15726,
779,
6965,
12,
18,
566,
339,
286,
614,
66,
275,
9038,
14,
10843,
2031,
1392,
680,
6041,
8,
888,
14,
31293,
9,
2286,
26452,
275,
28965,
5358,
29169,
8,
75,
29,
75,
12,
302,
29,
78,
12,
5131,
29,
4468,
12,
8201,
29,
5683,
9,
272,
3598,
14,
4050,
480,
11768,
26,
1050,
511,
367,
314,
445,
6727,
11596,
846,
1015,
2685,
339,
1323,
275,
377,
14,
3861,
804,
8,
2271,
29,
888,
14,
31293,
12,
11180,
461,
29,
2960,
779,
797,
3672,
20,
430,
342,
339,
734,
275,
26452,
8,
56,
9,
339,
734,
275,
805,
779,
56,
467,
734,
5130,
67,
614,
66,
9,
339,
19252,
63,
548,
275,
19252,
63,
17167,
63,
3302,
1793,
8,
67,
614,
66,
12,
302,
29,
78,
12,
1022,
29,
75,
12,
5131,
29,
4468,
12,
8201,
29,
5683,
9,
339,
702,
734,
14,
1392,
508,
19252,
63,
548,
14,
1392,
339,
3915,
275,
734,
446,
19252,
63,
548,
272,
2329,
275,
980,
14,
2101,
8,
3028,
9,
272,
1390,
63,
1508,
275,
2329,
14,
988,
342,
339,
340,
440,
980,
14,
7520,
8,
548,
12,
19252,
63,
548,
304,
267,
870,
360,
35,
614,
34,
511,
3405,
358,
267,
870,
360,
705,
1425,
26,
1656,
8,
1508,
14,
827,
1062,
2329,
14,
988,
4059,
267,
870,
360,
1199,
26,
5320,
267,
870,
8,
548,
9,
267,
870,
360,
2062,
1072,
26,
5320,
267,
870,
8,
3928,
63,
548,
9,
267,
702,
756,
5493,
327,
14795,
511,
367,
32758,
614,
2286,
16604,
614,
275,
980,
14,
10483,
8,
67,
614,
66,
12,
359,
19,
12,
16,
12,
17,
12,
18,
566,
2286,
26452,
6265,
614,
275,
28965,
5358,
29169,
6265,
614,
8,
75,
29,
75,
12,
302,
29,
78,
12,
5131,
29,
4468,
12,
8201,
29,
5683,
9,
2286,
1323,
275,
377,
14,
3861,
804,
8,
2271,
29,
888,
14,
31293,
12,
11180,
461,
29,
2960,
779,
797,
3672,
20,
430,
342,
339,
734,
275,
26452,
6265,
614,
8,
56,
9,
339,
734,
275,
805,
779,
56,
467,
734,
5130,
3776,
614,
9,
339,
19252,
63,
548,
63,
6265,
614,
275,
980,
14,
10483,
8,
3928,
63,
548,
12,
359,
19,
12,
16,
12,
17,
12,
18,
566,
339,
702,
734,
14,
1392,
508,
19252,
63,
548,
63,
6265,
614,
14,
1392,
339,
3915,
275,
734,
446,
19252,
63,
548,
63,
6265,
614,
272,
2329,
275,
980,
14,
2101,
8,
3028,
9,
272,
1390,
63,
1508,
275,
2329,
14,
988,
342,
339,
340,
440,
980,
14,
7520,
8,
548,
12,
19252,
63,
548,
63,
6265,
614,
304,
267,
870,
360,
6265,
614,
511,
3405,
358,
267,
870,
360,
705,
1425,
26,
1656,
8,
1508,
14,
827,
1062,
2329,
14,
988,
4059,
267,
870,
360,
1199,
26,
5320,
267,
870,
8,
548,
9,
267,
870,
360,
2062,
1072,
26,
5320,
267,
870,
8,
3928,
63,
548,
9,
267,
702,
756,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
363,
8149,
363,
275,
298,
41,
290,
22311,
70,
10723,
2,
199,
363,
7307,
363,
275,
298,
7384,
6171,
12,
1910,
4380,
2124,
477,
603,
1888,
3093,
2,
199,
363,
22461,
363,
275,
2097,
41,
290,
22311,
70,
10723,
937,
199,
363,
1682,
363,
275,
298,
19,
13,
8501,
6289,
2,
199,
363,
26665,
363,
275,
298,
44,
1311,
33,
16871,
2,
199,
363,
2123,
363,
275,
298,
647,
4643,
13,
2374,
32,
3098,
2634,
2,
199,
199,
646,
2680,
465,
980,
199,
646,
3598,
199,
199,
504,
14377,
14,
5819,
14,
4174,
14,
4912,
492,
4945,
199,
504,
14377,
492,
1101,
199,
504,
14377,
492,
805,
199,
646,
14377,
14,
3128,
465,
377,
199,
199,
504,
27959,
18,
14,
3684,
14,
7721,
492,
334,
14072,
5358,
29169,
12,
3660,
28965,
5358,
29169,
6265,
614,
9,
199,
199,
318,
19252,
63,
17167,
63,
3302,
1793,
8,
67,
614,
66,
12,
1022,
12,
302,
12,
5131,
12,
8201,
304,
272,
734,
275,
980,
14,
4250,
8,
67,
614,
66,
14,
1392,
9,
339,
367,
519,
315,
4945,
8,
548,
14,
1392,
59,
17,
4682,
267,
367,
286,
315,
4945,
8,
548,
14,
1392,
59,
18,
4682,
288,
367,
671,
315,
4945,
8,
548,
14,
1392,
59,
19,
4682,
355,
734,
3981,
82,
12,
67,
12,
88,
61,
275,
19252,
63,
17167,
63,
7721,
63,
1143,
8,
1143,
29,
67,
614,
66,
3981,
82,
12,
67,
12,
88,
467,
1022,
29,
75,
12,
302,
29,
78,
12,
5131,
29,
4468,
12,
8201,
29,
5683,
9,
272,
372,
734,
199,
199,
318,
19252,
63,
17167,
63,
7721,
63,
1143,
8,
1143,
12,
1022,
12,
302,
12,
5131,
12,
8201,
304,
272,
702,
1962,
14,
8322,
508,
413,
272,
734,
275,
980,
14,
4250,
8,
1143,
14,
1392,
9,
272,
367,
284,
315,
4945,
8,
1143,
14,
1392,
59,
16,
4682,
267,
308,
275,
1022,
267,
12657,
275,
378,
267,
367,
1335,
315,
4945,
8,
988,
8,
16,
12,
284,
13,
78,
501,
18,
395,
1748,
8,
1143,
14,
1392,
59,
16,
467,
284,
11,
78,
501,
18,
11,
17,
2298,
288,
12657,
847,
413,
288,
5295,
275,
1962,
59,
74,
61,
1011,
499,
14,
288,
702,
5295,
690,
378,
14,
288,
702,
308,
2356,
1022,
288,
702,
5131,
690,
378,
14,
288,
308,
847,
5131,
627,
5295,
288,
702,
308,
2356,
1022,
267,
702,
12657,
2695,
302,
267,
702,
308,
2356,
1022,
267,
308,
275,
308,
1011,
8201,
267,
734,
59,
73,
61,
275,
1962,
59,
73,
61,
1182,
308,
272,
372,
734,
421,
199,
318,
5678,
63,
396,
837,
339,
9245,
275,
4114,
272,
4730,
275,
650,
272,
8850,
275,
841,
272,
3522,
63,
890,
275,
499,
339,
2215,
275,
359,
6324,
12,
4730,
12,
8850,
12,
3522,
63,
890,
61,
339,
1022,
275,
499,
272,
302,
275,
959,
272,
327,
675,
282,
7282,
574,
402,
5131,
880,
27572,
4364,
25613,
4007,
5131,
2498,
1536,
16925,
272,
5131,
275,
413,
14,
21,
272,
8201,
275,
378,
14,
2194,
2286,
327,
14795,
511,
367,
445,
614,
34,
339,
9038,
275,
980,
14,
2355,
14,
15726,
779,
6965,
12,
18,
566,
339,
286,
614,
66,
275,
9038,
14,
10843,
2031,
1392,
680,
6041,
8,
888,
14,
31293,
9,
2286,
26452,
275,
28965,
5358,
29169,
8,
75,
29,
75,
12,
302,
29,
78,
12,
5131,
29,
4468,
12,
8201,
29,
5683,
9,
272,
3598,
14,
4050,
480,
11768,
26,
1050,
511,
367,
314,
445,
6727,
11596,
846,
1015,
2685,
339,
1323,
275,
377,
14,
3861,
804,
8,
2271,
29,
888,
14,
31293,
12,
11180,
461,
29,
2960,
779,
797,
3672,
20,
430,
342,
339,
734,
275,
26452,
8,
56,
9,
339,
734,
275,
805,
779,
56,
467,
734,
5130,
67,
614,
66,
9,
339,
19252,
63,
548,
275,
19252,
63,
17167,
63,
3302,
1793,
8,
67,
614,
66,
12,
302,
29,
78,
12,
1022,
29,
75,
12,
5131,
29,
4468,
12,
8201,
29,
5683,
9,
339,
702,
734,
14,
1392,
508,
19252,
63,
548,
14,
1392,
339,
3915,
275,
734,
446,
19252,
63,
548,
272,
2329,
275,
980,
14,
2101,
8,
3028,
9,
272,
1390,
63,
1508,
275,
2329,
14,
988,
342,
339,
340,
440,
980,
14,
7520,
8,
548,
12,
19252,
63,
548,
304,
267,
870,
360,
35,
614,
34,
511,
3405,
358,
267,
870,
360,
705,
1425,
26,
1656,
8,
1508,
14,
827,
1062,
2329,
14,
988,
4059,
267,
870,
360,
1199,
26,
5320,
267,
870,
8,
548,
9,
267,
870,
360,
2062,
1072,
26,
5320,
267,
870,
8,
3928,
63,
548,
9,
267,
702,
756,
5493,
327,
14795,
511,
367,
32758,
614,
2286,
16604,
614,
275,
980,
14,
10483,
8,
67,
614,
66,
12,
359,
19,
12,
16,
12,
17,
12,
18,
566,
2286,
26452,
6265,
614,
275,
28965,
5358,
29169,
6265,
614,
8,
75,
29,
75,
12,
302,
29,
78,
12,
5131,
29,
4468,
12,
8201,
29,
5683,
9,
2286,
1323,
275,
377,
14,
3861,
804,
8,
2271,
29,
888,
14,
31293,
12,
11180,
461,
29,
2960,
779,
797,
3672,
20,
430,
342,
339,
734,
275,
26452,
6265,
614,
8,
56,
9,
339,
734,
275,
805,
779,
56,
467,
734,
5130,
3776,
614,
9,
339,
19252,
63,
548,
63,
6265,
614,
275,
980,
14,
10483,
8,
3928,
63,
548,
12,
359,
19,
12,
16,
12,
17,
12,
18,
566,
339,
702,
734,
14,
1392,
508,
19252,
63,
548,
63,
6265,
614,
14,
1392,
339,
3915,
275,
734,
446,
19252,
63,
548,
63,
6265,
614,
272,
2329,
275,
980,
14,
2101,
8,
3028,
9,
272,
1390,
63,
1508,
275,
2329,
14,
988,
342,
339,
340,
440,
980,
14,
7520,
8,
548,
12,
19252,
63,
548,
63,
6265,
614,
304,
267,
870,
360,
6265,
614,
511,
3405,
358,
267,
870,
360,
705,
1425,
26,
1656,
8,
1508,
14,
827,
1062,
2329,
14,
988,
4059,
267,
870,
360,
1199,
26,
5320,
267,
870,
8,
548,
9,
267,
870,
360,
2062,
1072,
26,
5320,
267,
870,
8,
3928,
63,
548,
9,
267,
702,
756,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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part of Invenio.
# Copyright (C) 2013 CERN.
#
# Invenio is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# Invenio is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Invenio; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
import optparse
import sys
from invenio.legacy.docextract.record import create_records, print_records
from invenio.legacy.refextract.kbs import get_kbs
from invenio.legacy.docextract.text import re_group_captured_multiple_space
from invenio.legacy.refextract.regexs import re_punctuation
DESCRIPTION = """Utility to convert journal names from abbreviations
or full names to their short form"""
HELP_MESSAGE = """
-o, --out Write the extracted references, in xml form, to a file
rather than standard output.
"""
USAGE_MESSAGE = """Usage: convert_journals [options] file1 [file2 ...]
Command options: %s
Examples:
convert_journals -o /home/chayward/thesis-out.xml /home/chayward/thesis.xml
""" % HELP_MESSAGE
def mangle_value(kb, value):
value = re_punctuation.sub(u' ', value.upper())
value = re_group_captured_multiple_space.sub(u' ', value)
value = value.strip()
standardized_titles = kb[1]
if value in standardized_titles:
value = standardized_titles[value]
return value
def mangle(kb, value):
try:
title, volume, page = value.split(',')
except ValueError:
pass
else:
value = '%s,%s,%s' % (mangle_value(kb, title), volume, page)
return value
def convert_journals(kb, record):
for subfield in record.find_subfields('999C5s'):
subfield.value = mangle(kb, subfield.value)
for subfield in record.find_subfields('773__p'):
subfield.value = mangle_value(kb, subfield.value)
return record
def convert_journals_list(kb, records):
return [convert_journals(kb, record) for record in records]
def write_records(config, records):
"""Write marcxml to file
* Output xml header
* Output collection opening tag
* Output xml for each record
* Output collection closing tag
"""
if config.xmlfile:
out = open(config.xmlfile, 'w')
else:
out = sys.stdout
xml = print_records(records)
try:
print >>out, xml
out.flush()
finally:
if config.xmlfile:
out.close()
def usage(wmsg=None, err_code=0):
"""Display a usage message for refextract on the standard error stream and
then exit.
@param wmsg: (string) some kind of brief warning message for the user.
@param err_code: (integer) an error code to be passed to halt,
which is called after the usage message has been printed.
@return: None.
"""
# Display the help information and the warning in the stderr stream
# 'help_message' is global
if wmsg:
print >> sys.stderr, wmsg
print >> sys.stderr, USAGE_MESSAGE
sys.exit(err_code)
def cli_main(options, args):
if options.help or not args:
usage()
return
if options.kb_journals:
kbs_files = {'journals': options.kb_journals}
else:
kbs_files = {}
kb = get_kbs(custom_kbs_files=kbs_files)['journals']
out_records = []
for path in args:
f = open(path)
try:
xml = f.read()
finally:
f.close()
out_records += convert_journals_list(kb, create_records(xml))
write_records(options, out_records)
def get_cli_options():
"""Get the various arguments and options from the command line and populate
a dictionary of cli_options.
@return: (tuple) of 2 elements. First element is a dictionary of cli
options and flags, set as appropriate; Second element is a list of cli
arguments.
"""
parser = optparse.OptionParser(description=DESCRIPTION,
usage=USAGE_MESSAGE,
add_help_option=False)
# Display help and exit
parser.add_option('-h', '--help', action='store_true')
# Write out MARC XML references to the specified file
parser.add_option('-o', '--out', dest='xmlfile')
# Handle verbosity
parser.add_option('-v', '--verbose', type=int, dest='verbosity', default=0)
# Specify a different journals database
parser.add_option('--kb-journals', dest='kb_journals')
return parser.parse_args()
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
12235,
14,
199,
3,
1898,
334,
35,
9,
6171,
24354,
14,
199,
3,
199,
3,
12235,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
199,
3,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
12235,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
199,
3,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
12235,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
199,
3,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
15673,
13,
13421,
12,
8217,
14,
199,
199,
646,
8691,
199,
646,
984,
199,
199,
504,
13640,
14,
10000,
14,
1117,
301,
400,
1957,
14,
3059,
492,
1218,
63,
6502,
12,
870,
63,
6502,
199,
504,
13640,
14,
10000,
14,
264,
771,
400,
1957,
14,
75,
1533,
492,
664,
63,
75,
1533,
199,
199,
504,
13640,
14,
10000,
14,
1117,
301,
400,
1957,
14,
505,
492,
295,
63,
923,
63,
28345,
63,
6048,
63,
2638,
199,
504,
13640,
14,
10000,
14,
264,
771,
400,
1957,
14,
3821,
83,
492,
295,
63,
25181,
421,
199,
17705,
275,
408,
17505,
370,
3957,
9605,
1561,
687,
2236,
23988,
1298,
199,
269,
2615,
1561,
370,
3932,
3974,
1824,
624,
199,
199,
17930,
63,
8272,
275,
408,
523,
446,
79,
12,
1553,
548,
3322,
6990,
314,
12509,
6941,
12,
315,
2748,
1824,
12,
370,
282,
570,
2432,
7830,
2419,
4465,
1072,
14,
199,
624,
199,
199,
20274,
63,
8272,
275,
408,
7692,
26,
3957,
63,
743,
31212,
359,
1419,
61,
570,
17,
359,
493,
18,
21214,
199,
3110,
1511,
26,
450,
83,
199,
22787,
26,
272,
3957,
63,
743,
31212,
446,
79,
1182,
4219,
15,
335,
1187,
3079,
15,
14925,
13,
548,
14,
1652,
1182,
4219,
15,
335,
1187,
3079,
15,
14925,
14,
1652,
199,
624,
450,
29269,
63,
8272,
421,
199,
318,
333,
4593,
63,
585,
8,
7862,
12,
574,
304,
272,
574,
275,
295,
63,
25181,
14,
954,
8,
85,
7,
1656,
574,
14,
4142,
1012,
272,
574,
275,
295,
63,
923,
63,
28345,
63,
6048,
63,
2638,
14,
954,
8,
85,
7,
1656,
574,
9,
272,
574,
275,
574,
14,
1913,
342,
339,
28974,
7068,
63,
8916,
275,
19932,
59,
17,
61,
272,
340,
574,
315,
28974,
7068,
63,
8916,
26,
267,
574,
275,
28974,
7068,
63,
8916,
59,
585,
61,
339,
372,
574,
421,
199,
318,
333,
4593,
8,
7862,
12,
574,
304,
272,
862,
26,
267,
2538,
12,
3301,
12,
2034,
275,
574,
14,
1294,
11917,
272,
871,
1722,
26,
267,
986,
272,
587,
26,
267,
574,
275,
1543,
83,
8719,
83,
8719,
83,
7,
450,
334,
29602,
63,
585,
8,
7862,
12,
2538,
395,
3301,
12,
2034,
9,
272,
372,
574,
199,
199,
318,
3957,
63,
743,
31212,
8,
7862,
12,
2777,
304,
272,
367,
31014,
315,
2777,
14,
1623,
63,
954,
955,
360,
5637,
35,
21,
83,
735,
267,
31014,
14,
585,
275,
333,
4593,
8,
7862,
12,
31014,
14,
585,
9,
272,
367,
31014,
315,
2777,
14,
1623,
63,
954,
955,
360,
18507,
363,
80,
735,
267,
31014,
14,
585,
275,
333,
4593,
63,
585,
8,
7862,
12,
31014,
14,
585,
9,
272,
372,
2777,
421,
199,
318,
3957,
63,
743,
31212,
63,
513,
8,
7862,
12,
5767,
304,
272,
372,
359,
3916,
63,
743,
31212,
8,
7862,
12,
2777,
9,
367,
2777,
315,
5767,
61,
421,
199,
318,
2218,
63,
6502,
8,
888,
12,
5767,
304,
272,
408,
3534,
7557,
67,
1652,
370,
570,
339,
627,
7242,
2748,
1406,
272,
627,
7242,
3245,
13618,
1947,
272,
627,
7242,
2748,
367,
1924,
2777,
272,
627,
7242,
3245,
11261,
1947,
272,
408,
272,
340,
1101,
14,
10198,
12059,
26,
267,
734,
275,
1551,
8,
888,
14,
10198,
12059,
12,
283,
87,
358,
272,
587,
26,
267,
734,
275,
984,
14,
2703,
339,
2748,
275,
870,
63,
6502,
8,
6502,
9,
339,
862,
26,
267,
870,
4331,
548,
12,
2748,
267,
734,
14,
4939,
342,
272,
3753,
26,
267,
340,
1101,
14,
10198,
12059,
26,
288,
734,
14,
1600,
342,
421,
199,
318,
4503,
8,
87,
1328,
29,
403,
12,
2329,
63,
600,
29,
16,
304,
272,
408,
7687,
282,
4503,
1245,
367,
295,
771,
400,
1957,
641,
314,
4465,
1125,
2547,
436,
2126,
2066,
4458,
14,
2126,
768,
635,
336,
1328,
26,
334,
875,
9,
2005,
4928,
402,
29226,
5721,
1245,
367,
314,
922,
14,
2126,
768,
635,
2329,
63,
600,
26,
334,
4115,
9,
376,
1125,
1233,
370,
506,
3032,
370,
394,
4478,
12,
267,
1314,
365,
2797,
2410,
314,
4503,
1245,
965,
2757,
12487,
14,
2126,
768,
1107,
26,
488,
14,
272,
408,
272,
327,
12175,
314,
1720,
2556,
436,
314,
5721,
315,
314,
4635,
2547,
272,
327,
283,
3437,
63,
1188,
7,
365,
2288,
272,
340,
336,
1328,
26,
267,
870,
4331,
984,
14,
3083,
12,
336,
1328,
272,
870,
4331,
984,
14,
3083,
12,
19635,
2962,
63,
8272,
272,
984,
14,
2224,
8,
1508,
63,
600,
9,
421,
199,
318,
5053,
63,
973,
8,
1419,
12,
1249,
304,
272,
340,
1511,
14,
3437,
503,
440,
1249,
26,
267,
4503,
342,
267,
372,
339,
340,
1511,
14,
7862,
63,
743,
31212,
26,
267,
1022,
1533,
63,
1725,
275,
791,
743,
31212,
356,
1511,
14,
7862,
63,
743,
31212,
93,
272,
587,
26,
267,
1022,
1533,
63,
1725,
275,
1052,
339,
19932,
275,
664,
63,
75,
1533,
8,
4229,
63,
75,
1533,
63,
1725,
29,
75,
1533,
63,
1725,
11820,
743,
31212,
418,
339,
734,
63,
6502,
275,
942,
272,
367,
931,
315,
1249,
26,
267,
289,
275,
1551,
8,
515,
9,
267,
862,
26,
288
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
12235,
14,
199,
3,
1898,
334,
35,
9,
6171,
24354,
14,
199,
3,
199,
3,
12235,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
199,
3,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
12235,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
199,
3,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
12235,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
199,
3,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
15673,
13,
13421,
12,
8217,
14,
199,
199,
646,
8691,
199,
646,
984,
199,
199,
504,
13640,
14,
10000,
14,
1117,
301,
400,
1957,
14,
3059,
492,
1218,
63,
6502,
12,
870,
63,
6502,
199,
504,
13640,
14,
10000,
14,
264,
771,
400,
1957,
14,
75,
1533,
492,
664,
63,
75,
1533,
199,
199,
504,
13640,
14,
10000,
14,
1117,
301,
400,
1957,
14,
505,
492,
295,
63,
923,
63,
28345,
63,
6048,
63,
2638,
199,
504,
13640,
14,
10000,
14,
264,
771,
400,
1957,
14,
3821,
83,
492,
295,
63,
25181,
421,
199,
17705,
275,
408,
17505,
370,
3957,
9605,
1561,
687,
2236,
23988,
1298,
199,
269,
2615,
1561,
370,
3932,
3974,
1824,
624,
199,
199,
17930,
63,
8272,
275,
408,
523,
446,
79,
12,
1553,
548,
3322,
6990,
314,
12509,
6941,
12,
315,
2748,
1824,
12,
370,
282,
570,
2432,
7830,
2419,
4465,
1072,
14,
199,
624,
199,
199,
20274,
63,
8272,
275,
408,
7692,
26,
3957,
63,
743,
31212,
359,
1419,
61,
570,
17,
359,
493,
18,
21214,
199,
3110,
1511,
26,
450,
83,
199,
22787,
26,
272,
3957,
63,
743,
31212,
446,
79,
1182,
4219,
15,
335,
1187,
3079,
15,
14925,
13,
548,
14,
1652,
1182,
4219,
15,
335,
1187,
3079,
15,
14925,
14,
1652,
199,
624,
450,
29269,
63,
8272,
421,
199,
318,
333,
4593,
63,
585,
8,
7862,
12,
574,
304,
272,
574,
275,
295,
63,
25181,
14,
954,
8,
85,
7,
1656,
574,
14,
4142,
1012,
272,
574,
275,
295,
63,
923,
63,
28345,
63,
6048,
63,
2638,
14,
954,
8,
85,
7,
1656,
574,
9,
272,
574,
275,
574,
14,
1913,
342,
339,
28974,
7068,
63,
8916,
275,
19932,
59,
17,
61,
272,
340,
574,
315,
28974,
7068,
63,
8916,
26,
267,
574,
275,
28974,
7068,
63,
8916,
59,
585,
61,
339,
372,
574,
421,
199,
318,
333,
4593,
8,
7862,
12,
574,
304,
272,
862,
26,
267,
2538,
12,
3301,
12,
2034,
275,
574,
14,
1294,
11917,
272,
871,
1722,
26,
267,
986,
272,
587,
26,
267,
574,
275,
1543,
83,
8719,
83,
8719,
83,
7,
450,
334,
29602,
63,
585,
8,
7862,
12,
2538,
395,
3301,
12,
2034,
9,
272,
372,
574,
199,
199,
318,
3957,
63,
743,
31212,
8,
7862,
12,
2777,
304,
272,
367,
31014,
315,
2777,
14,
1623,
63,
954,
955,
360,
5637,
35,
21,
83,
735,
267,
31014,
14,
585,
275,
333,
4593,
8,
7862,
12,
31014,
14,
585,
9,
272,
367,
31014,
315,
2777,
14,
1623,
63,
954,
955,
360,
18507,
363,
80,
735,
267,
31014,
14,
585,
275,
333,
4593,
63,
585,
8,
7862,
12,
31014,
14,
585,
9,
272,
372,
2777,
421,
199,
318,
3957,
63,
743,
31212,
63,
513,
8,
7862,
12,
5767,
304,
272,
372,
359,
3916,
63,
743,
31212,
8,
7862,
12,
2777,
9,
367,
2777,
315,
5767,
61,
421,
199,
318,
2218,
63,
6502,
8,
888,
12,
5767,
304,
272,
408,
3534,
7557,
67,
1652,
370,
570,
339,
627,
7242,
2748,
1406,
272,
627,
7242,
3245,
13618,
1947,
272,
627,
7242,
2748,
367,
1924,
2777,
272,
627,
7242,
3245,
11261,
1947,
272,
408,
272,
340,
1101,
14,
10198,
12059,
26,
267,
734,
275,
1551,
8,
888,
14,
10198,
12059,
12,
283,
87,
358,
272,
587,
26,
267,
734,
275,
984,
14,
2703,
339,
2748,
275,
870,
63,
6502,
8,
6502,
9,
339,
862,
26,
267,
870,
4331,
548,
12,
2748,
267,
734,
14,
4939,
342,
272,
3753,
26,
267,
340,
1101,
14,
10198,
12059,
26,
288,
734,
14,
1600,
342,
421,
199,
318,
4503,
8,
87,
1328,
29,
403,
12,
2329,
63,
600,
29,
16,
304,
272,
408,
7687,
282,
4503,
1245,
367,
295,
771,
400,
1957,
641,
314,
4465,
1125,
2547,
436,
2126,
2066,
4458,
14,
2126,
768,
635,
336,
1328,
26,
334,
875,
9,
2005,
4928,
402,
29226,
5721,
1245,
367,
314,
922,
14,
2126,
768,
635,
2329,
63,
600,
26,
334,
4115,
9,
376,
1125,
1233,
370,
506,
3032,
370,
394,
4478,
12,
267,
1314,
365,
2797,
2410,
314,
4503,
1245,
965,
2757,
12487,
14,
2126,
768,
1107,
26,
488,
14,
272,
408,
272,
327,
12175,
314,
1720,
2556,
436,
314,
5721,
315,
314,
4635,
2547,
272,
327,
283,
3437,
63,
1188,
7,
365,
2288,
272,
340,
336,
1328,
26,
267,
870,
4331,
984,
14,
3083,
12,
336,
1328,
272,
870,
4331,
984,
14,
3083,
12,
19635,
2962,
63,
8272,
272,
984,
14,
2224,
8,
1508,
63,
600,
9,
421,
199,
318,
5053,
63,
973,
8,
1419,
12,
1249,
304,
272,
340,
1511,
14,
3437,
503,
440,
1249,
26,
267,
4503,
342,
267,
372,
339,
340,
1511,
14,
7862,
63,
743,
31212,
26,
267,
1022,
1533,
63,
1725,
275,
791,
743,
31212,
356,
1511,
14,
7862,
63,
743,
31212,
93,
272,
587,
26,
267,
1022,
1533,
63,
1725,
275,
1052,
339,
19932,
275,
664,
63,
75,
1533,
8,
4229,
63,
75,
1533,
63,
1725,
29,
75,
1533,
63,
1725,
11820,
743,
31212,
418,
339,
734,
63,
6502,
275,
942,
272,
367,
931,
315,
1249,
26,
267,
289,
275,
1551,
8,
515,
9,
267,
862,
26,
288,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
Unow/edx-platform
|
lms/djangoapps/instructor/features/data_download.py
|
34
|
3374
|
"""
Define steps for instructor dashboard - data download tab
acceptance tests.
"""
# pylint: disable=C0111
# pylint: disable=W0621
from lettuce import world, step
from nose.tools import assert_in, assert_regexp_matches # pylint: disable=E0611
from terrain.steps import reload_the_page
from splinter.request_handler.request_handler import RequestHandler
@step(u'I see a table of student profiles')
def find_student_profile_table(step): # pylint: disable=unused-argument
# Find the grading configuration display
world.wait_for_visible('#data-student-profiles-table')
# Wait for the data table to be populated
world.wait_for(lambda _: world.css_text('#data-student-profiles-table') not in [u'', u'Loading...'])
if world.role == 'instructor':
expected_data = [
world.instructor.username,
world.instructor.email,
world.instructor.profile.name,
world.instructor.profile.gender,
world.instructor.profile.goals
]
elif world.role == 'staff':
expected_data = [
world.staff.username,
world.staff.email,
world.staff.profile.name,
world.staff.profile.gender,
world.staff.profile.goals
]
for datum in expected_data:
assert_in(datum, world.css_text('#data-student-profiles-table'))
@step(u"I do not see a button to 'List enrolled students' profile information'")
def no_student_profile_table(step): # pylint: disable=unused-argument
world.is_css_not_present('input[name="list-profiles"]')
@step(u"I see the grading configuration for the course")
def find_grading_config(step): # pylint: disable=unused-argument
# Find the grading configuration display
world.wait_for_visible('#data-grade-config-text')
# expected config is the default grading configuration from common/lib/xmodule/xmodule/course_module.py
expected_config = u"""-----------------------------------------------------------------------------
Course grader:
<class 'xmodule.graders.WeightedSubsectionsGrader'>
Graded sections:
subgrader=<class 'xmodule.graders.AssignmentFormatGrader'>, type=Homework, category=Homework, weight=0.15
subgrader=<class 'xmodule.graders.AssignmentFormatGrader'>, type=Lab, category=Lab, weight=0.15
subgrader=<class 'xmodule.graders.AssignmentFormatGrader'>, type=Midterm Exam, category=Midterm Exam, weight=0.3
subgrader=<class 'xmodule.graders.AssignmentFormatGrader'>, type=Final Exam, category=Final Exam, weight=0.4
-----------------------------------------------------------------------------
Listing grading context for course edx/999/Test_Course
graded sections:
[]
all descriptors:
length=0"""
assert_in(expected_config, world.css_text('#data-grade-config-text'))
@step(u"I see a grade report csv file in the reports table")
def find_grade_report_csv_link(step): # pylint: disable=unused-argument
# Need to reload the page to see the grades download table
reload_the_page(step)
world.wait_for_visible('#report-downloads-table')
# Find table and assert a .csv file is present
expected_file_regexp = 'edx_999_Test_Course_grade_report_\d{4}-\d{2}-\d{2}-\d{4}\.csv'
assert_regexp_matches(
world.css_html('#report-downloads-table'), expected_file_regexp,
msg="Expected grade report filename was not found."
)
|
agpl-3.0
|
[
624,
199,
16213,
7124,
367,
17724,
17216,
446,
666,
5235,
5174,
199,
28519,
2295,
14,
199,
624,
199,
199,
3,
4287,
26,
3507,
29,
35,
28107,
199,
3,
4287,
26,
3507,
29,
55,
1690,
2025,
199,
199,
504,
4691,
84,
3683,
492,
6701,
12,
3650,
199,
504,
11354,
14,
2537,
492,
702,
63,
262,
12,
702,
63,
11191,
63,
6742,
221,
327,
4287,
26,
3507,
29,
37,
1690,
845,
199,
504,
2044,
6322,
14,
5895,
492,
13101,
63,
1589,
63,
1606,
199,
504,
2249,
25240,
14,
1069,
63,
2232,
14,
1069,
63,
2232,
492,
4784,
2461,
421,
199,
32,
2926,
8,
85,
7,
41,
1937,
282,
1817,
402,
6474,
17390,
358,
199,
318,
2342,
63,
5500,
63,
2913,
63,
1224,
8,
2926,
304,
221,
327,
4287,
26,
3507,
29,
8618,
13,
2094,
272,
327,
6668,
314,
22815,
2897,
2929,
272,
6701,
14,
2573,
63,
509,
63,
6604,
7863,
576,
13,
5500,
13,
11225,
13,
1224,
358,
339,
327,
13144,
367,
314,
666,
1817,
370,
506,
16460,
272,
6701,
14,
2573,
63,
509,
8,
2734,
24700,
6701,
14,
3919,
63,
505,
7863,
576,
13,
5500,
13,
11225,
13,
1224,
358,
440,
315,
359,
85,
6448,
399,
7,
19236,
1396,
1105,
339,
340,
6701,
14,
3756,
508,
283,
14891,
356,
267,
1420,
63,
576,
275,
359,
288,
6701,
14,
14891,
14,
2473,
12,
288,
6701,
14,
14891,
14,
2123,
12,
288,
6701,
14,
14891,
14,
2913,
14,
354,
12,
288,
6701,
14,
14891,
14,
2913,
14,
15791,
12,
288,
6701,
14,
14891,
14,
2913,
14,
30970,
267,
1622,
272,
916,
6701,
14,
3756,
508,
283,
7018,
356,
267,
1420,
63,
576,
275,
359,
288,
6701,
14,
7018,
14,
2473,
12,
288,
6701,
14,
7018,
14,
2123,
12,
288,
6701,
14,
7018,
14,
2913,
14,
354,
12,
288,
6701,
14,
7018,
14,
2913,
14,
15791,
12,
288,
6701,
14,
7018,
14,
2913,
14,
30970,
267,
1622,
272,
367,
18908,
315,
1420,
63,
576,
26,
267,
702,
63,
262,
8,
18945,
12,
6701,
14,
3919,
63,
505,
7863,
576,
13,
5500,
13,
11225,
13,
1224,
1333,
421,
199,
32,
2926,
8,
85,
2,
41,
886,
440,
1937,
282,
5528,
370,
283,
1296,
26802,
18557,
7,
4690,
2556,
9859,
199,
318,
949,
63,
5500,
63,
2913,
63,
1224,
8,
2926,
304,
221,
327,
4287,
26,
3507,
29,
8618,
13,
2094,
272,
6701,
14,
374,
63,
3919,
63,
1397,
63,
1881,
360,
1210,
59,
354,
628,
513,
13,
11225,
937,
358,
421,
199,
32,
2926,
8,
85,
2,
41,
1937,
314,
22815,
2897,
367,
314,
2518,
531,
199,
318,
2342,
63,
16050,
63,
888,
8,
2926,
304,
221,
327,
4287,
26,
3507,
29,
8618,
13,
2094,
272,
327,
6668,
314,
22815,
2897,
2929,
272,
6701,
14,
2573,
63,
509,
63,
6604,
7863,
576,
13,
4523,
13,
888,
13,
505,
358,
272,
327,
1420,
1101,
365,
314,
849,
22815,
2897,
687,
2863,
15,
773,
15,
14293,
15,
14293,
15,
1972,
63,
578,
14,
647,
272,
1420,
63,
888,
275,
399,
624,
3606,
8684,
199,
6979,
27741,
26,
199,
28,
533,
283,
14293,
14,
926,
7735,
14,
6004,
8364,
2610,
7786,
5761,
424,
8423,
199,
199,
5761,
770,
10189,
26,
523,
1007,
17556,
18987,
533,
283,
14293,
14,
926,
7735,
14,
19321,
3484,
5761,
424,
7,
6244,
730,
29,
12054,
800,
12,
4637,
29,
12054,
800,
12,
5401,
29,
16,
14,
1046,
523,
1007,
17556,
18987,
533,
283,
14293,
14,
926,
7735,
14,
19321,
3484,
5761,
424,
7,
6244,
730,
29,
22511,
12,
4637,
29,
22511,
12,
5401,
29,
16,
14,
1046,
523,
1007,
17556,
18987,
533,
283,
14293,
14,
926,
7735,
14,
19321,
3484,
5761,
424,
7,
6244,
730,
29,
28735,
5125,
1316,
455,
12,
4637,
29,
28735,
5125,
1316,
455,
12,
5401,
29,
16,
14,
19,
523,
1007,
17556,
18987,
533,
283,
14293,
14,
926,
7735,
14,
19321,
3484,
5761,
424,
7,
6244,
730,
29,
12776,
1316,
455,
12,
4637,
29,
12776,
1316,
455,
12,
5401,
29,
16,
14,
20,
199,
3606,
8684,
199,
26138,
22815,
1067,
367,
2518,
22435,
15,
5637,
15,
774,
63,
6979,
199,
13688,
10189,
26,
199,
8607,
199,
452,
15428,
26,
199,
1267,
29,
16,
624,
272,
702,
63,
262,
8,
2062,
63,
888,
12,
6701,
14,
3919,
63,
505,
7863,
576,
13,
4523,
13,
888,
13,
505,
1333,
421,
199,
32,
2926,
8,
85,
2,
41,
1937,
282,
16183,
3622,
7392,
570,
315,
314,
13924,
1817,
531,
199,
318,
2342,
63,
4523,
63,
3070,
63,
4737,
63,
1073,
8,
2926,
304,
221,
327,
4287,
26,
3507,
29,
8618,
13,
2094,
272,
327,
14012,
370,
13101,
314,
2034,
370,
1937,
314,
1999,
3424,
5235,
1817,
272,
13101,
63,
1589,
63,
1606,
8,
2926,
9,
272,
6701,
14,
2573,
63,
509,
63,
6604,
7863,
3070,
13,
20373,
13,
1224,
358,
272,
327,
6668,
1817,
436,
702,
282,
1275,
4737,
570,
365,
3451,
272,
1420,
63,
493,
63,
11191,
275,
283,
8268,
63,
5637,
63,
774,
63,
6979,
63,
4523,
63,
3070,
18005,
68,
91,
20,
93,
2696,
68,
91,
18,
93,
2696,
68,
91,
18,
93,
2696,
68,
91,
20,
93,
4537,
4737,
7,
272,
702,
63,
11191,
63,
6742,
8,
267,
6701,
14,
3919,
63,
1360,
7863,
3070,
13,
20373,
13,
1224,
659,
1420,
63,
493,
63,
11191,
12,
267,
1499,
628,
6964,
16183,
3622,
1788,
1990,
440,
1911,
2122,
272,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
16213,
7124,
367,
17724,
17216,
446,
666,
5235,
5174,
199,
28519,
2295,
14,
199,
624,
199,
199,
3,
4287,
26,
3507,
29,
35,
28107,
199,
3,
4287,
26,
3507,
29,
55,
1690,
2025,
199,
199,
504,
4691,
84,
3683,
492,
6701,
12,
3650,
199,
504,
11354,
14,
2537,
492,
702,
63,
262,
12,
702,
63,
11191,
63,
6742,
221,
327,
4287,
26,
3507,
29,
37,
1690,
845,
199,
504,
2044,
6322,
14,
5895,
492,
13101,
63,
1589,
63,
1606,
199,
504,
2249,
25240,
14,
1069,
63,
2232,
14,
1069,
63,
2232,
492,
4784,
2461,
421,
199,
32,
2926,
8,
85,
7,
41,
1937,
282,
1817,
402,
6474,
17390,
358,
199,
318,
2342,
63,
5500,
63,
2913,
63,
1224,
8,
2926,
304,
221,
327,
4287,
26,
3507,
29,
8618,
13,
2094,
272,
327,
6668,
314,
22815,
2897,
2929,
272,
6701,
14,
2573,
63,
509,
63,
6604,
7863,
576,
13,
5500,
13,
11225,
13,
1224,
358,
339,
327,
13144,
367,
314,
666,
1817,
370,
506,
16460,
272,
6701,
14,
2573,
63,
509,
8,
2734,
24700,
6701,
14,
3919,
63,
505,
7863,
576,
13,
5500,
13,
11225,
13,
1224,
358,
440,
315,
359,
85,
6448,
399,
7,
19236,
1396,
1105,
339,
340,
6701,
14,
3756,
508,
283,
14891,
356,
267,
1420,
63,
576,
275,
359,
288,
6701,
14,
14891,
14,
2473,
12,
288,
6701,
14,
14891,
14,
2123,
12,
288,
6701,
14,
14891,
14,
2913,
14,
354,
12,
288,
6701,
14,
14891,
14,
2913,
14,
15791,
12,
288,
6701,
14,
14891,
14,
2913,
14,
30970,
267,
1622,
272,
916,
6701,
14,
3756,
508,
283,
7018,
356,
267,
1420,
63,
576,
275,
359,
288,
6701,
14,
7018,
14,
2473,
12,
288,
6701,
14,
7018,
14,
2123,
12,
288,
6701,
14,
7018,
14,
2913,
14,
354,
12,
288,
6701,
14,
7018,
14,
2913,
14,
15791,
12,
288,
6701,
14,
7018,
14,
2913,
14,
30970,
267,
1622,
272,
367,
18908,
315,
1420,
63,
576,
26,
267,
702,
63,
262,
8,
18945,
12,
6701,
14,
3919,
63,
505,
7863,
576,
13,
5500,
13,
11225,
13,
1224,
1333,
421,
199,
32,
2926,
8,
85,
2,
41,
886,
440,
1937,
282,
5528,
370,
283,
1296,
26802,
18557,
7,
4690,
2556,
9859,
199,
318,
949,
63,
5500,
63,
2913,
63,
1224,
8,
2926,
304,
221,
327,
4287,
26,
3507,
29,
8618,
13,
2094,
272,
6701,
14,
374,
63,
3919,
63,
1397,
63,
1881,
360,
1210,
59,
354,
628,
513,
13,
11225,
937,
358,
421,
199,
32,
2926,
8,
85,
2,
41,
1937,
314,
22815,
2897,
367,
314,
2518,
531,
199,
318,
2342,
63,
16050,
63,
888,
8,
2926,
304,
221,
327,
4287,
26,
3507,
29,
8618,
13,
2094,
272,
327,
6668,
314,
22815,
2897,
2929,
272,
6701,
14,
2573,
63,
509,
63,
6604,
7863,
576,
13,
4523,
13,
888,
13,
505,
358,
272,
327,
1420,
1101,
365,
314,
849,
22815,
2897,
687,
2863,
15,
773,
15,
14293,
15,
14293,
15,
1972,
63,
578,
14,
647,
272,
1420,
63,
888,
275,
399,
624,
3606,
8684,
199,
6979,
27741,
26,
199,
28,
533,
283,
14293,
14,
926,
7735,
14,
6004,
8364,
2610,
7786,
5761,
424,
8423,
199,
199,
5761,
770,
10189,
26,
523,
1007,
17556,
18987,
533,
283,
14293,
14,
926,
7735,
14,
19321,
3484,
5761,
424,
7,
6244,
730,
29,
12054,
800,
12,
4637,
29,
12054,
800,
12,
5401,
29,
16,
14,
1046,
523,
1007,
17556,
18987,
533,
283,
14293,
14,
926,
7735,
14,
19321,
3484,
5761,
424,
7,
6244,
730,
29,
22511,
12,
4637,
29,
22511,
12,
5401,
29,
16,
14,
1046,
523,
1007,
17556,
18987,
533,
283,
14293,
14,
926,
7735,
14,
19321,
3484,
5761,
424,
7,
6244,
730,
29,
28735,
5125,
1316,
455,
12,
4637,
29,
28735,
5125,
1316,
455,
12,
5401,
29,
16,
14,
19,
523,
1007,
17556,
18987,
533,
283,
14293,
14,
926,
7735,
14,
19321,
3484,
5761,
424,
7,
6244,
730,
29,
12776,
1316,
455,
12,
4637,
29,
12776,
1316,
455,
12,
5401,
29,
16,
14,
20,
199,
3606,
8684,
199,
26138,
22815,
1067,
367,
2518,
22435,
15,
5637,
15,
774,
63,
6979,
199,
13688,
10189,
26,
199,
8607,
199,
452,
15428,
26,
199,
1267,
29,
16,
624,
272,
702,
63,
262,
8,
2062,
63,
888,
12,
6701,
14,
3919,
63,
505,
7863,
576,
13,
4523,
13,
888,
13,
505,
1333,
421,
199,
32,
2926,
8,
85,
2,
41,
1937,
282,
16183,
3622,
7392,
570,
315,
314,
13924,
1817,
531,
199,
318,
2342,
63,
4523,
63,
3070,
63,
4737,
63,
1073,
8,
2926,
304,
221,
327,
4287,
26,
3507,
29,
8618,
13,
2094,
272,
327,
14012,
370,
13101,
314,
2034,
370,
1937,
314,
1999,
3424,
5235,
1817,
272,
13101,
63,
1589,
63,
1606,
8,
2926,
9,
272,
6701,
14,
2573,
63,
509,
63,
6604,
7863,
3070,
13,
20373,
13,
1224,
358,
272,
327,
6668,
1817,
436,
702,
282,
1275,
4737,
570,
365,
3451,
272,
1420,
63,
493,
63,
11191,
275,
283,
8268,
63,
5637,
63,
774,
63,
6979,
63,
4523,
63,
3070,
18005,
68,
91,
20,
93,
2696,
68,
91,
18,
93,
2696,
68,
91,
18,
93,
2696,
68,
91,
20,
93,
4537,
4737,
7,
272,
702,
63,
11191,
63,
6742,
8,
267,
6701,
14,
3919,
63,
1360,
7863,
3070,
13,
20373,
13,
1224,
659,
1420,
63,
493,
63,
11191,
12,
267,
1499,
628,
6964,
16183,
3622,
1788,
1990,
440,
1911,
2122,
272,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
candango/firenado
|
tests/util/url_util_test.py
|
2
|
1895
|
#!/usr/bin/env python
#
# Copyright 2015-2021 Flavio Garcia
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from firenado.util.url_util import rooted_path
import unittest
class UrlUtilTestCase(unittest.TestCase):
""" Case that tests the file util functions.
"""
def test_root_url_with_slash_in_front_and_back(self):
""" Happy scenario, root_url with slash back to back
"""
root_url = "/root/"
path = "/ext"
expected = "/root/ext"
rooted_url = rooted_path(root_url, path)
self.assertEqual(expected, rooted_url)
def test_root_url_with_slash_in_front(self):
""" Happy scenario too, root_url with slash in front
"""
root_url = "/root"
path = "/ext"
expected = "/root/ext"
rooted_url = rooted_path(root_url, path)
self.assertEqual(expected, rooted_url)
def test_root_url_no_slash(self):
""" root_url with no slash
"""
root_url = "root"
path = "/ext"
expected = "/root/ext"
rooted_url = rooted_path(root_url, path)
self.assertEqual(expected, rooted_url)
def test_root_on_root(self):
""" root_url pessimistic on root
"""
root_url = "root/"
path = "/"
expected = "/root"
rooted_url = rooted_path(root_url, path)
self.assertEqual(expected, rooted_url)
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
6900,
13,
22150,
481,
416,
32052,
598,
285,
16521,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
259,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
504,
5883,
828,
5129,
14,
1974,
14,
633,
63,
1974,
492,
882,
5731,
63,
515,
199,
646,
2882,
421,
199,
533,
20503,
9562,
1746,
8,
2796,
14,
1746,
304,
272,
408,
12425,
626,
2295,
314,
570,
4884,
3423,
14,
272,
408,
339,
347,
511,
63,
1231,
63,
633,
63,
1045,
63,
7001,
63,
262,
63,
14708,
63,
460,
63,
894,
8,
277,
304,
267,
408,
869,
18869,
15728,
12,
1738,
63,
633,
543,
14457,
1771,
370,
1771,
267,
408,
267,
1738,
63,
633,
275,
3286,
1231,
6687,
267,
931,
275,
3286,
832,
2,
267,
1420,
275,
3286,
1231,
15,
832,
2,
267,
882,
5731,
63,
633,
275,
882,
5731,
63,
515,
8,
1231,
63,
633,
12,
931,
9,
267,
291,
14,
629,
8,
2062,
12,
882,
5731,
63,
633,
9,
339,
347,
511,
63,
1231,
63,
633,
63,
1045,
63,
7001,
63,
262,
63,
14708,
8,
277,
304,
267,
408,
869,
18869,
15728,
4634,
12,
1738,
63,
633,
543,
14457,
315,
13738,
267,
408,
267,
1738,
63,
633,
275,
3286,
1231,
2,
267,
931,
275,
3286,
832,
2,
267,
1420,
275,
3286,
1231,
15,
832,
2,
267,
882,
5731,
63,
633,
275,
882,
5731,
63,
515,
8,
1231,
63,
633,
12,
931,
9,
267,
291,
14,
629,
8,
2062,
12,
882,
5731,
63,
633,
9,
339,
347,
511,
63,
1231,
63,
633,
63,
889,
63,
7001,
8,
277,
304,
267,
408,
1738,
63,
633,
543,
949,
14457,
267,
408,
267,
1738,
63,
633,
275,
298,
1231,
2,
267,
931,
275,
3286,
832,
2,
267,
1420,
275,
3286,
1231,
15,
832,
2,
267,
882,
5731,
63,
633,
275,
882,
5731,
63,
515,
8,
1231,
63,
633,
12,
931,
9,
267,
291,
14,
629,
8,
2062,
12,
882,
5731,
63,
633,
9,
339,
347,
511,
63,
1231,
63,
265,
63,
1231,
8,
277,
304,
267,
408,
1738,
63,
633,
299,
397,
5206,
6937,
641,
1738,
267,
408,
267,
1738,
63,
633,
275,
298,
1231,
6687,
267,
931,
275,
10609,
267,
1420,
275,
3286,
1231,
2,
267,
882,
5731,
63,
633,
275,
882,
5731,
63,
515,
8,
1231,
63,
633,
12,
931,
9,
267,
291,
14,
629,
8,
2062,
12,
882,
5731,
63,
633,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
6900,
13,
22150,
481,
416,
32052,
598,
285,
16521,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
259,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
504,
5883,
828,
5129,
14,
1974,
14,
633,
63,
1974,
492,
882,
5731,
63,
515,
199,
646,
2882,
421,
199,
533,
20503,
9562,
1746,
8,
2796,
14,
1746,
304,
272,
408,
12425,
626,
2295,
314,
570,
4884,
3423,
14,
272,
408,
339,
347,
511,
63,
1231,
63,
633,
63,
1045,
63,
7001,
63,
262,
63,
14708,
63,
460,
63,
894,
8,
277,
304,
267,
408,
869,
18869,
15728,
12,
1738,
63,
633,
543,
14457,
1771,
370,
1771,
267,
408,
267,
1738,
63,
633,
275,
3286,
1231,
6687,
267,
931,
275,
3286,
832,
2,
267,
1420,
275,
3286,
1231,
15,
832,
2,
267,
882,
5731,
63,
633,
275,
882,
5731,
63,
515,
8,
1231,
63,
633,
12,
931,
9,
267,
291,
14,
629,
8,
2062,
12,
882,
5731,
63,
633,
9,
339,
347,
511,
63,
1231,
63,
633,
63,
1045,
63,
7001,
63,
262,
63,
14708,
8,
277,
304,
267,
408,
869,
18869,
15728,
4634,
12,
1738,
63,
633,
543,
14457,
315,
13738,
267,
408,
267,
1738,
63,
633,
275,
3286,
1231,
2,
267,
931,
275,
3286,
832,
2,
267,
1420,
275,
3286,
1231,
15,
832,
2,
267,
882,
5731,
63,
633,
275,
882,
5731,
63,
515,
8,
1231,
63,
633,
12,
931,
9,
267,
291,
14,
629,
8,
2062,
12,
882,
5731,
63,
633,
9,
339,
347,
511,
63,
1231,
63,
633,
63,
889,
63,
7001,
8,
277,
304,
267,
408,
1738,
63,
633,
543,
949,
14457,
267,
408,
267,
1738,
63,
633,
275,
298,
1231,
2,
267,
931,
275,
3286,
832,
2,
267,
1420,
275,
3286,
1231,
15,
832,
2,
267,
882,
5731,
63,
633,
275,
882,
5731,
63,
515,
8,
1231,
63,
633,
12,
931,
9,
267,
291,
14,
629,
8,
2062,
12,
882,
5731,
63,
633,
9,
339,
347,
511,
63,
1231,
63,
265,
63,
1231,
8,
277,
304,
267,
408,
1738,
63,
633,
299,
397,
5206,
6937,
641,
1738,
267,
408,
267,
1738,
63,
633,
275,
298,
1231,
6687,
267,
931,
275,
10609,
267,
1420,
275,
3286,
1231,
2,
267,
882,
5731,
63,
633,
275,
882,
5731,
63,
515,
8,
1231,
63,
633,
12,
931,
9,
267,
291,
14,
629,
8,
2062,
12,
882,
5731,
63,
633,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
azmikamis/ud032
|
Lesson_5_Problem_Set/02-Region_Cities/region.py
|
9
|
1642
|
#!/usr/bin/env python
"""
Use an aggregation query to answer the following question.
Which Region in India has the largest number of cities with longitude between 75 and 80?
Please modify only the 'make_pipeline' function so that it creates and returns an aggregation
pipeline that can be passed to the MongoDB aggregate function. As in our examples in this lesson,
the aggregation pipeline should be a list of one or more dictionary objects.
Please review the lesson examples if you are unsure of the syntax.
Your code will be run against a MongoDB instance that we have provided. If you want to run this
code locally on your machine, you have to install MongoDB, download and insert the dataset.
For instructions related to MongoDB setup and datasets please see Course Materials.
Please note that the dataset you are using here is a smaller version of the twitter dataset used in
examples in this lesson. If you attempt some of the same queries that we looked at in the lesson
examples, your results will be different.
"""
def get_db(db_name):
from pymongo import MongoClient
client = MongoClient('localhost:27017')
db = client[db_name]
return db
def make_pipeline():
# complete the aggregation pipeline
pipeline = [ ]
return pipeline
def aggregate(db, pipeline):
result = db.cities.aggregate(pipeline)
return result
if __name__ == '__main__':
db = get_db('examples')
pipeline = make_pipeline()
result = aggregate(db, pipeline)
import pprint
pprint.pprint(result["result"][0])
assert len(result["result"]) == 1
assert result["result"][0]["_id"] == 'Tamil Nadu'
|
agpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
624,
199,
6119,
376,
18384,
1827,
370,
6385,
314,
2569,
7894,
14,
9948,
199,
31619,
22240,
315,
1010,
2391,
965,
314,
17451,
1329,
402,
286,
12107,
543,
18154,
3382,
13098,
436,
5939,
31,
199,
199,
8254,
2811,
1454,
314,
283,
1875,
63,
7379,
7,
805,
880,
626,
652,
8491,
436,
2529,
376,
18384,
221,
199,
7379,
626,
883,
506,
3032,
370,
314,
28458,
9531,
805,
14,
3709,
315,
4154,
7251,
315,
642,
6656,
265,
12,
221,
199,
1589,
18384,
7679,
1077,
506,
282,
769,
402,
1373,
503,
1655,
2600,
2251,
14,
221,
199,
8254,
11248,
314,
6656,
265,
7251,
340,
1265,
787,
625,
3253,
402,
314,
6302,
14,
199,
199,
14398,
1233,
911,
506,
1255,
6169,
282,
28458,
1256,
626,
781,
1172,
2741,
14,
982,
1265,
2934,
370,
1255,
642,
221,
199,
600,
17738,
641,
2195,
6844,
12,
1265,
1172,
370,
3907,
28458,
12,
5235,
436,
5518,
314,
4789,
14,
199,
1858,
15794,
4048,
370,
28458,
3272,
436,
13148,
8749,
1937,
5531,
26570,
83,
14,
199,
199,
8254,
5317,
626,
314,
4789,
1265,
787,
1808,
2348,
365,
282,
12700,
1015,
402,
314,
15811,
4789,
1202,
315,
221,
199,
8589,
315,
642,
6656,
265,
14,
982,
1265,
7427,
2005,
402,
314,
2011,
9212,
626,
781,
21182,
737,
315,
314,
6656,
265,
221,
199,
8589,
12,
2195,
2058,
911,
506,
3365,
14,
199,
624,
199,
199,
318,
664,
63,
697,
8,
697,
63,
354,
304,
272,
687,
21878,
492,
13503,
3041,
272,
1890,
275,
13503,
3041,
360,
5967,
26,
1465,
9570,
358,
272,
1592,
275,
1890,
59,
697,
63,
354,
61,
272,
372,
1592,
199,
199,
318,
1852,
63,
7379,
837,
272,
327,
4890,
314,
18384,
7679,
272,
7679,
275,
359,
1622,
272,
372,
7679,
199,
199,
318,
9531,
8,
697,
12,
7679,
304,
272,
754,
275,
1592,
14,
18207,
14,
7516,
8,
7379,
9,
272,
372,
754,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
1592,
275,
664,
63,
697,
360,
8589,
358,
272,
7679,
275,
1852,
63,
7379,
342,
272,
754,
275,
9531,
8,
697,
12,
7679,
9,
272,
492,
10933,
272,
10933,
14,
15380,
8,
1099,
905,
1099,
9210,
16,
566,
272,
702,
822,
8,
1099,
905,
1099,
3135,
508,
413,
272,
702,
754,
905,
1099,
9210,
16,
7541,
63,
344,
937,
508,
283,
52,
455,
382,
653,
350,
85,
7,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
624,
199,
6119,
376,
18384,
1827,
370,
6385,
314,
2569,
7894,
14,
9948,
199,
31619,
22240,
315,
1010,
2391,
965,
314,
17451,
1329,
402,
286,
12107,
543,
18154,
3382,
13098,
436,
5939,
31,
199,
199,
8254,
2811,
1454,
314,
283,
1875,
63,
7379,
7,
805,
880,
626,
652,
8491,
436,
2529,
376,
18384,
221,
199,
7379,
626,
883,
506,
3032,
370,
314,
28458,
9531,
805,
14,
3709,
315,
4154,
7251,
315,
642,
6656,
265,
12,
221,
199,
1589,
18384,
7679,
1077,
506,
282,
769,
402,
1373,
503,
1655,
2600,
2251,
14,
221,
199,
8254,
11248,
314,
6656,
265,
7251,
340,
1265,
787,
625,
3253,
402,
314,
6302,
14,
199,
199,
14398,
1233,
911,
506,
1255,
6169,
282,
28458,
1256,
626,
781,
1172,
2741,
14,
982,
1265,
2934,
370,
1255,
642,
221,
199,
600,
17738,
641,
2195,
6844,
12,
1265,
1172,
370,
3907,
28458,
12,
5235,
436,
5518,
314,
4789,
14,
199,
1858,
15794,
4048,
370,
28458,
3272,
436,
13148,
8749,
1937,
5531,
26570,
83,
14,
199,
199,
8254,
5317,
626,
314,
4789,
1265,
787,
1808,
2348,
365,
282,
12700,
1015,
402,
314,
15811,
4789,
1202,
315,
221,
199,
8589,
315,
642,
6656,
265,
14,
982,
1265,
7427,
2005,
402,
314,
2011,
9212,
626,
781,
21182,
737,
315,
314,
6656,
265,
221,
199,
8589,
12,
2195,
2058,
911,
506,
3365,
14,
199,
624,
199,
199,
318,
664,
63,
697,
8,
697,
63,
354,
304,
272,
687,
21878,
492,
13503,
3041,
272,
1890,
275,
13503,
3041,
360,
5967,
26,
1465,
9570,
358,
272,
1592,
275,
1890,
59,
697,
63,
354,
61,
272,
372,
1592,
199,
199,
318,
1852,
63,
7379,
837,
272,
327,
4890,
314,
18384,
7679,
272,
7679,
275,
359,
1622,
272,
372,
7679,
199,
199,
318,
9531,
8,
697,
12,
7679,
304,
272,
754,
275,
1592,
14,
18207,
14,
7516,
8,
7379,
9,
272,
372,
754,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
1592,
275,
664,
63,
697,
360,
8589,
358,
272,
7679,
275,
1852,
63,
7379,
342,
272,
754,
275,
9531,
8,
697,
12,
7679,
9,
272,
492,
10933,
272,
10933,
14,
15380,
8,
1099,
905,
1099,
9210,
16,
566,
272,
702,
822,
8,
1099,
905,
1099,
3135,
508,
413,
272,
702,
754,
905,
1099,
9210,
16,
7541,
63,
344,
937,
508,
283,
52,
455,
382,
653,
350,
85,
7,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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