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
|
|---|---|---|---|---|---|---|---|---|
thomas-krenn/TKperf
|
src/perfTest/StdyState.py
|
1
|
5481
|
'''
Created on Aug 26, 2014
@author: gschoenb
'''
import logging
import numpy as np
import json
from lxml import etree
class StdyState(object):
'''
Used to define a stable state of a device
'''
## Max number of carried out test rounds.
testRnds = 25
## Always use a sliding window of 4 to measure performance values.
testMesWindow = 4
def __init__(self):
'''
Constructor
'''
## Number of rounds until steady state has been reached
self.__rounds = 0
## Number of round where steady state has been reached.
self.__stdyRnds = []
## Dependent variable to detect steady state.
self.__stdyValues = []
##Measured average in measurement window
self.__stdyAvg = 0
##Slope of steady regression line.
self.__stdySlope = []
##States if the steady state has been reached or not
self.__reachStdyState = None
def getRnds(self): return self.__rounds
def getStdyRnds(self): return self.__stdyRnds
def getStdyAvg(self): return self.__stdyAvg
def getStdyValues(self): return self.__stdyValues
def getStdySlope(self): return self.__stdySlope
def setReachStdyState(self,s): self.__reachStdyState = s
def isSteady(self):
'''
Return if the current state is steady.
@return: True if yes, False if no
@exception RuntimeError if state is not set (None)
'''
if self.__reachStdyState == None:
raise RuntimeError, "steady state is none"
return self.__reachStdyState
def checkSteadyState(self,xs,ys,rounds):
'''
Checks if the steady is reached for the given values.
The steady state is defined by the allowed data excursion from the average (+-10%), and
the allowed slope excursion of the linear regression best fit line (+-5%).
@param xs Values on x axis
@param ys Corresponding values for xs on y axis
@param rounds Number of carried out rounds
@return True (k*x+d is slope line) if steady state is reached, False if not
'''
stdyState = True
maxY = max(ys)
minY = min(ys)
avg = sum(ys)/len(ys)#calc average of values
#allow max excursion of 20% of average
avgRange = avg * 0.20
if (maxY - minY) > avgRange:
stdyState = False
#do linear regression to calculate slope of linear best fit
y = np.array(ys)
x = np.array(xs)
A = np.vstack([x, np.ones(len(x))]).T
#calculate k*x+d
k, d = np.linalg.lstsq(A, y, rcond=-1)[0]
#as we have a measurement window of 4, we calculate
#the slope excursion in the window
slopeExc = k * self.testMesWindow
if slopeExc < 0:
slopeExc *= -1
maxSlopeExc = avg * 0.10 #allowed are 10% of avg
if slopeExc > maxSlopeExc:
stdyState = False
self.__rounds = rounds
self.__stdyRnds = xs
self.__stdyValues = ys
self.__stdyAvg = avg
# Clear previous slope
self.__stdySlope = []
self.__stdySlope.extend([k,d])
self.__reachStdyState = stdyState
return stdyState
def appendXml(self,r):
'''
Append the information about a steady state test to a XML node.
@param root The xml root tag to append the new elements to
'''
data = json.dumps(list(self.__stdyRnds))
e = etree.SubElement(r,'stdyrounds')
e.text = data
data = json.dumps(list(self.__stdyValues))
e = etree.SubElement(r,'stdyvalues')
e.text = data
data = json.dumps(self.__stdySlope)
e = etree.SubElement(r,'stdyslope')
e.text = data
data = json.dumps(self.__stdyAvg)
e = etree.SubElement(r,'stdyavg')
e.text = data
data = json.dumps(self.__reachStdyState)
e = etree.SubElement(r,'reachstdystate')
e.text = data
data = json.dumps(self.__rounds)
e = etree.SubElement(r,'rndnr')
e.text = data
def fromXml(self,root):
'''
Loads the information about a steady state from XML.
@param root The given element containing the information about
the object to be initialized.
'''
self.__stdyRnds = json.loads(root.findtext('stdyrounds'))
self.__stdyValues = json.loads(root.findtext('stdyvalues'))
self.__stdySlope = json.loads(root.findtext('stdyslope'))
self.__stdyAvg = json.loads(root.findtext('stdyavg'))
self.__reachStdyState = json.loads(root.findtext('reachstdystate'))
self.__rounds = json.loads(root.findtext('rndnr'))
logging.info("########### Loading steady state from xml ###########")
self.toLog()
def toLog(self):
'''
Log information about the steady state and how it
has been reached.
'''
logging.info("Rounds of steady state:")
logging.info(self.__stdyRnds)
logging.info("Steady values:")
logging.info(self.__stdyValues)
logging.info("K and d of steady best fit slope:")
logging.info(self.__stdySlope)
logging.info("Steady average:")
logging.info(self.__stdyAvg)
logging.info("Stopped after round number:")
logging.info(self.__rounds)
logging.info("Reached steady state:")
logging.info(self.__reachStdyState)
|
gpl-3.0
|
[
2344,
199,
10502,
641,
25298,
7875,
12,
6927,
199,
199,
32,
2502,
26,
8763,
2239,
287,
66,
199,
2344,
199,
199,
646,
2050,
199,
646,
2680,
465,
980,
199,
646,
2022,
199,
504,
14490,
492,
7559,
199,
199,
533,
1933,
8161,
2223,
8,
785,
304,
272,
1449,
272,
8051,
370,
5627,
282,
17830,
1174,
402,
282,
2243,
272,
1449,
272,
925,
8228,
1329,
402,
9590,
18906,
734,
511,
27194,
14,
272,
511,
50,
78,
795,
275,
5661,
272,
925,
16763,
675,
282,
27498,
1098,
4353,
402,
841,
370,
9775,
10238,
1338,
14,
272,
511,
45,
397,
4301,
275,
841,
339,
347,
636,
826,
721,
277,
304,
267,
1449,
267,
20297,
267,
1449,
267,
925,
4860,
402,
27194,
5133,
308,
13558,
89,
1174,
965,
2757,
13075,
267,
291,
855,
23171,
275,
378,
267,
925,
4860,
402,
6168,
2382,
308,
13558,
89,
1174,
965,
2757,
13075,
14,
267,
291,
855,
1516,
89,
50,
78,
795,
275,
942,
267,
925,
1487,
5476,
1750,
370,
9696,
308,
13558,
89,
1174,
14,
267,
291,
855,
1516,
89,
6550,
275,
942,
267,
925,
1352,
305,
3297,
8095,
315,
18216,
4353,
267,
291,
855,
1516,
89,
16650,
275,
378,
267,
925,
51,
14363,
402,
308,
13558,
89,
10864,
1004,
14,
267,
291,
855,
1516,
89,
51,
14363,
275,
942,
267,
925,
18010,
340,
314,
308,
13558,
89,
1174,
965,
2757,
13075,
503,
440,
267,
291,
855,
12784,
933,
8161,
2223,
275,
488,
339,
347,
664,
50,
78,
795,
8,
277,
304,
372,
291,
855,
23171,
272,
347,
664,
933,
8161,
50,
78,
795,
8,
277,
304,
372,
291,
855,
1516,
89,
50,
78,
795,
272,
347,
664,
933,
8161,
16650,
8,
277,
304,
372,
291,
855,
1516,
89,
16650,
272,
347,
664,
933,
8161,
6550,
8,
277,
304,
372,
291,
855,
1516,
89,
6550,
272,
347,
664,
933,
8161,
51,
14363,
8,
277,
304,
372,
291,
855,
1516,
89,
51,
14363,
339,
347,
663,
497,
1225,
933,
8161,
2223,
8,
277,
12,
83,
304,
291,
855,
12784,
933,
8161,
2223,
275,
308,
339,
347,
365,
51,
13558,
89,
8,
277,
304,
267,
1449,
267,
1432,
340,
314,
1453,
1174,
365,
308,
13558,
89,
14,
267,
768,
1107,
26,
715,
340,
9456,
12,
756,
340,
949,
267,
768,
1971,
6064,
340,
1174,
365,
440,
663,
334,
403,
9,
267,
1449,
267,
340,
291,
855,
12784,
933,
8161,
2223,
508,
488,
26,
288,
746,
6064,
12,
298,
3054,
89,
1174,
365,
7179,
2,
267,
372,
291,
855,
12784,
933,
8161,
2223,
339,
347,
1104,
51,
13558,
89,
2223,
8,
277,
12,
7977,
12,
588,
12,
23171,
304,
267,
1449,
267,
13813,
340,
314,
308,
13558,
89,
365,
13075,
367,
314,
1627,
1338,
14,
267,
710,
308,
13558,
89,
1174,
365,
3247,
701,
314,
4370,
666,
444,
895,
438,
687,
314,
8095,
334,
16341,
709,
5,
395,
436,
267,
314,
4370,
24140,
444,
895,
438,
402,
314,
7798,
10864,
5526,
5542,
1004,
334,
16341,
21,
5,
680,
267,
768,
635,
12965,
13468,
641,
671,
3114,
267,
768,
635,
19205,
7499,
31137,
1338,
367,
12965,
641,
612,
3114,
267,
768,
635,
27194,
4860,
402,
9590,
18906,
734,
27194,
267,
768,
1107,
715,
334,
75,
10,
88,
11,
68,
365,
24140,
1004,
9,
340,
308,
13558,
89,
1174,
365,
13075,
12,
756,
340,
440,
267,
1449,
267,
2418,
89,
2223,
275,
715,
267,
1390,
57,
275,
1390,
8,
588,
9,
267,
1748,
57,
275,
1748,
8,
588,
9,
267,
12402,
275,
3089,
8,
588,
2447,
552,
8,
588,
28017,
8104,
8095,
402,
1338,
267,
327,
3306,
1390,
444,
895,
438,
402,
3388,
5,
402,
8095,
267,
12402,
4709,
275,
12402,
627,
378,
14,
1165,
267,
340,
334,
988,
57,
446,
1748,
57,
9,
690,
12402,
4709,
26,
288,
2418,
89,
2223,
275,
756,
398,
327,
1117,
7798,
10864,
370,
8671,
24140,
402,
7798,
5526,
5542,
267,
612,
275,
980,
14,
1144,
8,
588,
9,
267,
671,
275,
980,
14,
1144,
8,
7977,
9,
267,
437,
275,
980,
14,
20221,
779,
88,
12,
980,
14,
4548,
8,
552,
8,
88,
430,
6575,
52,
267,
327,
12063,
1022,
10,
88,
11,
68,
267,
1022,
12,
366,
275,
980,
14,
10096,
14,
6916,
3526,
8,
33,
12,
612,
12,
519,
2067,
4022,
17,
2788,
16,
61,
398,
327,
305,
781,
1172,
282,
18216,
4353,
402,
841,
12,
781,
8671,
267,
327,
1589,
24140,
444,
895,
438,
315,
221,
314,
4353,
267,
24140,
20702,
275,
1022,
627,
291,
14,
396,
45,
397,
4301,
267,
340,
24140,
20702,
665,
378,
26,
288,
24140,
20702,
9000,
446,
17,
267,
1390,
51,
14363,
20702,
275,
12402,
627,
378,
14,
709,
327,
6541,
787,
1616,
5,
402,
12402,
267,
340,
24140,
20702,
690,
1390,
51,
14363,
20702,
26,
288,
2418,
89,
2223,
275,
756,
398,
291,
855,
23171,
275,
27194,
267,
291,
855,
1516,
89,
50,
78,
795,
275,
12965,
267,
291,
855,
1516,
89,
6550,
275,
19205,
267,
291,
855,
1516,
89,
16650,
275,
12402,
267,
327,
14836,
4136,
24140,
267,
291,
855,
1516,
89,
51,
14363,
275,
942,
267,
291,
855,
1516,
89,
51,
14363,
14,
2880,
779,
75,
12,
68,
566,
267,
291,
855,
12784,
933,
8161,
2223,
275,
2418,
89,
2223,
267,
372,
2418,
89,
2223,
339,
347,
5666,
8672,
8,
277,
12,
82,
304,
267,
1449,
267,
18726,
314,
2556,
3595,
282,
308,
13558,
89,
1174,
511,
370,
282,
4692,
1031,
14,
267,
768,
635,
1738,
710,
2748,
1738,
1947,
370,
5666,
314,
892,
4008,
370,
267,
1449,
267,
666,
275,
2022,
14,
4180,
8,
513,
8,
277,
855,
1516,
89,
50,
78,
795,
430,
267,
325,
275,
7559,
14,
10571,
8,
82,
2584,
1516,
89,
23171,
358,
267,
325,
14,
505,
275,
666,
398,
666,
275,
2022,
14,
4180,
8,
513,
8,
277,
855,
1516,
89,
6550,
430,
267,
325,
275,
7559,
14,
10571,
8,
82,
2584,
1516,
89,
1459,
358,
267,
325,
14,
505,
275,
666,
398,
666,
275,
2022,
14,
4180,
8,
277,
855,
1516,
89,
51,
14363,
9,
267,
325,
275,
7559,
14,
10571,
8,
82,
2584,
1516,
588,
14363,
358,
267,
325,
14,
505,
275,
666,
398,
666,
275,
2022,
14,
4180,
8,
277,
855,
1516,
89,
16650,
9,
267,
325,
275,
7559,
14
] |
[
199,
10502,
641,
25298,
7875,
12,
6927,
199,
199,
32,
2502,
26,
8763,
2239,
287,
66,
199,
2344,
199,
199,
646,
2050,
199,
646,
2680,
465,
980,
199,
646,
2022,
199,
504,
14490,
492,
7559,
199,
199,
533,
1933,
8161,
2223,
8,
785,
304,
272,
1449,
272,
8051,
370,
5627,
282,
17830,
1174,
402,
282,
2243,
272,
1449,
272,
925,
8228,
1329,
402,
9590,
18906,
734,
511,
27194,
14,
272,
511,
50,
78,
795,
275,
5661,
272,
925,
16763,
675,
282,
27498,
1098,
4353,
402,
841,
370,
9775,
10238,
1338,
14,
272,
511,
45,
397,
4301,
275,
841,
339,
347,
636,
826,
721,
277,
304,
267,
1449,
267,
20297,
267,
1449,
267,
925,
4860,
402,
27194,
5133,
308,
13558,
89,
1174,
965,
2757,
13075,
267,
291,
855,
23171,
275,
378,
267,
925,
4860,
402,
6168,
2382,
308,
13558,
89,
1174,
965,
2757,
13075,
14,
267,
291,
855,
1516,
89,
50,
78,
795,
275,
942,
267,
925,
1487,
5476,
1750,
370,
9696,
308,
13558,
89,
1174,
14,
267,
291,
855,
1516,
89,
6550,
275,
942,
267,
925,
1352,
305,
3297,
8095,
315,
18216,
4353,
267,
291,
855,
1516,
89,
16650,
275,
378,
267,
925,
51,
14363,
402,
308,
13558,
89,
10864,
1004,
14,
267,
291,
855,
1516,
89,
51,
14363,
275,
942,
267,
925,
18010,
340,
314,
308,
13558,
89,
1174,
965,
2757,
13075,
503,
440,
267,
291,
855,
12784,
933,
8161,
2223,
275,
488,
339,
347,
664,
50,
78,
795,
8,
277,
304,
372,
291,
855,
23171,
272,
347,
664,
933,
8161,
50,
78,
795,
8,
277,
304,
372,
291,
855,
1516,
89,
50,
78,
795,
272,
347,
664,
933,
8161,
16650,
8,
277,
304,
372,
291,
855,
1516,
89,
16650,
272,
347,
664,
933,
8161,
6550,
8,
277,
304,
372,
291,
855,
1516,
89,
6550,
272,
347,
664,
933,
8161,
51,
14363,
8,
277,
304,
372,
291,
855,
1516,
89,
51,
14363,
339,
347,
663,
497,
1225,
933,
8161,
2223,
8,
277,
12,
83,
304,
291,
855,
12784,
933,
8161,
2223,
275,
308,
339,
347,
365,
51,
13558,
89,
8,
277,
304,
267,
1449,
267,
1432,
340,
314,
1453,
1174,
365,
308,
13558,
89,
14,
267,
768,
1107,
26,
715,
340,
9456,
12,
756,
340,
949,
267,
768,
1971,
6064,
340,
1174,
365,
440,
663,
334,
403,
9,
267,
1449,
267,
340,
291,
855,
12784,
933,
8161,
2223,
508,
488,
26,
288,
746,
6064,
12,
298,
3054,
89,
1174,
365,
7179,
2,
267,
372,
291,
855,
12784,
933,
8161,
2223,
339,
347,
1104,
51,
13558,
89,
2223,
8,
277,
12,
7977,
12,
588,
12,
23171,
304,
267,
1449,
267,
13813,
340,
314,
308,
13558,
89,
365,
13075,
367,
314,
1627,
1338,
14,
267,
710,
308,
13558,
89,
1174,
365,
3247,
701,
314,
4370,
666,
444,
895,
438,
687,
314,
8095,
334,
16341,
709,
5,
395,
436,
267,
314,
4370,
24140,
444,
895,
438,
402,
314,
7798,
10864,
5526,
5542,
1004,
334,
16341,
21,
5,
680,
267,
768,
635,
12965,
13468,
641,
671,
3114,
267,
768,
635,
19205,
7499,
31137,
1338,
367,
12965,
641,
612,
3114,
267,
768,
635,
27194,
4860,
402,
9590,
18906,
734,
27194,
267,
768,
1107,
715,
334,
75,
10,
88,
11,
68,
365,
24140,
1004,
9,
340,
308,
13558,
89,
1174,
365,
13075,
12,
756,
340,
440,
267,
1449,
267,
2418,
89,
2223,
275,
715,
267,
1390,
57,
275,
1390,
8,
588,
9,
267,
1748,
57,
275,
1748,
8,
588,
9,
267,
12402,
275,
3089,
8,
588,
2447,
552,
8,
588,
28017,
8104,
8095,
402,
1338,
267,
327,
3306,
1390,
444,
895,
438,
402,
3388,
5,
402,
8095,
267,
12402,
4709,
275,
12402,
627,
378,
14,
1165,
267,
340,
334,
988,
57,
446,
1748,
57,
9,
690,
12402,
4709,
26,
288,
2418,
89,
2223,
275,
756,
398,
327,
1117,
7798,
10864,
370,
8671,
24140,
402,
7798,
5526,
5542,
267,
612,
275,
980,
14,
1144,
8,
588,
9,
267,
671,
275,
980,
14,
1144,
8,
7977,
9,
267,
437,
275,
980,
14,
20221,
779,
88,
12,
980,
14,
4548,
8,
552,
8,
88,
430,
6575,
52,
267,
327,
12063,
1022,
10,
88,
11,
68,
267,
1022,
12,
366,
275,
980,
14,
10096,
14,
6916,
3526,
8,
33,
12,
612,
12,
519,
2067,
4022,
17,
2788,
16,
61,
398,
327,
305,
781,
1172,
282,
18216,
4353,
402,
841,
12,
781,
8671,
267,
327,
1589,
24140,
444,
895,
438,
315,
221,
314,
4353,
267,
24140,
20702,
275,
1022,
627,
291,
14,
396,
45,
397,
4301,
267,
340,
24140,
20702,
665,
378,
26,
288,
24140,
20702,
9000,
446,
17,
267,
1390,
51,
14363,
20702,
275,
12402,
627,
378,
14,
709,
327,
6541,
787,
1616,
5,
402,
12402,
267,
340,
24140,
20702,
690,
1390,
51,
14363,
20702,
26,
288,
2418,
89,
2223,
275,
756,
398,
291,
855,
23171,
275,
27194,
267,
291,
855,
1516,
89,
50,
78,
795,
275,
12965,
267,
291,
855,
1516,
89,
6550,
275,
19205,
267,
291,
855,
1516,
89,
16650,
275,
12402,
267,
327,
14836,
4136,
24140,
267,
291,
855,
1516,
89,
51,
14363,
275,
942,
267,
291,
855,
1516,
89,
51,
14363,
14,
2880,
779,
75,
12,
68,
566,
267,
291,
855,
12784,
933,
8161,
2223,
275,
2418,
89,
2223,
267,
372,
2418,
89,
2223,
339,
347,
5666,
8672,
8,
277,
12,
82,
304,
267,
1449,
267,
18726,
314,
2556,
3595,
282,
308,
13558,
89,
1174,
511,
370,
282,
4692,
1031,
14,
267,
768,
635,
1738,
710,
2748,
1738,
1947,
370,
5666,
314,
892,
4008,
370,
267,
1449,
267,
666,
275,
2022,
14,
4180,
8,
513,
8,
277,
855,
1516,
89,
50,
78,
795,
430,
267,
325,
275,
7559,
14,
10571,
8,
82,
2584,
1516,
89,
23171,
358,
267,
325,
14,
505,
275,
666,
398,
666,
275,
2022,
14,
4180,
8,
513,
8,
277,
855,
1516,
89,
6550,
430,
267,
325,
275,
7559,
14,
10571,
8,
82,
2584,
1516,
89,
1459,
358,
267,
325,
14,
505,
275,
666,
398,
666,
275,
2022,
14,
4180,
8,
277,
855,
1516,
89,
51,
14363,
9,
267,
325,
275,
7559,
14,
10571,
8,
82,
2584,
1516,
588,
14363,
358,
267,
325,
14,
505,
275,
666,
398,
666,
275,
2022,
14,
4180,
8,
277,
855,
1516,
89,
16650,
9,
267,
325,
275,
7559,
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,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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
] |
HugoJH/HideIntoPNG
|
Tests/test_embedder.py
|
1
|
1476
|
from os import makedirs
from os.path import exists, join, dirname, basename
from shutil import rmtree
from ..hideintopng.embedder import Embedder
def test_insert_payload():
_resetResultsFolder()
embedder = Embedder()
containerFilePath = join(dirname(__file__), "mock/ninja.png")
payloadFilePath = join(dirname(__file__), "mock/ramen.png")
mockfileFilePath = join(dirname(__file__), "mock/ninjaThatAteTheRamen.png")
containerData = b''
with open(containerFilePath, "rb") as containerFD:
containerData = containerFD.read()
payloadData = b''
with open(payloadFilePath, "rb") as payloadFD:
payloadData = payloadFD.read()
result = embedder.insertPayload(containerData, basename(payloadFilePath).encode('utf-8'), payloadData)
with open(mockfileFilePath, "rb") as mockFD:
assert mockFD.read() == result
def test_extract_payload():
_resetResultsFolder()
embedder = Embedder()
containerFilePath = join(dirname(__file__), "mock/ninjaThatAteTheRamen.png")
payload = b''
with (open(containerFilePath, "rb")) as containerFD:
payload = embedder.extractPayload(containerFD.read())
with open(join(dirname(__file__), "mock/", "ramen.png"),"rb") as mockFD:
assert payload['data'] == mockFD.read()
def _resetResultsFolder():
if exists(join(dirname(__file__), "results")):
rmtree(join(dirname(__file__), "results"))
makedirs(join(dirname(__file__), "results"))
|
mit
|
[
504,
747,
492,
1852,
3220,
199,
504,
747,
14,
515,
492,
3495,
12,
4263,
12,
9017,
12,
9593,
199,
504,
5145,
492,
20978,
199,
199,
504,
2508,
8191,
442,
411,
2753,
14,
6427,
424,
492,
24297,
424,
421,
199,
318,
511,
63,
3176,
63,
4749,
837,
272,
485,
3958,
6579,
7850,
342,
272,
6441,
424,
275,
24297,
424,
342,
272,
3970,
14225,
275,
4263,
8,
3475,
3460,
493,
10139,
298,
1805,
15,
8675,
14,
4524,
531,
272,
4886,
14225,
275,
4263,
8,
3475,
3460,
493,
10139,
298,
1805,
15,
1186,
78,
14,
4524,
531,
272,
1683,
493,
14225,
275,
4263,
8,
3475,
3460,
493,
10139,
298,
1805,
15,
8675,
17231,
33,
266,
1918,
50,
313,
78,
14,
4524,
531,
339,
3970,
1451,
275,
330,
891,
272,
543,
1551,
8,
3600,
14225,
12,
298,
4848,
531,
465,
3970,
7902,
26,
267,
3970,
1451,
275,
3970,
7902,
14,
739,
342,
339,
4886,
1451,
275,
330,
891,
272,
543,
1551,
8,
4749,
14225,
12,
298,
4848,
531,
465,
4886,
7902,
26,
267,
4886,
1451,
275,
4886,
7902,
14,
739,
342,
339,
754,
275,
6441,
424,
14,
3176,
17215,
8,
3600,
1451,
12,
9593,
8,
4749,
14225,
680,
2143,
360,
1624,
13,
24,
659,
4886,
1451,
9,
272,
543,
1551,
8,
1805,
493,
14225,
12,
298,
4848,
531,
465,
1683,
7902,
26,
267,
702,
1683,
7902,
14,
739,
342,
508,
754,
199,
199,
318,
511,
63,
5005,
63,
4749,
837,
272,
485,
3958,
6579,
7850,
342,
272,
6441,
424,
275,
24297,
424,
342,
339,
3970,
14225,
275,
4263,
8,
3475,
3460,
493,
10139,
298,
1805,
15,
8675,
17231,
33,
266,
1918,
50,
313,
78,
14,
4524,
531,
339,
4886,
275,
330,
891,
272,
543,
334,
1490,
8,
3600,
14225,
12,
298,
4848,
2237,
465,
3970,
7902,
26,
267,
4886,
275,
6441,
424,
14,
5005,
17215,
8,
3600,
7902,
14,
739,
1012,
339,
543,
1551,
8,
904,
8,
3475,
3460,
493,
10139,
298,
1805,
10665,
298,
1186,
78,
14,
4524,
1288,
2,
4848,
531,
465,
1683,
7902,
26,
267,
702,
4886,
459,
576,
418,
508,
1683,
7902,
14,
739,
342,
199,
199,
318,
485,
3958,
6579,
7850,
837,
272,
340,
3495,
8,
904,
8,
3475,
3460,
493,
10139,
298,
2604,
14150,
267,
20978,
8,
904,
8,
3475,
3460,
493,
10139,
298,
2604,
2237,
272,
1852,
3220,
8,
904,
8,
3475,
3460,
493,
10139,
298,
2604,
2237,
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
] |
[
747,
492,
1852,
3220,
199,
504,
747,
14,
515,
492,
3495,
12,
4263,
12,
9017,
12,
9593,
199,
504,
5145,
492,
20978,
199,
199,
504,
2508,
8191,
442,
411,
2753,
14,
6427,
424,
492,
24297,
424,
421,
199,
318,
511,
63,
3176,
63,
4749,
837,
272,
485,
3958,
6579,
7850,
342,
272,
6441,
424,
275,
24297,
424,
342,
272,
3970,
14225,
275,
4263,
8,
3475,
3460,
493,
10139,
298,
1805,
15,
8675,
14,
4524,
531,
272,
4886,
14225,
275,
4263,
8,
3475,
3460,
493,
10139,
298,
1805,
15,
1186,
78,
14,
4524,
531,
272,
1683,
493,
14225,
275,
4263,
8,
3475,
3460,
493,
10139,
298,
1805,
15,
8675,
17231,
33,
266,
1918,
50,
313,
78,
14,
4524,
531,
339,
3970,
1451,
275,
330,
891,
272,
543,
1551,
8,
3600,
14225,
12,
298,
4848,
531,
465,
3970,
7902,
26,
267,
3970,
1451,
275,
3970,
7902,
14,
739,
342,
339,
4886,
1451,
275,
330,
891,
272,
543,
1551,
8,
4749,
14225,
12,
298,
4848,
531,
465,
4886,
7902,
26,
267,
4886,
1451,
275,
4886,
7902,
14,
739,
342,
339,
754,
275,
6441,
424,
14,
3176,
17215,
8,
3600,
1451,
12,
9593,
8,
4749,
14225,
680,
2143,
360,
1624,
13,
24,
659,
4886,
1451,
9,
272,
543,
1551,
8,
1805,
493,
14225,
12,
298,
4848,
531,
465,
1683,
7902,
26,
267,
702,
1683,
7902,
14,
739,
342,
508,
754,
199,
199,
318,
511,
63,
5005,
63,
4749,
837,
272,
485,
3958,
6579,
7850,
342,
272,
6441,
424,
275,
24297,
424,
342,
339,
3970,
14225,
275,
4263,
8,
3475,
3460,
493,
10139,
298,
1805,
15,
8675,
17231,
33,
266,
1918,
50,
313,
78,
14,
4524,
531,
339,
4886,
275,
330,
891,
272,
543,
334,
1490,
8,
3600,
14225,
12,
298,
4848,
2237,
465,
3970,
7902,
26,
267,
4886,
275,
6441,
424,
14,
5005,
17215,
8,
3600,
7902,
14,
739,
1012,
339,
543,
1551,
8,
904,
8,
3475,
3460,
493,
10139,
298,
1805,
10665,
298,
1186,
78,
14,
4524,
1288,
2,
4848,
531,
465,
1683,
7902,
26,
267,
702,
4886,
459,
576,
418,
508,
1683,
7902,
14,
739,
342,
199,
199,
318,
485,
3958,
6579,
7850,
837,
272,
340,
3495,
8,
904,
8,
3475,
3460,
493,
10139,
298,
2604,
14150,
267,
20978,
8,
904,
8,
3475,
3460,
493,
10139,
298,
2604,
2237,
272,
1852,
3220,
8,
904,
8,
3475,
3460,
493,
10139,
298,
2604,
2237,
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,
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,
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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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
ksrajkumar/openerp-6.1
|
openerp/addons/itara_crm_lead/dms_crm_lead.py
|
1
|
3635
|
# -*- 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, timedelta
from dateutil.relativedelta import relativedelta
import time
from osv import fields, osv
from tools.translate import _
import decimal_precision as dp
import netsvc
from datetime import date
class lead_contact_address(osv.osv):
_name="lead.contact.address"
_description="Address fields"
_columns={
'add_cont_id':fields.many2one("crm.lead", 'Addional contact'),
'name':fields.char("Contact Name",size=68),
'street':fields.char("Street", size=128),
'street2':fields.char("Street2", size=128),
'zip':fields.char("Zip",size=24),
'city':fields.char("City",size=64),
'state_id': fields.many2one("res.country.state", 'Fed. State', domain="[('country_id','=',country_id)]"),
'country_id': fields.many2one('res.country', 'Country'),
'phone':fields.char("Phone",size=24),
'fax':fields.char("Fax",size=24),
'mobile':fields.char("Mobile",size=24),
}
lead_contact_address()
class crm(osv.osv):
_inherit = "crm.lead"
####3#Seq Id Generation#########
def id_generation(self, cr, uid, ids,*args):
for o in self.browse(cr, uid, ids, context={}):
if o.id_number == '/':
seq_no = self.pool.get('ir.sequence').get(cr, uid, 'crm.lead.form.seq')
self.write(cr, uid, o.id, {'id_number': seq_no,})
else:
raise osv.except_osv(_('ID No Alredy Generated !'),
_('ID No Alredy Generated!'))
return True
#####END seqId##########
_columns = {
'id_number':fields.char('ID Number',size=64, readonly=True),
'birth_date' : fields.date('Birth date'),
'age':fields.char('Age',size=68),
'addition_contact':fields.one2many("lead.contact.address",'add_cont_id','Additional Contacts'),
'heard_about':fields.selection([('friend','Friend'),('internet','Internet'),('others','Others')],'How U heard abt us'),
'others_heard':fields.char(" ",size=128),
'tick_link_id':fields.many2one('ticket.list','Tickets', domain="['&',('sal_per_id','=',uid), ('allocation_date','<', time.strftime('%Y-%m-%d 23:59:59').encode('utf8')), ('allocation_date','>=', time.strftime('%Y-%m-%d 00:00:00').encode('utf8'))]"),
}
_defaults = {
'id_number': lambda obj, cr, uid, context: '/',
}
def onchange_birth_date(self,cr, uid, ids, birth_date):
val = {}
days_in_year = 365.25
if birth_date:
sp_date = birth_date.split("-")
b_date = date(int(sp_date[0]),int(sp_date[1]),int(sp_date[2]))
age_cal = int((date.today() - b_date).days/days_in_year)
val = {'value':
{
'age' : str(age_cal),
}}
return val
crm()
|
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,
12,
6871,
199,
504,
22208,
14,
32300,
492,
20599,
199,
646,
900,
199,
199,
504,
9506,
492,
1504,
12,
9506,
199,
504,
7249,
14,
5275,
492,
485,
199,
646,
6107,
63,
6833,
465,
12392,
199,
646,
1851,
10599,
199,
504,
2197,
492,
1434,
199,
199,
533,
12690,
63,
7811,
63,
1562,
8,
4795,
14,
4795,
304,
272,
485,
354,
628,
13799,
14,
7811,
14,
1562,
2,
272,
485,
1802,
628,
1476,
1504,
2,
272,
485,
3406,
3126,
272,
283,
525,
63,
11096,
63,
344,
356,
955,
14,
3479,
18,
368,
480,
15213,
14,
13799,
401,
283,
2767,
328,
8125,
8966,
659,
272,
283,
354,
356,
955,
14,
1560,
480,
14499,
2812,
401,
890,
29,
2333,
395,
272,
283,
20451,
356,
955,
14,
1560,
480,
933,
7936,
401,
1568,
29,
3933,
395,
272,
283,
20451,
18,
356,
955,
14,
1560,
480,
933,
7936,
18,
401,
1568,
29,
3933,
395,
272,
283,
3065,
356,
955,
14,
1560,
480,
8674,
401,
890,
29,
1194,
395,
272,
283,
3690,
356,
955,
14,
1560,
480,
17024,
401,
890,
29,
772,
395,
272,
283,
929,
63,
344,
356,
1504,
14,
3479,
18,
368,
480,
470,
14,
6063,
14,
929,
401,
283,
38,
379,
14,
8511,
297,
2881,
628,
19412,
6063,
63,
344,
18937,
6063,
63,
344,
1874,
1288,
272,
283,
6063,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
470,
14,
6063,
297,
283,
17393,
659,
272,
283,
9339,
356,
955,
14,
1560,
480,
15199,
401,
890,
29,
1194,
395,
272,
283,
667,
88,
356,
955,
14,
1560,
480,
38,
1219,
401,
890,
29,
1194,
395,
272,
283,
11375,
356,
955,
14,
1560,
480,
27245,
401,
890,
29,
1194,
395,
272,
789,
199,
13799,
63,
7811,
63,
1562,
342,
199,
199,
533,
2467,
77,
8,
4795,
14,
4795,
304,
272,
485,
6486,
275,
298,
15213,
14,
13799,
2,
199,
199,
381,
19,
3,
11205,
15418,
1464,
425,
516,
3,
272,
347,
1305,
63,
15043,
8,
277,
12,
2467,
12,
1747,
12,
2762,
19166,
589,
304,
267,
367,
312,
315,
291,
14,
4570,
8,
1556,
12,
1747,
12,
2762,
12,
1067,
16420,
288,
340,
312,
14,
344,
63,
1955,
508,
20549,
355,
5412,
63,
889,
275,
291,
14,
2293,
14,
362,
360,
723,
14,
4041,
1959,
362,
8,
1556,
12,
1747,
12,
283,
15213,
14,
13799,
14,
964,
14,
3610,
358,
507,
263,
291,
14,
952,
8,
1556,
12,
1747,
12,
312,
14,
344,
12,
791,
344,
63,
1955,
356,
5412,
63,
889,
12,
1552,
6722,
587,
26,
507,
263,
746,
9506,
14,
2590,
63,
4795,
6723,
998,
3091,
4580,
581,
89,
17065,
8546,
659,
490,
4018,
998,
3091,
4580,
581,
89,
17065,
1,
1333,
199,
198,
1107,
715,
199,
8776,
3902,
5412,
1304,
516,
309,
339,
485,
3406,
275,
469,
267,
283,
344,
63,
1955,
356,
955,
14,
1560,
360,
998,
4860,
297,
890,
29,
772,
12,
6863,
29,
549,
395,
199,
198,
7,
10907,
63,
602,
7,
520,
1504,
14,
602,
360,
29229,
1434,
659,
199,
198,
7,
474,
356,
955,
14,
1560,
360,
20480,
297,
890,
29,
2333,
395,
199,
198,
7,
26799,
63,
7811,
356,
955,
14,
368,
18,
3479,
480,
13799,
14,
7811,
14,
1562,
21891,
525,
63,
11096,
63,
344,
1673,
8824,
1448,
11961,
659,
199,
198,
7,
426,
1005,
63,
10254,
356,
955,
14,
5592,
8318,
23472,
1673,
38,
8528,
8157,
4901,
1673,
29820,
8157,
21714,
1673,
8632,
83,
2665,
7,
18335,
738,
946,
1005,
2236,
84,
2739,
659,
199,
198,
7,
21714,
63,
426,
1005,
356,
955,
14,
1560,
480,
3872,
890,
29,
3933,
395,
199,
198,
1133,
2000,
63,
1073,
63,
344,
356,
955,
14,
3479,
18,
368,
360,
9201,
14,
513,
1673,
11763,
8716,
297,
2881,
628,
459,
16749,
360,
6327,
63,
529,
63,
344,
18937,
1535,
395,
661,
14940,
63,
602,
1673,
28,
297,
900,
14,
6205,
3508,
57,
3295,
77,
3295,
68,
6546,
26,
1427,
26,
1427,
1959,
2143,
360,
1624,
24,
3855,
661,
14940,
63,
602,
1673,
30,
4009,
900,
14,
6205,
3508,
57,
3295,
77,
3295,
68,
8733,
26,
383,
26,
383,
1959,
2143,
360,
1624,
24,
27738,
1288,
507,
1362,
789,
272,
485,
4322,
275,
469,
268,
283,
344,
63,
1955,
356,
2400,
1559,
12,
2467,
12,
1747,
12,
1067,
26,
17220,
1362,
789,
339,
347,
20258,
63,
10907,
63,
602,
8,
277,
12,
1556,
12,
1747,
12,
2762,
12,
21036,
63,
602,
304,
1362,
198,
637,
275,
1052,
267,
7609,
63,
262,
63,
3403,
275,
28046,
14,
821,
1362,
198,
692,
21036,
63,
602,
26,
19066,
198,
681,
63,
602,
275,
21036,
63,
602,
14,
1294,
6096,
531,
19066,
198,
66,
63,
602,
275,
1434,
8,
442,
8,
681,
63,
602,
59,
16,
2522,
442,
8,
681,
63,
602,
59,
17,
2522,
442,
8,
681,
63,
602,
59,
18,
2459,
355,
11437,
63,
915,
275,
1109,
1332,
602,
14,
8136,
342,
446,
330,
63,
602,
680,
4899,
15,
4899,
63
] |
[
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,
12,
6871,
199,
504,
22208,
14,
32300,
492,
20599,
199,
646,
900,
199,
199,
504,
9506,
492,
1504,
12,
9506,
199,
504,
7249,
14,
5275,
492,
485,
199,
646,
6107,
63,
6833,
465,
12392,
199,
646,
1851,
10599,
199,
504,
2197,
492,
1434,
199,
199,
533,
12690,
63,
7811,
63,
1562,
8,
4795,
14,
4795,
304,
272,
485,
354,
628,
13799,
14,
7811,
14,
1562,
2,
272,
485,
1802,
628,
1476,
1504,
2,
272,
485,
3406,
3126,
272,
283,
525,
63,
11096,
63,
344,
356,
955,
14,
3479,
18,
368,
480,
15213,
14,
13799,
401,
283,
2767,
328,
8125,
8966,
659,
272,
283,
354,
356,
955,
14,
1560,
480,
14499,
2812,
401,
890,
29,
2333,
395,
272,
283,
20451,
356,
955,
14,
1560,
480,
933,
7936,
401,
1568,
29,
3933,
395,
272,
283,
20451,
18,
356,
955,
14,
1560,
480,
933,
7936,
18,
401,
1568,
29,
3933,
395,
272,
283,
3065,
356,
955,
14,
1560,
480,
8674,
401,
890,
29,
1194,
395,
272,
283,
3690,
356,
955,
14,
1560,
480,
17024,
401,
890,
29,
772,
395,
272,
283,
929,
63,
344,
356,
1504,
14,
3479,
18,
368,
480,
470,
14,
6063,
14,
929,
401,
283,
38,
379,
14,
8511,
297,
2881,
628,
19412,
6063,
63,
344,
18937,
6063,
63,
344,
1874,
1288,
272,
283,
6063,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
470,
14,
6063,
297,
283,
17393,
659,
272,
283,
9339,
356,
955,
14,
1560,
480,
15199,
401,
890,
29,
1194,
395,
272,
283,
667,
88,
356,
955,
14,
1560,
480,
38,
1219,
401,
890,
29,
1194,
395,
272,
283,
11375,
356,
955,
14,
1560,
480,
27245,
401,
890,
29,
1194,
395,
272,
789,
199,
13799,
63,
7811,
63,
1562,
342,
199,
199,
533,
2467,
77,
8,
4795,
14,
4795,
304,
272,
485,
6486,
275,
298,
15213,
14,
13799,
2,
199,
199,
381,
19,
3,
11205,
15418,
1464,
425,
516,
3,
272,
347,
1305,
63,
15043,
8,
277,
12,
2467,
12,
1747,
12,
2762,
19166,
589,
304,
267,
367,
312,
315,
291,
14,
4570,
8,
1556,
12,
1747,
12,
2762,
12,
1067,
16420,
288,
340,
312,
14,
344,
63,
1955,
508,
20549,
355,
5412,
63,
889,
275,
291,
14,
2293,
14,
362,
360,
723,
14,
4041,
1959,
362,
8,
1556,
12,
1747,
12,
283,
15213,
14,
13799,
14,
964,
14,
3610,
358,
507,
263,
291,
14,
952,
8,
1556,
12,
1747,
12,
312,
14,
344,
12,
791,
344,
63,
1955,
356,
5412,
63,
889,
12,
1552,
6722,
587,
26,
507,
263,
746,
9506,
14,
2590,
63,
4795,
6723,
998,
3091,
4580,
581,
89,
17065,
8546,
659,
490,
4018,
998,
3091,
4580,
581,
89,
17065,
1,
1333,
199,
198,
1107,
715,
199,
8776,
3902,
5412,
1304,
516,
309,
339,
485,
3406,
275,
469,
267,
283,
344,
63,
1955,
356,
955,
14,
1560,
360,
998,
4860,
297,
890,
29,
772,
12,
6863,
29,
549,
395,
199,
198,
7,
10907,
63,
602,
7,
520,
1504,
14,
602,
360,
29229,
1434,
659,
199,
198,
7,
474,
356,
955,
14,
1560,
360,
20480,
297,
890,
29,
2333,
395,
199,
198,
7,
26799,
63,
7811,
356,
955,
14,
368,
18,
3479,
480,
13799,
14,
7811,
14,
1562,
21891,
525,
63,
11096,
63,
344,
1673,
8824,
1448,
11961,
659,
199,
198,
7,
426,
1005,
63,
10254,
356,
955,
14,
5592,
8318,
23472,
1673,
38,
8528,
8157,
4901,
1673,
29820,
8157,
21714,
1673,
8632,
83,
2665,
7,
18335,
738,
946,
1005,
2236,
84,
2739,
659,
199,
198,
7,
21714,
63,
426,
1005,
356,
955,
14,
1560,
480,
3872,
890,
29,
3933,
395,
199,
198,
1133,
2000,
63,
1073,
63,
344,
356,
955,
14,
3479,
18,
368,
360,
9201,
14,
513,
1673,
11763,
8716,
297,
2881,
628,
459,
16749,
360,
6327,
63,
529,
63,
344,
18937,
1535,
395,
661,
14940,
63,
602,
1673,
28,
297,
900,
14,
6205,
3508,
57,
3295,
77,
3295,
68,
6546,
26,
1427,
26,
1427,
1959,
2143,
360,
1624,
24,
3855,
661,
14940,
63,
602,
1673,
30,
4009,
900,
14,
6205,
3508,
57,
3295,
77,
3295,
68,
8733,
26,
383,
26,
383,
1959,
2143,
360,
1624,
24,
27738,
1288,
507,
1362,
789,
272,
485,
4322,
275,
469,
268,
283,
344,
63,
1955,
356,
2400,
1559,
12,
2467,
12,
1747,
12,
1067,
26,
17220,
1362,
789,
339,
347,
20258,
63,
10907,
63,
602,
8,
277,
12,
1556,
12,
1747,
12,
2762,
12,
21036,
63,
602,
304,
1362,
198,
637,
275,
1052,
267,
7609,
63,
262,
63,
3403,
275,
28046,
14,
821,
1362,
198,
692,
21036,
63,
602,
26,
19066,
198,
681,
63,
602,
275,
21036,
63,
602,
14,
1294,
6096,
531,
19066,
198,
66,
63,
602,
275,
1434,
8,
442,
8,
681,
63,
602,
59,
16,
2522,
442,
8,
681,
63,
602,
59,
17,
2522,
442,
8,
681,
63,
602,
59,
18,
2459,
355,
11437,
63,
915,
275,
1109,
1332,
602,
14,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
perlygatekeeper/glowing-robot
|
Little_Alchemy_2/Scraper_python/env/lib/python3.7/site-packages/pip/_internal/commands/__init__.py
|
9
|
2295
|
"""
Package containing all pip commands
"""
from __future__ import absolute_import
from pip._internal.commands.completion import CompletionCommand
from pip._internal.commands.configuration import ConfigurationCommand
from pip._internal.commands.debug import DebugCommand
from pip._internal.commands.download import DownloadCommand
from pip._internal.commands.freeze import FreezeCommand
from pip._internal.commands.hash import HashCommand
from pip._internal.commands.help import HelpCommand
from pip._internal.commands.list import ListCommand
from pip._internal.commands.check import CheckCommand
from pip._internal.commands.search import SearchCommand
from pip._internal.commands.show import ShowCommand
from pip._internal.commands.install import InstallCommand
from pip._internal.commands.uninstall import UninstallCommand
from pip._internal.commands.wheel import WheelCommand
from pip._internal.utils.typing import MYPY_CHECK_RUNNING
if MYPY_CHECK_RUNNING:
from typing import List, Type
from pip._internal.cli.base_command import Command
commands_order = [
InstallCommand,
DownloadCommand,
UninstallCommand,
FreezeCommand,
ListCommand,
ShowCommand,
CheckCommand,
ConfigurationCommand,
SearchCommand,
WheelCommand,
HashCommand,
CompletionCommand,
DebugCommand,
HelpCommand,
] # type: List[Type[Command]]
commands_dict = {c.name: c for c in commands_order}
def get_summaries(ordered=True):
"""Yields sorted (command name, command summary) tuples."""
if ordered:
cmditems = _sort_commands(commands_dict, commands_order)
else:
cmditems = commands_dict.items()
for name, command_class in cmditems:
yield (name, command_class.summary)
def get_similar_commands(name):
"""Command name auto-correct."""
from difflib import get_close_matches
name = name.lower()
close_commands = get_close_matches(name, commands_dict.keys())
if close_commands:
return close_commands[0]
else:
return False
def _sort_commands(cmddict, order):
def keyfn(key):
try:
return order.index(key[1])
except ValueError:
# unordered items should come last
return 0xff
return sorted(cmddict.items(), key=keyfn)
|
artistic-2.0
|
[
624,
199,
8599,
3035,
1006,
7305,
3718,
199,
624,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
504,
7305,
423,
4672,
14,
4405,
14,
13207,
492,
12515,
296,
3110,
199,
504,
7305,
423,
4672,
14,
4405,
14,
4758,
492,
11595,
3110,
199,
504,
7305,
423,
4672,
14,
4405,
14,
1757,
492,
14245,
3110,
199,
504,
7305,
423,
4672,
14,
4405,
14,
4249,
492,
17955,
3110,
199,
504,
7305,
423,
4672,
14,
4405,
14,
18459,
492,
2868,
806,
3110,
199,
504,
7305,
423,
4672,
14,
4405,
14,
2227,
492,
16101,
3110,
199,
504,
7305,
423,
4672,
14,
4405,
14,
3437,
492,
15456,
3110,
199,
504,
7305,
423,
4672,
14,
4405,
14,
513,
492,
3820,
3110,
199,
504,
7305,
423,
4672,
14,
4405,
14,
1074,
492,
2670,
3110,
199,
504,
7305,
423,
4672,
14,
4405,
14,
1733,
492,
8730,
3110,
199,
504,
7305,
423,
4672,
14,
4405,
14,
2384,
492,
12968,
3110,
199,
504,
7305,
423,
4672,
14,
4405,
14,
3174,
492,
13276,
3110,
199,
504,
7305,
423,
4672,
14,
4405,
14,
19502,
492,
1910,
3174,
3110,
199,
504,
7305,
423,
4672,
14,
4405,
14,
11798,
492,
26161,
3110,
199,
199,
504,
7305,
423,
4672,
14,
1208,
14,
29747,
492,
603,
57,
4521,
63,
8936,
63,
17305,
199,
199,
692,
603,
57,
4521,
63,
8936,
63,
17305,
26,
272,
687,
14090,
492,
3820,
12,
2434,
272,
687,
7305,
423,
4672,
14,
2764,
14,
1095,
63,
1531,
492,
5817,
199,
199,
4405,
63,
1648,
275,
359,
272,
13276,
3110,
12,
272,
17955,
3110,
12,
272,
1910,
3174,
3110,
12,
272,
2868,
806,
3110,
12,
272,
3820,
3110,
12,
272,
12968,
3110,
12,
272,
2670,
3110,
12,
272,
11595,
3110,
12,
272,
8730,
3110,
12,
272,
26161,
3110,
12,
272,
16101,
3110,
12,
272,
12515,
296,
3110,
12,
272,
14245,
3110,
12,
272,
15456,
3110,
12,
199,
61,
221,
327,
730,
26,
3820,
59,
804,
59,
3110,
2677,
199,
199,
4405,
63,
807,
275,
469,
67,
14,
354,
26,
286,
367,
286,
315,
3718,
63,
1648,
93,
421,
199,
318,
664,
63,
19883,
8,
8235,
29,
549,
304,
272,
408,
22889,
83,
3355,
334,
1531,
536,
12,
1414,
6212,
9,
6346,
1041,
339,
340,
7741,
26,
267,
6904,
328,
3733,
275,
485,
3191,
63,
4405,
8,
4405,
63,
807,
12,
3718,
63,
1648,
9,
272,
587,
26,
267,
6904,
328,
3733,
275,
3718,
63,
807,
14,
1744,
342,
339,
367,
536,
12,
1414,
63,
533,
315,
6904,
328,
3733,
26,
267,
1995,
334,
354,
12,
1414,
63,
533,
14,
4705,
9,
421,
199,
318,
664,
63,
23079,
63,
4405,
8,
354,
304,
272,
408,
3110,
536,
2599,
13,
4525,
1041,
272,
687,
27070,
492,
664,
63,
1600,
63,
6742,
339,
536,
275,
536,
14,
2325,
342,
339,
4002,
63,
4405,
275,
664,
63,
1600,
63,
6742,
8,
354,
12,
3718,
63,
807,
14,
1612,
1012,
339,
340,
4002,
63,
4405,
26,
267,
372,
4002,
63,
4405,
59,
16,
61,
272,
587,
26,
267,
372,
756,
421,
199,
318,
485,
3191,
63,
4405,
8,
1760,
807,
12,
1865,
304,
272,
347,
790,
2324,
8,
498,
304,
267,
862,
26,
288,
372,
1865,
14,
1080,
8,
498,
59,
17,
566,
267,
871,
1722,
26,
288,
327,
31716,
2974,
1077,
11492,
2061,
288,
372,
378,
3581,
339,
372,
3355,
8,
1760,
807,
14,
1744,
1062,
790,
29,
498,
2324,
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
] |
[
199,
8599,
3035,
1006,
7305,
3718,
199,
624,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
504,
7305,
423,
4672,
14,
4405,
14,
13207,
492,
12515,
296,
3110,
199,
504,
7305,
423,
4672,
14,
4405,
14,
4758,
492,
11595,
3110,
199,
504,
7305,
423,
4672,
14,
4405,
14,
1757,
492,
14245,
3110,
199,
504,
7305,
423,
4672,
14,
4405,
14,
4249,
492,
17955,
3110,
199,
504,
7305,
423,
4672,
14,
4405,
14,
18459,
492,
2868,
806,
3110,
199,
504,
7305,
423,
4672,
14,
4405,
14,
2227,
492,
16101,
3110,
199,
504,
7305,
423,
4672,
14,
4405,
14,
3437,
492,
15456,
3110,
199,
504,
7305,
423,
4672,
14,
4405,
14,
513,
492,
3820,
3110,
199,
504,
7305,
423,
4672,
14,
4405,
14,
1074,
492,
2670,
3110,
199,
504,
7305,
423,
4672,
14,
4405,
14,
1733,
492,
8730,
3110,
199,
504,
7305,
423,
4672,
14,
4405,
14,
2384,
492,
12968,
3110,
199,
504,
7305,
423,
4672,
14,
4405,
14,
3174,
492,
13276,
3110,
199,
504,
7305,
423,
4672,
14,
4405,
14,
19502,
492,
1910,
3174,
3110,
199,
504,
7305,
423,
4672,
14,
4405,
14,
11798,
492,
26161,
3110,
199,
199,
504,
7305,
423,
4672,
14,
1208,
14,
29747,
492,
603,
57,
4521,
63,
8936,
63,
17305,
199,
199,
692,
603,
57,
4521,
63,
8936,
63,
17305,
26,
272,
687,
14090,
492,
3820,
12,
2434,
272,
687,
7305,
423,
4672,
14,
2764,
14,
1095,
63,
1531,
492,
5817,
199,
199,
4405,
63,
1648,
275,
359,
272,
13276,
3110,
12,
272,
17955,
3110,
12,
272,
1910,
3174,
3110,
12,
272,
2868,
806,
3110,
12,
272,
3820,
3110,
12,
272,
12968,
3110,
12,
272,
2670,
3110,
12,
272,
11595,
3110,
12,
272,
8730,
3110,
12,
272,
26161,
3110,
12,
272,
16101,
3110,
12,
272,
12515,
296,
3110,
12,
272,
14245,
3110,
12,
272,
15456,
3110,
12,
199,
61,
221,
327,
730,
26,
3820,
59,
804,
59,
3110,
2677,
199,
199,
4405,
63,
807,
275,
469,
67,
14,
354,
26,
286,
367,
286,
315,
3718,
63,
1648,
93,
421,
199,
318,
664,
63,
19883,
8,
8235,
29,
549,
304,
272,
408,
22889,
83,
3355,
334,
1531,
536,
12,
1414,
6212,
9,
6346,
1041,
339,
340,
7741,
26,
267,
6904,
328,
3733,
275,
485,
3191,
63,
4405,
8,
4405,
63,
807,
12,
3718,
63,
1648,
9,
272,
587,
26,
267,
6904,
328,
3733,
275,
3718,
63,
807,
14,
1744,
342,
339,
367,
536,
12,
1414,
63,
533,
315,
6904,
328,
3733,
26,
267,
1995,
334,
354,
12,
1414,
63,
533,
14,
4705,
9,
421,
199,
318,
664,
63,
23079,
63,
4405,
8,
354,
304,
272,
408,
3110,
536,
2599,
13,
4525,
1041,
272,
687,
27070,
492,
664,
63,
1600,
63,
6742,
339,
536,
275,
536,
14,
2325,
342,
339,
4002,
63,
4405,
275,
664,
63,
1600,
63,
6742,
8,
354,
12,
3718,
63,
807,
14,
1612,
1012,
339,
340,
4002,
63,
4405,
26,
267,
372,
4002,
63,
4405,
59,
16,
61,
272,
587,
26,
267,
372,
756,
421,
199,
318,
485,
3191,
63,
4405,
8,
1760,
807,
12,
1865,
304,
272,
347,
790,
2324,
8,
498,
304,
267,
862,
26,
288,
372,
1865,
14,
1080,
8,
498,
59,
17,
566,
267,
871,
1722,
26,
288,
327,
31716,
2974,
1077,
11492,
2061,
288,
372,
378,
3581,
339,
372,
3355,
8,
1760,
807,
14,
1744,
1062,
790,
29,
498,
2324,
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,
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,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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
] |
stormsson/procedural_city_generation_wrapper
|
vendor/josauder/procedural_city_generation/roadmap/growth_rules/organic.py
|
2
|
1707
|
from __future__ import division
import numpy as np
import random
from procedural_city_generation.roadmap.Vertex import Vertex
from procedural_city_generation.additional_stuff.rotate import rotate
from procedural_city_generation.additional_stuff.Singleton import Singleton
singleton=Singleton("roadmap")
def organic(vertex, b):
#Sammelt Numerische Werte aus Variables-Objekt
pForward=singleton.organicpForward
pTurn=singleton.organicpTurn
lMin=singleton.organiclMin
lMax=singleton.organiclMax
suggested_vertices=[]
weiter=False
#Berechnet den Vektor des letzten Weges zu diesem Punkt
previous_vector=np.array(vertex.coords-vertex.neighbours[len(vertex.neighbours)-1].coords)
previous_vector=previous_vector/np.linalg.norm(previous_vector)
#Geradeaus
v=random.uniform(lMin, lMax)*previous_vector
random_number=random.randint(0, 100)
if random_number<=pForward:
k=Vertex(vertex.coords+rotate(np.random.uniform(-30, 30), v))
suggested_vertices.append(k)
#Rechts
v=random.uniform(lMin, lMax)*previous_vector
random_number=random.randint(0, 100)
if random_number<=b*pTurn:
k=Vertex(vertex.coords+rotate(np.random.uniform(-120, -60), v))
suggested_vertices.append(k)
weiter=True
#Links
v=random.uniform(lMin, lMax)*previous_vector
random_number=random.randint(0, 100)
if random_number<=b*pTurn:
k=Vertex(vertex.coords+rotate(np.random.uniform(60, 120), v))
suggested_vertices.append(k)
weiter=True
#Seed!
if not weiter:
vertex.seed=True
singleton.global_lists.vertex_queue.append([vertex, 0])
return suggested_vertices
|
mpl-2.0
|
[
504,
636,
2443,
363,
492,
4629,
199,
199,
646,
2680,
465,
980,
199,
646,
2196,
199,
199,
504,
557,
6867,
4889,
63,
3690,
63,
15043,
14,
5063,
1130,
14,
9787,
492,
5444,
3858,
199,
504,
557,
6867,
4889,
63,
3690,
63,
15043,
14,
8460,
63,
14573,
14,
12873,
492,
20071,
199,
199,
504,
557,
6867,
4889,
63,
3690,
63,
15043,
14,
8460,
63,
14573,
14,
28456,
492,
13050,
1860,
199,
199,
24675,
29,
28456,
480,
5063,
1130,
531,
199,
199,
318,
20765,
530,
8,
11417,
12,
330,
304,
339,
327,
51,
455,
278,
4116,
653,
940,
5719,
595,
644,
281,
266,
282,
527,
17198,
13,
5665,
5711,
84,
272,
299,
12984,
29,
24675,
14,
19916,
530,
80,
12984,
272,
299,
16838,
29,
24675,
14,
19916,
530,
80,
16838,
272,
634,
4649,
29,
24675,
14,
19916,
73,
429,
4649,
272,
634,
4261,
29,
24675,
14,
19916,
73,
429,
4261,
2378,
25697,
63,
12637,
9811,
272,
781,
1661,
29,
797,
339,
327,
3655,
264,
335,
846,
5376,
812,
5711,
8270,
18618,
1026,
3903,
724,
2136,
3389,
1315,
85,
18833,
21678,
510,
1778,
84,
272,
4136,
63,
4106,
29,
1590,
14,
1144,
8,
11417,
14,
8032,
13,
11417,
14,
685,
4594,
16363,
59,
552,
8,
11417,
14,
685,
4594,
16363,
7216,
17,
1055,
8032,
9,
272,
4136,
63,
4106,
29,
6352,
63,
4106,
15,
1590,
14,
10096,
14,
4791,
8,
6352,
63,
4106,
9,
2378,
327,
27866,
9587,
65,
527,
272,
373,
29,
2355,
14,
8830,
8,
76,
4649,
12,
634,
4261,
3342,
6352,
63,
4106,
272,
2196,
63,
1955,
29,
2355,
14,
8393,
8,
16,
12,
2948,
9,
272,
340,
2196,
63,
1955,
12932,
80,
12984,
26,
267,
1022,
29,
9787,
8,
11417,
14,
8032,
11,
12873,
8,
1590,
14,
2355,
14,
8830,
2801,
1216,
12,
4233,
395,
373,
430,
267,
25697,
63,
12637,
14,
740,
8,
75,
9,
339,
327,
497,
335,
1086,
272,
373,
29,
2355,
14,
8830,
8,
76,
4649,
12,
634,
4261,
3342,
6352,
63,
4106,
272,
2196,
63,
1955,
29,
2355,
14,
8393,
8,
16,
12,
2948,
9,
272,
340,
2196,
63,
1955,
12932,
66,
10,
80,
16838,
26,
267,
1022,
29,
9787,
8,
11417,
14,
8032,
11,
12873,
8,
1590,
14,
2355,
14,
8830,
2801,
6708,
12,
446,
2259,
395,
373,
430,
267,
25697,
63,
12637,
14,
740,
8,
75,
9,
267,
781,
1661,
29,
549,
339,
327,
16974,
272,
373,
29,
2355,
14,
8830,
8,
76,
4649,
12,
634,
4261,
3342,
6352,
63,
4106,
272,
2196,
63,
1955,
29,
2355,
14,
8393,
8,
16,
12,
2948,
9,
272,
340,
2196,
63,
1955,
12932,
66,
10,
80,
16838,
26,
267,
1022,
29,
9787,
8,
11417,
14,
8032,
11,
12873,
8,
1590,
14,
2355,
14,
8830,
8,
2259,
12,
13960,
395,
373,
430,
267,
25697,
63,
12637,
14,
740,
8,
75,
9,
267,
781,
1661,
29,
549,
339,
327,
19554,
1,
272,
340,
440,
781,
1661,
26,
267,
12759,
14,
5176,
29,
549,
267,
19768,
14,
2966,
63,
6717,
14,
11417,
63,
1825,
14,
740,
779,
11417,
12,
378,
566,
339,
372,
25697,
63,
12637,
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
] |
[
636,
2443,
363,
492,
4629,
199,
199,
646,
2680,
465,
980,
199,
646,
2196,
199,
199,
504,
557,
6867,
4889,
63,
3690,
63,
15043,
14,
5063,
1130,
14,
9787,
492,
5444,
3858,
199,
504,
557,
6867,
4889,
63,
3690,
63,
15043,
14,
8460,
63,
14573,
14,
12873,
492,
20071,
199,
199,
504,
557,
6867,
4889,
63,
3690,
63,
15043,
14,
8460,
63,
14573,
14,
28456,
492,
13050,
1860,
199,
199,
24675,
29,
28456,
480,
5063,
1130,
531,
199,
199,
318,
20765,
530,
8,
11417,
12,
330,
304,
339,
327,
51,
455,
278,
4116,
653,
940,
5719,
595,
644,
281,
266,
282,
527,
17198,
13,
5665,
5711,
84,
272,
299,
12984,
29,
24675,
14,
19916,
530,
80,
12984,
272,
299,
16838,
29,
24675,
14,
19916,
530,
80,
16838,
272,
634,
4649,
29,
24675,
14,
19916,
73,
429,
4649,
272,
634,
4261,
29,
24675,
14,
19916,
73,
429,
4261,
2378,
25697,
63,
12637,
9811,
272,
781,
1661,
29,
797,
339,
327,
3655,
264,
335,
846,
5376,
812,
5711,
8270,
18618,
1026,
3903,
724,
2136,
3389,
1315,
85,
18833,
21678,
510,
1778,
84,
272,
4136,
63,
4106,
29,
1590,
14,
1144,
8,
11417,
14,
8032,
13,
11417,
14,
685,
4594,
16363,
59,
552,
8,
11417,
14,
685,
4594,
16363,
7216,
17,
1055,
8032,
9,
272,
4136,
63,
4106,
29,
6352,
63,
4106,
15,
1590,
14,
10096,
14,
4791,
8,
6352,
63,
4106,
9,
2378,
327,
27866,
9587,
65,
527,
272,
373,
29,
2355,
14,
8830,
8,
76,
4649,
12,
634,
4261,
3342,
6352,
63,
4106,
272,
2196,
63,
1955,
29,
2355,
14,
8393,
8,
16,
12,
2948,
9,
272,
340,
2196,
63,
1955,
12932,
80,
12984,
26,
267,
1022,
29,
9787,
8,
11417,
14,
8032,
11,
12873,
8,
1590,
14,
2355,
14,
8830,
2801,
1216,
12,
4233,
395,
373,
430,
267,
25697,
63,
12637,
14,
740,
8,
75,
9,
339,
327,
497,
335,
1086,
272,
373,
29,
2355,
14,
8830,
8,
76,
4649,
12,
634,
4261,
3342,
6352,
63,
4106,
272,
2196,
63,
1955,
29,
2355,
14,
8393,
8,
16,
12,
2948,
9,
272,
340,
2196,
63,
1955,
12932,
66,
10,
80,
16838,
26,
267,
1022,
29,
9787,
8,
11417,
14,
8032,
11,
12873,
8,
1590,
14,
2355,
14,
8830,
2801,
6708,
12,
446,
2259,
395,
373,
430,
267,
25697,
63,
12637,
14,
740,
8,
75,
9,
267,
781,
1661,
29,
549,
339,
327,
16974,
272,
373,
29,
2355,
14,
8830,
8,
76,
4649,
12,
634,
4261,
3342,
6352,
63,
4106,
272,
2196,
63,
1955,
29,
2355,
14,
8393,
8,
16,
12,
2948,
9,
272,
340,
2196,
63,
1955,
12932,
66,
10,
80,
16838,
26,
267,
1022,
29,
9787,
8,
11417,
14,
8032,
11,
12873,
8,
1590,
14,
2355,
14,
8830,
8,
2259,
12,
13960,
395,
373,
430,
267,
25697,
63,
12637,
14,
740,
8,
75,
9,
267,
781,
1661,
29,
549,
339,
327,
19554,
1,
272,
340,
440,
781,
1661,
26,
267,
12759,
14,
5176,
29,
549,
267,
19768,
14,
2966,
63,
6717,
14,
11417,
63,
1825,
14,
740,
779,
11417,
12,
378,
566,
339,
372,
25697,
63,
12637,
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,
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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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
hassoon3/odoo
|
addons/sale_margin/sale_margin.py
|
31
|
4691
|
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 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 openerp.osv import fields, osv
import openerp.addons.decimal_precision as dp
class sale_order_line(osv.osv):
_inherit = "sale.order.line"
def product_id_change(self, cr, uid, ids, pricelist, product, qty=0,
uom=False, qty_uos=0, uos=False, name='', partner_id=False,
lang=False, update_tax=True, date_order=False, packaging=False, fiscal_position=False, flag=False, context=None):
res = super(sale_order_line, self).product_id_change(cr, uid, ids, pricelist, product, qty=qty,
uom=uom, qty_uos=qty_uos, uos=uos, name=name, partner_id=partner_id,
lang=lang, update_tax=update_tax, date_order=date_order, packaging=packaging, fiscal_position=fiscal_position, flag=flag, context=context)
if not pricelist:
return res
if context is None:
context = {}
frm_cur = self.pool.get('res.users').browse(cr, uid, uid).company_id.currency_id.id
to_cur = self.pool.get('product.pricelist').browse(cr, uid, [pricelist])[0].currency_id.id
if product:
product = self.pool['product.product'].browse(cr, uid, product, context=context)
purchase_price = product.standard_price
to_uom = res.get('product_uom', uom)
if to_uom != product.uom_id.id:
purchase_price = self.pool['product.uom']._compute_price(cr, uid, product.uom_id.id, purchase_price, to_uom)
ctx = context.copy()
ctx['date'] = date_order
price = self.pool.get('res.currency').compute(cr, uid, frm_cur, to_cur, purchase_price, round=False, context=ctx)
res['value'].update({'purchase_price': price})
return res
def _product_margin(self, cr, uid, ids, field_name, arg, context=None):
cur_obj = self.pool.get('res.currency')
res = {}
for line in self.browse(cr, uid, ids, context=context):
cur = line.order_id.pricelist_id.currency_id
res[line.id] = 0
if line.product_id:
tmp_margin = line.price_subtotal - ((line.purchase_price or line.product_id.standard_price) * line.product_uos_qty)
res[line.id] = cur_obj.round(cr, uid, cur, tmp_margin)
return res
_columns = {
'margin': fields.function(_product_margin, string='Margin', digits_compute= dp.get_precision('Product Price'),
store = True),
'purchase_price': fields.float('Cost Price', digits_compute= dp.get_precision('Product Price'))
}
class sale_order(osv.osv):
_inherit = "sale.order"
def _product_margin(self, cr, uid, ids, field_name, arg, context=None):
result = {}
for sale in self.browse(cr, uid, ids, context=context):
result[sale.id] = 0.0
for line in sale.order_line:
if line.state == 'cancel':
continue
result[sale.id] += line.margin or 0.0
return result
def _get_order(self, cr, uid, ids, context=None):
result = {}
for line in self.pool.get('sale.order.line').browse(cr, uid, ids, context=context):
result[line.order_id.id] = True
return result.keys()
_columns = {
'margin': fields.function(_product_margin, string='Margin', help="It gives profitability by calculating the difference between the Unit Price and the cost price.", store={
'sale.order.line': (_get_order, ['margin', 'purchase_price', 'order_id'], 20),
'sale.order': (lambda self, cr, uid, ids, c={}: ids, ['order_line'], 20),
}, digits_compute= dp.get_precision('Product Price')),
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
8664,
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,
5166,
14,
4795,
492,
1504,
12,
9506,
199,
646,
5166,
14,
10788,
14,
6355,
63,
6833,
465,
12392,
199,
199,
533,
13590,
63,
1648,
63,
604,
8,
4795,
14,
4795,
304,
272,
485,
6486,
275,
298,
8515,
14,
1648,
14,
604,
2,
339,
347,
3336,
63,
344,
63,
1461,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
25162,
12,
3336,
12,
13556,
29,
16,
12,
288,
19842,
29,
797,
12,
13556,
63,
20560,
29,
16,
12,
399,
736,
29,
797,
12,
536,
4581,
5854,
63,
344,
29,
797,
12,
288,
6339,
29,
797,
12,
1678,
63,
5530,
29,
549,
12,
1434,
63,
1648,
29,
797,
12,
27369,
29,
797,
12,
18672,
63,
3124,
29,
797,
12,
3305,
29,
797,
12,
1067,
29,
403,
304,
267,
522,
275,
1613,
8,
8515,
63,
1648,
63,
604,
12,
291,
680,
2558,
63,
344,
63,
1461,
8,
1556,
12,
1747,
12,
2762,
12,
25162,
12,
3336,
12,
13556,
29,
5643,
12,
288,
19842,
29,
7519,
12,
13556,
63,
20560,
29,
5643,
63,
20560,
12,
399,
736,
29,
20560,
12,
536,
29,
354,
12,
5854,
63,
344,
29,
3899,
63,
344,
12,
288,
6339,
29,
4159,
12,
1678,
63,
5530,
29,
873,
63,
5530,
12,
1434,
63,
1648,
29,
602,
63,
1648,
12,
27369,
29,
27796,
12,
18672,
63,
3124,
29,
18646,
63,
3124,
12,
3305,
29,
4173,
12,
1067,
29,
1100,
9,
267,
340,
440,
25162,
26,
288,
372,
522,
267,
340,
1067,
365,
488,
26,
288,
1067,
275,
1052,
267,
289,
5682,
63,
895,
275,
291,
14,
2293,
14,
362,
360,
470,
14,
3707,
1959,
4570,
8,
1556,
12,
1747,
12,
1747,
680,
4627,
63,
344,
14,
4968,
63,
344,
14,
344,
267,
370,
63,
895,
275,
291,
14,
2293,
14,
362,
360,
2558,
14,
17385,
1959,
4570,
8,
1556,
12,
1747,
12,
359,
17385,
11057,
16,
1055,
4968,
63,
344,
14,
344,
267,
340,
3336,
26,
288,
3336,
275,
291,
14,
2293,
459,
2558,
14,
2558,
2278,
4570,
8,
1556,
12,
1747,
12,
3336,
12,
1067,
29,
1100,
9,
288,
15932,
63,
4777,
275,
3336,
14,
6807,
63,
4777,
288,
370,
63,
7519,
275,
522,
14,
362,
360,
2558,
63,
7519,
297,
19842,
9,
288,
340,
370,
63,
7519,
1137,
3336,
14,
7519,
63,
344,
14,
344,
26,
355,
15932,
63,
4777,
275,
291,
14,
2293,
459,
2558,
14,
7519,
26099,
3357,
63,
4777,
8,
1556,
12,
1747,
12,
3336,
14,
7519,
63,
344,
14,
344,
12,
15932,
63,
4777,
12,
370,
63,
7519,
9,
288,
4027,
275,
1067,
14,
1574,
342,
288,
4027,
459,
602,
418,
275,
1434,
63,
1648,
288,
8033,
275,
291,
14,
2293,
14,
362,
360,
470,
14,
4968,
1959,
3357,
8,
1556,
12,
1747,
12,
289,
5682,
63,
895,
12,
370,
63,
895,
12,
15932,
63,
4777,
12,
6168,
29,
797,
12,
1067,
29,
3799,
9,
288,
522,
459,
585,
2278,
873,
3252,
9533,
63,
4777,
356,
8033,
1552,
267,
372,
522,
339,
347,
485,
2558,
63,
9650,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
901,
63,
354,
12,
1680,
12,
1067,
29,
403,
304,
267,
1094,
63,
1113,
275,
291,
14,
2293,
14,
362,
360,
470,
14,
4968,
358,
267,
522,
275,
1052,
267,
367,
1004,
315,
291,
14,
4570,
8,
1556,
12,
1747,
12,
2762,
12,
1067,
29,
1100,
304,
288,
1094,
275,
1004,
14,
1648,
63,
344,
14,
17385,
63,
344,
14,
4968,
63,
344,
288,
522,
59,
604,
14,
344,
61,
275,
378,
288,
340,
1004,
14,
2558,
63,
344,
26,
355,
3529,
63,
9650,
275,
1004,
14,
4777,
63,
954,
2923,
446,
3666,
604,
14,
9533,
63,
4777,
503,
1004,
14,
2558,
63,
344,
14,
6807,
63,
4777,
9,
627,
1004,
14,
2558,
63,
20560,
63,
5643,
9,
355,
522,
59,
604,
14,
344,
61,
275,
1094,
63,
1113,
14,
2363,
8,
1556,
12,
1747,
12,
1094,
12,
3529,
63,
9650,
9,
267,
372,
522,
339,
485,
3406,
275,
469,
267,
283,
9650,
356,
1504,
14,
1593,
1547,
2558,
63,
9650,
12,
1059,
534,
15182,
297,
7576,
63,
3357,
29,
12392,
14,
362,
63,
6833,
360,
5884,
20276,
659,
1598,
3877,
275,
715,
395,
267,
283,
9533,
63,
4777,
356,
1504,
14,
1609,
360,
15568,
20276,
297,
7576,
63,
3357,
29,
12392,
14,
362,
63,
6833,
360,
5884,
20276,
1333,
272,
789,
421,
199,
533,
13590,
63,
1648,
8,
4795,
14,
4795,
304,
272,
485,
6486,
275,
298,
8515,
14,
1648,
2,
339,
347,
485,
2558,
63,
9650,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
901,
63,
354,
12,
1680,
12,
1067,
29,
403,
304,
267,
754,
275,
1052,
267,
367,
13590,
315,
291,
14,
4570,
8,
1556,
12,
1747,
12,
2762,
12,
1067,
29,
1100,
304,
288,
754,
59,
8515,
14,
344,
61,
275,
378,
14,
16,
288,
367,
1004,
315,
13590,
14,
1648,
63,
604,
26,
355,
340,
1004,
14,
929,
508,
283,
6406,
356,
490,
1980,
355,
754,
59,
8515,
14,
344,
61,
847,
1004,
14
] |
[
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
8664,
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,
5166,
14,
4795,
492,
1504,
12,
9506,
199,
646,
5166,
14,
10788,
14,
6355,
63,
6833,
465,
12392,
199,
199,
533,
13590,
63,
1648,
63,
604,
8,
4795,
14,
4795,
304,
272,
485,
6486,
275,
298,
8515,
14,
1648,
14,
604,
2,
339,
347,
3336,
63,
344,
63,
1461,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
25162,
12,
3336,
12,
13556,
29,
16,
12,
288,
19842,
29,
797,
12,
13556,
63,
20560,
29,
16,
12,
399,
736,
29,
797,
12,
536,
4581,
5854,
63,
344,
29,
797,
12,
288,
6339,
29,
797,
12,
1678,
63,
5530,
29,
549,
12,
1434,
63,
1648,
29,
797,
12,
27369,
29,
797,
12,
18672,
63,
3124,
29,
797,
12,
3305,
29,
797,
12,
1067,
29,
403,
304,
267,
522,
275,
1613,
8,
8515,
63,
1648,
63,
604,
12,
291,
680,
2558,
63,
344,
63,
1461,
8,
1556,
12,
1747,
12,
2762,
12,
25162,
12,
3336,
12,
13556,
29,
5643,
12,
288,
19842,
29,
7519,
12,
13556,
63,
20560,
29,
5643,
63,
20560,
12,
399,
736,
29,
20560,
12,
536,
29,
354,
12,
5854,
63,
344,
29,
3899,
63,
344,
12,
288,
6339,
29,
4159,
12,
1678,
63,
5530,
29,
873,
63,
5530,
12,
1434,
63,
1648,
29,
602,
63,
1648,
12,
27369,
29,
27796,
12,
18672,
63,
3124,
29,
18646,
63,
3124,
12,
3305,
29,
4173,
12,
1067,
29,
1100,
9,
267,
340,
440,
25162,
26,
288,
372,
522,
267,
340,
1067,
365,
488,
26,
288,
1067,
275,
1052,
267,
289,
5682,
63,
895,
275,
291,
14,
2293,
14,
362,
360,
470,
14,
3707,
1959,
4570,
8,
1556,
12,
1747,
12,
1747,
680,
4627,
63,
344,
14,
4968,
63,
344,
14,
344,
267,
370,
63,
895,
275,
291,
14,
2293,
14,
362,
360,
2558,
14,
17385,
1959,
4570,
8,
1556,
12,
1747,
12,
359,
17385,
11057,
16,
1055,
4968,
63,
344,
14,
344,
267,
340,
3336,
26,
288,
3336,
275,
291,
14,
2293,
459,
2558,
14,
2558,
2278,
4570,
8,
1556,
12,
1747,
12,
3336,
12,
1067,
29,
1100,
9,
288,
15932,
63,
4777,
275,
3336,
14,
6807,
63,
4777,
288,
370,
63,
7519,
275,
522,
14,
362,
360,
2558,
63,
7519,
297,
19842,
9,
288,
340,
370,
63,
7519,
1137,
3336,
14,
7519,
63,
344,
14,
344,
26,
355,
15932,
63,
4777,
275,
291,
14,
2293,
459,
2558,
14,
7519,
26099,
3357,
63,
4777,
8,
1556,
12,
1747,
12,
3336,
14,
7519,
63,
344,
14,
344,
12,
15932,
63,
4777,
12,
370,
63,
7519,
9,
288,
4027,
275,
1067,
14,
1574,
342,
288,
4027,
459,
602,
418,
275,
1434,
63,
1648,
288,
8033,
275,
291,
14,
2293,
14,
362,
360,
470,
14,
4968,
1959,
3357,
8,
1556,
12,
1747,
12,
289,
5682,
63,
895,
12,
370,
63,
895,
12,
15932,
63,
4777,
12,
6168,
29,
797,
12,
1067,
29,
3799,
9,
288,
522,
459,
585,
2278,
873,
3252,
9533,
63,
4777,
356,
8033,
1552,
267,
372,
522,
339,
347,
485,
2558,
63,
9650,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
901,
63,
354,
12,
1680,
12,
1067,
29,
403,
304,
267,
1094,
63,
1113,
275,
291,
14,
2293,
14,
362,
360,
470,
14,
4968,
358,
267,
522,
275,
1052,
267,
367,
1004,
315,
291,
14,
4570,
8,
1556,
12,
1747,
12,
2762,
12,
1067,
29,
1100,
304,
288,
1094,
275,
1004,
14,
1648,
63,
344,
14,
17385,
63,
344,
14,
4968,
63,
344,
288,
522,
59,
604,
14,
344,
61,
275,
378,
288,
340,
1004,
14,
2558,
63,
344,
26,
355,
3529,
63,
9650,
275,
1004,
14,
4777,
63,
954,
2923,
446,
3666,
604,
14,
9533,
63,
4777,
503,
1004,
14,
2558,
63,
344,
14,
6807,
63,
4777,
9,
627,
1004,
14,
2558,
63,
20560,
63,
5643,
9,
355,
522,
59,
604,
14,
344,
61,
275,
1094,
63,
1113,
14,
2363,
8,
1556,
12,
1747,
12,
1094,
12,
3529,
63,
9650,
9,
267,
372,
522,
339,
485,
3406,
275,
469,
267,
283,
9650,
356,
1504,
14,
1593,
1547,
2558,
63,
9650,
12,
1059,
534,
15182,
297,
7576,
63,
3357,
29,
12392,
14,
362,
63,
6833,
360,
5884,
20276,
659,
1598,
3877,
275,
715,
395,
267,
283,
9533,
63,
4777,
356,
1504,
14,
1609,
360,
15568,
20276,
297,
7576,
63,
3357,
29,
12392,
14,
362,
63,
6833,
360,
5884,
20276,
1333,
272,
789,
421,
199,
533,
13590,
63,
1648,
8,
4795,
14,
4795,
304,
272,
485,
6486,
275,
298,
8515,
14,
1648,
2,
339,
347,
485,
2558,
63,
9650,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
901,
63,
354,
12,
1680,
12,
1067,
29,
403,
304,
267,
754,
275,
1052,
267,
367,
13590,
315,
291,
14,
4570,
8,
1556,
12,
1747,
12,
2762,
12,
1067,
29,
1100,
304,
288,
754,
59,
8515,
14,
344,
61,
275,
378,
14,
16,
288,
367,
1004,
315,
13590,
14,
1648,
63,
604,
26,
355,
340,
1004,
14,
929,
508,
283,
6406,
356,
490,
1980,
355,
754,
59,
8515,
14,
344,
61,
847,
1004,
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,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', # 0x0a
'Pin ', # 0x0b
'Yu ', # 0x0c
'Xun ', # 0x0d
'Ji ', # 0x0e
'Jiong ', # 0x0f
'Xian ', # 0x10
'Mo ', # 0x11
'Hagi ', # 0x12
'Su ', # 0x13
'Jiong ', # 0x14
'[?] ', # 0x15
'Nie ', # 0x16
'Bo ', # 0x17
'Rang ', # 0x18
'Yi ', # 0x19
'Xian ', # 0x1a
'Yu ', # 0x1b
'Ju ', # 0x1c
'Lian ', # 0x1d
'Lian ', # 0x1e
'Yin ', # 0x1f
'Qiang ', # 0x20
'Ying ', # 0x21
'Long ', # 0x22
'Tong ', # 0x23
'Wei ', # 0x24
'Yue ', # 0x25
'Ling ', # 0x26
'Qu ', # 0x27
'Yao ', # 0x28
'Fan ', # 0x29
'Mi ', # 0x2a
'Lan ', # 0x2b
'Kui ', # 0x2c
'Lan ', # 0x2d
'Ji ', # 0x2e
'Dang ', # 0x2f
'Katsura ', # 0x30
'Lei ', # 0x31
'Lei ', # 0x32
'Hua ', # 0x33
'Feng ', # 0x34
'Zhi ', # 0x35
'Wei ', # 0x36
'Kui ', # 0x37
'Zhan ', # 0x38
'Huai ', # 0x39
'Li ', # 0x3a
'Ji ', # 0x3b
'Mi ', # 0x3c
'Lei ', # 0x3d
'Huai ', # 0x3e
'Luo ', # 0x3f
'Ji ', # 0x40
'Kui ', # 0x41
'Lu ', # 0x42
'Jian ', # 0x43
'San ', # 0x44
'[?] ', # 0x45
'Lei ', # 0x46
'Quan ', # 0x47
'Xiao ', # 0x48
'Yi ', # 0x49
'Luan ', # 0x4a
'Men ', # 0x4b
'Bie ', # 0x4c
'Hu ', # 0x4d
'Hu ', # 0x4e
'Lu ', # 0x4f
'Nue ', # 0x50
'Lu ', # 0x51
'Si ', # 0x52
'Xiao ', # 0x53
'Qian ', # 0x54
'Chu ', # 0x55
'Hu ', # 0x56
'Xu ', # 0x57
'Cuo ', # 0x58
'Fu ', # 0x59
'Xu ', # 0x5a
'Xu ', # 0x5b
'Lu ', # 0x5c
'Hu ', # 0x5d
'Yu ', # 0x5e
'Hao ', # 0x5f
'Jiao ', # 0x60
'Ju ', # 0x61
'Guo ', # 0x62
'Bao ', # 0x63
'Yan ', # 0x64
'Zhan ', # 0x65
'Zhan ', # 0x66
'Kui ', # 0x67
'Ban ', # 0x68
'Xi ', # 0x69
'Shu ', # 0x6a
'Chong ', # 0x6b
'Qiu ', # 0x6c
'Diao ', # 0x6d
'Ji ', # 0x6e
'Qiu ', # 0x6f
'Cheng ', # 0x70
'Shi ', # 0x71
'[?] ', # 0x72
'Di ', # 0x73
'Zhe ', # 0x74
'She ', # 0x75
'Yu ', # 0x76
'Gan ', # 0x77
'Zi ', # 0x78
'Hong ', # 0x79
'Hui ', # 0x7a
'Meng ', # 0x7b
'Ge ', # 0x7c
'Sui ', # 0x7d
'Xia ', # 0x7e
'Chai ', # 0x7f
'Shi ', # 0x80
'Yi ', # 0x81
'Ma ', # 0x82
'Xiang ', # 0x83
'Fang ', # 0x84
'E ', # 0x85
'Pa ', # 0x86
'Chi ', # 0x87
'Qian ', # 0x88
'Wen ', # 0x89
'Wen ', # 0x8a
'Rui ', # 0x8b
'Bang ', # 0x8c
'Bi ', # 0x8d
'Yue ', # 0x8e
'Yue ', # 0x8f
'Jun ', # 0x90
'Qi ', # 0x91
'Ran ', # 0x92
'Yin ', # 0x93
'Qi ', # 0x94
'Tian ', # 0x95
'Yuan ', # 0x96
'Jue ', # 0x97
'Hui ', # 0x98
'Qin ', # 0x99
'Qi ', # 0x9a
'Zhong ', # 0x9b
'Ya ', # 0x9c
'Ci ', # 0x9d
'Mu ', # 0x9e
'Wang ', # 0x9f
'Fen ', # 0xa0
'Fen ', # 0xa1
'Hang ', # 0xa2
'Gong ', # 0xa3
'Zao ', # 0xa4
'Fu ', # 0xa5
'Ran ', # 0xa6
'Jie ', # 0xa7
'Fu ', # 0xa8
'Chi ', # 0xa9
'Dou ', # 0xaa
'Piao ', # 0xab
'Xian ', # 0xac
'Ni ', # 0xad
'Te ', # 0xae
'Qiu ', # 0xaf
'You ', # 0xb0
'Zha ', # 0xb1
'Ping ', # 0xb2
'Chi ', # 0xb3
'You ', # 0xb4
'He ', # 0xb5
'Han ', # 0xb6
'Ju ', # 0xb7
'Li ', # 0xb8
'Fu ', # 0xb9
'Ran ', # 0xba
'Zha ', # 0xbb
'Gou ', # 0xbc
'Pi ', # 0xbd
'Bo ', # 0xbe
'Xian ', # 0xbf
'Zhu ', # 0xc0
'Diao ', # 0xc1
'Bie ', # 0xc2
'Bing ', # 0xc3
'Gu ', # 0xc4
'Ran ', # 0xc5
'Qu ', # 0xc6
'She ', # 0xc7
'Tie ', # 0xc8
'Ling ', # 0xc9
'Gu ', # 0xca
'Dan ', # 0xcb
'Gu ', # 0xcc
'Ying ', # 0xcd
'Li ', # 0xce
'Cheng ', # 0xcf
'Qu ', # 0xd0
'Mou ', # 0xd1
'Ge ', # 0xd2
'Ci ', # 0xd3
'Hui ', # 0xd4
'Hui ', # 0xd5
'Mang ', # 0xd6
'Fu ', # 0xd7
'Yang ', # 0xd8
'Wa ', # 0xd9
'Lie ', # 0xda
'Zhu ', # 0xdb
'Yi ', # 0xdc
'Xian ', # 0xdd
'Kuo ', # 0xde
'Jiao ', # 0xdf
'Li ', # 0xe0
'Yi ', # 0xe1
'Ping ', # 0xe2
'Ji ', # 0xe3
'Ha ', # 0xe4
'She ', # 0xe5
'Yi ', # 0xe6
'Wang ', # 0xe7
'Mo ', # 0xe8
'Qiong ', # 0xe9
'Qie ', # 0xea
'Gui ', # 0xeb
'Gong ', # 0xec
'Zhi ', # 0xed
'Man ', # 0xee
'Ebi ', # 0xef
'Zhi ', # 0xf0
'Jia ', # 0xf1
'Rao ', # 0xf2
'Si ', # 0xf3
'Qi ', # 0xf4
'Xing ', # 0xf5
'Lie ', # 0xf6
'Qiu ', # 0xf7
'Shao ', # 0xf8
'Yong ', # 0xf9
'Jia ', # 0xfa
'Shui ', # 0xfb
'Che ', # 0xfc
'Bai ', # 0xfd
'E ', # 0xfe
'Han ', # 0xff
)
|
gpl-3.0
|
[
576,
275,
334,
199,
7,
52,
13780,
1656,
259,
327,
378,
88,
383,
199,
7,
25728,
1656,
259,
327,
378,
88,
614,
199,
7,
50,
1907,
1656,
259,
327,
378,
88,
996,
199,
7,
50,
1907,
1656,
259,
327,
378,
88,
1644,
199,
7,
19910,
1656,
259,
327,
378,
88,
966,
199,
7,
40,
7420,
1656,
259,
327,
378,
88,
1717,
199,
7,
18176,
1656,
259,
327,
378,
88,
1690,
199,
7,
27032,
1656,
259,
327,
378,
88,
1780,
199,
7,
52,
1907,
1656,
259,
327,
378,
88,
2036,
199,
7,
45,
621,
1656,
259,
327,
378,
88,
1643,
199,
7,
57,
324,
1656,
259,
327,
378,
88,
16,
65,
199,
7,
19909,
1656,
259,
327,
378,
88,
16,
66,
199,
7,
24388,
1656,
259,
327,
378,
88,
16,
67,
199,
7,
56,
324,
1656,
259,
327,
378,
88,
16,
68,
199,
7,
16911,
1656,
259,
327,
378,
88,
16,
69,
199,
7,
16911,
951,
1656,
259,
327,
378,
88,
16,
70,
199,
7,
56,
5653,
1656,
259,
327,
378,
88,
709,
199,
7,
3716,
1656,
259,
327,
378,
88,
845,
199,
7,
40,
643,
73,
1656,
259,
327,
378,
88,
713,
199,
7,
27032,
1656,
259,
327,
378,
88,
969,
199,
7,
16911,
951,
1656,
259,
327,
378,
88,
1079,
199,
17892,
1656,
259,
327,
378,
88,
1046,
199,
7,
46,
1873,
1656,
259,
327,
378,
88,
975,
199,
7,
2208,
1656,
259,
327,
378,
88,
1196,
199,
7,
50,
621,
1656,
259,
327,
378,
88,
1085,
199,
7,
21001,
1656,
259,
327,
378,
88,
1167,
199,
7,
56,
5653,
1656,
259,
327,
378,
88,
17,
65,
199,
7,
24388,
1656,
259,
327,
378,
88,
17,
66,
199,
7,
24783,
1656,
259,
327,
378,
88,
17,
67,
199,
7,
44,
5653,
1656,
259,
327,
378,
88,
17,
68,
199,
7,
44,
5653,
1656,
259,
327,
378,
88,
17,
69,
199,
7,
57,
262,
1656,
259,
327,
378,
88,
17,
70,
199,
7,
19910,
621,
1656,
259,
327,
378,
88,
1165,
199,
7,
57,
316,
1656,
259,
327,
378,
88,
2025,
199,
7,
9551,
1656,
259,
327,
378,
88,
1081,
199,
7,
52,
951,
1656,
259,
327,
378,
88,
1789,
199,
7,
6004,
73,
1656,
259,
327,
378,
88,
1194,
199,
7,
57,
310,
1656,
259,
327,
378,
88,
821,
199,
7,
44,
316,
1656,
259,
327,
378,
88,
1479,
199,
7,
2371,
1656,
259,
327,
378,
88,
1465,
199,
7,
57,
8035,
1656,
259,
327,
378,
88,
1651,
199,
7,
29745,
1656,
259,
327,
378,
88,
1398,
199,
7,
14738,
1656,
259,
327,
378,
88,
18,
65,
199,
7,
44,
290,
1656,
259,
327,
378,
88,
18,
66,
199,
7,
43,
1907,
1656,
259,
327,
378,
88,
18,
67,
199,
7,
44,
290,
1656,
259,
327,
378,
88,
18,
68,
199,
7,
16911,
1656,
259,
327,
378,
88,
18,
69,
199,
7,
36,
621,
1656,
259,
327,
378,
88,
18,
70,
199,
7,
43,
1956,
12417,
1656,
259,
327,
378,
88,
1216,
199,
7,
2553,
73,
1656,
259,
327,
378,
88,
2192,
199,
7,
2553,
73,
1656,
259,
327,
378,
88,
708,
199,
7,
40,
1458,
1656,
259,
327,
378,
88,
1153,
199,
7,
38,
7420,
1656,
259,
327,
378,
88,
1082,
199,
7,
58,
5812,
1656,
259,
327,
378,
88,
1276,
199,
7,
6004,
73,
1656,
259,
327,
378,
88,
1344,
199,
7,
43,
1907,
1656,
259,
327,
378,
88,
1401,
199,
7,
12674,
290,
1656,
259,
327,
378,
88,
1703,
199,
7,
40,
1458,
73,
1656,
259,
327,
378,
88,
1355,
199,
7,
13009,
1656,
259,
327,
378,
88,
19,
65,
199,
7,
16911,
1656,
259,
327,
378,
88,
19,
66,
199,
7,
14738,
1656,
259,
327,
378,
88,
19,
67,
199,
7,
2553,
73,
1656,
259,
327,
378,
88,
19,
68,
199,
7,
40,
1458,
73,
1656,
259,
327,
378,
88,
19,
69,
199,
7,
44,
13780,
1656,
259,
327,
378,
88,
19,
70,
199,
7,
16911,
1656,
259,
327,
378,
88,
2167,
199,
7,
43,
1907,
1656,
259,
327,
378,
88,
2953,
199,
7,
18176,
1656,
259,
327,
378,
88,
2260,
199,
7,
42,
5653,
1656,
259,
327,
378,
88,
2824,
199,
7,
23906,
1656,
259,
327,
378,
88,
1602,
199,
17892,
1656,
259,
327,
378,
88,
2322,
199,
7,
2553,
73,
1656,
259,
327,
378,
88,
2466,
199,
7,
2371,
290,
1656,
259,
327,
378,
88,
2417,
199,
7,
56,
18939,
1656,
259,
327,
378,
88,
2006,
199,
7,
21001,
1656,
259,
327,
378,
88,
1887,
199,
7,
44,
7856,
1656,
259,
327,
378,
88,
20,
65,
199,
7,
29230,
1656,
259,
327,
378,
88,
20,
66,
199,
7,
34,
1873,
1656,
259,
327,
378,
88,
20,
67,
199,
7,
25542,
1656,
259,
327,
378,
88,
20,
68,
199,
7,
25542,
1656,
259,
327,
378,
88,
20,
69,
199,
7,
18176,
1656,
259,
327,
378,
88,
20,
70,
199,
7,
46,
310,
1656,
259,
327,
378,
88,
1400,
199,
7,
18176,
1656,
259,
327,
378,
88,
2869,
199,
7,
18934,
1656,
259,
327,
378,
88,
2528,
199,
7,
56,
18939,
1656,
259,
327,
378,
88,
2481,
199,
7,
49,
5653,
1656,
259,
327,
378,
88,
1477,
199,
7,
1049,
85,
1656,
259,
327,
378,
88,
1229,
199,
7,
25542,
1656,
259,
327,
378,
88,
1367,
199,
7,
56,
85,
1656,
259,
327,
378,
88,
1641,
199,
7,
35,
13780,
1656,
259,
327,
378,
88,
2010,
199,
7,
19590,
1656,
259,
327,
378,
88,
1427,
199,
7,
56,
85,
1656,
259,
327,
378,
88,
21,
65,
199,
7,
56,
85,
1656,
259,
327,
378,
88,
21,
66,
199,
7,
18176,
1656,
259,
327,
378,
88,
21,
67,
199,
7,
25542,
1656,
259,
327,
378,
88,
21,
68,
199,
7,
24388,
1656,
259,
327,
378,
88,
21,
69,
199,
7,
40,
8035,
1656,
259,
327,
378,
88,
21,
70,
199,
7,
42,
18939,
1656,
259,
327,
378,
88,
2259,
199,
7,
24783,
1656,
259,
327,
378,
88,
2976,
199,
7,
11548,
79,
1656,
259,
327,
378,
88,
2789,
199,
7,
34,
8035,
1656,
259,
327,
378,
88,
2766,
199,
7,
26797,
1656,
259,
327,
378,
88,
772,
199,
7,
12674,
290,
1656,
259,
327,
378,
88,
2182,
199,
7,
12674
] |
[
275,
334,
199,
7,
52,
13780,
1656,
259,
327,
378,
88,
383,
199,
7,
25728,
1656,
259,
327,
378,
88,
614,
199,
7,
50,
1907,
1656,
259,
327,
378,
88,
996,
199,
7,
50,
1907,
1656,
259,
327,
378,
88,
1644,
199,
7,
19910,
1656,
259,
327,
378,
88,
966,
199,
7,
40,
7420,
1656,
259,
327,
378,
88,
1717,
199,
7,
18176,
1656,
259,
327,
378,
88,
1690,
199,
7,
27032,
1656,
259,
327,
378,
88,
1780,
199,
7,
52,
1907,
1656,
259,
327,
378,
88,
2036,
199,
7,
45,
621,
1656,
259,
327,
378,
88,
1643,
199,
7,
57,
324,
1656,
259,
327,
378,
88,
16,
65,
199,
7,
19909,
1656,
259,
327,
378,
88,
16,
66,
199,
7,
24388,
1656,
259,
327,
378,
88,
16,
67,
199,
7,
56,
324,
1656,
259,
327,
378,
88,
16,
68,
199,
7,
16911,
1656,
259,
327,
378,
88,
16,
69,
199,
7,
16911,
951,
1656,
259,
327,
378,
88,
16,
70,
199,
7,
56,
5653,
1656,
259,
327,
378,
88,
709,
199,
7,
3716,
1656,
259,
327,
378,
88,
845,
199,
7,
40,
643,
73,
1656,
259,
327,
378,
88,
713,
199,
7,
27032,
1656,
259,
327,
378,
88,
969,
199,
7,
16911,
951,
1656,
259,
327,
378,
88,
1079,
199,
17892,
1656,
259,
327,
378,
88,
1046,
199,
7,
46,
1873,
1656,
259,
327,
378,
88,
975,
199,
7,
2208,
1656,
259,
327,
378,
88,
1196,
199,
7,
50,
621,
1656,
259,
327,
378,
88,
1085,
199,
7,
21001,
1656,
259,
327,
378,
88,
1167,
199,
7,
56,
5653,
1656,
259,
327,
378,
88,
17,
65,
199,
7,
24388,
1656,
259,
327,
378,
88,
17,
66,
199,
7,
24783,
1656,
259,
327,
378,
88,
17,
67,
199,
7,
44,
5653,
1656,
259,
327,
378,
88,
17,
68,
199,
7,
44,
5653,
1656,
259,
327,
378,
88,
17,
69,
199,
7,
57,
262,
1656,
259,
327,
378,
88,
17,
70,
199,
7,
19910,
621,
1656,
259,
327,
378,
88,
1165,
199,
7,
57,
316,
1656,
259,
327,
378,
88,
2025,
199,
7,
9551,
1656,
259,
327,
378,
88,
1081,
199,
7,
52,
951,
1656,
259,
327,
378,
88,
1789,
199,
7,
6004,
73,
1656,
259,
327,
378,
88,
1194,
199,
7,
57,
310,
1656,
259,
327,
378,
88,
821,
199,
7,
44,
316,
1656,
259,
327,
378,
88,
1479,
199,
7,
2371,
1656,
259,
327,
378,
88,
1465,
199,
7,
57,
8035,
1656,
259,
327,
378,
88,
1651,
199,
7,
29745,
1656,
259,
327,
378,
88,
1398,
199,
7,
14738,
1656,
259,
327,
378,
88,
18,
65,
199,
7,
44,
290,
1656,
259,
327,
378,
88,
18,
66,
199,
7,
43,
1907,
1656,
259,
327,
378,
88,
18,
67,
199,
7,
44,
290,
1656,
259,
327,
378,
88,
18,
68,
199,
7,
16911,
1656,
259,
327,
378,
88,
18,
69,
199,
7,
36,
621,
1656,
259,
327,
378,
88,
18,
70,
199,
7,
43,
1956,
12417,
1656,
259,
327,
378,
88,
1216,
199,
7,
2553,
73,
1656,
259,
327,
378,
88,
2192,
199,
7,
2553,
73,
1656,
259,
327,
378,
88,
708,
199,
7,
40,
1458,
1656,
259,
327,
378,
88,
1153,
199,
7,
38,
7420,
1656,
259,
327,
378,
88,
1082,
199,
7,
58,
5812,
1656,
259,
327,
378,
88,
1276,
199,
7,
6004,
73,
1656,
259,
327,
378,
88,
1344,
199,
7,
43,
1907,
1656,
259,
327,
378,
88,
1401,
199,
7,
12674,
290,
1656,
259,
327,
378,
88,
1703,
199,
7,
40,
1458,
73,
1656,
259,
327,
378,
88,
1355,
199,
7,
13009,
1656,
259,
327,
378,
88,
19,
65,
199,
7,
16911,
1656,
259,
327,
378,
88,
19,
66,
199,
7,
14738,
1656,
259,
327,
378,
88,
19,
67,
199,
7,
2553,
73,
1656,
259,
327,
378,
88,
19,
68,
199,
7,
40,
1458,
73,
1656,
259,
327,
378,
88,
19,
69,
199,
7,
44,
13780,
1656,
259,
327,
378,
88,
19,
70,
199,
7,
16911,
1656,
259,
327,
378,
88,
2167,
199,
7,
43,
1907,
1656,
259,
327,
378,
88,
2953,
199,
7,
18176,
1656,
259,
327,
378,
88,
2260,
199,
7,
42,
5653,
1656,
259,
327,
378,
88,
2824,
199,
7,
23906,
1656,
259,
327,
378,
88,
1602,
199,
17892,
1656,
259,
327,
378,
88,
2322,
199,
7,
2553,
73,
1656,
259,
327,
378,
88,
2466,
199,
7,
2371,
290,
1656,
259,
327,
378,
88,
2417,
199,
7,
56,
18939,
1656,
259,
327,
378,
88,
2006,
199,
7,
21001,
1656,
259,
327,
378,
88,
1887,
199,
7,
44,
7856,
1656,
259,
327,
378,
88,
20,
65,
199,
7,
29230,
1656,
259,
327,
378,
88,
20,
66,
199,
7,
34,
1873,
1656,
259,
327,
378,
88,
20,
67,
199,
7,
25542,
1656,
259,
327,
378,
88,
20,
68,
199,
7,
25542,
1656,
259,
327,
378,
88,
20,
69,
199,
7,
18176,
1656,
259,
327,
378,
88,
20,
70,
199,
7,
46,
310,
1656,
259,
327,
378,
88,
1400,
199,
7,
18176,
1656,
259,
327,
378,
88,
2869,
199,
7,
18934,
1656,
259,
327,
378,
88,
2528,
199,
7,
56,
18939,
1656,
259,
327,
378,
88,
2481,
199,
7,
49,
5653,
1656,
259,
327,
378,
88,
1477,
199,
7,
1049,
85,
1656,
259,
327,
378,
88,
1229,
199,
7,
25542,
1656,
259,
327,
378,
88,
1367,
199,
7,
56,
85,
1656,
259,
327,
378,
88,
1641,
199,
7,
35,
13780,
1656,
259,
327,
378,
88,
2010,
199,
7,
19590,
1656,
259,
327,
378,
88,
1427,
199,
7,
56,
85,
1656,
259,
327,
378,
88,
21,
65,
199,
7,
56,
85,
1656,
259,
327,
378,
88,
21,
66,
199,
7,
18176,
1656,
259,
327,
378,
88,
21,
67,
199,
7,
25542,
1656,
259,
327,
378,
88,
21,
68,
199,
7,
24388,
1656,
259,
327,
378,
88,
21,
69,
199,
7,
40,
8035,
1656,
259,
327,
378,
88,
21,
70,
199,
7,
42,
18939,
1656,
259,
327,
378,
88,
2259,
199,
7,
24783,
1656,
259,
327,
378,
88,
2976,
199,
7,
11548,
79,
1656,
259,
327,
378,
88,
2789,
199,
7,
34,
8035,
1656,
259,
327,
378,
88,
2766,
199,
7,
26797,
1656,
259,
327,
378,
88,
772,
199,
7,
12674,
290,
1656,
259,
327,
378,
88,
2182,
199,
7,
12674,
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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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
zhounanshu/Flask-AppBuilder
|
examples/masterdetail/testdata.py
|
3
|
1443
|
from app import db
from app.models import ContactGroup, Gender, Contact
import random
from datetime import datetime
def get_random_name(names_list, size=1):
name_lst = [names_list[random.randrange(0, len(names_list))].capitalize() for i in range(0, size)]
return " ".join(name_lst)
try:
db.session.add(ContactGroup(name='Friends'))
db.session.add(ContactGroup(name='Family'))
db.session.add(ContactGroup(name='Work'))
db.session.commit()
except:
db.session.rollback()
try:
db.session.add(Gender(name='Male'))
db.session.add(Gender(name='Female'))
db.session.commit()
except:
db.session.rollback()
f = open('NAMES.DIC', "rb")
names_list = [x.strip() for x in f.readlines()]
f.close()
for i in range(1, 50):
c = Contact()
c.name = get_random_name(names_list, random.randrange(2, 6))
c.address = 'Street ' + names_list[random.randrange(0, len(names_list))]
c.personal_phone = random.randrange(1111111, 9999999)
c.personal_celphone = random.randrange(1111111, 9999999)
c.contact_group_id = random.randrange(1, 4)
c.gender_id = random.randrange(1, 3)
year = random.choice(range(1900, 2012))
month = random.choice(range(1, 12))
day = random.choice(range(1, 28))
c.birthday = datetime(year, month, day)
db.session.add(c)
try:
db.session.commit()
print("inserted {0}".format(c))
except:
db.session.rollback()
|
bsd-3-clause
|
[
504,
1145,
492,
1592,
199,
504,
1145,
14,
992,
492,
18684,
2448,
12,
598,
13747,
12,
18684,
199,
646,
2196,
199,
504,
2197,
492,
2197,
421,
199,
318,
664,
63,
2355,
63,
354,
8,
1247,
63,
513,
12,
1568,
29,
17,
304,
272,
536,
63,
6916,
275,
359,
1247,
63,
513,
59,
2355,
14,
20539,
8,
16,
12,
822,
8,
1247,
63,
513,
430,
1055,
18351,
342,
367,
284,
315,
1425,
8,
16,
12,
1568,
1874,
272,
372,
298,
3680,
904,
8,
354,
63,
6916,
9,
421,
199,
893,
26,
272,
1592,
14,
1730,
14,
525,
8,
14499,
2448,
8,
354,
534,
38,
13010,
1333,
272,
1592,
14,
1730,
14,
525,
8,
14499,
2448,
8,
354,
534,
16345,
1333,
272,
1592,
14,
1730,
14,
525,
8,
14499,
2448,
8,
354,
534,
6517,
1333,
272,
1592,
14,
1730,
14,
3543,
342,
199,
2590,
26,
272,
1592,
14,
1730,
14,
10437,
342,
199,
199,
893,
26,
272,
1592,
14,
1730,
14,
525,
8,
8168,
424,
8,
354,
534,
45,
1895,
1333,
272,
1592,
14,
1730,
14,
525,
8,
8168,
424,
8,
354,
534,
3456,
17667,
1333,
272,
1592,
14,
1730,
14,
3543,
342,
199,
2590,
26,
272,
1592,
14,
1730,
14,
10437,
342,
199,
199,
70,
275,
1551,
360,
14546,
14,
36,
948,
297,
298,
4848,
531,
199,
1247,
63,
513,
275,
359,
88,
14,
1913,
342,
367,
671,
315,
289,
14,
9684,
5106,
199,
199,
70,
14,
1600,
342,
199,
199,
509,
284,
315,
1425,
8,
17,
12,
5238,
304,
272,
286,
275,
18684,
342,
272,
286,
14,
354,
275,
664,
63,
2355,
63,
354,
8,
1247,
63,
513,
12,
2196,
14,
20539,
8,
18,
12,
1227,
430,
272,
286,
14,
1562,
275,
283,
933,
7936,
283,
435,
1561,
63,
513,
59,
2355,
14,
20539,
8,
16,
12,
822,
8,
1247,
63,
513,
10524,
272,
286,
14,
28686,
63,
9339,
275,
2196,
14,
20539,
8,
6984,
6673,
12,
221,
5008,
5637,
9,
272,
286,
14,
28686,
63,
6067,
9339,
275,
2196,
14,
20539,
8,
6984,
6673,
12,
221,
5008,
5637,
9,
272,
286,
14,
7811,
63,
923,
63,
344,
275,
2196,
14,
20539,
8,
17,
12,
841,
9,
272,
286,
14,
15791,
63,
344,
275,
2196,
14,
20539,
8,
17,
12,
650,
9,
272,
5361,
275,
2196,
14,
5095,
8,
1842,
8,
26631,
12,
6029,
430,
272,
5794,
275,
2196,
14,
5095,
8,
1842,
8,
17,
12,
3144,
430,
272,
5382,
275,
2196,
14,
5095,
8,
1842,
8,
17,
12,
7294,
430,
272,
286,
14,
15881,
275,
2197,
8,
3403,
12,
5794,
12,
5382,
9,
272,
1592,
14,
1730,
14,
525,
8,
67,
9,
272,
862,
26,
267,
1592,
14,
1730,
14,
3543,
342,
267,
870,
480,
28565,
469,
16,
5469,
908,
8,
67,
430,
272,
871,
26,
267,
1592,
14,
1730,
14,
10437,
342,
1362,
16872,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1145,
492,
1592,
199,
504,
1145,
14,
992,
492,
18684,
2448,
12,
598,
13747,
12,
18684,
199,
646,
2196,
199,
504,
2197,
492,
2197,
421,
199,
318,
664,
63,
2355,
63,
354,
8,
1247,
63,
513,
12,
1568,
29,
17,
304,
272,
536,
63,
6916,
275,
359,
1247,
63,
513,
59,
2355,
14,
20539,
8,
16,
12,
822,
8,
1247,
63,
513,
430,
1055,
18351,
342,
367,
284,
315,
1425,
8,
16,
12,
1568,
1874,
272,
372,
298,
3680,
904,
8,
354,
63,
6916,
9,
421,
199,
893,
26,
272,
1592,
14,
1730,
14,
525,
8,
14499,
2448,
8,
354,
534,
38,
13010,
1333,
272,
1592,
14,
1730,
14,
525,
8,
14499,
2448,
8,
354,
534,
16345,
1333,
272,
1592,
14,
1730,
14,
525,
8,
14499,
2448,
8,
354,
534,
6517,
1333,
272,
1592,
14,
1730,
14,
3543,
342,
199,
2590,
26,
272,
1592,
14,
1730,
14,
10437,
342,
199,
199,
893,
26,
272,
1592,
14,
1730,
14,
525,
8,
8168,
424,
8,
354,
534,
45,
1895,
1333,
272,
1592,
14,
1730,
14,
525,
8,
8168,
424,
8,
354,
534,
3456,
17667,
1333,
272,
1592,
14,
1730,
14,
3543,
342,
199,
2590,
26,
272,
1592,
14,
1730,
14,
10437,
342,
199,
199,
70,
275,
1551,
360,
14546,
14,
36,
948,
297,
298,
4848,
531,
199,
1247,
63,
513,
275,
359,
88,
14,
1913,
342,
367,
671,
315,
289,
14,
9684,
5106,
199,
199,
70,
14,
1600,
342,
199,
199,
509,
284,
315,
1425,
8,
17,
12,
5238,
304,
272,
286,
275,
18684,
342,
272,
286,
14,
354,
275,
664,
63,
2355,
63,
354,
8,
1247,
63,
513,
12,
2196,
14,
20539,
8,
18,
12,
1227,
430,
272,
286,
14,
1562,
275,
283,
933,
7936,
283,
435,
1561,
63,
513,
59,
2355,
14,
20539,
8,
16,
12,
822,
8,
1247,
63,
513,
10524,
272,
286,
14,
28686,
63,
9339,
275,
2196,
14,
20539,
8,
6984,
6673,
12,
221,
5008,
5637,
9,
272,
286,
14,
28686,
63,
6067,
9339,
275,
2196,
14,
20539,
8,
6984,
6673,
12,
221,
5008,
5637,
9,
272,
286,
14,
7811,
63,
923,
63,
344,
275,
2196,
14,
20539,
8,
17,
12,
841,
9,
272,
286,
14,
15791,
63,
344,
275,
2196,
14,
20539,
8,
17,
12,
650,
9,
272,
5361,
275,
2196,
14,
5095,
8,
1842,
8,
26631,
12,
6029,
430,
272,
5794,
275,
2196,
14,
5095,
8,
1842,
8,
17,
12,
3144,
430,
272,
5382,
275,
2196,
14,
5095,
8,
1842,
8,
17,
12,
7294,
430,
272,
286,
14,
15881,
275,
2197,
8,
3403,
12,
5794,
12,
5382,
9,
272,
1592,
14,
1730,
14,
525,
8,
67,
9,
272,
862,
26,
267,
1592,
14,
1730,
14,
3543,
342,
267,
870,
480,
28565,
469,
16,
5469,
908,
8,
67,
430,
272,
871,
26,
267,
1592,
14,
1730,
14,
10437,
342,
1362,
16872,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
yjmade/odoo
|
openerp/addons/test_workflow/models.py
|
337
|
2268
|
# -*- coding: utf-8 -*-
import openerp.osv.orm
class m(openerp.osv.orm.Model):
""" A model for which we will define a workflow (see data.xml). """
_name = 'test.workflow.model'
def print_(self, cr, uid, ids, s, context=None):
print ' Running activity `%s` for record %s' % (s, ids)
return True
def print_a(self, cr, uid, ids, context=None):
return self.print_(cr, uid, ids, 'a', context)
def print_b(self, cr, uid, ids, context=None):
return self.print_(cr, uid, ids, 'b', context)
def print_c(self, cr, uid, ids, context=None):
return self.print_(cr, uid, ids, 'c', context)
def condition(self, cr, uid, ids, context=None):
m = self.pool['test.workflow.trigger']
for r in m.browse(cr, uid, [1], context=context):
if not r.value:
return False
return True
def trigger(self, cr, uid, context=None):
return openerp.workflow.trg_trigger(uid, 'test.workflow.trigger', 1, cr)
class n(openerp.osv.orm.Model):
""" A model used for the trigger feature. """
_name = 'test.workflow.trigger'
_columns = { 'value': openerp.osv.fields.boolean('Value') }
_defaults = { 'value': False }
class a(openerp.osv.orm.Model):
_name = 'test.workflow.model.a'
_columns = { 'value': openerp.osv.fields.integer('Value') }
_defaults = { 'value': 0 }
class b(openerp.osv.orm.Model):
_name = 'test.workflow.model.b'
_inherit = 'test.workflow.model.a'
class c(openerp.osv.orm.Model):
_name = 'test.workflow.model.c'
_inherit = 'test.workflow.model.a'
class d(openerp.osv.orm.Model):
_name = 'test.workflow.model.d'
_inherit = 'test.workflow.model.a'
class e(openerp.osv.orm.Model):
_name = 'test.workflow.model.e'
_inherit = 'test.workflow.model.a'
for name in 'bcdefghijkl':
#
# Do not use type() to create the class here, but use the class construct.
# This is because the __module__ of the new class would be the one of the
# metaclass that provides method __new__!
#
class NewModel(openerp.osv.orm.Model):
_name = 'test.workflow.model.%s' % name
_inherit = 'test.workflow.model.a'
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
646,
5166,
14,
4795,
14,
1025,
199,
199,
533,
333,
8,
11267,
14,
4795,
14,
1025,
14,
1685,
304,
272,
408,
437,
1402,
367,
1314,
781,
911,
5627,
282,
10431,
334,
3239,
666,
14,
1652,
680,
408,
272,
485,
354,
275,
283,
396,
14,
8856,
14,
1238,
7,
339,
347,
870,
2531,
277,
12,
2467,
12,
1747,
12,
2762,
12,
308,
12,
1067,
29,
403,
304,
267,
870,
283,
221,
26848,
10679,
18633,
83,
64,
367,
2777,
450,
83,
7,
450,
334,
83,
12,
2762,
9,
267,
372,
715,
339,
347,
870,
63,
65,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
29,
403,
304,
267,
372,
291,
14,
1361,
2531,
1556,
12,
1747,
12,
2762,
12,
283,
65,
297,
1067,
9,
339,
347,
870,
63,
66,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
29,
403,
304,
267,
372,
291,
14,
1361,
2531,
1556,
12,
1747,
12,
2762,
12,
283,
66,
297,
1067,
9,
339,
347,
870,
63,
67,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
29,
403,
304,
267,
372,
291,
14,
1361,
2531,
1556,
12,
1747,
12,
2762,
12,
283,
67,
297,
1067,
9,
339,
347,
5558,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
29,
403,
304,
267,
333,
275,
291,
14,
2293,
459,
396,
14,
8856,
14,
7631,
418,
267,
367,
519,
315,
333,
14,
4570,
8,
1556,
12,
1747,
12,
359,
17,
467,
1067,
29,
1100,
304,
288,
340,
440,
519,
14,
585,
26,
355,
372,
756,
267,
372,
715,
339,
347,
6804,
8,
277,
12,
2467,
12,
1747,
12,
1067,
29,
403,
304,
267,
372,
5166,
14,
8856,
14,
31612,
63,
7631,
8,
1535,
12,
283,
396,
14,
8856,
14,
7631,
297,
413,
12,
2467,
9,
199,
199,
533,
302,
8,
11267,
14,
4795,
14,
1025,
14,
1685,
304,
272,
408,
437,
1402,
1202,
367,
314,
6804,
3878,
14,
408,
272,
485,
354,
275,
283,
396,
14,
8856,
14,
7631,
7,
272,
485,
3406,
275,
469,
283,
585,
356,
5166,
14,
4795,
14,
955,
14,
4871,
360,
1110,
358,
789,
272,
485,
4322,
275,
469,
283,
585,
356,
756,
789,
199,
199,
533,
282,
8,
11267,
14,
4795,
14,
1025,
14,
1685,
304,
272,
485,
354,
275,
283,
396,
14,
8856,
14,
1238,
14,
65,
7,
272,
485,
3406,
275,
469,
283,
585,
356,
5166,
14,
4795,
14,
955,
14,
4115,
360,
1110,
358,
789,
272,
485,
4322,
275,
469,
283,
585,
356,
378,
789,
199,
199,
533,
330,
8,
11267,
14,
4795,
14,
1025,
14,
1685,
304,
272,
485,
354,
275,
283,
396,
14,
8856,
14,
1238,
14,
66,
7,
272,
485,
6486,
275,
283,
396,
14,
8856,
14,
1238,
14,
65,
7,
199,
199,
533,
286,
8,
11267,
14,
4795,
14,
1025,
14,
1685,
304,
272,
485,
354,
275,
283,
396,
14,
8856,
14,
1238,
14,
67,
7,
272,
485,
6486,
275,
283,
396,
14,
8856,
14,
1238,
14,
65,
7,
199,
199,
533,
366,
8,
11267,
14,
4795,
14,
1025,
14,
1685,
304,
272,
485,
354,
275,
283,
396,
14,
8856,
14,
1238,
14,
68,
7,
272,
485,
6486,
275,
283,
396,
14,
8856,
14,
1238,
14,
65,
7,
199,
199,
533,
325,
8,
11267,
14,
4795,
14,
1025,
14,
1685,
304,
272,
485,
354,
275,
283,
396,
14,
8856,
14,
1238,
14,
69,
7,
272,
485,
6486,
275,
283,
396,
14,
8856,
14,
1238,
14,
65,
7,
199,
199,
509,
536,
315,
283,
3776,
318,
3561,
7879,
9503,
356,
272,
327,
272,
327,
4226,
440,
675,
730,
342,
370,
1218,
314,
1021,
2348,
12,
1325,
675,
314,
1021,
6982,
14,
272,
327,
961,
365,
2952,
314,
636,
578,
363,
402,
314,
892,
1021,
3955,
506,
314,
1373,
402,
314,
272,
327,
17074,
626,
6571,
1083,
636,
1222,
363,
1,
272,
327,
272,
1021,
7053,
1685,
8,
11267,
14,
4795,
14,
1025,
14,
1685,
304,
267,
485,
354,
275,
283,
396,
14,
8856,
14,
1238,
4111,
83,
7,
450,
536,
267,
485,
6486,
275,
283,
396,
14,
8856,
14,
1238,
14,
65,
7,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
646,
5166,
14,
4795,
14,
1025,
199,
199,
533,
333,
8,
11267,
14,
4795,
14,
1025,
14,
1685,
304,
272,
408,
437,
1402,
367,
1314,
781,
911,
5627,
282,
10431,
334,
3239,
666,
14,
1652,
680,
408,
272,
485,
354,
275,
283,
396,
14,
8856,
14,
1238,
7,
339,
347,
870,
2531,
277,
12,
2467,
12,
1747,
12,
2762,
12,
308,
12,
1067,
29,
403,
304,
267,
870,
283,
221,
26848,
10679,
18633,
83,
64,
367,
2777,
450,
83,
7,
450,
334,
83,
12,
2762,
9,
267,
372,
715,
339,
347,
870,
63,
65,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
29,
403,
304,
267,
372,
291,
14,
1361,
2531,
1556,
12,
1747,
12,
2762,
12,
283,
65,
297,
1067,
9,
339,
347,
870,
63,
66,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
29,
403,
304,
267,
372,
291,
14,
1361,
2531,
1556,
12,
1747,
12,
2762,
12,
283,
66,
297,
1067,
9,
339,
347,
870,
63,
67,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
29,
403,
304,
267,
372,
291,
14,
1361,
2531,
1556,
12,
1747,
12,
2762,
12,
283,
67,
297,
1067,
9,
339,
347,
5558,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
29,
403,
304,
267,
333,
275,
291,
14,
2293,
459,
396,
14,
8856,
14,
7631,
418,
267,
367,
519,
315,
333,
14,
4570,
8,
1556,
12,
1747,
12,
359,
17,
467,
1067,
29,
1100,
304,
288,
340,
440,
519,
14,
585,
26,
355,
372,
756,
267,
372,
715,
339,
347,
6804,
8,
277,
12,
2467,
12,
1747,
12,
1067,
29,
403,
304,
267,
372,
5166,
14,
8856,
14,
31612,
63,
7631,
8,
1535,
12,
283,
396,
14,
8856,
14,
7631,
297,
413,
12,
2467,
9,
199,
199,
533,
302,
8,
11267,
14,
4795,
14,
1025,
14,
1685,
304,
272,
408,
437,
1402,
1202,
367,
314,
6804,
3878,
14,
408,
272,
485,
354,
275,
283,
396,
14,
8856,
14,
7631,
7,
272,
485,
3406,
275,
469,
283,
585,
356,
5166,
14,
4795,
14,
955,
14,
4871,
360,
1110,
358,
789,
272,
485,
4322,
275,
469,
283,
585,
356,
756,
789,
199,
199,
533,
282,
8,
11267,
14,
4795,
14,
1025,
14,
1685,
304,
272,
485,
354,
275,
283,
396,
14,
8856,
14,
1238,
14,
65,
7,
272,
485,
3406,
275,
469,
283,
585,
356,
5166,
14,
4795,
14,
955,
14,
4115,
360,
1110,
358,
789,
272,
485,
4322,
275,
469,
283,
585,
356,
378,
789,
199,
199,
533,
330,
8,
11267,
14,
4795,
14,
1025,
14,
1685,
304,
272,
485,
354,
275,
283,
396,
14,
8856,
14,
1238,
14,
66,
7,
272,
485,
6486,
275,
283,
396,
14,
8856,
14,
1238,
14,
65,
7,
199,
199,
533,
286,
8,
11267,
14,
4795,
14,
1025,
14,
1685,
304,
272,
485,
354,
275,
283,
396,
14,
8856,
14,
1238,
14,
67,
7,
272,
485,
6486,
275,
283,
396,
14,
8856,
14,
1238,
14,
65,
7,
199,
199,
533,
366,
8,
11267,
14,
4795,
14,
1025,
14,
1685,
304,
272,
485,
354,
275,
283,
396,
14,
8856,
14,
1238,
14,
68,
7,
272,
485,
6486,
275,
283,
396,
14,
8856,
14,
1238,
14,
65,
7,
199,
199,
533,
325,
8,
11267,
14,
4795,
14,
1025,
14,
1685,
304,
272,
485,
354,
275,
283,
396,
14,
8856,
14,
1238,
14,
69,
7,
272,
485,
6486,
275,
283,
396,
14,
8856,
14,
1238,
14,
65,
7,
199,
199,
509,
536,
315,
283,
3776,
318,
3561,
7879,
9503,
356,
272,
327,
272,
327,
4226,
440,
675,
730,
342,
370,
1218,
314,
1021,
2348,
12,
1325,
675,
314,
1021,
6982,
14,
272,
327,
961,
365,
2952,
314,
636,
578,
363,
402,
314,
892,
1021,
3955,
506,
314,
1373,
402,
314,
272,
327,
17074,
626,
6571,
1083,
636,
1222,
363,
1,
272,
327,
272,
1021,
7053,
1685,
8,
11267,
14,
4795,
14,
1025,
14,
1685,
304,
267,
485,
354,
275,
283,
396,
14,
8856,
14,
1238,
4111,
83,
7,
450,
536,
267,
485,
6486,
275,
283,
396,
14,
8856,
14,
1238,
14,
65,
7,
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,
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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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
rclmenezes/sqlalchemy
|
examples/dynamic_dict/dynamic_dict.py
|
1
|
2521
|
class ProxyDict(object):
def __init__(self, parent, collection_name, childclass, keyname):
self.parent = parent
self.collection_name = collection_name
self.childclass = childclass
self.keyname = keyname
@property
def collection(self):
return getattr(self.parent, self.collection_name)
def keys(self):
descriptor = getattr(self.childclass, self.keyname)
return [x[0] for x in self.collection.values(descriptor)]
def __getitem__(self, key):
x = self.collection.filter_by(**{self.keyname:key}).first()
if x:
return x
else:
raise KeyError(key)
def __setitem__(self, key, value):
try:
existing = self[key]
self.collection.remove(existing)
except KeyError:
pass
self.collection.append(value)
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import create_engine, Column, Integer, String, ForeignKey
from sqlalchemy.orm import sessionmaker, relationship
engine = create_engine('sqlite://', echo=True)
Base = declarative_base(engine)
class Parent(Base):
__tablename__ = 'parent'
id = Column(Integer, primary_key=True)
name = Column(String(50))
_collection = relationship("Child", lazy="dynamic",
cascade="all, delete-orphan")
@property
def child_map(self):
return ProxyDict(self, '_collection', Child, 'key')
class Child(Base):
__tablename__ = 'child'
id = Column(Integer, primary_key=True)
key = Column(String(50))
parent_id = Column(Integer, ForeignKey('parent.id'))
def __repr__(self):
return "Child(key=%r)" % self.key
Base.metadata.create_all()
sess = sessionmaker()()
p1 = Parent(name='p1')
sess.add(p1)
print "\n---------begin setting nodes, autoflush occurs\n"
p1.child_map['k1'] = Child(key='k1')
p1.child_map['k2'] = Child(key='k2')
# this will autoflush the current map.
# ['k1', 'k2']
print "\n---------print keys - flushes first\n"
print p1.child_map.keys()
# k1
print "\n---------print 'k1' node\n"
print p1.child_map['k1']
print "\n---------update 'k2' node - must find existing, and replace\n"
p1.child_map['k2'] = Child(key='k2')
print "\n---------print 'k2' key - flushes first\n"
# k2
print p1.child_map['k2']
print "\n---------print all child nodes\n"
# [k1, k2b]
print sess.query(Child).all()
|
mit
|
[
533,
12373,
2141,
8,
785,
304,
1128,
347,
636,
826,
721,
277,
12,
1676,
12,
3245,
63,
354,
12,
1982,
533,
12,
790,
354,
304,
1039,
291,
14,
1708,
275,
1676,
1039,
291,
14,
3627,
63,
354,
275,
3245,
63,
354,
1039,
291,
14,
1739,
533,
275,
1982,
533,
1039,
291,
14,
30499,
275,
790,
354,
2958,
768,
1829,
1128,
347,
3245,
8,
277,
304,
1039,
372,
2519,
8,
277,
14,
1708,
12,
291,
14,
3627,
63,
354,
9,
2958,
347,
2883,
8,
277,
304,
1039,
5872,
275,
2519,
8,
277,
14,
1739,
533,
12,
291,
14,
30499,
9,
1039,
372,
359,
88,
59,
16,
61,
367,
671,
315,
291,
14,
3627,
14,
1459,
8,
4120,
1874,
2958,
347,
636,
6095,
721,
277,
12,
790,
304,
1039,
671,
275,
291,
14,
3627,
14,
1541,
63,
991,
25679,
277,
14,
30499,
26,
498,
21385,
2246,
342,
1039,
340,
671,
26,
1675,
372,
671,
1039,
587,
26,
1675,
746,
4067,
8,
498,
9,
2958,
347,
636,
8617,
721,
277,
12,
790,
12,
574,
304,
1039,
862,
26,
1675,
3411,
275,
291,
59,
498,
61,
1675,
291,
14,
3627,
14,
2168,
8,
5952,
9,
1039,
871,
4067,
26,
1675,
986,
1039,
291,
14,
3627,
14,
740,
8,
585,
9,
2999,
199,
504,
8335,
14,
832,
14,
12164,
1905,
492,
30191,
63,
1095,
202,
199,
504,
8335,
492,
1218,
63,
3908,
12,
4996,
12,
7225,
12,
2624,
12,
12718,
202,
199,
504,
8335,
14,
1025,
492,
2351,
14367,
12,
8931,
2999,
199,
3908,
275,
1218,
63,
3908,
360,
10659,
921,
297,
11343,
29,
549,
9,
202,
199,
1563,
275,
30191,
63,
1095,
8,
3908,
9,
2999,
199,
533,
16396,
8,
1563,
304,
1128,
636,
10983,
363,
275,
283,
1708,
7,
1128,
1305,
275,
4996,
8,
2674,
12,
5062,
63,
498,
29,
549,
9,
1128,
536,
275,
4996,
8,
1558,
8,
1400,
430,
1128,
485,
3627,
275,
8931,
480,
3493,
401,
9617,
628,
7764,
401,
202,
2511,
22809,
628,
452,
12,
3145,
13,
22161,
531,
2958,
768,
1829,
1128,
347,
1982,
63,
1130,
8,
277,
304,
1039,
372,
12373,
2141,
8,
277,
12,
2513,
3627,
297,
12988,
12,
283,
498,
358,
2999,
199,
533,
12988,
8,
1563,
304,
1128,
636,
10983,
363,
275,
283,
1739,
7,
1128,
1305,
275,
4996,
8,
2674,
12,
5062,
63,
498,
29,
549,
9,
1128,
790,
275,
4996,
8,
1558,
8,
1400,
430,
1128,
1676,
63,
344,
275,
4996,
8,
2674,
12,
12718,
360,
1708,
14,
344,
1333,
2958,
347,
636,
2722,
721,
277,
304,
1039,
372,
298,
3493,
8,
498,
2458,
82,
2924,
450,
291,
14,
498,
2999,
199,
1563,
14,
2343,
14,
981,
63,
452,
342,
2999,
199,
5480,
275,
2351,
14367,
342,
342,
2999,
199,
80,
17,
275,
16396,
8,
354,
534,
80,
17,
358,
202,
199,
5480,
14,
525,
8,
80,
17,
9,
2999,
199,
1361,
1867,
78,
9960,
5037,
4260,
3380,
12,
2599,
4939,
11058,
60,
78,
2,
202,
199,
80,
17,
14,
1739,
63,
1130,
459,
75,
17,
418,
275,
12988,
8,
498,
534,
75,
17,
358,
202,
199,
80,
17,
14,
1739,
63,
1130,
459,
75,
18,
418,
275,
12988,
8,
498,
534,
75,
18,
358,
2999,
199,
3,
642,
911,
2599,
4939,
314,
1453,
2341,
14,
202,
199,
3,
788,
75,
17,
297,
283,
75,
18,
418,
202,
199,
1361,
1867,
78,
9960,
1361,
2883,
446,
8976,
397,
1642,
60,
78,
2,
202,
199,
1361,
299,
17,
14,
1739,
63,
1130,
14,
1612,
342,
2999,
199,
3,
1022,
17,
202,
199,
1361,
1867,
78,
9960,
1361,
283,
75,
17,
7,
1031,
60,
78,
2,
202,
199,
1361,
299,
17,
14,
1739,
63,
1130,
459,
75,
17,
418,
2999,
199,
1361,
1867,
78,
9960,
873,
283,
75,
18,
7,
1031,
446,
1471,
2342,
3411,
12,
436,
3350,
60,
78,
2,
202,
199,
80,
17,
14,
1739,
63,
1130,
459,
75,
18,
418,
275,
12988,
8,
498,
534,
75,
18,
358,
2999,
199,
1361,
1867,
78,
9960,
1361,
283,
75,
18,
7,
790,
446,
8976,
397,
1642,
60,
78,
2,
202,
199,
3,
1022,
18,
202,
199,
1361,
299,
17,
14,
1739,
63,
1130,
459,
75,
18,
418,
2999,
199,
1361,
1867,
78,
9960,
1361,
1006,
1982,
3380,
60,
78,
2,
202,
199,
3,
359,
75,
17,
12,
1022,
18,
66,
61,
202,
199,
1361,
4043,
14,
1131,
8,
3493,
680,
452,
342,
10060,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
12373,
2141,
8,
785,
304,
1128,
347,
636,
826,
721,
277,
12,
1676,
12,
3245,
63,
354,
12,
1982,
533,
12,
790,
354,
304,
1039,
291,
14,
1708,
275,
1676,
1039,
291,
14,
3627,
63,
354,
275,
3245,
63,
354,
1039,
291,
14,
1739,
533,
275,
1982,
533,
1039,
291,
14,
30499,
275,
790,
354,
2958,
768,
1829,
1128,
347,
3245,
8,
277,
304,
1039,
372,
2519,
8,
277,
14,
1708,
12,
291,
14,
3627,
63,
354,
9,
2958,
347,
2883,
8,
277,
304,
1039,
5872,
275,
2519,
8,
277,
14,
1739,
533,
12,
291,
14,
30499,
9,
1039,
372,
359,
88,
59,
16,
61,
367,
671,
315,
291,
14,
3627,
14,
1459,
8,
4120,
1874,
2958,
347,
636,
6095,
721,
277,
12,
790,
304,
1039,
671,
275,
291,
14,
3627,
14,
1541,
63,
991,
25679,
277,
14,
30499,
26,
498,
21385,
2246,
342,
1039,
340,
671,
26,
1675,
372,
671,
1039,
587,
26,
1675,
746,
4067,
8,
498,
9,
2958,
347,
636,
8617,
721,
277,
12,
790,
12,
574,
304,
1039,
862,
26,
1675,
3411,
275,
291,
59,
498,
61,
1675,
291,
14,
3627,
14,
2168,
8,
5952,
9,
1039,
871,
4067,
26,
1675,
986,
1039,
291,
14,
3627,
14,
740,
8,
585,
9,
2999,
199,
504,
8335,
14,
832,
14,
12164,
1905,
492,
30191,
63,
1095,
202,
199,
504,
8335,
492,
1218,
63,
3908,
12,
4996,
12,
7225,
12,
2624,
12,
12718,
202,
199,
504,
8335,
14,
1025,
492,
2351,
14367,
12,
8931,
2999,
199,
3908,
275,
1218,
63,
3908,
360,
10659,
921,
297,
11343,
29,
549,
9,
202,
199,
1563,
275,
30191,
63,
1095,
8,
3908,
9,
2999,
199,
533,
16396,
8,
1563,
304,
1128,
636,
10983,
363,
275,
283,
1708,
7,
1128,
1305,
275,
4996,
8,
2674,
12,
5062,
63,
498,
29,
549,
9,
1128,
536,
275,
4996,
8,
1558,
8,
1400,
430,
1128,
485,
3627,
275,
8931,
480,
3493,
401,
9617,
628,
7764,
401,
202,
2511,
22809,
628,
452,
12,
3145,
13,
22161,
531,
2958,
768,
1829,
1128,
347,
1982,
63,
1130,
8,
277,
304,
1039,
372,
12373,
2141,
8,
277,
12,
2513,
3627,
297,
12988,
12,
283,
498,
358,
2999,
199,
533,
12988,
8,
1563,
304,
1128,
636,
10983,
363,
275,
283,
1739,
7,
1128,
1305,
275,
4996,
8,
2674,
12,
5062,
63,
498,
29,
549,
9,
1128,
790,
275,
4996,
8,
1558,
8,
1400,
430,
1128,
1676,
63,
344,
275,
4996,
8,
2674,
12,
12718,
360,
1708,
14,
344,
1333,
2958,
347,
636,
2722,
721,
277,
304,
1039,
372,
298,
3493,
8,
498,
2458,
82,
2924,
450,
291,
14,
498,
2999,
199,
1563,
14,
2343,
14,
981,
63,
452,
342,
2999,
199,
5480,
275,
2351,
14367,
342,
342,
2999,
199,
80,
17,
275,
16396,
8,
354,
534,
80,
17,
358,
202,
199,
5480,
14,
525,
8,
80,
17,
9,
2999,
199,
1361,
1867,
78,
9960,
5037,
4260,
3380,
12,
2599,
4939,
11058,
60,
78,
2,
202,
199,
80,
17,
14,
1739,
63,
1130,
459,
75,
17,
418,
275,
12988,
8,
498,
534,
75,
17,
358,
202,
199,
80,
17,
14,
1739,
63,
1130,
459,
75,
18,
418,
275,
12988,
8,
498,
534,
75,
18,
358,
2999,
199,
3,
642,
911,
2599,
4939,
314,
1453,
2341,
14,
202,
199,
3,
788,
75,
17,
297,
283,
75,
18,
418,
202,
199,
1361,
1867,
78,
9960,
1361,
2883,
446,
8976,
397,
1642,
60,
78,
2,
202,
199,
1361,
299,
17,
14,
1739,
63,
1130,
14,
1612,
342,
2999,
199,
3,
1022,
17,
202,
199,
1361,
1867,
78,
9960,
1361,
283,
75,
17,
7,
1031,
60,
78,
2,
202,
199,
1361,
299,
17,
14,
1739,
63,
1130,
459,
75,
17,
418,
2999,
199,
1361,
1867,
78,
9960,
873,
283,
75,
18,
7,
1031,
446,
1471,
2342,
3411,
12,
436,
3350,
60,
78,
2,
202,
199,
80,
17,
14,
1739,
63,
1130,
459,
75,
18,
418,
275,
12988,
8,
498,
534,
75,
18,
358,
2999,
199,
1361,
1867,
78,
9960,
1361,
283,
75,
18,
7,
790,
446,
8976,
397,
1642,
60,
78,
2,
202,
199,
3,
1022,
18,
202,
199,
1361,
299,
17,
14,
1739,
63,
1130,
459,
75,
18,
418,
2999,
199,
1361,
1867,
78,
9960,
1361,
1006,
1982,
3380,
60,
78,
2,
202,
199,
3,
359,
75,
17,
12,
1022,
18,
66,
61,
202,
199,
1361,
4043,
14,
1131,
8,
3493,
680,
452,
342,
10060,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
ATIX-AG/ansible
|
lib/ansible/plugins/lookup/dict.py
|
7
|
1954
|
# (c) 2014, Kent R. Spillner <kspillner@acm.org>
# (c) 2017 Ansible Project
# 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
DOCUMENTATION = """
lookup: dict
version_added: "1.5"
short_description: returns key/value pair items from dictionaries
description:
- Takes dictionaries as input and returns a list with each item in the list being a dictionary with 'key' and 'value' as
keys to the previous dictionary's structure.
options:
_terms:
description:
- A list of dictionaries
required: True
"""
EXAMPLES = """
tasks:
- name: show dictionary
debug: msg="{{item.key}}: {{item.value}}"
with_dict: {a: 1, b: 2, c: 3}
# with predefined vars
vars:
users:
alice:
name: Alice Appleworth
telephone: 123-456-7890
bob:
name: Bob Bananarama
telephone: 987-654-3210
tasks:
- name: Print phone records
debug:
msg: "User {{ item.key }} is {{ item.value.name }} ({{ item.value.telephone }})"
loop: "{{ lookup('dict', users) }}"
"""
RETURN = """
_list:
description:
- list of composed dictonaries with key and value
type: list
"""
import collections
from ansible.errors import AnsibleError
from ansible.plugins.lookup import LookupBase
class LookupModule(LookupBase):
def run(self, terms, variables=None, **kwargs):
# FIXME: can remove once with_ special case is removed
if not isinstance(terms, list):
terms = [terms]
results = []
for term in terms:
# Expect any type of Mapping, notably hostvars
if not isinstance(term, collections.Mapping):
raise AnsibleError("with_dict expects a dict")
results.extend(self._flatten_hash_to_list(term))
return results
|
gpl-3.0
|
[
3,
334,
67,
9,
6927,
12,
1804,
484,
820,
14,
8360,
778,
1372,
665,
75,
681,
778,
1372,
32,
645,
77,
14,
1308,
30,
199,
3,
334,
67,
9,
9708,
2622,
7290,
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,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
8948,
275,
408,
272,
4237,
26,
1211,
272,
1015,
63,
3270,
26,
298,
17,
14,
21,
2,
272,
3974,
63,
1802,
26,
2529,
790,
15,
585,
4092,
2974,
687,
11196,
272,
1369,
26,
267,
446,
17415,
11196,
465,
1324,
436,
2529,
282,
769,
543,
1924,
1242,
315,
314,
769,
3769,
282,
2600,
543,
283,
498,
7,
436,
283,
585,
7,
465,
881,
2883,
370,
314,
4136,
2600,
1159,
5523,
14,
272,
1511,
26,
267,
485,
9187,
26,
288,
1369,
26,
355,
446,
437,
769,
402,
11196,
288,
1415,
26,
715,
199,
624,
199,
199,
8918,
275,
408,
199,
5054,
26,
523,
446,
536,
26,
2498,
2600,
272,
3105,
26,
1499,
628,
3638,
1053,
14,
498,
4863,
26,
8448,
1053,
14,
585,
30618,
272,
543,
63,
807,
26,
469,
65,
26,
413,
12,
330,
26,
499,
12,
286,
26,
650,
93,
199,
199,
3,
543,
27684,
6802,
199,
2936,
26,
523,
4390,
26,
272,
741,
1885,
26,
489,
536,
26,
437,
3037,
21257,
584,
273,
489,
14001,
9339,
26,
11869,
13,
11419,
13,
23,
13173,
272,
26961,
26,
489,
536,
26,
699,
2873,
699,
290,
290,
285,
14541,
489,
14001,
9339,
26,
1749,
1555,
13,
11157,
13,
708,
709,
199,
5054,
26,
523,
446,
536,
26,
9101,
14617,
5767,
272,
3105,
26,
489,
1499,
26,
298,
1899,
8448,
1242,
14,
498,
3586,
365,
8448,
1242,
14,
585,
14,
354,
3586,
334,
3638,
1242,
14,
585,
14,
15253,
9339,
789,
1552,
2,
272,
4438,
26,
7370,
4237,
360,
807,
297,
4390,
9,
7820,
199,
624,
199,
199,
9677,
275,
408,
523,
485,
513,
26,
272,
1369,
26,
489,
446,
769,
402,
26356,
1211,
265,
3433,
543,
790,
436,
574,
272,
730,
26,
769,
199,
624,
199,
646,
5055,
199,
199,
504,
3242,
14,
2550,
492,
13358,
199,
504,
3242,
14,
5265,
14,
3892,
492,
12785,
1563,
421,
199,
533,
12785,
2377,
8,
7521,
1563,
304,
339,
347,
1255,
8,
277,
12,
2895,
12,
2860,
29,
403,
12,
1011,
958,
304,
398,
327,
7600,
26,
883,
2813,
5403,
543,
63,
4539,
1930,
365,
4829,
267,
340,
440,
1228,
8,
9187,
12,
769,
304,
288,
2895,
275,
359,
9187,
61,
398,
2058,
275,
942,
267,
367,
6707,
315,
2895,
26,
288,
327,
15100,
1263,
730,
402,
12340,
12,
440,
6665,
21835,
288,
340,
440,
1228,
8,
5125,
12,
5055,
14,
7674,
304,
355,
746,
13358,
480,
1045,
63,
807,
14292,
282,
1211,
531,
953,
2058,
14,
2880,
8,
277,
423,
8487,
63,
2227,
63,
475,
63,
513,
8,
5125,
430,
267,
372,
2058,
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
] |
[
334,
67,
9,
6927,
12,
1804,
484,
820,
14,
8360,
778,
1372,
665,
75,
681,
778,
1372,
32,
645,
77,
14,
1308,
30,
199,
3,
334,
67,
9,
9708,
2622,
7290,
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,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
8948,
275,
408,
272,
4237,
26,
1211,
272,
1015,
63,
3270,
26,
298,
17,
14,
21,
2,
272,
3974,
63,
1802,
26,
2529,
790,
15,
585,
4092,
2974,
687,
11196,
272,
1369,
26,
267,
446,
17415,
11196,
465,
1324,
436,
2529,
282,
769,
543,
1924,
1242,
315,
314,
769,
3769,
282,
2600,
543,
283,
498,
7,
436,
283,
585,
7,
465,
881,
2883,
370,
314,
4136,
2600,
1159,
5523,
14,
272,
1511,
26,
267,
485,
9187,
26,
288,
1369,
26,
355,
446,
437,
769,
402,
11196,
288,
1415,
26,
715,
199,
624,
199,
199,
8918,
275,
408,
199,
5054,
26,
523,
446,
536,
26,
2498,
2600,
272,
3105,
26,
1499,
628,
3638,
1053,
14,
498,
4863,
26,
8448,
1053,
14,
585,
30618,
272,
543,
63,
807,
26,
469,
65,
26,
413,
12,
330,
26,
499,
12,
286,
26,
650,
93,
199,
199,
3,
543,
27684,
6802,
199,
2936,
26,
523,
4390,
26,
272,
741,
1885,
26,
489,
536,
26,
437,
3037,
21257,
584,
273,
489,
14001,
9339,
26,
11869,
13,
11419,
13,
23,
13173,
272,
26961,
26,
489,
536,
26,
699,
2873,
699,
290,
290,
285,
14541,
489,
14001,
9339,
26,
1749,
1555,
13,
11157,
13,
708,
709,
199,
5054,
26,
523,
446,
536,
26,
9101,
14617,
5767,
272,
3105,
26,
489,
1499,
26,
298,
1899,
8448,
1242,
14,
498,
3586,
365,
8448,
1242,
14,
585,
14,
354,
3586,
334,
3638,
1242,
14,
585,
14,
15253,
9339,
789,
1552,
2,
272,
4438,
26,
7370,
4237,
360,
807,
297,
4390,
9,
7820,
199,
624,
199,
199,
9677,
275,
408,
523,
485,
513,
26,
272,
1369,
26,
489,
446,
769,
402,
26356,
1211,
265,
3433,
543,
790,
436,
574,
272,
730,
26,
769,
199,
624,
199,
646,
5055,
199,
199,
504,
3242,
14,
2550,
492,
13358,
199,
504,
3242,
14,
5265,
14,
3892,
492,
12785,
1563,
421,
199,
533,
12785,
2377,
8,
7521,
1563,
304,
339,
347,
1255,
8,
277,
12,
2895,
12,
2860,
29,
403,
12,
1011,
958,
304,
398,
327,
7600,
26,
883,
2813,
5403,
543,
63,
4539,
1930,
365,
4829,
267,
340,
440,
1228,
8,
9187,
12,
769,
304,
288,
2895,
275,
359,
9187,
61,
398,
2058,
275,
942,
267,
367,
6707,
315,
2895,
26,
288,
327,
15100,
1263,
730,
402,
12340,
12,
440,
6665,
21835,
288,
340,
440,
1228,
8,
5125,
12,
5055,
14,
7674,
304,
355,
746,
13358,
480,
1045,
63,
807,
14292,
282,
1211,
531,
953,
2058,
14,
2880,
8,
277,
423,
8487,
63,
2227,
63,
475,
63,
513,
8,
5125,
430,
267,
372,
2058,
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,
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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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
] |
Kazade/NeHe-Website
|
google_appengine/lib/django-1.2/django/contrib/localflavor/in_/in_states.py
|
296
|
1859
|
"""
A mapping of state misspellings/abbreviations to normalized abbreviations, and
an alphabetical list of states for use as `choices` in a formfield.
This exists in this standalone file so that it's only imported into memory
when explicitly needed.
"""
STATE_CHOICES = (
('KA', 'Karnataka'),
('AP', 'Andhra Pradesh'),
('KL', 'Kerala'),
('TN', 'Tamil Nadu'),
('MH', 'Maharashtra'),
('UP', 'Uttar Pradesh'),
('GA', 'Goa'),
('GJ', 'Gujarat'),
('RJ', 'Rajasthan'),
('HP', 'Himachal Pradesh'),
('JK', 'Jammu and Kashmir'),
('AR', 'Arunachal Pradesh'),
('AS', 'Assam'),
('BR', 'Bihar'),
('CG', 'Chattisgarh'),
('HR', 'Haryana'),
('JH', 'Jharkhand'),
('MP', 'Madhya Pradesh'),
('MN', 'Manipur'),
('ML', 'Meghalaya'),
('MZ', 'Mizoram'),
('NL', 'Nagaland'),
('OR', 'Orissa'),
('PB', 'Punjab'),
('SK', 'Sikkim'),
('TR', 'Tripura'),
('UA', 'Uttarakhand'),
('WB', 'West Bengal'),
# Union Territories
('AN', 'Andaman and Nicobar'),
('CH', 'Chandigarh'),
('DN', 'Dadra and Nagar Haveli'),
('DD', 'Daman and Diu'),
('DL', 'Delhi'),
('LD', 'Lakshadweep'),
('PY', 'Pondicherry'),
)
STATES_NORMALIZED = {
'ka': 'KA',
'karnatka': 'KA',
'tn': 'TN',
'tamilnad': 'TN',
'tamilnadu': 'TN',
'andra pradesh': 'AP',
'andrapradesh': 'AP',
'andhrapradesh': 'AP',
'maharastra': 'MH',
'mh': 'MH',
'ap': 'AP',
'dl': 'DL',
'dd': 'DD',
'br': 'BR',
'ar': 'AR',
'sk': 'SK',
'kl': 'KL',
'ga': 'GA',
'rj': 'RJ',
'rajastan': 'RJ',
'rajasthan': 'RJ',
'hp': 'HP',
'ua': 'UA',
'up': 'UP',
'mp': 'MP',
'mz': 'MZ',
'bengal': 'WB',
'westbengal': 'WB',
'mizo': 'MZ',
'orisa': 'OR',
'odisa': 'OR',
'or': 'OR',
'ar': 'AR',
}
|
bsd-3-clause
|
[
624,
199,
33,
4412,
402,
1174,
3201,
32252,
780,
15,
371,
23988,
1298,
370,
9657,
2236,
23988,
1298,
12,
436,
199,
290,
23331,
3294,
769,
402,
6363,
367,
675,
465,
658,
4577,
64,
315,
282,
21388,
14,
199,
199,
2765,
3495,
315,
642,
18042,
570,
880,
626,
652,
1159,
1454,
8439,
1901,
4402,
199,
6526,
7662,
4346,
14,
199,
624,
199,
199,
6689,
63,
16236,
275,
334,
272,
661,
19606,
297,
283,
43,
1060,
419,
7351,
659,
272,
661,
1282,
297,
283,
3325,
72,
345,
510,
345,
271,
609,
659,
272,
661,
14307,
297,
283,
43,
281,
14774,
659,
272,
661,
52,
46,
297,
283,
52,
455,
382,
653,
350,
85,
659,
272,
661,
30668,
297,
283,
11903,
8210,
305,
517,
345,
659,
272,
661,
2160,
297,
283,
53,
84,
5369,
510,
345,
271,
609,
659,
272,
661,
9741,
297,
283,
7250,
65,
659,
272,
661,
39,
42,
297,
283,
11548,
7338,
292,
659,
272,
661,
50,
42,
297,
283,
1537,
74,
1810,
19262,
659,
272,
661,
18635,
297,
283,
40,
11744,
335,
279,
510,
345,
271,
609,
659,
272,
661,
25575,
297,
283,
42,
455,
6553,
436,
1804,
1119,
77,
723,
659,
272,
661,
689,
297,
283,
33,
1065,
1225,
279,
510,
345,
271,
609,
659,
272,
661,
1179,
297,
283,
9824,
455,
659,
272,
661,
7184,
297,
283,
17975,
8210,
659,
272,
661,
4064,
297,
283,
21954,
280,
1226,
285,
72,
659,
272,
661,
14784,
297,
283,
40,
695,
6738,
659,
272,
661,
42,
40,
297,
283,
42,
72,
1096,
6868,
659,
272,
661,
1658,
297,
283,
45,
350,
3577,
65,
510,
345,
271,
609,
659,
272,
661,
16237,
297,
283,
2395,
711,
300,
659,
272,
661,
1698,
297,
283,
1352,
3561,
279,
1187,
65,
659,
272,
661,
45,
58,
297,
283,
45,
565,
269,
455,
659,
272,
661,
14176,
297,
283,
46,
643,
279,
460,
659,
272,
661,
726,
297,
283,
15736,
28023,
659,
272,
661,
13167,
297,
283,
48,
324,
74,
371,
659,
272,
661,
8656,
297,
283,
51,
3258,
75,
1017,
659,
272,
661,
1766,
297,
283,
6948,
6653,
65,
659,
272,
661,
21659,
297,
283,
53,
84,
5369,
1151,
6868,
659,
272,
661,
24819,
297,
283,
55,
597,
699,
7420,
279,
659,
339,
327,
15961,
13861,
11133,
6112,
272,
661,
879,
297,
283,
3325,
455,
290,
436,
653,
12802,
1700,
659,
272,
661,
1244,
297,
283,
27039,
18367,
285,
72,
659,
272,
661,
10872,
297,
283,
36,
350,
345,
436,
653,
643,
285,
26858,
317,
659,
272,
661,
5745,
297,
283,
36,
455,
290,
436,
3757,
85,
659,
272,
661,
8045,
297,
283,
6994,
5812,
659,
272,
661,
6533,
297,
283,
44,
1151,
609,
350,
87,
7840,
659,
272,
661,
4521,
297,
283,
48,
265,
328,
7641,
651,
659,
199,
9,
199,
199,
23162,
63,
10765,
18732,
275,
469,
272,
283,
7351,
356,
283,
19606,
297,
272,
283,
75,
1060,
292,
7351,
356,
283,
19606,
297,
272,
283,
5889,
356,
283,
52,
46,
297,
272,
283,
84,
455,
382,
78,
350,
356,
283,
52,
46,
297,
272,
283,
84,
455,
382,
78,
350,
85,
356,
283,
52,
46,
297,
272,
283,
19125,
299,
345,
271,
609,
356,
283,
1282,
297,
272,
283,
460,
1330,
345,
271,
609,
356,
283,
1282,
297,
272,
283,
460,
72,
1330,
345,
271,
609,
356,
283,
1282,
297,
272,
283,
391,
8210,
1810,
345,
356,
283,
30668,
297,
272,
283,
17077,
356,
283,
30668,
297,
272,
283,
439,
356,
283,
1282,
297,
272,
283,
5030,
356,
283,
8045,
297,
272,
283,
617,
356,
283,
5745,
297,
272,
283,
3289,
356,
283,
7184,
297,
272,
283,
285,
356,
283,
689,
297,
272,
283,
1339,
356,
283,
8656,
297,
272,
283,
9503,
356,
283,
14307,
297,
272,
283,
5294,
356,
283,
9741,
297,
272,
283,
82,
74,
356,
283,
50,
42,
297,
272,
283,
345,
74,
1810,
290,
356,
283,
50,
42,
297,
272,
283,
345,
74,
1810,
19262,
356,
283,
50,
42,
297,
272,
283,
12025,
356,
283,
18635,
297,
272,
283,
1458,
356,
283,
21659,
297,
272,
283,
384,
356,
283,
2160,
297,
272,
283,
311,
356,
283,
1658,
297,
272,
283,
28808,
356,
283,
45,
58,
297,
272,
283,
66,
7420,
279,
356,
283,
24819,
297,
272,
283,
19082,
66,
7420,
279,
356,
283,
24819,
297,
272,
283,
77,
565,
79,
356,
283,
45,
58,
297,
272,
283,
269,
13655,
356,
283,
726,
297,
272,
283,
79,
328,
2231,
356,
283,
726,
297,
272,
283,
269,
356,
283,
726,
297,
272,
283,
285,
356,
283,
689,
297,
199,
93,
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
] |
[
199,
33,
4412,
402,
1174,
3201,
32252,
780,
15,
371,
23988,
1298,
370,
9657,
2236,
23988,
1298,
12,
436,
199,
290,
23331,
3294,
769,
402,
6363,
367,
675,
465,
658,
4577,
64,
315,
282,
21388,
14,
199,
199,
2765,
3495,
315,
642,
18042,
570,
880,
626,
652,
1159,
1454,
8439,
1901,
4402,
199,
6526,
7662,
4346,
14,
199,
624,
199,
199,
6689,
63,
16236,
275,
334,
272,
661,
19606,
297,
283,
43,
1060,
419,
7351,
659,
272,
661,
1282,
297,
283,
3325,
72,
345,
510,
345,
271,
609,
659,
272,
661,
14307,
297,
283,
43,
281,
14774,
659,
272,
661,
52,
46,
297,
283,
52,
455,
382,
653,
350,
85,
659,
272,
661,
30668,
297,
283,
11903,
8210,
305,
517,
345,
659,
272,
661,
2160,
297,
283,
53,
84,
5369,
510,
345,
271,
609,
659,
272,
661,
9741,
297,
283,
7250,
65,
659,
272,
661,
39,
42,
297,
283,
11548,
7338,
292,
659,
272,
661,
50,
42,
297,
283,
1537,
74,
1810,
19262,
659,
272,
661,
18635,
297,
283,
40,
11744,
335,
279,
510,
345,
271,
609,
659,
272,
661,
25575,
297,
283,
42,
455,
6553,
436,
1804,
1119,
77,
723,
659,
272,
661,
689,
297,
283,
33,
1065,
1225,
279,
510,
345,
271,
609,
659,
272,
661,
1179,
297,
283,
9824,
455,
659,
272,
661,
7184,
297,
283,
17975,
8210,
659,
272,
661,
4064,
297,
283,
21954,
280,
1226,
285,
72,
659,
272,
661,
14784,
297,
283,
40,
695,
6738,
659,
272,
661,
42,
40,
297,
283,
42,
72,
1096,
6868,
659,
272,
661,
1658,
297,
283,
45,
350,
3577,
65,
510,
345,
271,
609,
659,
272,
661,
16237,
297,
283,
2395,
711,
300,
659,
272,
661,
1698,
297,
283,
1352,
3561,
279,
1187,
65,
659,
272,
661,
45,
58,
297,
283,
45,
565,
269,
455,
659,
272,
661,
14176,
297,
283,
46,
643,
279,
460,
659,
272,
661,
726,
297,
283,
15736,
28023,
659,
272,
661,
13167,
297,
283,
48,
324,
74,
371,
659,
272,
661,
8656,
297,
283,
51,
3258,
75,
1017,
659,
272,
661,
1766,
297,
283,
6948,
6653,
65,
659,
272,
661,
21659,
297,
283,
53,
84,
5369,
1151,
6868,
659,
272,
661,
24819,
297,
283,
55,
597,
699,
7420,
279,
659,
339,
327,
15961,
13861,
11133,
6112,
272,
661,
879,
297,
283,
3325,
455,
290,
436,
653,
12802,
1700,
659,
272,
661,
1244,
297,
283,
27039,
18367,
285,
72,
659,
272,
661,
10872,
297,
283,
36,
350,
345,
436,
653,
643,
285,
26858,
317,
659,
272,
661,
5745,
297,
283,
36,
455,
290,
436,
3757,
85,
659,
272,
661,
8045,
297,
283,
6994,
5812,
659,
272,
661,
6533,
297,
283,
44,
1151,
609,
350,
87,
7840,
659,
272,
661,
4521,
297,
283,
48,
265,
328,
7641,
651,
659,
199,
9,
199,
199,
23162,
63,
10765,
18732,
275,
469,
272,
283,
7351,
356,
283,
19606,
297,
272,
283,
75,
1060,
292,
7351,
356,
283,
19606,
297,
272,
283,
5889,
356,
283,
52,
46,
297,
272,
283,
84,
455,
382,
78,
350,
356,
283,
52,
46,
297,
272,
283,
84,
455,
382,
78,
350,
85,
356,
283,
52,
46,
297,
272,
283,
19125,
299,
345,
271,
609,
356,
283,
1282,
297,
272,
283,
460,
1330,
345,
271,
609,
356,
283,
1282,
297,
272,
283,
460,
72,
1330,
345,
271,
609,
356,
283,
1282,
297,
272,
283,
391,
8210,
1810,
345,
356,
283,
30668,
297,
272,
283,
17077,
356,
283,
30668,
297,
272,
283,
439,
356,
283,
1282,
297,
272,
283,
5030,
356,
283,
8045,
297,
272,
283,
617,
356,
283,
5745,
297,
272,
283,
3289,
356,
283,
7184,
297,
272,
283,
285,
356,
283,
689,
297,
272,
283,
1339,
356,
283,
8656,
297,
272,
283,
9503,
356,
283,
14307,
297,
272,
283,
5294,
356,
283,
9741,
297,
272,
283,
82,
74,
356,
283,
50,
42,
297,
272,
283,
345,
74,
1810,
290,
356,
283,
50,
42,
297,
272,
283,
345,
74,
1810,
19262,
356,
283,
50,
42,
297,
272,
283,
12025,
356,
283,
18635,
297,
272,
283,
1458,
356,
283,
21659,
297,
272,
283,
384,
356,
283,
2160,
297,
272,
283,
311,
356,
283,
1658,
297,
272,
283,
28808,
356,
283,
45,
58,
297,
272,
283,
66,
7420,
279,
356,
283,
24819,
297,
272,
283,
19082,
66,
7420,
279,
356,
283,
24819,
297,
272,
283,
77,
565,
79,
356,
283,
45,
58,
297,
272,
283,
269,
13655,
356,
283,
726,
297,
272,
283,
79,
328,
2231,
356,
283,
726,
297,
272,
283,
269,
356,
283,
726,
297,
272,
283,
285,
356,
283,
689,
297,
199,
93,
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,
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,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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
] |
abhattad4/Digi-Menu
|
digimenu2/tests/custom_pk/fields.py
|
379
|
1731
|
import random
import string
from django.db import models
from django.utils import six
from django.utils.encoding import python_2_unicode_compatible
@python_2_unicode_compatible
class MyWrapper(object):
def __init__(self, value):
self.value = value
def __repr__(self):
return "<%s: %s>" % (self.__class__.__name__, self.value)
def __str__(self):
return self.value
def __eq__(self, other):
if isinstance(other, self.__class__):
return self.value == other.value
return self.value == other
class MyAutoField(models.CharField):
def __init__(self, *args, **kwargs):
kwargs['max_length'] = 10
super(MyAutoField, self).__init__(*args, **kwargs)
def pre_save(self, instance, add):
value = getattr(instance, self.attname, None)
if not value:
value = MyWrapper(''.join(random.sample(string.ascii_lowercase, 10)))
setattr(instance, self.attname, value)
return value
def to_python(self, value):
if not value:
return
if not isinstance(value, MyWrapper):
value = MyWrapper(value)
return value
def from_db_value(self, value, expression, connection, context):
if not value:
return
return MyWrapper(value)
def get_db_prep_save(self, value, connection):
if not value:
return
if isinstance(value, MyWrapper):
return six.text_type(value)
return value
def get_db_prep_value(self, value, connection, prepared=False):
if not value:
return
if isinstance(value, MyWrapper):
return six.text_type(value)
return value
|
bsd-3-clause
|
[
646,
2196,
199,
646,
1059,
199,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
1208,
492,
3816,
199,
504,
1639,
14,
1208,
14,
2991,
492,
2366,
63,
18,
63,
2975,
63,
6490,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
4932,
4590,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
574,
304,
267,
291,
14,
585,
275,
574,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
23054,
83,
26,
450,
83,
4335,
450,
334,
277,
855,
533,
4914,
354,
3108,
291,
14,
585,
9,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
585,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
340,
1228,
8,
1848,
12,
291,
855,
533,
18580,
288,
372,
291,
14,
585,
508,
1163,
14,
585,
267,
372,
291,
14,
585,
508,
1163,
421,
199,
533,
4932,
4378,
8,
992,
14,
2183,
304,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
2074,
459,
988,
63,
1267,
418,
275,
1616,
267,
1613,
8,
5713,
4378,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
339,
347,
876,
63,
2117,
8,
277,
12,
1256,
12,
1050,
304,
267,
574,
275,
2519,
8,
842,
12,
291,
14,
13651,
12,
488,
9,
267,
340,
440,
574,
26,
288,
574,
275,
4932,
4590,
17840,
904,
8,
2355,
14,
3271,
8,
875,
14,
4371,
63,
21636,
12,
1616,
1724,
288,
5371,
8,
842,
12,
291,
14,
13651,
12,
574,
9,
267,
372,
574,
339,
347,
370,
63,
1548,
8,
277,
12,
574,
304,
267,
340,
440,
574,
26,
288,
372,
267,
340,
440,
1228,
8,
585,
12,
4932,
4590,
304,
288,
574,
275,
4932,
4590,
8,
585,
9,
267,
372,
574,
339,
347,
687,
63,
697,
63,
585,
8,
277,
12,
574,
12,
3965,
12,
1950,
12,
1067,
304,
267,
340,
440,
574,
26,
288,
372,
267,
372,
4932,
4590,
8,
585,
9,
339,
347,
664,
63,
697,
63,
10837,
63,
2117,
8,
277,
12,
574,
12,
1950,
304,
267,
340,
440,
574,
26,
288,
372,
267,
340,
1228,
8,
585,
12,
4932,
4590,
304,
288,
372,
3816,
14,
505,
63,
466,
8,
585,
9,
267,
372,
574,
339,
347,
664,
63,
697,
63,
10837,
63,
585,
8,
277,
12,
574,
12,
1950,
12,
16318,
29,
797,
304,
267,
340,
440,
574,
26,
288,
372,
267,
340,
1228,
8,
585,
12,
4932,
4590,
304,
288,
372,
3816,
14,
505,
63,
466,
8,
585,
9,
267,
372,
574,
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
] |
[
2196,
199,
646,
1059,
199,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
1208,
492,
3816,
199,
504,
1639,
14,
1208,
14,
2991,
492,
2366,
63,
18,
63,
2975,
63,
6490,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
4932,
4590,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
574,
304,
267,
291,
14,
585,
275,
574,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
23054,
83,
26,
450,
83,
4335,
450,
334,
277,
855,
533,
4914,
354,
3108,
291,
14,
585,
9,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
585,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
340,
1228,
8,
1848,
12,
291,
855,
533,
18580,
288,
372,
291,
14,
585,
508,
1163,
14,
585,
267,
372,
291,
14,
585,
508,
1163,
421,
199,
533,
4932,
4378,
8,
992,
14,
2183,
304,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
2074,
459,
988,
63,
1267,
418,
275,
1616,
267,
1613,
8,
5713,
4378,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
339,
347,
876,
63,
2117,
8,
277,
12,
1256,
12,
1050,
304,
267,
574,
275,
2519,
8,
842,
12,
291,
14,
13651,
12,
488,
9,
267,
340,
440,
574,
26,
288,
574,
275,
4932,
4590,
17840,
904,
8,
2355,
14,
3271,
8,
875,
14,
4371,
63,
21636,
12,
1616,
1724,
288,
5371,
8,
842,
12,
291,
14,
13651,
12,
574,
9,
267,
372,
574,
339,
347,
370,
63,
1548,
8,
277,
12,
574,
304,
267,
340,
440,
574,
26,
288,
372,
267,
340,
440,
1228,
8,
585,
12,
4932,
4590,
304,
288,
574,
275,
4932,
4590,
8,
585,
9,
267,
372,
574,
339,
347,
687,
63,
697,
63,
585,
8,
277,
12,
574,
12,
3965,
12,
1950,
12,
1067,
304,
267,
340,
440,
574,
26,
288,
372,
267,
372,
4932,
4590,
8,
585,
9,
339,
347,
664,
63,
697,
63,
10837,
63,
2117,
8,
277,
12,
574,
12,
1950,
304,
267,
340,
440,
574,
26,
288,
372,
267,
340,
1228,
8,
585,
12,
4932,
4590,
304,
288,
372,
3816,
14,
505,
63,
466,
8,
585,
9,
267,
372,
574,
339,
347,
664,
63,
697,
63,
10837,
63,
585,
8,
277,
12,
574,
12,
1950,
12,
16318,
29,
797,
304,
267,
340,
440,
574,
26,
288,
372,
267,
340,
1228,
8,
585,
12,
4932,
4590,
304,
288,
372,
3816,
14,
505,
63,
466,
8,
585,
9,
267,
372,
574,
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,
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,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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
] |
earsneyes/ardupilot
|
Tools/LogAnalyzer/tests/TestVibration.py
|
261
|
3069
|
from LogAnalyzer import Test,TestResult
import DataflashLog
import numpy
class TestVibration(Test):
'''test for accelerometer vibration (accX/accY/accZ) within recommendations'''
def __init__(self):
Test.__init__(self)
self.name = "Vibration"
def run(self, logdata, verbose):
self.result = TestResult()
if logdata.vehicleType != "ArduCopter":
self.result.status = TestResult.StatusType.NA
return
# constants
gravity = -9.81
aimRangeWarnXY = 1.5
aimRangeFailXY = 3.0
aimRangeWarnZ = 2.0 # gravity +/- aim range
aimRangeFailZ = 5.0 # gravity +/- aim range
if not "IMU" in logdata.channels:
self.result.status = TestResult.StatusType.UNKNOWN
self.result.statusMessage = "No IMU log data"
return
# find some stable LOITER data to analyze, at least 10 seconds
chunks = DataflashLog.DataflashLogHelper.findLoiterChunks(logdata, minLengthSeconds=10, noRCInputs=True)
if not chunks:
self.result.status = TestResult.StatusType.UNKNOWN
self.result.statusMessage = "No stable LOITER log data found"
return
# for now we'll just use the first (largest) chunk of LOITER data
# TODO: ignore the first couple of secs to avoid bad data during transition - or can we check more analytically that we're stable?
# TODO: accumulate all LOITER chunks over min size, or just use the largest one?
startLine = chunks[0][0]
endLine = chunks[0][1]
#print "TestVibration using LOITER chunk from lines %s to %s" % (`startLine`, `endLine`)
def getStdDevIMU(logdata, channelName, startLine,endLine):
loiterData = logdata.channels["IMU"][channelName].getSegment(startLine,endLine)
numpyData = numpy.array(loiterData.dictData.values())
return numpy.std(numpyData)
# use 2x standard deviations as the metric, so if 95% of samples lie within the aim range we're good
stdDevX = abs(2 * getStdDevIMU(logdata,"AccX",startLine,endLine))
stdDevY = abs(2 * getStdDevIMU(logdata,"AccY",startLine,endLine))
stdDevZ = abs(2 * getStdDevIMU(logdata,"AccZ",startLine,endLine))
if (stdDevX > aimRangeFailXY) or (stdDevY > aimRangeFailXY) or (stdDevZ > aimRangeFailZ):
self.result.status = TestResult.StatusType.FAIL
self.result.statusMessage = "Vibration too high (X:%.2fg, Y:%.2fg, Z:%.2fg)" % (stdDevX,stdDevY,stdDevZ)
elif (stdDevX > aimRangeWarnXY) or (stdDevY > aimRangeWarnXY) or (stdDevZ > aimRangeWarnZ):
self.result.status = TestResult.StatusType.WARN
self.result.statusMessage = "Vibration slightly high (X:%.2fg, Y:%.2fg, Z:%.2fg)" % (stdDevX,stdDevY,stdDevZ)
else:
self.result.status = TestResult.StatusType.GOOD
self.result.statusMessage = "Good vibration values (X:%.2fg, Y:%.2fg, Z:%.2fg)" % (stdDevX,stdDevY,stdDevZ)
|
gpl-3.0
|
[
504,
5297,
17606,
492,
1379,
12,
13120,
199,
646,
3918,
11331,
2445,
199,
199,
646,
2680,
421,
199,
533,
1379,
54,
1892,
1754,
8,
774,
304,
272,
1449,
396,
367,
1066,
15421,
5864,
351,
1321,
66,
1754,
334,
5470,
56,
15,
5470,
57,
15,
5470,
58,
9,
4453,
27747,
1298,
2344,
339,
347,
636,
826,
721,
277,
304,
267,
1379,
855,
826,
721,
277,
9,
267,
291,
14,
354,
275,
298,
54,
1892,
1754,
2,
2378,
347,
1255,
8,
277,
12,
943,
576,
12,
3376,
304,
267,
291,
14,
1099,
275,
23795,
342,
398,
340,
943,
576,
14,
20073,
804,
1137,
298,
31924,
18268,
351,
582,
288,
291,
14,
1099,
14,
1205,
275,
23795,
14,
3694,
804,
14,
7170,
288,
372,
398,
327,
5262,
267,
1999,
18936,
263,
275,
446,
25,
14,
2835,
267,
282,
1017,
4709,
22673,
8195,
275,
413,
14,
21,
267,
282,
1017,
4709,
4874,
8195,
275,
650,
14,
16,
267,
282,
1017,
4709,
22673,
58,
221,
275,
499,
14,
16,
221,
327,
1999,
18936,
435,
22551,
282,
1017,
1425,
267,
282,
1017,
4709,
4874,
58,
221,
275,
959,
14,
16,
221,
327,
1999,
18936,
435,
22551,
282,
1017,
1425,
398,
340,
440,
298,
1469,
53,
2,
315,
943,
576,
14,
6324,
26,
288,
291,
14,
1099,
14,
1205,
275,
23795,
14,
3694,
804,
14,
11588,
288,
291,
14,
1099,
14,
1205,
2209,
275,
298,
1944,
18211,
53,
943,
666,
2,
288,
372,
398,
327,
2342,
2005,
17830,
3412,
11084,
666,
370,
19897,
12,
737,
5210,
1616,
4696,
267,
8291,
275,
3918,
11331,
2445,
14,
1451,
11331,
2445,
4433,
14,
1623,
2041,
1661,
9856,
83,
8,
793,
576,
12,
1748,
4625,
13165,
29,
709,
12,
949,
8205,
15124,
29,
549,
9,
267,
340,
440,
8291,
26,
288,
291,
14,
1099,
14,
1205,
275,
23795,
14,
3694,
804,
14,
11588,
288,
291,
14,
1099,
14,
1205,
2209,
275,
298,
1944,
17830,
3412,
11084,
943,
666,
1911,
2,
263,
288,
372,
398,
327,
367,
3063,
781,
7171,
2951,
675,
314,
1642,
334,
9828,
3199,
9,
3728,
402,
3412,
11084,
666,
267,
327,
3254,
26,
3686,
314,
1642,
17535,
402,
20091,
370,
5126,
4875,
666,
5309,
14116,
446,
503,
883,
781,
1104,
1655,
5909,
17269,
626,
781,
3984,
17830,
31,
267,
327,
3254,
26,
30535,
1006,
3412,
11084,
8291,
1806,
1748,
1568,
12,
503,
2951,
675,
314,
17451,
1373,
31,
267,
1343,
3049,
275,
8291,
59,
16,
1527,
16,
61,
267,
1284,
3049,
257,
275,
8291,
59,
16,
1527,
17,
61,
267,
327,
1361,
298,
774,
54,
1892,
1754,
1808,
3412,
11084,
3728,
687,
2385,
450,
83,
370,
450,
83,
2,
450,
13493,
928,
3049,
3559,
658,
500,
3049,
10522,
398,
347,
664,
11976,
12680,
1469,
53,
8,
793,
576,
12,
3623,
985,
12,
1343,
3049,
12,
500,
3049,
304,
288,
560,
1661,
1451,
275,
943,
576,
14,
6324,
905,
1469,
53,
9210,
2775,
985,
1055,
362,
12520,
8,
928,
3049,
12,
500,
3049,
9,
288,
2680,
1451,
221,
275,
2680,
14,
1144,
8,
320,
1661,
1451,
14,
807,
1451,
14,
1459,
1012,
288,
372,
2680,
14,
1516,
8,
4714,
1451,
9,
398,
327,
675,
499,
88,
4465,
29052,
1298,
465,
314,
6370,
12,
880,
340,
16102,
5,
402,
5845,
1212,
69,
4453,
314,
282,
1017,
1425,
781,
3984,
6954,
267,
2418,
12680,
56,
275,
2853,
8,
18,
627,
664,
11976,
12680,
1469,
53,
8,
793,
576,
4589,
26828,
56,
401,
928,
3049,
12,
500,
3049,
430,
267,
2418,
12680,
57,
275,
2853,
8,
18,
627,
664,
11976,
12680,
1469,
53,
8,
793,
576,
4589,
26828,
57,
401,
928,
3049,
12,
500,
3049,
430,
267,
2418,
12680,
58,
275,
2853,
8,
18,
627,
664,
11976,
12680,
1469,
53,
8,
793,
576,
4589,
26828,
58,
401,
928,
3049,
12,
500,
3049,
430,
267,
340,
334,
1516,
12680,
56,
690,
282,
1017,
4709,
4874,
8195,
9,
503,
334,
1516,
12680,
57,
690,
282,
1017,
4709,
4874,
8195,
9,
503,
334,
1516,
12680,
58,
690,
282,
1017,
4709,
4874,
58,
304,
288,
291,
14,
1099,
14,
1205,
275,
23795,
14,
3694,
804,
14,
8784,
288,
291,
14,
1099,
14,
1205,
2209,
275,
298,
54,
1892,
1754,
4634,
4721,
334,
56,
2689,
14,
18,
9681,
12,
1488,
2689,
14,
18,
9681,
12,
3107,
2689,
14,
18,
9681,
2924,
450,
334,
1516,
12680,
56,
12,
1516,
12680,
57,
12,
1516,
12680,
58,
9,
267,
916,
334,
1516,
12680,
56,
690,
282,
1017,
4709,
22673,
8195,
9,
503,
334,
1516,
12680,
57,
690,
282,
1017,
4709,
22673,
8195,
9,
503,
334,
1516,
12680,
58,
690,
282,
1017,
4709,
22673,
58,
304,
288,
291,
14,
1099,
14,
1205,
275,
23795,
14,
3694,
804,
14,
17449,
288,
291,
14,
1099,
14,
1205,
2209,
275,
298,
54,
1892,
1754,
18023,
4721,
334,
56,
2689,
14,
18,
9681,
12,
1488,
2689,
14,
18,
9681,
12,
3107,
2689,
14,
18,
9681,
2924,
450,
334,
1516,
12680,
56,
12,
1516,
12680,
57,
12,
1516,
12680,
58,
9,
267,
587,
26,
288,
291,
14,
1099,
14,
1205,
275,
23795,
14,
3694,
804,
14,
17316,
36,
288,
291,
14,
1099,
14,
1205,
2209,
275,
298,
20652,
1321,
66,
1754,
1338,
334,
56,
2689,
14,
18,
9681,
12,
1488,
2689,
14,
18,
9681,
12,
3107,
2689,
14,
18,
9681,
2924,
450,
334,
1516,
12680,
56,
12,
1516,
12680,
57,
12,
1516,
12680,
58,
9,
13359,
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
] |
[
5297,
17606,
492,
1379,
12,
13120,
199,
646,
3918,
11331,
2445,
199,
199,
646,
2680,
421,
199,
533,
1379,
54,
1892,
1754,
8,
774,
304,
272,
1449,
396,
367,
1066,
15421,
5864,
351,
1321,
66,
1754,
334,
5470,
56,
15,
5470,
57,
15,
5470,
58,
9,
4453,
27747,
1298,
2344,
339,
347,
636,
826,
721,
277,
304,
267,
1379,
855,
826,
721,
277,
9,
267,
291,
14,
354,
275,
298,
54,
1892,
1754,
2,
2378,
347,
1255,
8,
277,
12,
943,
576,
12,
3376,
304,
267,
291,
14,
1099,
275,
23795,
342,
398,
340,
943,
576,
14,
20073,
804,
1137,
298,
31924,
18268,
351,
582,
288,
291,
14,
1099,
14,
1205,
275,
23795,
14,
3694,
804,
14,
7170,
288,
372,
398,
327,
5262,
267,
1999,
18936,
263,
275,
446,
25,
14,
2835,
267,
282,
1017,
4709,
22673,
8195,
275,
413,
14,
21,
267,
282,
1017,
4709,
4874,
8195,
275,
650,
14,
16,
267,
282,
1017,
4709,
22673,
58,
221,
275,
499,
14,
16,
221,
327,
1999,
18936,
435,
22551,
282,
1017,
1425,
267,
282,
1017,
4709,
4874,
58,
221,
275,
959,
14,
16,
221,
327,
1999,
18936,
435,
22551,
282,
1017,
1425,
398,
340,
440,
298,
1469,
53,
2,
315,
943,
576,
14,
6324,
26,
288,
291,
14,
1099,
14,
1205,
275,
23795,
14,
3694,
804,
14,
11588,
288,
291,
14,
1099,
14,
1205,
2209,
275,
298,
1944,
18211,
53,
943,
666,
2,
288,
372,
398,
327,
2342,
2005,
17830,
3412,
11084,
666,
370,
19897,
12,
737,
5210,
1616,
4696,
267,
8291,
275,
3918,
11331,
2445,
14,
1451,
11331,
2445,
4433,
14,
1623,
2041,
1661,
9856,
83,
8,
793,
576,
12,
1748,
4625,
13165,
29,
709,
12,
949,
8205,
15124,
29,
549,
9,
267,
340,
440,
8291,
26,
288,
291,
14,
1099,
14,
1205,
275,
23795,
14,
3694,
804,
14,
11588,
288,
291,
14,
1099,
14,
1205,
2209,
275,
298,
1944,
17830,
3412,
11084,
943,
666,
1911,
2,
263,
288,
372,
398,
327,
367,
3063,
781,
7171,
2951,
675,
314,
1642,
334,
9828,
3199,
9,
3728,
402,
3412,
11084,
666,
267,
327,
3254,
26,
3686,
314,
1642,
17535,
402,
20091,
370,
5126,
4875,
666,
5309,
14116,
446,
503,
883,
781,
1104,
1655,
5909,
17269,
626,
781,
3984,
17830,
31,
267,
327,
3254,
26,
30535,
1006,
3412,
11084,
8291,
1806,
1748,
1568,
12,
503,
2951,
675,
314,
17451,
1373,
31,
267,
1343,
3049,
275,
8291,
59,
16,
1527,
16,
61,
267,
1284,
3049,
257,
275,
8291,
59,
16,
1527,
17,
61,
267,
327,
1361,
298,
774,
54,
1892,
1754,
1808,
3412,
11084,
3728,
687,
2385,
450,
83,
370,
450,
83,
2,
450,
13493,
928,
3049,
3559,
658,
500,
3049,
10522,
398,
347,
664,
11976,
12680,
1469,
53,
8,
793,
576,
12,
3623,
985,
12,
1343,
3049,
12,
500,
3049,
304,
288,
560,
1661,
1451,
275,
943,
576,
14,
6324,
905,
1469,
53,
9210,
2775,
985,
1055,
362,
12520,
8,
928,
3049,
12,
500,
3049,
9,
288,
2680,
1451,
221,
275,
2680,
14,
1144,
8,
320,
1661,
1451,
14,
807,
1451,
14,
1459,
1012,
288,
372,
2680,
14,
1516,
8,
4714,
1451,
9,
398,
327,
675,
499,
88,
4465,
29052,
1298,
465,
314,
6370,
12,
880,
340,
16102,
5,
402,
5845,
1212,
69,
4453,
314,
282,
1017,
1425,
781,
3984,
6954,
267,
2418,
12680,
56,
275,
2853,
8,
18,
627,
664,
11976,
12680,
1469,
53,
8,
793,
576,
4589,
26828,
56,
401,
928,
3049,
12,
500,
3049,
430,
267,
2418,
12680,
57,
275,
2853,
8,
18,
627,
664,
11976,
12680,
1469,
53,
8,
793,
576,
4589,
26828,
57,
401,
928,
3049,
12,
500,
3049,
430,
267,
2418,
12680,
58,
275,
2853,
8,
18,
627,
664,
11976,
12680,
1469,
53,
8,
793,
576,
4589,
26828,
58,
401,
928,
3049,
12,
500,
3049,
430,
267,
340,
334,
1516,
12680,
56,
690,
282,
1017,
4709,
4874,
8195,
9,
503,
334,
1516,
12680,
57,
690,
282,
1017,
4709,
4874,
8195,
9,
503,
334,
1516,
12680,
58,
690,
282,
1017,
4709,
4874,
58,
304,
288,
291,
14,
1099,
14,
1205,
275,
23795,
14,
3694,
804,
14,
8784,
288,
291,
14,
1099,
14,
1205,
2209,
275,
298,
54,
1892,
1754,
4634,
4721,
334,
56,
2689,
14,
18,
9681,
12,
1488,
2689,
14,
18,
9681,
12,
3107,
2689,
14,
18,
9681,
2924,
450,
334,
1516,
12680,
56,
12,
1516,
12680,
57,
12,
1516,
12680,
58,
9,
267,
916,
334,
1516,
12680,
56,
690,
282,
1017,
4709,
22673,
8195,
9,
503,
334,
1516,
12680,
57,
690,
282,
1017,
4709,
22673,
8195,
9,
503,
334,
1516,
12680,
58,
690,
282,
1017,
4709,
22673,
58,
304,
288,
291,
14,
1099,
14,
1205,
275,
23795,
14,
3694,
804,
14,
17449,
288,
291,
14,
1099,
14,
1205,
2209,
275,
298,
54,
1892,
1754,
18023,
4721,
334,
56,
2689,
14,
18,
9681,
12,
1488,
2689,
14,
18,
9681,
12,
3107,
2689,
14,
18,
9681,
2924,
450,
334,
1516,
12680,
56,
12,
1516,
12680,
57,
12,
1516,
12680,
58,
9,
267,
587,
26,
288,
291,
14,
1099,
14,
1205,
275,
23795,
14,
3694,
804,
14,
17316,
36,
288,
291,
14,
1099,
14,
1205,
2209,
275,
298,
20652,
1321,
66,
1754,
1338,
334,
56,
2689,
14,
18,
9681,
12,
1488,
2689,
14,
18,
9681,
12,
3107,
2689,
14,
18,
9681,
2924,
450,
334,
1516,
12680,
56,
12,
1516,
12680,
57,
12,
1516,
12680,
58,
9,
13359,
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,
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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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
ryanj/origin
|
vendor/github.com/google/certificate-transparency/python/demo/vdb/verifiable_log.py
|
30
|
2096
|
import hashlib, base64
# Basic verifiable log, for demo purposes only
class VerifiableLog:
def __init__(self):
self._entries = []
self._cache = {}
def append(self, val):
self._entries.append(val)
def get_entries(self, start, end):
return self._entries[start:end + 1]
def get_tree_head(self, seq=None):
if seq is None:
seq = len(self._entries)
if seq > len(self._entries):
raise
return {
'tree_size': seq,
'sha256_root_hash': base64.b64encode(self._calc_mth(0, seq)) if seq else None,
}
def consistency_proof(self, first, second):
return [base64.b64encode(self._calc_mth(a, b)) for a, b in self._subproof(first, 0, second, True)]
def inclusion_proof(self, m, n):
return [base64.b64encode(self._calc_mth(a, b)) for a, b in self._path(m, 0, n)]
def _calc_mth(self, start, end):
k = '%i-%i' % (start, end)
rv = self._cache.get(k, None)
if not rv:
stack = []
tree_size = end - start
for idx, leaf in enumerate(self._entries[start:end]):
stack.append(hashlib.sha256(chr(0) + leaf).digest())
for _ in range(bin(idx).replace('b', '')[::-1].index('0') if idx + 1 < tree_size else len(stack) - 1):
stack[-2:] = [hashlib.sha256(chr(1) + stack[-2] + stack[-1]).digest()]
rv = stack[0]
self._cache[k] = rv
return rv
def _subproof(self, m, start_n, end_n, b):
n = end_n - start_n
if m == n:
if b:
return []
else:
return [(start_n, end_n)]
else:
k = 1 << (len(bin(n - 1)) - 3)
if m <= k:
return self._subproof(m, start_n, start_n + k, b) + [(start_n + k, end_n)]
else:
return self._subproof(m - k, start_n + k, end_n, False) + [(start_n, start_n + k)]
def _path(self, m, start_n, end_n):
n = end_n - start_n
if n == 1:
return []
else:
k = 1 << (len(bin(n - 1)) - 3)
if m < k:
return self._path(m, start_n, start_n + k) + [(start_n + k, end_n)]
else:
return self._path(m - k, start_n + k, end_n) + [(start_n, start_n + k)]
|
apache-2.0
|
[
646,
8337,
12,
1300,
772,
199,
199,
3,
10082,
809,
1903,
461,
943,
12,
367,
14779,
12901,
1454,
199,
533,
5444,
1903,
461,
2445,
26,
523,
347,
636,
826,
721,
277,
304,
272,
291,
423,
3189,
275,
942,
272,
291,
423,
1637,
275,
1052,
819,
347,
5666,
8,
277,
12,
1139,
304,
272,
291,
423,
3189,
14,
740,
8,
637,
9,
819,
347,
664,
63,
3189,
8,
277,
12,
1343,
12,
1284,
304,
272,
372,
291,
423,
3189,
59,
928,
26,
500,
435,
413,
61,
819,
347,
664,
63,
2350,
63,
2993,
8,
277,
12,
5412,
29,
403,
304,
272,
340,
5412,
365,
488,
26,
489,
5412,
275,
822,
8,
277,
423,
3189,
9,
272,
340,
5412,
690,
822,
8,
277,
423,
3189,
304,
489,
746,
272,
372,
469,
489,
283,
2350,
63,
890,
356,
5412,
12,
489,
283,
4835,
3912,
63,
1231,
63,
2227,
356,
1300,
772,
14,
66,
772,
2143,
8,
277,
423,
8104,
63,
77,
273,
8,
16,
12,
5412,
430,
340,
5412,
587,
488,
12,
272,
789,
819,
347,
17754,
63,
496,
1618,
8,
277,
12,
1642,
12,
3499,
304,
272,
372,
359,
1095,
772,
14,
66,
772,
2143,
8,
277,
423,
8104,
63,
77,
273,
8,
65,
12,
330,
430,
367,
282,
12,
330,
315,
291,
423,
954,
496,
1618,
8,
2246,
12,
378,
12,
3499,
12,
715,
1874,
819,
347,
20396,
63,
496,
1618,
8,
277,
12,
333,
12,
302,
304,
272,
372,
359,
1095,
772,
14,
66,
772,
2143,
8,
277,
423,
8104,
63,
77,
273,
8,
65,
12,
330,
430,
367,
282,
12,
330,
315,
291,
423,
515,
8,
77,
12,
378,
12,
302,
1874,
819,
347,
485,
8104,
63,
77,
273,
8,
277,
12,
1343,
12,
1284,
304,
272,
1022,
275,
1543,
73,
3295,
73,
7,
450,
334,
928,
12,
1284,
9,
272,
4336,
275,
291,
423,
1637,
14,
362,
8,
75,
12,
488,
9,
272,
340,
440,
4336,
26,
489,
3464,
275,
942,
489,
3123,
63,
890,
275,
1284,
446,
1343,
489,
367,
4280,
12,
11747,
315,
3874,
8,
277,
423,
3189,
59,
928,
26,
500,
4682,
267,
3464,
14,
740,
8,
24722,
14,
4835,
3912,
8,
10194,
8,
16,
9,
435,
11747,
680,
5671,
1012,
267,
367,
485,
315,
1425,
8,
1393,
8,
2996,
680,
1814,
360,
66,
297,
4074,
14172,
17,
1055,
1080,
360,
16,
358,
340,
4280,
435,
413,
665,
3123,
63,
890,
587,
822,
8,
2340,
9,
446,
413,
304,
881,
3464,
1988,
18,
2938,
275,
359,
24722,
14,
4835,
3912,
8,
10194,
8,
17,
9,
435,
3464,
1988,
18,
61,
435,
3464,
1988,
17,
6575,
5671,
5106,
489,
4336,
275,
3464,
59,
16,
61,
489,
291,
423,
1637,
59,
75,
61,
275,
4336,
272,
372,
4336,
819,
347,
485,
954,
496,
1618,
8,
277,
12,
333,
12,
1343,
63,
78,
12,
1284,
63,
78,
12,
330,
304,
272,
302,
275,
1284,
63,
78,
446,
1343,
63,
78,
272,
340,
333,
508,
302,
26,
489,
340,
330,
26,
267,
372,
942,
489,
587,
26,
267,
372,
3842,
928,
63,
78,
12,
1284,
63,
78,
1874,
272,
587,
26,
489,
1022,
275,
413,
5213,
334,
552,
8,
1393,
8,
78,
446,
413,
430,
446,
650,
9,
489,
340,
333,
2695,
1022,
26,
267,
372,
291,
423,
954,
496,
1618,
8,
77,
12,
1343,
63,
78,
12,
1343,
63,
78,
435,
1022,
12,
330,
9,
435,
3842,
928,
63,
78,
435,
1022,
12,
1284,
63,
78,
1874,
489,
587,
26,
267,
372,
291,
423,
954,
496,
1618,
8,
77,
446,
1022,
12,
1343,
63,
78,
435,
1022,
12,
1284,
63,
78,
12,
756,
9,
435,
3842,
928,
63,
78,
12,
1343,
63,
78,
435,
1022,
1874,
819,
347,
485,
515,
8,
277,
12,
333,
12,
1343,
63,
78,
12,
1284,
63,
78,
304,
272,
302,
275,
1284,
63,
78,
446,
1343,
63,
78,
272,
340,
302,
508,
413,
26,
489,
372,
942,
272,
587,
26,
489,
1022,
275,
413,
5213,
334,
552,
8,
1393,
8,
78,
446,
413,
430,
446,
650,
9,
489,
340,
333,
665,
1022,
26,
267,
372,
291,
423,
515,
8,
77,
12,
1343,
63,
78,
12,
1343,
63,
78,
435,
1022,
9,
435,
3842,
928,
63,
78,
435,
1022,
12,
1284,
63,
78,
1874,
489,
587,
26,
267,
372,
291,
423,
515,
8,
77,
446,
1022,
12,
1343,
63,
78,
435,
1022,
12,
1284,
63,
78,
9,
435,
3842,
928,
63,
78,
12,
1343,
63,
78,
435,
1022,
1874,
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
] |
[
8337,
12,
1300,
772,
199,
199,
3,
10082,
809,
1903,
461,
943,
12,
367,
14779,
12901,
1454,
199,
533,
5444,
1903,
461,
2445,
26,
523,
347,
636,
826,
721,
277,
304,
272,
291,
423,
3189,
275,
942,
272,
291,
423,
1637,
275,
1052,
819,
347,
5666,
8,
277,
12,
1139,
304,
272,
291,
423,
3189,
14,
740,
8,
637,
9,
819,
347,
664,
63,
3189,
8,
277,
12,
1343,
12,
1284,
304,
272,
372,
291,
423,
3189,
59,
928,
26,
500,
435,
413,
61,
819,
347,
664,
63,
2350,
63,
2993,
8,
277,
12,
5412,
29,
403,
304,
272,
340,
5412,
365,
488,
26,
489,
5412,
275,
822,
8,
277,
423,
3189,
9,
272,
340,
5412,
690,
822,
8,
277,
423,
3189,
304,
489,
746,
272,
372,
469,
489,
283,
2350,
63,
890,
356,
5412,
12,
489,
283,
4835,
3912,
63,
1231,
63,
2227,
356,
1300,
772,
14,
66,
772,
2143,
8,
277,
423,
8104,
63,
77,
273,
8,
16,
12,
5412,
430,
340,
5412,
587,
488,
12,
272,
789,
819,
347,
17754,
63,
496,
1618,
8,
277,
12,
1642,
12,
3499,
304,
272,
372,
359,
1095,
772,
14,
66,
772,
2143,
8,
277,
423,
8104,
63,
77,
273,
8,
65,
12,
330,
430,
367,
282,
12,
330,
315,
291,
423,
954,
496,
1618,
8,
2246,
12,
378,
12,
3499,
12,
715,
1874,
819,
347,
20396,
63,
496,
1618,
8,
277,
12,
333,
12,
302,
304,
272,
372,
359,
1095,
772,
14,
66,
772,
2143,
8,
277,
423,
8104,
63,
77,
273,
8,
65,
12,
330,
430,
367,
282,
12,
330,
315,
291,
423,
515,
8,
77,
12,
378,
12,
302,
1874,
819,
347,
485,
8104,
63,
77,
273,
8,
277,
12,
1343,
12,
1284,
304,
272,
1022,
275,
1543,
73,
3295,
73,
7,
450,
334,
928,
12,
1284,
9,
272,
4336,
275,
291,
423,
1637,
14,
362,
8,
75,
12,
488,
9,
272,
340,
440,
4336,
26,
489,
3464,
275,
942,
489,
3123,
63,
890,
275,
1284,
446,
1343,
489,
367,
4280,
12,
11747,
315,
3874,
8,
277,
423,
3189,
59,
928,
26,
500,
4682,
267,
3464,
14,
740,
8,
24722,
14,
4835,
3912,
8,
10194,
8,
16,
9,
435,
11747,
680,
5671,
1012,
267,
367,
485,
315,
1425,
8,
1393,
8,
2996,
680,
1814,
360,
66,
297,
4074,
14172,
17,
1055,
1080,
360,
16,
358,
340,
4280,
435,
413,
665,
3123,
63,
890,
587,
822,
8,
2340,
9,
446,
413,
304,
881,
3464,
1988,
18,
2938,
275,
359,
24722,
14,
4835,
3912,
8,
10194,
8,
17,
9,
435,
3464,
1988,
18,
61,
435,
3464,
1988,
17,
6575,
5671,
5106,
489,
4336,
275,
3464,
59,
16,
61,
489,
291,
423,
1637,
59,
75,
61,
275,
4336,
272,
372,
4336,
819,
347,
485,
954,
496,
1618,
8,
277,
12,
333,
12,
1343,
63,
78,
12,
1284,
63,
78,
12,
330,
304,
272,
302,
275,
1284,
63,
78,
446,
1343,
63,
78,
272,
340,
333,
508,
302,
26,
489,
340,
330,
26,
267,
372,
942,
489,
587,
26,
267,
372,
3842,
928,
63,
78,
12,
1284,
63,
78,
1874,
272,
587,
26,
489,
1022,
275,
413,
5213,
334,
552,
8,
1393,
8,
78,
446,
413,
430,
446,
650,
9,
489,
340,
333,
2695,
1022,
26,
267,
372,
291,
423,
954,
496,
1618,
8,
77,
12,
1343,
63,
78,
12,
1343,
63,
78,
435,
1022,
12,
330,
9,
435,
3842,
928,
63,
78,
435,
1022,
12,
1284,
63,
78,
1874,
489,
587,
26,
267,
372,
291,
423,
954,
496,
1618,
8,
77,
446,
1022,
12,
1343,
63,
78,
435,
1022,
12,
1284,
63,
78,
12,
756,
9,
435,
3842,
928,
63,
78,
12,
1343,
63,
78,
435,
1022,
1874,
819,
347,
485,
515,
8,
277,
12,
333,
12,
1343,
63,
78,
12,
1284,
63,
78,
304,
272,
302,
275,
1284,
63,
78,
446,
1343,
63,
78,
272,
340,
302,
508,
413,
26,
489,
372,
942,
272,
587,
26,
489,
1022,
275,
413,
5213,
334,
552,
8,
1393,
8,
78,
446,
413,
430,
446,
650,
9,
489,
340,
333,
665,
1022,
26,
267,
372,
291,
423,
515,
8,
77,
12,
1343,
63,
78,
12,
1343,
63,
78,
435,
1022,
9,
435,
3842,
928,
63,
78,
435,
1022,
12,
1284,
63,
78,
1874,
489,
587,
26,
267,
372,
291,
423,
515,
8,
77,
446,
1022,
12,
1343,
63,
78,
435,
1022,
12,
1284,
63,
78,
9,
435,
3842,
928,
63,
78,
12,
1343,
63,
78,
435,
1022,
1874,
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,
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
] |
seecr/meresco-harvester
|
test/datastoretest.py
|
1
|
2742
|
## begin license ##
#
# "Meresco Harvester" consists of two subsystems, namely an OAI-harvester and
# a web-control panel.
# "Meresco Harvester" is originally called "Sahara" and was developed for
# SURFnet by:
# Seek You Too B.V. (CQ2) http://www.cq2.nl
#
# Copyright (C) 2021 Seecr (Seek You Too B.V.) https://seecr.nl
# Copyright (C) 2021 The Netherlands Institute for Sound and Vision https://beeldengeluid.nl
#
# This file is part of "Meresco Harvester"
#
# "Meresco Harvester" 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.
#
# "Meresco Harvester" 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 "Meresco Harvester"; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
## end license ##
from seecr.test import SeecrTestCase
from meresco.harvester.datastore import DataStore, OldDataStore
class DataStoreTest(SeecrTestCase):
def setUp(self):
SeecrTestCase.setUp(self)
self.n = 0
def idfn():
self.n += 1
return 'mock:{}'.format(self.n)
self.store = DataStore(self.tempdir, id_fn=idfn)
def testData(self):
self.store.addData('mijnidentifier', 'datatype', {'mijn':'data'})
d = self.store.getData('mijnidentifier', 'datatype')
self.assertEqual({'mijn': 'data', '@id': 'mock:1'}, d)
d['mijn'] = 'andere data'
self.store.addData('mijnidentifier', 'datatype', d)
d = self.store.getData('mijnidentifier', 'datatype')
self.assertEqual({'mijn': 'andere data', '@id': 'mock:2', '@base': 'mock:1'}, d)
self.store.deleteData('mijnidentifier', 'datatype')
self.assertRaises(ValueError, lambda: self.store.getData('mijnidentifier', 'datatype'))
self.assertEqual({'mijn': 'andere data', '@id': 'mock:2', '@base': 'mock:1'}, self.store.getData('mijnidentifier', 'datatype', 'mock:2'))
def testListData(self):
self.store.addData('nr:1', 'datatype', {'mijn':'data'})
self.store.addData('nr:2', 'datatype', {'mijn':'data'})
self.store.addData('nr:3', 'other', {'mijn':'data'})
self.assertEqual(['nr:1', 'nr:2'], self.store.listForDatatype('datatype'))
def testGuid(self):
self.assertRaises(NotImplementedError, lambda: self.store.getGuid('someid'))
|
gpl-2.0
|
[
309,
5386,
4190,
925,
199,
3,
199,
3,
298,
1352,
470,
331,
25378,
26691,
2,
18581,
402,
2877,
1007,
19135,
12,
536,
590,
376,
593,
7730,
13,
8210,
26691,
436,
199,
3,
282,
3330,
13,
2785,
12748,
14,
199,
3,
298,
1352,
470,
331,
25378,
26691,
2,
365,
20657,
2797,
298,
12226,
27314,
2,
436,
1990,
477,
27813,
367,
199,
3,
428,
1230,
38,
846,
701,
26,
199,
3,
1666,
75,
2047,
22893,
699,
14,
54,
14,
334,
25370,
18,
9,
1455,
921,
1544,
14,
26853,
18,
14,
7530,
199,
3,
199,
3,
1898,
334,
35,
9,
499,
15385,
3240,
825,
82,
334,
19168,
2047,
22893,
699,
14,
54,
4959,
4178,
921,
261,
825,
82,
14,
7530,
199,
3,
1898,
334,
35,
9,
499,
15385,
710,
5612,
728,
31813,
1010,
25585,
367,
428,
1034,
436,
6561,
438,
4178,
921,
1235,
352,
848,
24920,
1535,
14,
7530,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
298,
1352,
470,
331,
25378,
26691,
2,
199,
3,
199,
3,
298,
1352,
470,
331,
25378,
26691,
2,
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,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
298,
1352,
470,
331,
25378,
26691,
2,
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,
298,
1352,
470,
331,
25378,
26691,
11436,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
1933,
12,
12066,
11844,
12,
8226,
12,
4828,
221,
11315,
13,
10067,
221,
8217,
199,
3,
199,
309,
1284,
4190,
925,
199,
199,
504,
542,
825,
82,
14,
396,
492,
3240,
825,
82,
1746,
199,
199,
504,
562,
470,
331,
14,
8210,
26691,
14,
11450,
492,
3918,
5502,
12,
21238,
1451,
5502,
199,
199,
533,
3918,
5502,
774,
8,
1513,
825,
82,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
3240,
825,
82,
1746,
14,
5996,
8,
277,
9,
267,
291,
14,
78,
275,
378,
267,
347,
1305,
2324,
837,
288,
291,
14,
78,
847,
413,
288,
372,
283,
1805,
26,
11123,
908,
8,
277,
14,
78,
9,
267,
291,
14,
1617,
275,
3918,
5502,
8,
277,
14,
11567,
12,
1305,
63,
2324,
29,
344,
2324,
9,
339,
347,
511,
1451,
8,
277,
304,
267,
291,
14,
1617,
14,
525,
1451,
360,
2664,
24016,
5364,
297,
283,
14184,
297,
791,
2664,
24016,
5242,
576,
3071,
267,
366,
275,
291,
14,
1617,
14,
29276,
360,
2664,
24016,
5364,
297,
283,
14184,
358,
267,
291,
14,
629,
3252,
2664,
24016,
356,
283,
576,
297,
10267,
344,
356,
283,
1805,
26,
17,
2267,
366,
9,
267,
366,
459,
2664,
24016,
418,
275,
283,
290,
271,
264,
666,
7,
267,
291,
14,
1617,
14,
525,
1451,
360,
2664,
24016,
5364,
297,
283,
14184,
297,
366,
9,
267,
366,
275,
291,
14,
1617,
14,
29276,
360,
2664,
24016,
5364,
297,
283,
14184,
358,
267,
291,
14,
629,
3252,
2664,
24016,
356,
283,
290,
271,
264,
666,
297,
10267,
344,
356,
283,
1805,
26,
18,
297,
10267,
1095,
356,
283,
1805,
26,
17,
2267,
366,
9,
267,
291,
14,
1617,
14,
1807,
1451,
360,
2664,
24016,
5364,
297,
283,
14184,
358,
267,
291,
14,
1855,
8,
3393,
12,
2400,
26,
291,
14,
1617,
14,
29276,
360,
2664,
24016,
5364,
297,
283,
14184,
1333,
267,
291,
14,
629,
3252,
2664,
24016,
356,
283,
290,
271,
264,
666,
297,
10267,
344,
356,
283,
1805,
26,
18,
297,
10267,
1095,
356,
283,
1805,
26,
17,
2267,
291,
14,
1617,
14,
29276,
360,
2664,
24016,
5364,
297,
283,
14184,
297,
283,
1805,
26,
18,
1333,
339,
347,
511,
1296,
1451,
8,
277,
304,
267,
291,
14,
1617,
14,
525,
1451,
360,
7865,
26,
17,
297,
283,
14184,
297,
791,
2664,
24016,
5242,
576,
3071,
267,
291,
14,
1617,
14,
525,
1451,
360,
7865,
26,
18,
297,
283,
14184,
297,
791,
2664,
24016,
5242,
576,
3071,
267,
291,
14,
1617,
14,
525,
1451,
360,
7865,
26,
19,
297,
283,
1848,
297,
791,
2664,
24016,
5242,
576,
3071,
267,
291,
14,
629,
2941,
7865,
26,
17,
297,
283,
7865,
26,
18,
995,
291,
14,
1617,
14,
513,
1858,
28369,
8588,
360,
14184,
1333,
339,
347,
511,
18834,
8,
277,
304,
267,
291,
14,
1855,
8,
18097,
12,
2400,
26,
291,
14,
1617,
14,
362,
18834,
360,
3972,
344,
1333,
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
] |
[
5386,
4190,
925,
199,
3,
199,
3,
298,
1352,
470,
331,
25378,
26691,
2,
18581,
402,
2877,
1007,
19135,
12,
536,
590,
376,
593,
7730,
13,
8210,
26691,
436,
199,
3,
282,
3330,
13,
2785,
12748,
14,
199,
3,
298,
1352,
470,
331,
25378,
26691,
2,
365,
20657,
2797,
298,
12226,
27314,
2,
436,
1990,
477,
27813,
367,
199,
3,
428,
1230,
38,
846,
701,
26,
199,
3,
1666,
75,
2047,
22893,
699,
14,
54,
14,
334,
25370,
18,
9,
1455,
921,
1544,
14,
26853,
18,
14,
7530,
199,
3,
199,
3,
1898,
334,
35,
9,
499,
15385,
3240,
825,
82,
334,
19168,
2047,
22893,
699,
14,
54,
4959,
4178,
921,
261,
825,
82,
14,
7530,
199,
3,
1898,
334,
35,
9,
499,
15385,
710,
5612,
728,
31813,
1010,
25585,
367,
428,
1034,
436,
6561,
438,
4178,
921,
1235,
352,
848,
24920,
1535,
14,
7530,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
298,
1352,
470,
331,
25378,
26691,
2,
199,
3,
199,
3,
298,
1352,
470,
331,
25378,
26691,
2,
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,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
298,
1352,
470,
331,
25378,
26691,
2,
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,
298,
1352,
470,
331,
25378,
26691,
11436,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
1933,
12,
12066,
11844,
12,
8226,
12,
4828,
221,
11315,
13,
10067,
221,
8217,
199,
3,
199,
309,
1284,
4190,
925,
199,
199,
504,
542,
825,
82,
14,
396,
492,
3240,
825,
82,
1746,
199,
199,
504,
562,
470,
331,
14,
8210,
26691,
14,
11450,
492,
3918,
5502,
12,
21238,
1451,
5502,
199,
199,
533,
3918,
5502,
774,
8,
1513,
825,
82,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
3240,
825,
82,
1746,
14,
5996,
8,
277,
9,
267,
291,
14,
78,
275,
378,
267,
347,
1305,
2324,
837,
288,
291,
14,
78,
847,
413,
288,
372,
283,
1805,
26,
11123,
908,
8,
277,
14,
78,
9,
267,
291,
14,
1617,
275,
3918,
5502,
8,
277,
14,
11567,
12,
1305,
63,
2324,
29,
344,
2324,
9,
339,
347,
511,
1451,
8,
277,
304,
267,
291,
14,
1617,
14,
525,
1451,
360,
2664,
24016,
5364,
297,
283,
14184,
297,
791,
2664,
24016,
5242,
576,
3071,
267,
366,
275,
291,
14,
1617,
14,
29276,
360,
2664,
24016,
5364,
297,
283,
14184,
358,
267,
291,
14,
629,
3252,
2664,
24016,
356,
283,
576,
297,
10267,
344,
356,
283,
1805,
26,
17,
2267,
366,
9,
267,
366,
459,
2664,
24016,
418,
275,
283,
290,
271,
264,
666,
7,
267,
291,
14,
1617,
14,
525,
1451,
360,
2664,
24016,
5364,
297,
283,
14184,
297,
366,
9,
267,
366,
275,
291,
14,
1617,
14,
29276,
360,
2664,
24016,
5364,
297,
283,
14184,
358,
267,
291,
14,
629,
3252,
2664,
24016,
356,
283,
290,
271,
264,
666,
297,
10267,
344,
356,
283,
1805,
26,
18,
297,
10267,
1095,
356,
283,
1805,
26,
17,
2267,
366,
9,
267,
291,
14,
1617,
14,
1807,
1451,
360,
2664,
24016,
5364,
297,
283,
14184,
358,
267,
291,
14,
1855,
8,
3393,
12,
2400,
26,
291,
14,
1617,
14,
29276,
360,
2664,
24016,
5364,
297,
283,
14184,
1333,
267,
291,
14,
629,
3252,
2664,
24016,
356,
283,
290,
271,
264,
666,
297,
10267,
344,
356,
283,
1805,
26,
18,
297,
10267,
1095,
356,
283,
1805,
26,
17,
2267,
291,
14,
1617,
14,
29276,
360,
2664,
24016,
5364,
297,
283,
14184,
297,
283,
1805,
26,
18,
1333,
339,
347,
511,
1296,
1451,
8,
277,
304,
267,
291,
14,
1617,
14,
525,
1451,
360,
7865,
26,
17,
297,
283,
14184,
297,
791,
2664,
24016,
5242,
576,
3071,
267,
291,
14,
1617,
14,
525,
1451,
360,
7865,
26,
18,
297,
283,
14184,
297,
791,
2664,
24016,
5242,
576,
3071,
267,
291,
14,
1617,
14,
525,
1451,
360,
7865,
26,
19,
297,
283,
1848,
297,
791,
2664,
24016,
5242,
576,
3071,
267,
291,
14,
629,
2941,
7865,
26,
17,
297,
283,
7865,
26,
18,
995,
291,
14,
1617,
14,
513,
1858,
28369,
8588,
360,
14184,
1333,
339,
347,
511,
18834,
8,
277,
304,
267,
291,
14,
1855,
8,
18097,
12,
2400,
26,
291,
14,
1617,
14,
362,
18834,
360,
3972,
344,
1333,
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,
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,
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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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
jasonzzz/ansible-modules-core
|
cloud/rackspace/rax_cdb_database.py
|
51
|
4856
|
#!/usr/bin/python -tt
# 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/>.
# This is a DOCUMENTATION stub specific to this module, it extends
# a documentation fragment located in ansible.utils.module_docs_fragments
DOCUMENTATION = '''
module: rax_cdb_database
short_description: 'create / delete a database in the Cloud Databases'
description:
- create / delete a database in the Cloud Databases.
version_added: "1.8"
options:
cdb_id:
description:
- The databases server UUID
default: null
name:
description:
- Name to give to the database
default: null
character_set:
description:
- Set of symbols and encodings
default: 'utf8'
collate:
description:
- Set of rules for comparing characters in a character set
default: 'utf8_general_ci'
state:
description:
- Indicate desired state of the resource
choices: ['present', 'absent']
default: present
author: "Simon JAILLET (@jails)"
extends_documentation_fragment: rackspace
'''
EXAMPLES = '''
- name: Build a database in Cloud Databases
tasks:
- name: Database build request
local_action:
module: rax_cdb_database
credentials: ~/.raxpub
region: IAD
cdb_id: 323e7ce0-9cb0-11e3-a5e2-0800200c9a66
name: db1
state: present
register: rax_db_database
'''
try:
import pyrax
HAS_PYRAX = True
except ImportError:
HAS_PYRAX = False
def find_database(instance, name):
try:
database = instance.get_database(name)
except Exception:
return False
return database
def save_database(module, cdb_id, name, character_set, collate):
cdb = pyrax.cloud_databases
try:
instance = cdb.get(cdb_id)
except Exception as e:
module.fail_json(msg='%s' % e.message)
changed = False
database = find_database(instance, name)
if not database:
try:
database = instance.create_database(name=name,
character_set=character_set,
collate=collate)
except Exception as e:
module.fail_json(msg='%s' % e.message)
else:
changed = True
module.exit_json(changed=changed, action='create',
database=rax_to_dict(database))
def delete_database(module, cdb_id, name):
cdb = pyrax.cloud_databases
try:
instance = cdb.get(cdb_id)
except Exception as e:
module.fail_json(msg='%s' % e.message)
changed = False
database = find_database(instance, name)
if database:
try:
database.delete()
except Exception as e:
module.fail_json(msg='%s' % e.message)
else:
changed = True
module.exit_json(changed=changed, action='delete',
database=rax_to_dict(database))
def rax_cdb_database(module, state, cdb_id, name, character_set, collate):
# act on the state
if state == 'present':
save_database(module, cdb_id, name, character_set, collate)
elif state == 'absent':
delete_database(module, cdb_id, name)
def main():
argument_spec = rax_argument_spec()
argument_spec.update(
dict(
cdb_id=dict(type='str', required=True),
name=dict(type='str', required=True),
character_set=dict(type='str', default='utf8'),
collate=dict(type='str', default='utf8_general_ci'),
state=dict(default='present', choices=['present', 'absent'])
)
)
module = AnsibleModule(
argument_spec=argument_spec,
required_together=rax_required_together(),
)
if not HAS_PYRAX:
module.fail_json(msg='pyrax is required for this module')
cdb_id = module.params.get('cdb_id')
name = module.params.get('name')
character_set = module.params.get('character_set')
collate = module.params.get('collate')
state = module.params.get('state')
setup_rax_module(module, pyrax)
rax_cdb_database(module, state, cdb_id, name, character_set, collate)
# import module snippets
from ansible.module_utils.basic import *
from ansible.module_utils.rax import *
# invoke the module
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
446,
6215,
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,
961,
365,
282,
29970,
2594,
10098,
2488,
370,
642,
859,
12,
652,
16879,
199,
3,
282,
3794,
7956,
16180,
315,
3242,
14,
1208,
14,
578,
63,
4757,
63,
18047,
199,
8948,
275,
1449,
199,
578,
26,
16937,
63,
24035,
63,
4659,
199,
3612,
63,
1802,
26,
283,
981,
1182,
3145,
282,
3050,
315,
314,
8142,
8692,
83,
7,
199,
1802,
26,
523,
446,
1218,
1182,
3145,
282,
3050,
315,
314,
8142,
8692,
83,
14,
199,
1023,
63,
3270,
26,
298,
17,
14,
24,
2,
199,
1419,
26,
523,
286,
697,
63,
344,
26,
272,
1369,
26,
489,
446,
710,
16219,
1654,
11134,
272,
849,
26,
2973,
523,
536,
26,
272,
1369,
26,
489,
446,
2812,
370,
8120,
370,
314,
3050,
272,
849,
26,
2973,
523,
4528,
63,
409,
26,
272,
1369,
26,
489,
446,
2494,
402,
6698,
436,
14134,
272,
849,
26,
283,
1624,
24,
7,
523,
1048,
750,
26,
272,
1369,
26,
489,
446,
2494,
402,
4713,
367,
20234,
4110,
315,
282,
4528,
663,
272,
849,
26,
283,
1624,
24,
63,
10706,
63,
559,
7,
523,
1174,
26,
272,
1369,
26,
489,
446,
1010,
10188,
6387,
1174,
402,
314,
2073,
272,
3415,
26,
788,
1881,
297,
283,
5575,
418,
272,
849,
26,
3451,
199,
2502,
26,
298,
7467,
265,
1603,
6593,
44,
775,
8593,
74,
1054,
83,
2924,
199,
11036,
63,
9970,
63,
7677,
26,
660,
346,
2638,
199,
2344,
199,
199,
8918,
275,
1449,
199,
13,
536,
26,
6516,
282,
3050,
315,
8142,
8692,
83,
523,
6527,
26,
272,
446,
536,
26,
8692,
1900,
1056,
489,
2257,
63,
1287,
26,
267,
859,
26,
16937,
63,
24035,
63,
4659,
267,
6235,
26,
25975,
14495,
5645,
267,
4897,
26,
473,
1554,
267,
286,
697,
63,
344,
26,
650,
1789,
69,
23,
301,
16,
13,
25,
2894,
16,
13,
845,
69,
19,
13,
65,
21,
69,
18,
13,
25822,
1840,
67,
25,
65,
1272,
267,
536,
26,
1592,
17,
267,
1174,
26,
3451,
489,
2274,
26,
16937,
63,
697,
63,
4659,
199,
2344,
199,
199,
893,
26,
272,
492,
23944,
272,
7509,
63,
4521,
2847,
56,
275,
715,
199,
2590,
3545,
26,
272,
7509,
63,
4521,
2847,
56,
275,
756,
421,
199,
318,
2342,
63,
4659,
8,
842,
12,
536,
304,
272,
862,
26,
267,
3050,
275,
1256,
14,
362,
63,
4659,
8,
354,
9,
272,
871,
2186,
26,
267,
372,
756,
339,
372,
3050,
421,
199,
318,
3354,
63,
4659,
8,
578,
12,
286,
697,
63,
344,
12,
536,
12,
4528,
63,
409,
12,
1048,
750,
304,
272,
286,
697,
275,
23944,
14,
4091,
63,
17439,
339,
862,
26,
267,
1256,
275,
286,
697,
14,
362,
8,
24035,
63,
344,
9,
272,
871,
2186,
465,
325,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
9569,
83,
7,
450,
325,
14,
1188,
9,
339,
2896,
275,
756,
339,
3050,
275,
2342,
63,
4659,
8,
842,
12,
536,
9,
339,
340,
440,
3050,
26,
267,
862,
26,
288,
3050,
275,
1256,
14,
981,
63,
4659,
8,
354,
29,
354,
12,
6059,
4528,
63,
409,
29,
10856,
63,
409,
12,
6059,
1048,
750,
29,
761,
750,
9,
267,
871,
2186,
465,
325,
26,
288,
859,
14,
1633,
63,
1001,
8,
1328,
9569,
83,
7,
450,
325,
14,
1188,
9,
267,
587,
26,
288,
2896,
275,
715,
339,
859,
14,
2224,
63,
1001,
8,
2489,
29,
2489,
12,
1595,
534,
981,
297,
2151,
3050,
29,
14495,
63,
475,
63,
807,
8,
4659,
430,
421,
199,
318,
3145,
63,
4659,
8,
578,
12,
286,
697,
63,
344,
12,
536,
304,
272,
286,
697,
275,
23944,
14,
4091,
63,
17439,
339,
862,
26,
267,
1256,
275,
286,
697,
14,
362,
8,
24035,
63,
344,
9,
272,
871,
2186,
465,
325,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
9569,
83,
7,
450,
325,
14,
1188,
9,
339,
2896,
275,
756,
339,
3050,
275,
2342,
63,
4659,
8,
842,
12,
536,
9,
339,
340,
3050,
26,
267,
862,
26,
288,
3050,
14,
1807,
342,
267,
871,
2186,
465,
325,
26,
288,
859,
14,
1633,
63,
1001,
8,
1328,
9569,
83,
7,
450,
325,
14,
1188,
9,
267,
587,
26,
288,
2896,
275,
715,
339,
859,
14,
2224,
63,
1001,
8,
2489,
29,
2489,
12,
1595,
534,
1807,
297,
2151,
3050,
29,
14495,
63,
475,
63,
807,
8,
4659,
430,
421,
199,
318,
16937,
63,
24035,
63,
4659,
8,
578,
12,
1174,
12,
286,
697,
63,
344,
12,
536,
12,
4528,
63,
409,
12,
1048,
750,
304,
339,
327,
2454,
641,
314,
1174,
272,
340,
1174,
508,
283,
1881,
356,
267,
3354,
63,
4659,
8,
578,
12,
286,
697,
63,
344,
12,
536,
12,
4528,
63,
409,
12,
1048,
750,
9,
272,
916,
1174,
508,
283,
5575,
356,
267,
3145,
63,
4659,
8,
578,
12,
286,
697,
63,
344,
12,
536,
9,
421,
199,
318,
2446,
837,
272,
1423,
63,
1650,
275,
16937,
63,
2094,
63,
1650,
342,
272,
1423,
63,
1650,
14,
873,
8,
267,
1211,
8,
288,
286,
697,
63,
344,
29,
807,
8,
466,
534,
495,
297,
1415,
29,
549,
395,
288,
536,
29,
807,
8,
466,
534,
495,
297,
1415,
29,
549,
395,
288,
4528,
63,
409,
29,
807
] |
[
2647,
15,
1393,
15,
1548,
446,
6215,
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,
961,
365,
282,
29970,
2594,
10098,
2488,
370,
642,
859,
12,
652,
16879,
199,
3,
282,
3794,
7956,
16180,
315,
3242,
14,
1208,
14,
578,
63,
4757,
63,
18047,
199,
8948,
275,
1449,
199,
578,
26,
16937,
63,
24035,
63,
4659,
199,
3612,
63,
1802,
26,
283,
981,
1182,
3145,
282,
3050,
315,
314,
8142,
8692,
83,
7,
199,
1802,
26,
523,
446,
1218,
1182,
3145,
282,
3050,
315,
314,
8142,
8692,
83,
14,
199,
1023,
63,
3270,
26,
298,
17,
14,
24,
2,
199,
1419,
26,
523,
286,
697,
63,
344,
26,
272,
1369,
26,
489,
446,
710,
16219,
1654,
11134,
272,
849,
26,
2973,
523,
536,
26,
272,
1369,
26,
489,
446,
2812,
370,
8120,
370,
314,
3050,
272,
849,
26,
2973,
523,
4528,
63,
409,
26,
272,
1369,
26,
489,
446,
2494,
402,
6698,
436,
14134,
272,
849,
26,
283,
1624,
24,
7,
523,
1048,
750,
26,
272,
1369,
26,
489,
446,
2494,
402,
4713,
367,
20234,
4110,
315,
282,
4528,
663,
272,
849,
26,
283,
1624,
24,
63,
10706,
63,
559,
7,
523,
1174,
26,
272,
1369,
26,
489,
446,
1010,
10188,
6387,
1174,
402,
314,
2073,
272,
3415,
26,
788,
1881,
297,
283,
5575,
418,
272,
849,
26,
3451,
199,
2502,
26,
298,
7467,
265,
1603,
6593,
44,
775,
8593,
74,
1054,
83,
2924,
199,
11036,
63,
9970,
63,
7677,
26,
660,
346,
2638,
199,
2344,
199,
199,
8918,
275,
1449,
199,
13,
536,
26,
6516,
282,
3050,
315,
8142,
8692,
83,
523,
6527,
26,
272,
446,
536,
26,
8692,
1900,
1056,
489,
2257,
63,
1287,
26,
267,
859,
26,
16937,
63,
24035,
63,
4659,
267,
6235,
26,
25975,
14495,
5645,
267,
4897,
26,
473,
1554,
267,
286,
697,
63,
344,
26,
650,
1789,
69,
23,
301,
16,
13,
25,
2894,
16,
13,
845,
69,
19,
13,
65,
21,
69,
18,
13,
25822,
1840,
67,
25,
65,
1272,
267,
536,
26,
1592,
17,
267,
1174,
26,
3451,
489,
2274,
26,
16937,
63,
697,
63,
4659,
199,
2344,
199,
199,
893,
26,
272,
492,
23944,
272,
7509,
63,
4521,
2847,
56,
275,
715,
199,
2590,
3545,
26,
272,
7509,
63,
4521,
2847,
56,
275,
756,
421,
199,
318,
2342,
63,
4659,
8,
842,
12,
536,
304,
272,
862,
26,
267,
3050,
275,
1256,
14,
362,
63,
4659,
8,
354,
9,
272,
871,
2186,
26,
267,
372,
756,
339,
372,
3050,
421,
199,
318,
3354,
63,
4659,
8,
578,
12,
286,
697,
63,
344,
12,
536,
12,
4528,
63,
409,
12,
1048,
750,
304,
272,
286,
697,
275,
23944,
14,
4091,
63,
17439,
339,
862,
26,
267,
1256,
275,
286,
697,
14,
362,
8,
24035,
63,
344,
9,
272,
871,
2186,
465,
325,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
9569,
83,
7,
450,
325,
14,
1188,
9,
339,
2896,
275,
756,
339,
3050,
275,
2342,
63,
4659,
8,
842,
12,
536,
9,
339,
340,
440,
3050,
26,
267,
862,
26,
288,
3050,
275,
1256,
14,
981,
63,
4659,
8,
354,
29,
354,
12,
6059,
4528,
63,
409,
29,
10856,
63,
409,
12,
6059,
1048,
750,
29,
761,
750,
9,
267,
871,
2186,
465,
325,
26,
288,
859,
14,
1633,
63,
1001,
8,
1328,
9569,
83,
7,
450,
325,
14,
1188,
9,
267,
587,
26,
288,
2896,
275,
715,
339,
859,
14,
2224,
63,
1001,
8,
2489,
29,
2489,
12,
1595,
534,
981,
297,
2151,
3050,
29,
14495,
63,
475,
63,
807,
8,
4659,
430,
421,
199,
318,
3145,
63,
4659,
8,
578,
12,
286,
697,
63,
344,
12,
536,
304,
272,
286,
697,
275,
23944,
14,
4091,
63,
17439,
339,
862,
26,
267,
1256,
275,
286,
697,
14,
362,
8,
24035,
63,
344,
9,
272,
871,
2186,
465,
325,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
9569,
83,
7,
450,
325,
14,
1188,
9,
339,
2896,
275,
756,
339,
3050,
275,
2342,
63,
4659,
8,
842,
12,
536,
9,
339,
340,
3050,
26,
267,
862,
26,
288,
3050,
14,
1807,
342,
267,
871,
2186,
465,
325,
26,
288,
859,
14,
1633,
63,
1001,
8,
1328,
9569,
83,
7,
450,
325,
14,
1188,
9,
267,
587,
26,
288,
2896,
275,
715,
339,
859,
14,
2224,
63,
1001,
8,
2489,
29,
2489,
12,
1595,
534,
1807,
297,
2151,
3050,
29,
14495,
63,
475,
63,
807,
8,
4659,
430,
421,
199,
318,
16937,
63,
24035,
63,
4659,
8,
578,
12,
1174,
12,
286,
697,
63,
344,
12,
536,
12,
4528,
63,
409,
12,
1048,
750,
304,
339,
327,
2454,
641,
314,
1174,
272,
340,
1174,
508,
283,
1881,
356,
267,
3354,
63,
4659,
8,
578,
12,
286,
697,
63,
344,
12,
536,
12,
4528,
63,
409,
12,
1048,
750,
9,
272,
916,
1174,
508,
283,
5575,
356,
267,
3145,
63,
4659,
8,
578,
12,
286,
697,
63,
344,
12,
536,
9,
421,
199,
318,
2446,
837,
272,
1423,
63,
1650,
275,
16937,
63,
2094,
63,
1650,
342,
272,
1423,
63,
1650,
14,
873,
8,
267,
1211,
8,
288,
286,
697,
63,
344,
29,
807,
8,
466,
534,
495,
297,
1415,
29,
549,
395,
288,
536,
29,
807,
8,
466,
534,
495,
297,
1415,
29,
549,
395,
288,
4528,
63,
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
1,
1,
1,
1,
1
] |
onecloud/neutron
|
neutron/openstack/common/lockutils.py
|
16
|
9941
|
# Copyright 2011 OpenStack Foundation.
# 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.
import contextlib
import errno
import functools
import os
import shutil
import subprocess
import sys
import tempfile
import threading
import time
import weakref
from oslo.config import cfg
from neutron.openstack.common import fileutils
from neutron.openstack.common.gettextutils import _
from neutron.openstack.common import local
from neutron.openstack.common import log as logging
LOG = logging.getLogger(__name__)
util_opts = [
cfg.BoolOpt('disable_process_locking', default=False,
help='Whether to disable inter-process locks'),
cfg.StrOpt('lock_path',
default=os.environ.get("NEUTRON_LOCK_PATH"),
help=('Directory to use for lock files.'))
]
CONF = cfg.CONF
CONF.register_opts(util_opts)
def set_defaults(lock_path):
cfg.set_defaults(util_opts, lock_path=lock_path)
class _InterProcessLock(object):
"""Lock implementation which allows multiple locks, working around
issues like bugs.debian.org/cgi-bin/bugreport.cgi?bug=632857 and does
not require any cleanup. Since the lock is always held on a file
descriptor rather than outside of the process, the lock gets dropped
automatically if the process crashes, even if __exit__ is not executed.
There are no guarantees regarding usage by multiple green threads in a
single process here. This lock works only between processes. Exclusive
access between local threads should be achieved using the semaphores
in the @synchronized decorator.
Note these locks are released when the descriptor is closed, so it's not
safe to close the file descriptor while another green thread holds the
lock. Just opening and closing the lock file can break synchronisation,
so lock files must be accessed only using this abstraction.
"""
def __init__(self, name):
self.lockfile = None
self.fname = name
def __enter__(self):
self.lockfile = open(self.fname, 'w')
while True:
try:
# Using non-blocking locks since green threads are not
# patched to deal with blocking locking calls.
# Also upon reading the MSDN docs for locking(), it seems
# to have a laughable 10 attempts "blocking" mechanism.
self.trylock()
return self
except IOError as e:
if e.errno in (errno.EACCES, errno.EAGAIN):
# external locks synchronise things like iptables
# updates - give it some time to prevent busy spinning
time.sleep(0.01)
else:
raise
def __exit__(self, exc_type, exc_val, exc_tb):
try:
self.unlock()
self.lockfile.close()
except IOError:
LOG.exception(_("Could not release the acquired lock `%s`"),
self.fname)
def trylock(self):
raise NotImplementedError()
def unlock(self):
raise NotImplementedError()
class _WindowsLock(_InterProcessLock):
def trylock(self):
msvcrt.locking(self.lockfile.fileno(), msvcrt.LK_NBLCK, 1)
def unlock(self):
msvcrt.locking(self.lockfile.fileno(), msvcrt.LK_UNLCK, 1)
class _PosixLock(_InterProcessLock):
def trylock(self):
fcntl.lockf(self.lockfile, fcntl.LOCK_EX | fcntl.LOCK_NB)
def unlock(self):
fcntl.lockf(self.lockfile, fcntl.LOCK_UN)
if os.name == 'nt':
import msvcrt
InterProcessLock = _WindowsLock
else:
import fcntl
InterProcessLock = _PosixLock
_semaphores = weakref.WeakValueDictionary()
_semaphores_lock = threading.Lock()
@contextlib.contextmanager
def lock(name, lock_file_prefix=None, external=False, lock_path=None):
"""Context based lock
This function yields a `threading.Semaphore` instance (if we don't use
eventlet.monkey_patch(), else `semaphore.Semaphore`) unless external is
True, in which case, it'll yield an InterProcessLock instance.
:param lock_file_prefix: The lock_file_prefix argument is used to provide
lock files on disk with a meaningful prefix.
:param external: The external keyword argument denotes whether this lock
should work across multiple processes. This means that if two different
workers both run a a method decorated with @synchronized('mylock',
external=True), only one of them will execute at a time.
:param lock_path: The lock_path keyword argument is used to specify a
special location for external lock files to live. If nothing is set, then
CONF.lock_path is used as a default.
"""
with _semaphores_lock:
try:
sem = _semaphores[name]
except KeyError:
sem = threading.Semaphore()
_semaphores[name] = sem
with sem:
LOG.debug(_('Got semaphore "%(lock)s"'), {'lock': name})
# NOTE(mikal): I know this looks odd
if not hasattr(local.strong_store, 'locks_held'):
local.strong_store.locks_held = []
local.strong_store.locks_held.append(name)
try:
if external and not CONF.disable_process_locking:
LOG.debug(_('Attempting to grab file lock "%(lock)s"'),
{'lock': name})
# We need a copy of lock_path because it is non-local
local_lock_path = lock_path or CONF.lock_path
if not local_lock_path:
raise cfg.RequiredOptError('lock_path')
if not os.path.exists(local_lock_path):
fileutils.ensure_tree(local_lock_path)
LOG.info(_('Created lock path: %s'), local_lock_path)
def add_prefix(name, prefix):
if not prefix:
return name
sep = '' if prefix.endswith('-') else '-'
return '%s%s%s' % (prefix, sep, name)
# NOTE(mikal): the lock name cannot contain directory
# separators
lock_file_name = add_prefix(name.replace(os.sep, '_'),
lock_file_prefix)
lock_file_path = os.path.join(local_lock_path, lock_file_name)
try:
lock = InterProcessLock(lock_file_path)
with lock as lock:
LOG.debug(_('Got file lock "%(lock)s" at %(path)s'),
{'lock': name, 'path': lock_file_path})
yield lock
finally:
LOG.debug(_('Released file lock "%(lock)s" at %(path)s'),
{'lock': name, 'path': lock_file_path})
else:
yield sem
finally:
local.strong_store.locks_held.remove(name)
def synchronized(name, lock_file_prefix=None, external=False, lock_path=None):
"""Synchronization decorator.
Decorating a method like so::
@synchronized('mylock')
def foo(self, *args):
...
ensures that only one thread will execute the foo method at a time.
Different methods can share the same lock::
@synchronized('mylock')
def foo(self, *args):
...
@synchronized('mylock')
def bar(self, *args):
...
This way only one of either foo or bar can be executing at a time.
"""
def wrap(f):
@functools.wraps(f)
def inner(*args, **kwargs):
try:
with lock(name, lock_file_prefix, external, lock_path):
LOG.debug(_('Got semaphore / lock "%(function)s"'),
{'function': f.__name__})
return f(*args, **kwargs)
finally:
LOG.debug(_('Semaphore / lock released "%(function)s"'),
{'function': f.__name__})
return inner
return wrap
def synchronized_with_prefix(lock_file_prefix):
"""Partial object generator for the synchronization decorator.
Redefine @synchronized in each project like so::
(in nova/utils.py)
from nova.openstack.common import lockutils
synchronized = lockutils.synchronized_with_prefix('nova-')
(in nova/foo.py)
from nova import utils
@utils.synchronized('mylock')
def bar(self, *args):
...
The lock_file_prefix argument is used to provide lock files on disk with a
meaningful prefix.
"""
return functools.partial(synchronized, lock_file_prefix=lock_file_prefix)
def main(argv):
"""Create a dir for locks and pass it to command from arguments
If you run this:
python -m openstack.common.lockutils python setup.py testr <etc>
a temporary directory will be created for all your locks and passed to all
your tests in an environment variable. The temporary dir will be deleted
afterwards and the return value will be preserved.
"""
lock_dir = tempfile.mkdtemp()
os.environ["NEUTRON_LOCK_PATH"] = lock_dir
try:
ret_val = subprocess.call(argv[1:])
finally:
shutil.rmtree(lock_dir, ignore_errors=True)
return ret_val
if __name__ == '__main__':
sys.exit(main(sys.argv))
|
apache-2.0
|
[
3,
1898,
7760,
14260,
2752,
14,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
421,
199,
646,
15502,
199,
646,
7554,
199,
646,
9143,
199,
646,
747,
199,
646,
5145,
199,
646,
3873,
199,
646,
984,
199,
646,
5549,
199,
646,
5796,
199,
646,
900,
199,
646,
13852,
199,
199,
504,
11258,
14,
888,
492,
4810,
199,
199,
504,
8224,
14,
8512,
14,
2330,
492,
570,
1208,
199,
504,
8224,
14,
8512,
14,
2330,
14,
5152,
1208,
492,
485,
199,
504,
8224,
14,
8512,
14,
2330,
492,
2257,
199,
504,
8224,
14,
8512,
14,
2330,
492,
943,
465,
2050,
421,
199,
4947,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
1974,
63,
3291,
275,
359,
272,
4810,
14,
10349,
9985,
360,
5993,
63,
1412,
63,
24056,
297,
849,
29,
797,
12,
355,
1720,
534,
26625,
370,
3507,
1640,
13,
1412,
23340,
659,
272,
4810,
14,
19340,
360,
831,
63,
515,
297,
2049,
849,
29,
736,
14,
2314,
14,
362,
480,
6388,
934,
12758,
63,
4406,
63,
3243,
1288,
2049,
1720,
7782,
6231,
370,
675,
367,
4650,
1584,
12459,
199,
61,
421,
199,
3103,
275,
4810,
14,
3103,
199,
3103,
14,
2683,
63,
3291,
8,
1974,
63,
3291,
9,
421,
199,
318,
663,
63,
4322,
8,
831,
63,
515,
304,
272,
4810,
14,
409,
63,
4322,
8,
1974,
63,
3291,
12,
4650,
63,
515,
29,
831,
63,
515,
9,
421,
199,
533,
485,
2620,
3498,
6432,
8,
785,
304,
272,
408,
6432,
4514,
1314,
6127,
3663,
23340,
12,
6449,
6818,
272,
10876,
2839,
18227,
14,
23204,
14,
1308,
15,
13814,
13,
1393,
15,
1266,
3070,
14,
13814,
31,
1266,
29,
22,
12870,
1641,
436,
1630,
272,
440,
4409,
1263,
9058,
14,
9336,
314,
4650,
365,
3544,
23608,
641,
282,
570,
272,
5872,
7830,
2419,
9682,
402,
314,
2112,
12,
314,
4650,
7545,
17481,
272,
5847,
340,
314,
2112,
2467,
9030,
12,
2755,
340,
636,
2224,
363,
365,
440,
7934,
14,
339,
6006,
787,
949,
12072,
397,
12602,
4503,
701,
3663,
12431,
7183,
315,
282,
272,
2849,
2112,
2348,
14,
961,
4650,
5419,
1454,
3382,
10358,
14,
1316,
6563,
272,
2879,
3382,
2257,
7183,
1077,
506,
22175,
1354,
1808,
314,
542,
16502,
470,
272,
315,
314,
768,
16473,
1759,
7531,
14,
339,
3390,
3520,
23340,
787,
14286,
1380,
314,
5872,
365,
6876,
12,
880,
652,
1159,
440,
272,
5048,
370,
4002,
314,
570,
5872,
1830,
4573,
12431,
2462,
15164,
314,
272,
4650,
14,
13870,
13618,
436,
11261,
314,
4650,
570,
883,
2059,
15354,
19914,
12,
272,
880,
4650,
1584,
1471,
506,
13810,
1454,
1808,
642,
2236,
29639,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
536,
304,
267,
291,
14,
26204,
275,
488,
267,
291,
14,
5252,
275,
536,
339,
347,
636,
4200,
721,
277,
304,
267,
291,
14,
26204,
275,
1551,
8,
277,
14,
5252,
12,
283,
87,
358,
398,
1830,
715,
26,
288,
862,
26,
355,
327,
11719,
2222,
13,
13091,
23340,
3967,
12431,
7183,
787,
440,
355,
327,
19483,
370,
7962,
543,
14592,
27267,
4882,
14,
355,
327,
6121,
12188,
7664,
314,
603,
3693,
46,
9149,
367,
27267,
1062,
652,
12237,
355,
327,
370,
1172,
282,
1127,
3080,
461,
1616,
12454,
298,
13091,
2,
14729,
14,
355,
291,
14,
893,
831,
342,
355,
372,
291,
288,
871,
5925,
465,
325,
26,
355,
340,
325,
14,
7931,
315,
334,
7931,
14,
37,
7372,
654,
12,
7554,
14,
37,
1254,
9021,
304,
490,
327,
5957,
23340,
15354,
572,
7645,
2839,
29458,
490,
327,
7029,
446,
8120,
652,
2005,
900,
370,
7981,
10414,
89,
20749,
1835,
490,
900,
14,
4532,
8,
16,
14,
614,
9,
355,
587,
26,
490,
746,
339,
347,
636,
2224,
721,
277,
12,
3178,
63,
466,
12,
3178,
63,
637,
12,
3178,
63,
5842,
304,
267,
862,
26,
288,
291,
14,
17966,
342,
288,
291,
14,
26204,
14,
1600,
342,
267,
871,
5925,
26,
288,
5051,
14,
1971,
6115,
6531,
440,
4683,
314,
28320,
4650,
18633,
83,
64,
1288,
2079,
291,
14,
5252,
9,
339,
347,
862,
831,
8,
277,
304,
267,
746,
4279,
342,
339,
347,
28451,
8,
277,
304,
267,
746,
4279,
342,
421,
199,
533,
485,
8647,
6432,
1547,
2620,
3498,
6432,
304,
272,
347,
862,
831,
8,
277,
304,
267,
31756,
14,
24056,
8,
277,
14,
26204,
14,
9843,
1062,
31756,
14,
44,
43,
63,
46,
7847,
2504,
12,
413,
9,
339,
347,
28451,
8,
277,
304,
267,
31756,
14,
24056,
8,
277,
14,
26204,
14,
9843,
1062,
31756,
14,
44,
43,
63,
1734,
44,
2504,
12,
413,
9,
421,
199,
533,
485,
1575,
4174,
6432,
1547,
2620,
3498,
6432,
304,
272,
347,
862,
831,
8,
277,
304,
267,
12871,
14,
831,
70,
8,
277,
14,
26204,
12,
12871,
14,
4406,
63,
1438,
1204,
12871,
14,
4406,
63,
16170,
9,
339,
347,
28451,
8,
277,
304,
267,
12871,
14,
831,
70,
8,
277,
14,
26204,
12,
12871,
14,
4406,
63,
1734,
9,
421,
199,
692,
747,
14,
354,
508,
283,
343,
356,
272,
492,
31756,
272,
6551,
3498,
6432,
275,
485,
8647,
6432,
199,
2836,
26,
272,
492,
12871,
272,
6551,
3498,
6432,
275,
485,
1575,
4174,
6432,
199,
199,
63,
261,
16502,
470,
275,
13852,
14,
18889,
1110,
11728,
342,
199,
63,
261,
16502,
470,
63,
831,
275,
5796,
14,
6432,
342,
421,
199,
32,
23464,
14,
14237,
199,
318,
4650,
8,
354,
12,
4650,
63,
493
] |
[
1898,
7760,
14260,
2752,
14,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
421,
199,
646,
15502,
199,
646,
7554,
199,
646,
9143,
199,
646,
747,
199,
646,
5145,
199,
646,
3873,
199,
646,
984,
199,
646,
5549,
199,
646,
5796,
199,
646,
900,
199,
646,
13852,
199,
199,
504,
11258,
14,
888,
492,
4810,
199,
199,
504,
8224,
14,
8512,
14,
2330,
492,
570,
1208,
199,
504,
8224,
14,
8512,
14,
2330,
14,
5152,
1208,
492,
485,
199,
504,
8224,
14,
8512,
14,
2330,
492,
2257,
199,
504,
8224,
14,
8512,
14,
2330,
492,
943,
465,
2050,
421,
199,
4947,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
1974,
63,
3291,
275,
359,
272,
4810,
14,
10349,
9985,
360,
5993,
63,
1412,
63,
24056,
297,
849,
29,
797,
12,
355,
1720,
534,
26625,
370,
3507,
1640,
13,
1412,
23340,
659,
272,
4810,
14,
19340,
360,
831,
63,
515,
297,
2049,
849,
29,
736,
14,
2314,
14,
362,
480,
6388,
934,
12758,
63,
4406,
63,
3243,
1288,
2049,
1720,
7782,
6231,
370,
675,
367,
4650,
1584,
12459,
199,
61,
421,
199,
3103,
275,
4810,
14,
3103,
199,
3103,
14,
2683,
63,
3291,
8,
1974,
63,
3291,
9,
421,
199,
318,
663,
63,
4322,
8,
831,
63,
515,
304,
272,
4810,
14,
409,
63,
4322,
8,
1974,
63,
3291,
12,
4650,
63,
515,
29,
831,
63,
515,
9,
421,
199,
533,
485,
2620,
3498,
6432,
8,
785,
304,
272,
408,
6432,
4514,
1314,
6127,
3663,
23340,
12,
6449,
6818,
272,
10876,
2839,
18227,
14,
23204,
14,
1308,
15,
13814,
13,
1393,
15,
1266,
3070,
14,
13814,
31,
1266,
29,
22,
12870,
1641,
436,
1630,
272,
440,
4409,
1263,
9058,
14,
9336,
314,
4650,
365,
3544,
23608,
641,
282,
570,
272,
5872,
7830,
2419,
9682,
402,
314,
2112,
12,
314,
4650,
7545,
17481,
272,
5847,
340,
314,
2112,
2467,
9030,
12,
2755,
340,
636,
2224,
363,
365,
440,
7934,
14,
339,
6006,
787,
949,
12072,
397,
12602,
4503,
701,
3663,
12431,
7183,
315,
282,
272,
2849,
2112,
2348,
14,
961,
4650,
5419,
1454,
3382,
10358,
14,
1316,
6563,
272,
2879,
3382,
2257,
7183,
1077,
506,
22175,
1354,
1808,
314,
542,
16502,
470,
272,
315,
314,
768,
16473,
1759,
7531,
14,
339,
3390,
3520,
23340,
787,
14286,
1380,
314,
5872,
365,
6876,
12,
880,
652,
1159,
440,
272,
5048,
370,
4002,
314,
570,
5872,
1830,
4573,
12431,
2462,
15164,
314,
272,
4650,
14,
13870,
13618,
436,
11261,
314,
4650,
570,
883,
2059,
15354,
19914,
12,
272,
880,
4650,
1584,
1471,
506,
13810,
1454,
1808,
642,
2236,
29639,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
536,
304,
267,
291,
14,
26204,
275,
488,
267,
291,
14,
5252,
275,
536,
339,
347,
636,
4200,
721,
277,
304,
267,
291,
14,
26204,
275,
1551,
8,
277,
14,
5252,
12,
283,
87,
358,
398,
1830,
715,
26,
288,
862,
26,
355,
327,
11719,
2222,
13,
13091,
23340,
3967,
12431,
7183,
787,
440,
355,
327,
19483,
370,
7962,
543,
14592,
27267,
4882,
14,
355,
327,
6121,
12188,
7664,
314,
603,
3693,
46,
9149,
367,
27267,
1062,
652,
12237,
355,
327,
370,
1172,
282,
1127,
3080,
461,
1616,
12454,
298,
13091,
2,
14729,
14,
355,
291,
14,
893,
831,
342,
355,
372,
291,
288,
871,
5925,
465,
325,
26,
355,
340,
325,
14,
7931,
315,
334,
7931,
14,
37,
7372,
654,
12,
7554,
14,
37,
1254,
9021,
304,
490,
327,
5957,
23340,
15354,
572,
7645,
2839,
29458,
490,
327,
7029,
446,
8120,
652,
2005,
900,
370,
7981,
10414,
89,
20749,
1835,
490,
900,
14,
4532,
8,
16,
14,
614,
9,
355,
587,
26,
490,
746,
339,
347,
636,
2224,
721,
277,
12,
3178,
63,
466,
12,
3178,
63,
637,
12,
3178,
63,
5842,
304,
267,
862,
26,
288,
291,
14,
17966,
342,
288,
291,
14,
26204,
14,
1600,
342,
267,
871,
5925,
26,
288,
5051,
14,
1971,
6115,
6531,
440,
4683,
314,
28320,
4650,
18633,
83,
64,
1288,
2079,
291,
14,
5252,
9,
339,
347,
862,
831,
8,
277,
304,
267,
746,
4279,
342,
339,
347,
28451,
8,
277,
304,
267,
746,
4279,
342,
421,
199,
533,
485,
8647,
6432,
1547,
2620,
3498,
6432,
304,
272,
347,
862,
831,
8,
277,
304,
267,
31756,
14,
24056,
8,
277,
14,
26204,
14,
9843,
1062,
31756,
14,
44,
43,
63,
46,
7847,
2504,
12,
413,
9,
339,
347,
28451,
8,
277,
304,
267,
31756,
14,
24056,
8,
277,
14,
26204,
14,
9843,
1062,
31756,
14,
44,
43,
63,
1734,
44,
2504,
12,
413,
9,
421,
199,
533,
485,
1575,
4174,
6432,
1547,
2620,
3498,
6432,
304,
272,
347,
862,
831,
8,
277,
304,
267,
12871,
14,
831,
70,
8,
277,
14,
26204,
12,
12871,
14,
4406,
63,
1438,
1204,
12871,
14,
4406,
63,
16170,
9,
339,
347,
28451,
8,
277,
304,
267,
12871,
14,
831,
70,
8,
277,
14,
26204,
12,
12871,
14,
4406,
63,
1734,
9,
421,
199,
692,
747,
14,
354,
508,
283,
343,
356,
272,
492,
31756,
272,
6551,
3498,
6432,
275,
485,
8647,
6432,
199,
2836,
26,
272,
492,
12871,
272,
6551,
3498,
6432,
275,
485,
1575,
4174,
6432,
199,
199,
63,
261,
16502,
470,
275,
13852,
14,
18889,
1110,
11728,
342,
199,
63,
261,
16502,
470,
63,
831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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
] |
tomersamara/InfoSec
|
HW4/assemble.py
|
1
|
1844
|
#!/usr/bin/python
import subprocess
ASSEMBLY_TEMPLATE = '''
.intel_syntax noprefix
.globl main
main:
%s
'''
ASSEMBLE = 'gcc -xassembler - -o /dev/stdout -m32 -nostdlib -emain -Xlinker --oformat=binary'
def run(command, stdin):
proc = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
stdout, stderr = proc.communicate(stdin)
if stderr:
raise RuntimeError(stderr)
return stdout
def assemble_data(data):
return run(ASSEMBLE, ASSEMBLY_TEMPLATE % data)
def assemble_file(path):
return assemble_data(open(path, 'rb').read())
def main(path=None, assembly=None, ascii=False):
try:
assembly = assemble_file(path) if path else assemble_data(assembly)
if ascii:
output = []
for c in assembly:
n = ord(c)
if n >= 0x80:
output.append('\x1b[31m\\x%02x\x1b[0m' % n)
else:
output.append('\\x%02x' % n)
print('"%s"' % ''.join(output))
else:
print(repr(assembly))
except RuntimeError as error:
print(error)
if __name__ == '__main__':
import os, sys
ascii = False
direct = False
if '--help' in sys.argv or len(sys.argv) < 2:
name = os.path.basename(sys.argv[0])
print('USAGE:')
print('\t%s [--ascii] <file>' % name)
print('\t%s [--ascii] --direct <assembly-str>' % name)
sys.exit(1)
for arg in sys.argv[1:-1]:
if arg == '--ascii':
ascii = True
elif arg == '--direct':
direct = True
else:
print('Ignoring unrecognized flag %s' % arg)
if direct:
main(assembly=sys.argv[-1], ascii=ascii)
else:
main(path=sys.argv[-1], ascii=ascii)
|
mit
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
199,
646,
3873,
421,
199,
1179,
899,
4567,
6084,
63,
7433,
275,
1449,
199,
14,
22264,
63,
7093,
302,
411,
264,
970,
199,
14,
6463,
76,
2446,
199,
973,
26,
199,
5,
83,
199,
2344,
421,
199,
1179,
899,
4567,
906,
275,
283,
13112,
446,
88,
21263,
82,
446,
446,
79,
1182,
2374,
15,
2703,
446,
77,
708,
446,
889,
28683,
446,
69,
973,
446,
56,
20311,
1553,
79,
908,
29,
3008,
7,
421,
199,
318,
1255,
8,
1531,
12,
9009,
304,
272,
6499,
275,
3873,
14,
7942,
8,
1531,
12,
9009,
29,
5781,
14,
6089,
12,
3839,
29,
5781,
14,
6089,
12,
4635,
29,
5781,
14,
6089,
12,
5218,
29,
549,
9,
272,
3839,
12,
4635,
275,
6499,
14,
10664,
8,
6626,
9,
272,
340,
4635,
26,
267,
746,
6064,
8,
3083,
9,
272,
372,
3839,
421,
199,
318,
22931,
63,
576,
8,
576,
304,
272,
372,
1255,
8,
1179,
899,
4567,
906,
12,
4319,
899,
4567,
6084,
63,
7433,
450,
666,
9,
16872,
199,
318,
22931,
63,
493,
8,
515,
304,
272,
372,
22931,
63,
576,
8,
1490,
8,
515,
12,
283,
4848,
1959,
739,
1012,
421,
199,
318,
2446,
8,
515,
29,
403,
12,
24869,
29,
403,
12,
13294,
29,
797,
304,
272,
862,
26,
267,
24869,
275,
22931,
63,
493,
8,
515,
9,
340,
931,
587,
22931,
63,
576,
8,
17828,
9,
267,
340,
13294,
26,
288,
1072,
275,
942,
288,
367,
286,
315,
24869,
26,
355,
302,
275,
6206,
8,
67,
9,
355,
340,
302,
2356,
378,
88,
1257,
26,
490,
1072,
14,
740,
2258,
88,
17,
66,
59,
2192,
77,
1103,
88,
5,
996,
88,
60,
88,
17,
66,
59,
16,
77,
7,
450,
302,
9,
355,
587,
26,
490,
1072,
14,
740,
11671,
88,
5,
996,
88,
7,
450,
302,
9,
288,
870,
32681,
83,
4507,
450,
6522,
904,
8,
1199,
430,
267,
587,
26,
288,
870,
8,
2722,
8,
17828,
430,
272,
871,
6064,
465,
1125,
26,
267,
870,
8,
705,
9,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
492,
747,
12,
984,
339,
13294,
275,
756,
272,
4125,
275,
756,
339,
340,
2850,
3437,
7,
315,
984,
14,
3020,
503,
822,
8,
1274,
14,
3020,
9,
665,
499,
26,
267,
536,
275,
747,
14,
515,
14,
4846,
8,
1274,
14,
3020,
59,
16,
566,
267,
870,
360,
20274,
10993,
267,
870,
2258,
84,
5,
83,
19344,
4371,
61,
665,
493,
3524,
450,
536,
9,
267,
870,
2258,
84,
5,
83,
19344,
4371,
61,
1553,
2275,
665,
17828,
13,
495,
3524,
450,
536,
9,
267,
984,
14,
2224,
8,
17,
9,
339,
367,
1680,
315,
984,
14,
3020,
59,
17,
6809,
17,
2189,
267,
340,
1680,
508,
2850,
4371,
356,
288,
13294,
275,
715,
267,
916,
1680,
508,
2850,
2275,
356,
288,
4125,
275,
715,
267,
587,
26,
288,
870,
360,
32390,
24718,
3305,
450,
83,
7,
450,
1680,
9,
339,
340,
4125,
26,
267,
2446,
8,
17828,
29,
1274,
14,
3020,
1988,
17,
467,
13294,
29,
4371,
9,
272,
587,
26,
267,
2446,
8,
515,
29,
1274,
14,
3020,
1988,
17,
467,
13294,
29,
4371,
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
] |
[
2647,
15,
1393,
15,
1548,
199,
199,
646,
3873,
421,
199,
1179,
899,
4567,
6084,
63,
7433,
275,
1449,
199,
14,
22264,
63,
7093,
302,
411,
264,
970,
199,
14,
6463,
76,
2446,
199,
973,
26,
199,
5,
83,
199,
2344,
421,
199,
1179,
899,
4567,
906,
275,
283,
13112,
446,
88,
21263,
82,
446,
446,
79,
1182,
2374,
15,
2703,
446,
77,
708,
446,
889,
28683,
446,
69,
973,
446,
56,
20311,
1553,
79,
908,
29,
3008,
7,
421,
199,
318,
1255,
8,
1531,
12,
9009,
304,
272,
6499,
275,
3873,
14,
7942,
8,
1531,
12,
9009,
29,
5781,
14,
6089,
12,
3839,
29,
5781,
14,
6089,
12,
4635,
29,
5781,
14,
6089,
12,
5218,
29,
549,
9,
272,
3839,
12,
4635,
275,
6499,
14,
10664,
8,
6626,
9,
272,
340,
4635,
26,
267,
746,
6064,
8,
3083,
9,
272,
372,
3839,
421,
199,
318,
22931,
63,
576,
8,
576,
304,
272,
372,
1255,
8,
1179,
899,
4567,
906,
12,
4319,
899,
4567,
6084,
63,
7433,
450,
666,
9,
16872,
199,
318,
22931,
63,
493,
8,
515,
304,
272,
372,
22931,
63,
576,
8,
1490,
8,
515,
12,
283,
4848,
1959,
739,
1012,
421,
199,
318,
2446,
8,
515,
29,
403,
12,
24869,
29,
403,
12,
13294,
29,
797,
304,
272,
862,
26,
267,
24869,
275,
22931,
63,
493,
8,
515,
9,
340,
931,
587,
22931,
63,
576,
8,
17828,
9,
267,
340,
13294,
26,
288,
1072,
275,
942,
288,
367,
286,
315,
24869,
26,
355,
302,
275,
6206,
8,
67,
9,
355,
340,
302,
2356,
378,
88,
1257,
26,
490,
1072,
14,
740,
2258,
88,
17,
66,
59,
2192,
77,
1103,
88,
5,
996,
88,
60,
88,
17,
66,
59,
16,
77,
7,
450,
302,
9,
355,
587,
26,
490,
1072,
14,
740,
11671,
88,
5,
996,
88,
7,
450,
302,
9,
288,
870,
32681,
83,
4507,
450,
6522,
904,
8,
1199,
430,
267,
587,
26,
288,
870,
8,
2722,
8,
17828,
430,
272,
871,
6064,
465,
1125,
26,
267,
870,
8,
705,
9,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
492,
747,
12,
984,
339,
13294,
275,
756,
272,
4125,
275,
756,
339,
340,
2850,
3437,
7,
315,
984,
14,
3020,
503,
822,
8,
1274,
14,
3020,
9,
665,
499,
26,
267,
536,
275,
747,
14,
515,
14,
4846,
8,
1274,
14,
3020,
59,
16,
566,
267,
870,
360,
20274,
10993,
267,
870,
2258,
84,
5,
83,
19344,
4371,
61,
665,
493,
3524,
450,
536,
9,
267,
870,
2258,
84,
5,
83,
19344,
4371,
61,
1553,
2275,
665,
17828,
13,
495,
3524,
450,
536,
9,
267,
984,
14,
2224,
8,
17,
9,
339,
367,
1680,
315,
984,
14,
3020,
59,
17,
6809,
17,
2189,
267,
340,
1680,
508,
2850,
4371,
356,
288,
13294,
275,
715,
267,
916,
1680,
508,
2850,
2275,
356,
288,
4125,
275,
715,
267,
587,
26,
288,
870,
360,
32390,
24718,
3305,
450,
83,
7,
450,
1680,
9,
339,
340,
4125,
26,
267,
2446,
8,
17828,
29,
1274,
14,
3020,
1988,
17,
467,
13294,
29,
4371,
9,
272,
587,
26,
267,
2446,
8,
515,
29,
1274,
14,
3020,
1988,
17,
467,
13294,
29,
4371,
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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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
] |
wisechengyi/pants
|
tests/python/pants_test/backend/jvm/tasks/jvm_compile/zinc/test_zinc_compile.py
|
1
|
2016
|
# Copyright 2020 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).
from pants.backend.jvm.targets.java_library import JavaLibrary
from pants.backend.jvm.tasks.jvm_compile.compile_context import CompileContext
from pants.backend.jvm.tasks.jvm_compile.zinc.zinc_compile import BaseZincCompile
from pants.testutil.jvm.jvm_tool_task_test_base import JvmToolTaskTestBase
from pants.util.contextutil import temporary_file_path
class ZincCompileTest(JvmToolTaskTestBase):
@classmethod
def task_type(cls):
return BaseZincCompile
def setUp(self):
super().setUp()
self.java_target = self.make_target(":java", target_type=JavaLibrary)
def get_task(self, specs=[]):
context = self.context(target_roots=[self.target(spec) for spec in specs])
task = self.create_task(context)
return task
def test_spaces_preservend_when_populating_zinc_args_product_from_argfile(self):
with temporary_file_path() as arg_file_path:
compile_contexts = {
self.java_target: CompileContext(
self.java_target,
analysis_file="",
classes_dir="",
jar_file="",
log_dir="",
args_file=arg_file_path,
sources=[],
post_compile_merge_dir="",
)
}
task = self.get_task()
args = ["-classpath", "a.jar:b.jar", "-C-Xplugin:some_javac_plugin with args"]
task.context.products.safe_create_data(
"zinc_args", init_func=lambda: {self.java_target: []}
)
task.write_argsfile(compile_contexts[self.java_target], args)
task.register_extra_products_from_contexts([self.java_target], compile_contexts)
zinc_args = task.context.products.get_data("zinc_args")[self.java_target]
assert args == zinc_args
|
apache-2.0
|
[
3,
1898,
25455,
510,
2285,
2199,
8417,
334,
3239,
6483,
14,
1064,
680,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
3239,
5113,
680,
421,
199,
504,
18081,
14,
4620,
14,
15813,
14,
4684,
14,
6138,
63,
4342,
492,
9586,
7424,
199,
504,
18081,
14,
4620,
14,
15813,
14,
5054,
14,
15813,
63,
2014,
14,
2014,
63,
1100,
492,
24562,
2998,
199,
504,
18081,
14,
4620,
14,
15813,
14,
5054,
14,
15813,
63,
2014,
14,
90,
6559,
14,
90,
6559,
63,
2014,
492,
3523,
58,
6559,
12626,
199,
504,
18081,
14,
396,
1974,
14,
15813,
14,
15813,
63,
3557,
63,
1765,
63,
396,
63,
1095,
492,
1603,
2611,
5157,
4476,
14440,
199,
504,
18081,
14,
1974,
14,
1100,
1974,
492,
7937,
63,
493,
63,
515,
421,
199,
533,
3107,
6559,
12626,
774,
8,
42,
2611,
5157,
4476,
14440,
304,
272,
768,
3744,
272,
347,
2120,
63,
466,
8,
1886,
304,
267,
372,
3523,
58,
6559,
12626,
339,
347,
3613,
8,
277,
304,
267,
1613,
1252,
5996,
342,
398,
291,
14,
6138,
63,
1375,
275,
291,
14,
1875,
63,
1375,
20308,
6138,
401,
1347,
63,
466,
29,
12576,
7424,
9,
339,
347,
664,
63,
1765,
8,
277,
12,
15941,
17894,
267,
1067,
275,
291,
14,
1100,
8,
1375,
63,
12065,
1524,
277,
14,
1375,
8,
1650,
9,
367,
3158,
315,
15941,
566,
267,
2120,
275,
291,
14,
981,
63,
1765,
8,
1100,
9,
267,
372,
2120,
339,
347,
511,
63,
10749,
63,
657,
7297,
500,
63,
6526,
63,
1935,
20529,
63,
90,
6559,
63,
589,
63,
2558,
63,
504,
63,
1273,
493,
8,
277,
304,
267,
543,
7937,
63,
493,
63,
515,
342,
465,
1680,
63,
493,
63,
515,
26,
288,
6555,
63,
19010,
275,
469,
355,
291,
14,
6138,
63,
1375,
26,
24562,
2998,
8,
490,
291,
14,
6138,
63,
1375,
12,
490,
11284,
63,
493,
8772,
490,
3992,
63,
694,
8772,
490,
16290,
63,
493,
8772,
490,
943,
63,
694,
8772,
490,
1249,
63,
493,
29,
1273,
63,
493,
63,
515,
12,
490,
5274,
6034,
490,
2963,
63,
2014,
63,
5628,
63,
694,
8772,
355,
776,
288,
789,
288,
2120,
275,
291,
14,
362,
63,
1765,
342,
288,
1249,
275,
16984,
26977,
401,
298,
65,
14,
7338,
26,
66,
14,
7338,
401,
3905,
35,
13,
56,
2718,
26,
3972,
63,
30738,
645,
63,
2718,
543,
1249,
937,
288,
2120,
14,
1100,
14,
13336,
14,
3489,
63,
981,
63,
576,
8,
355,
298,
90,
6559,
63,
589,
401,
4205,
63,
1532,
29,
2734,
26,
469,
277,
14,
6138,
63,
1375,
26,
23455,
288,
776,
288,
2120,
14,
952,
63,
589,
493,
8,
2014,
63,
19010,
59,
277,
14,
6138,
63,
1375,
467,
1249,
9,
288,
2120,
14,
2683,
63,
2911,
63,
13336,
63,
504,
63,
19010,
779,
277,
14,
6138,
63,
1375,
467,
6555,
63,
19010,
9,
288,
1315,
6559,
63,
589,
275,
2120,
14,
1100,
14,
13336,
14,
362,
63,
576,
480,
90,
6559,
63,
589,
9981,
277,
14,
6138,
63,
1375,
61,
288,
702,
1249,
508,
1315,
6559,
63,
589,
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
] |
[
1898,
25455,
510,
2285,
2199,
8417,
334,
3239,
6483,
14,
1064,
680,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
3239,
5113,
680,
421,
199,
504,
18081,
14,
4620,
14,
15813,
14,
4684,
14,
6138,
63,
4342,
492,
9586,
7424,
199,
504,
18081,
14,
4620,
14,
15813,
14,
5054,
14,
15813,
63,
2014,
14,
2014,
63,
1100,
492,
24562,
2998,
199,
504,
18081,
14,
4620,
14,
15813,
14,
5054,
14,
15813,
63,
2014,
14,
90,
6559,
14,
90,
6559,
63,
2014,
492,
3523,
58,
6559,
12626,
199,
504,
18081,
14,
396,
1974,
14,
15813,
14,
15813,
63,
3557,
63,
1765,
63,
396,
63,
1095,
492,
1603,
2611,
5157,
4476,
14440,
199,
504,
18081,
14,
1974,
14,
1100,
1974,
492,
7937,
63,
493,
63,
515,
421,
199,
533,
3107,
6559,
12626,
774,
8,
42,
2611,
5157,
4476,
14440,
304,
272,
768,
3744,
272,
347,
2120,
63,
466,
8,
1886,
304,
267,
372,
3523,
58,
6559,
12626,
339,
347,
3613,
8,
277,
304,
267,
1613,
1252,
5996,
342,
398,
291,
14,
6138,
63,
1375,
275,
291,
14,
1875,
63,
1375,
20308,
6138,
401,
1347,
63,
466,
29,
12576,
7424,
9,
339,
347,
664,
63,
1765,
8,
277,
12,
15941,
17894,
267,
1067,
275,
291,
14,
1100,
8,
1375,
63,
12065,
1524,
277,
14,
1375,
8,
1650,
9,
367,
3158,
315,
15941,
566,
267,
2120,
275,
291,
14,
981,
63,
1765,
8,
1100,
9,
267,
372,
2120,
339,
347,
511,
63,
10749,
63,
657,
7297,
500,
63,
6526,
63,
1935,
20529,
63,
90,
6559,
63,
589,
63,
2558,
63,
504,
63,
1273,
493,
8,
277,
304,
267,
543,
7937,
63,
493,
63,
515,
342,
465,
1680,
63,
493,
63,
515,
26,
288,
6555,
63,
19010,
275,
469,
355,
291,
14,
6138,
63,
1375,
26,
24562,
2998,
8,
490,
291,
14,
6138,
63,
1375,
12,
490,
11284,
63,
493,
8772,
490,
3992,
63,
694,
8772,
490,
16290,
63,
493,
8772,
490,
943,
63,
694,
8772,
490,
1249,
63,
493,
29,
1273,
63,
493,
63,
515,
12,
490,
5274,
6034,
490,
2963,
63,
2014,
63,
5628,
63,
694,
8772,
355,
776,
288,
789,
288,
2120,
275,
291,
14,
362,
63,
1765,
342,
288,
1249,
275,
16984,
26977,
401,
298,
65,
14,
7338,
26,
66,
14,
7338,
401,
3905,
35,
13,
56,
2718,
26,
3972,
63,
30738,
645,
63,
2718,
543,
1249,
937,
288,
2120,
14,
1100,
14,
13336,
14,
3489,
63,
981,
63,
576,
8,
355,
298,
90,
6559,
63,
589,
401,
4205,
63,
1532,
29,
2734,
26,
469,
277,
14,
6138,
63,
1375,
26,
23455,
288,
776,
288,
2120,
14,
952,
63,
589,
493,
8,
2014,
63,
19010,
59,
277,
14,
6138,
63,
1375,
467,
1249,
9,
288,
2120,
14,
2683,
63,
2911,
63,
13336,
63,
504,
63,
19010,
779,
277,
14,
6138,
63,
1375,
467,
6555,
63,
19010,
9,
288,
1315,
6559,
63,
589,
275,
2120,
14,
1100,
14,
13336,
14,
362,
63,
576,
480,
90,
6559,
63,
589,
9981,
277,
14,
6138,
63,
1375,
61,
288,
702,
1249,
508,
1315,
6559,
63,
589,
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,
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,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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
] |
pombredanne/pants
|
tests/python/pants_test/backend/jvm/tasks/jvm_compile/java/test_cache_compile_integration.py
|
1
|
9202
|
# coding=utf-8
# Copyright 2015 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).
from __future__ import (absolute_import, division, generators, nested_scopes, print_function,
unicode_literals, with_statement)
import os
from collections import namedtuple
from textwrap import dedent
from pants.backend.jvm.tasks.jvm_compile.zinc.zinc_compile import ZincCompile
from pants.base.build_environment import get_buildroot
from pants.util.contextutil import temporary_dir
from pants.util.dirutil import safe_mkdir, safe_open, safe_rmtree
from pants_test.backend.jvm.tasks.jvm_compile.base_compile_integration_test import BaseCompileIT
class Compile(namedtuple('Compile', ['srcfiles', 'config', 'artifact_count'])):
pass
class CacheCompileIntegrationTest(BaseCompileIT):
def run_compile(self, target_spec, config, workdir):
args = ['compile', target_spec]
pants_run = self.run_pants_with_workdir(args, workdir, config)
self.assert_success(pants_run)
def create_file(self, path, value):
with safe_open(path, 'w') as f:
f.write(value)
def test_transitive_invalid_target_is_dep(self):
with temporary_dir() as cache_dir, \
temporary_dir(root_dir=get_buildroot()) as src_dir:
config = {
'cache.compile.zinc': {'write_to': [cache_dir], 'read_from': [cache_dir]},
'compile.zinc': {'incremental_caching': True},
'java': {'strict_deps': False},
}
target_dir = os.path.join(src_dir, 'org', 'pantsbuild', 'cachetest')
a_srcfile = os.path.join(target_dir, 'A.java')
b_srcfile = os.path.join(target_dir, 'B.java')
c_srcfile = os.path.join(target_dir, 'C.java')
buildfile = os.path.join(target_dir, 'BUILD')
self.create_file(a_srcfile,
dedent("""package org.pantsbuild.cachetest;
class A {}
"""))
self.create_file(b_srcfile,
dedent("""package org.pantsbuild.cachetest;
class B {
A a;
}
"""))
self.create_file(c_srcfile,
dedent("""package org.pantsbuild.cachetest;
class C {
A a;
}
"""))
self.create_file(buildfile,
dedent("""
java_library(name='a',
sources=['A.java']
)
java_library(name='b',
sources=['B.java'],
dependencies=[':a']
)
java_library(name='c',
sources=['C.java'],
dependencies=[':b']
)
"""))
c_spec = os.path.join(os.path.basename(src_dir), 'org', 'pantsbuild',
'cachetest:c')
with self.temporary_workdir() as workdir:
self.run_compile(c_spec, config, workdir)
# clean workdir
# rm cache entries for a and b
cache_dir_entries = os.listdir(os.path.join(cache_dir))
zinc_dir = os.path.join(cache_dir, cache_dir_entries[0])
c_or_a_cache_dirs = [subdir for subdir in os.listdir(zinc_dir)
if subdir.endswith('cachetest.a') or subdir.endswith('cachetest.c')]
for subdir in c_or_a_cache_dirs:
safe_rmtree(os.path.join(zinc_dir, subdir))
# run compile
with self.temporary_workdir() as workdir:
self.run_compile(c_spec, config, workdir)
def test_stale_artifacts_rmd_when_cache_used_with_zinc(self):
with temporary_dir() as cache_dir, \
self.temporary_workdir() as workdir, \
temporary_dir(root_dir=get_buildroot()) as src_dir:
config = {
'cache.compile.zinc': {'write_to': [cache_dir], 'read_from': [cache_dir]},
'compile.zinc': {'incremental_caching': True },
}
srcfile = os.path.join(src_dir, 'org', 'pantsbuild', 'cachetest', 'A.java')
buildfile = os.path.join(src_dir, 'org', 'pantsbuild', 'cachetest', 'BUILD')
self.create_file(srcfile,
dedent("""package org.pantsbuild.cachetest;
class A {}
class Main {}"""))
self.create_file(buildfile,
dedent("""java_library(name='cachetest',
sources=['A.java']
)"""))
cachetest_spec = os.path.join(os.path.basename(src_dir), 'org', 'pantsbuild',
'cachetest:cachetest')
# Caches values A.class, Main.class
self.run_compile(cachetest_spec, config, workdir)
self.create_file(srcfile,
dedent("""package org.pantsbuild.cachetest;
class A {}
class NotMain {}"""))
# Caches values A.class, NotMain.class and leaves them on the filesystem
self.run_compile(cachetest_spec, config, workdir)
self.create_file(srcfile,
dedent("""package org.pantsbuild.cachetest;
class A {}
class Main {}"""))
# Should cause NotMain.class to be removed
self.run_compile(cachetest_spec, config, workdir)
root = os.path.join(workdir, 'compile', 'zinc')
task_versions = [p for p in os.listdir(root) if p != 'current']
self.assertEqual(len(task_versions), 1, 'Expected 1 task version.')
versioned_root = os.path.join(root, task_versions[0])
per_target_dirs = os.listdir(versioned_root)
self.assertEqual(len(per_target_dirs), 1, 'Expected 1 target.')
target_workdir_root = os.path.join(versioned_root, per_target_dirs[0])
target_workdirs = os.listdir(target_workdir_root)
self.assertEqual(len(target_workdirs), 3, 'Expected 3 workdirs (current, and two versioned).')
self.assertIn('current', target_workdirs)
def classfiles(d):
cd = os.path.join(target_workdir_root, d, 'classes', 'org', 'pantsbuild', 'cachetest')
return sorted(os.listdir(cd))
# One workdir should contain NotMain, and the other should contain Main.
self.assertEquals(sorted(classfiles(w) for w in target_workdirs if w != 'current'),
sorted([['A.class', 'Main.class'], ['A.class', 'NotMain.class']]))
def test_incremental_caching(self):
"""Tests that with --no-incremental-caching, we don't write incremental artifacts."""
srcfile = 'A.java'
def config(incremental_caching):
return { 'compile.zinc': {'incremental_caching': incremental_caching} }
self._do_test_caching(
Compile({srcfile: "class A {}"}, config(False), 1),
Compile({srcfile: "final class A {}"}, config(False), 1),
Compile({srcfile: "public final class A {}"}, config(True), 2),
)
def test_incremental(self):
"""Tests that with --no-incremental and --no-incremental-caching, we always write artifacts."""
srcfile = 'A.java'
config = {'compile.zinc': {'incremental': False, 'incremental_caching': False}}
self._do_test_caching(
Compile({srcfile: "class A {}"}, config, 1),
Compile({srcfile: "final class A {}"}, config, 2),
Compile({srcfile: "public final class A {}"}, config, 3),
)
def _do_test_caching(self, *compiles):
"""Tests that the given compiles within the same workspace produce the given artifact counts."""
with temporary_dir() as cache_dir, \
self.temporary_workdir() as workdir, \
temporary_dir(root_dir=get_buildroot()) as src_dir:
def complete_config(config):
# Clone the input config and add cache settings.
cache_settings = {'write_to': [cache_dir], 'read_from': [cache_dir]}
return dict(config.items() + [('cache.compile.zinc', cache_settings)])
buildfile = os.path.join(src_dir, 'BUILD')
spec = os.path.join(src_dir, ':cachetest')
artifact_dir = os.path.join(cache_dir,
ZincCompile.stable_name(),
'{}.cachetest'.format(os.path.basename(src_dir)))
for c in compiles:
# Clear the src directory and recreate the files.
safe_mkdir(src_dir, clean=True)
self.create_file(buildfile,
"""java_library(name='cachetest', sources=rglobs('*.java', '*.scala'))""")
for name, content in c.srcfiles.items():
self.create_file(os.path.join(src_dir, name), content)
# Compile, and confirm that we have the right count of artifacts.
self.run_compile(spec, complete_config(c.config), workdir)
self.assertEquals(c.artifact_count, len(os.listdir(artifact_dir)))
class CacheCompileIntegrationWithoutZjarsTest(CacheCompileIntegrationTest):
_EXTRA_TASK_ARGS = ['--no-compile-zinc-use-classpath-jars']
|
apache-2.0
|
[
3,
2803,
29,
1624,
13,
24,
199,
3,
1898,
6900,
510,
2285,
2199,
8417,
334,
3239,
6483,
14,
1064,
680,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
3239,
5113,
680,
199,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
16952,
12,
6032,
63,
14129,
12,
870,
63,
1593,
12,
717,
2649,
63,
5955,
12,
543,
63,
6242,
9,
199,
199,
646,
747,
199,
504,
5055,
492,
12863,
199,
504,
13390,
492,
22622,
199,
199,
504,
18081,
14,
4620,
14,
15813,
14,
5054,
14,
15813,
63,
2014,
14,
90,
6559,
14,
90,
6559,
63,
2014,
492,
3107,
6559,
12626,
199,
504,
18081,
14,
1095,
14,
1506,
63,
5418,
492,
664,
63,
1506,
1231,
199,
504,
18081,
14,
1974,
14,
1100,
1974,
492,
7937,
63,
694,
199,
504,
18081,
14,
1974,
14,
694,
1974,
492,
5048,
63,
8215,
12,
5048,
63,
1490,
12,
5048,
63,
9242,
199,
504,
18081,
63,
396,
14,
4620,
14,
15813,
14,
5054,
14,
15813,
63,
2014,
14,
1095,
63,
2014,
63,
15092,
63,
396,
492,
3523,
12626,
649,
421,
199,
533,
24562,
8,
18921,
360,
12626,
297,
788,
2164,
1725,
297,
283,
888,
297,
283,
16154,
63,
835,
26536,
523,
986,
421,
199,
533,
11977,
12626,
20405,
774,
8,
1563,
12626,
649,
304,
819,
347,
1255,
63,
2014,
8,
277,
12,
1347,
63,
1650,
12,
1101,
12,
1736,
694,
304,
272,
1249,
275,
788,
2014,
297,
1347,
63,
1650,
61,
272,
18081,
63,
1065,
275,
291,
14,
1065,
63,
21970,
63,
1045,
63,
19132,
8,
589,
12,
1736,
694,
12,
1101,
9,
272,
291,
14,
479,
63,
3742,
8,
21970,
63,
1065,
9,
819,
347,
1218,
63,
493,
8,
277,
12,
931,
12,
574,
304,
272,
543,
5048,
63,
1490,
8,
515,
12,
283,
87,
358,
465,
289,
26,
489,
289,
14,
952,
8,
585,
9,
819,
347,
511,
63,
3936,
3013,
63,
3197,
63,
1375,
63,
374,
63,
2601,
8,
277,
304,
272,
543,
7937,
63,
694,
342,
465,
2581,
63,
694,
12,
971,
489,
7937,
63,
694,
8,
1231,
63,
694,
29,
362,
63,
1506,
1231,
1012,
465,
2928,
63,
694,
26,
2541,
1101,
275,
469,
267,
283,
1637,
14,
2014,
14,
90,
6559,
356,
791,
952,
63,
475,
356,
359,
1637,
63,
694,
467,
283,
739,
63,
504,
356,
359,
1637,
63,
694,
13888,
267,
283,
2014,
14,
90,
6559,
356,
791,
23760,
63,
22738,
356,
715,
1386,
267,
283,
6138,
356,
791,
4768,
63,
5846,
356,
756,
1386,
489,
789,
489,
1347,
63,
694,
275,
747,
14,
515,
14,
904,
8,
2164,
63,
694,
12,
283,
1308,
297,
283,
21970,
1506,
297,
283,
1637,
396,
358,
489,
282,
63,
29903,
275,
747,
14,
515,
14,
904,
8,
1375,
63,
694,
12,
283,
33,
14,
6138,
358,
489,
330,
63,
29903,
275,
747,
14,
515,
14,
904,
8,
1375,
63,
694,
12,
283,
34,
14,
6138,
358,
489,
286,
63,
29903,
275,
747,
14,
515,
14,
904,
8,
1375,
63,
694,
12,
283,
35,
14,
6138,
358,
489,
1900,
493,
275,
747,
14,
515,
14,
904,
8,
1375,
63,
694,
12,
283,
8248,
358,
2541,
291,
14,
981,
63,
493,
8,
65,
63,
29903,
12,
2432,
22622,
4852,
2491,
5981,
14,
21970,
1506,
14,
1637,
396,
27,
2079,
1021,
437,
1052,
2079,
24072,
489,
291,
14,
981,
63,
493,
8,
66,
63,
29903,
12,
2432,
22622,
4852,
2491,
5981,
14,
21970,
1506,
14,
1637,
396,
27,
2079,
1021,
699,
469,
1169,
437,
282,
27,
2079,
789,
2079,
24072,
489,
291,
14,
981,
63,
493,
8,
67,
63,
29903,
12,
2432,
22622,
4852,
2491,
5981,
14,
21970,
1506,
14,
1637,
396,
27,
2079,
1021,
445,
469,
1169,
437,
282,
27,
2079,
789,
2079,
24072,
2541,
291,
14,
981,
63,
493,
8,
1506,
493,
12,
2432,
22622,
4852,
2079,
12120,
63,
4342,
8,
354,
534,
65,
297,
4318,
5274,
2968,
33,
14,
6138,
418,
2079,
776,
199,
2079,
12120,
63,
4342,
8,
354,
534,
66,
297,
4318,
5274,
2968,
34,
14,
6138,
995,
4318,
5124,
1524,
356,
65,
418,
2079,
776,
199,
2079,
12120,
63,
4342,
8,
354,
534,
67,
297,
4318,
5274,
2968,
35,
14,
6138,
995,
4318,
5124,
1524,
356,
66,
418,
2079,
776,
2079,
24072,
2541,
286,
63,
1650,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
4846,
8,
2164,
63,
694,
395,
283,
1308,
297,
283,
21970,
1506,
297,
2511,
283,
1637,
396,
26,
67,
358,
2541,
543,
291,
14,
13555,
63,
19132,
342,
465,
1736,
694,
26,
267,
291,
14,
1065,
63,
2014,
8,
67,
63,
1650,
12,
1101,
12,
1736,
694,
9,
489,
327,
3633,
1736,
694,
2541,
327,
14267,
2581,
4811,
367,
282,
436,
330,
489,
2581,
63,
694,
63,
3189,
275,
747,
14,
7374,
8,
736,
14,
515,
14,
904,
8,
1637,
63,
694,
430,
489,
1315,
6559,
63,
694,
275,
747,
14,
515,
14,
904,
8,
1637,
63,
694,
12,
2581,
63,
694,
63,
3189,
59,
16,
566,
489,
286,
63,
269,
63,
65,
63,
1637,
63,
3220,
275,
359,
10622,
367,
15488,
315,
747,
14,
7374,
8,
90,
6559,
63,
694,
9,
2574,
340,
15488,
14,
4130,
360,
1637,
396,
14,
65,
358,
503,
15488,
14,
4130,
360,
1637,
396,
14,
67,
5440,
489,
367,
15488,
315,
286,
63,
269,
63,
65,
63,
1637,
63,
3220,
26,
267,
5048,
63,
9242,
8,
736,
14,
515,
14,
904,
8,
90,
6559,
63,
694,
12,
15488,
430,
2541,
327,
1255,
6555,
489,
543,
291,
14,
13555,
63,
19132,
342,
465,
1736,
694,
26,
267,
291,
14,
1065,
63,
2014,
8,
67,
63,
1650,
12,
1101,
12,
1736,
694,
9,
819,
347,
511,
63,
20102,
63,
30129,
63,
82,
1064,
63,
6526,
63,
1637,
63,
2972,
63,
1045,
63,
90,
6559,
8,
277,
304,
272,
543,
7937,
63,
694,
342,
465,
2581,
63,
694,
12,
971,
267,
291,
14,
13555,
63,
19132,
342,
465,
1736,
694,
12,
971,
267,
7937,
63,
694,
8,
1231,
63,
694,
29,
362,
63,
1506,
1231,
1012,
465,
2928,
63,
694,
26,
2541,
1101,
275,
469,
267,
283,
1637,
14,
2014,
14,
90,
6559,
356,
791,
952,
63,
475,
356,
359,
1637,
63,
694
] |
[
2803,
29,
1624,
13,
24,
199,
3,
1898,
6900,
510,
2285,
2199,
8417,
334,
3239,
6483,
14,
1064,
680,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
3239,
5113,
680,
199,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
16952,
12,
6032,
63,
14129,
12,
870,
63,
1593,
12,
717,
2649,
63,
5955,
12,
543,
63,
6242,
9,
199,
199,
646,
747,
199,
504,
5055,
492,
12863,
199,
504,
13390,
492,
22622,
199,
199,
504,
18081,
14,
4620,
14,
15813,
14,
5054,
14,
15813,
63,
2014,
14,
90,
6559,
14,
90,
6559,
63,
2014,
492,
3107,
6559,
12626,
199,
504,
18081,
14,
1095,
14,
1506,
63,
5418,
492,
664,
63,
1506,
1231,
199,
504,
18081,
14,
1974,
14,
1100,
1974,
492,
7937,
63,
694,
199,
504,
18081,
14,
1974,
14,
694,
1974,
492,
5048,
63,
8215,
12,
5048,
63,
1490,
12,
5048,
63,
9242,
199,
504,
18081,
63,
396,
14,
4620,
14,
15813,
14,
5054,
14,
15813,
63,
2014,
14,
1095,
63,
2014,
63,
15092,
63,
396,
492,
3523,
12626,
649,
421,
199,
533,
24562,
8,
18921,
360,
12626,
297,
788,
2164,
1725,
297,
283,
888,
297,
283,
16154,
63,
835,
26536,
523,
986,
421,
199,
533,
11977,
12626,
20405,
774,
8,
1563,
12626,
649,
304,
819,
347,
1255,
63,
2014,
8,
277,
12,
1347,
63,
1650,
12,
1101,
12,
1736,
694,
304,
272,
1249,
275,
788,
2014,
297,
1347,
63,
1650,
61,
272,
18081,
63,
1065,
275,
291,
14,
1065,
63,
21970,
63,
1045,
63,
19132,
8,
589,
12,
1736,
694,
12,
1101,
9,
272,
291,
14,
479,
63,
3742,
8,
21970,
63,
1065,
9,
819,
347,
1218,
63,
493,
8,
277,
12,
931,
12,
574,
304,
272,
543,
5048,
63,
1490,
8,
515,
12,
283,
87,
358,
465,
289,
26,
489,
289,
14,
952,
8,
585,
9,
819,
347,
511,
63,
3936,
3013,
63,
3197,
63,
1375,
63,
374,
63,
2601,
8,
277,
304,
272,
543,
7937,
63,
694,
342,
465,
2581,
63,
694,
12,
971,
489,
7937,
63,
694,
8,
1231,
63,
694,
29,
362,
63,
1506,
1231,
1012,
465,
2928,
63,
694,
26,
2541,
1101,
275,
469,
267,
283,
1637,
14,
2014,
14,
90,
6559,
356,
791,
952,
63,
475,
356,
359,
1637,
63,
694,
467,
283,
739,
63,
504,
356,
359,
1637,
63,
694,
13888,
267,
283,
2014,
14,
90,
6559,
356,
791,
23760,
63,
22738,
356,
715,
1386,
267,
283,
6138,
356,
791,
4768,
63,
5846,
356,
756,
1386,
489,
789,
489,
1347,
63,
694,
275,
747,
14,
515,
14,
904,
8,
2164,
63,
694,
12,
283,
1308,
297,
283,
21970,
1506,
297,
283,
1637,
396,
358,
489,
282,
63,
29903,
275,
747,
14,
515,
14,
904,
8,
1375,
63,
694,
12,
283,
33,
14,
6138,
358,
489,
330,
63,
29903,
275,
747,
14,
515,
14,
904,
8,
1375,
63,
694,
12,
283,
34,
14,
6138,
358,
489,
286,
63,
29903,
275,
747,
14,
515,
14,
904,
8,
1375,
63,
694,
12,
283,
35,
14,
6138,
358,
489,
1900,
493,
275,
747,
14,
515,
14,
904,
8,
1375,
63,
694,
12,
283,
8248,
358,
2541,
291,
14,
981,
63,
493,
8,
65,
63,
29903,
12,
2432,
22622,
4852,
2491,
5981,
14,
21970,
1506,
14,
1637,
396,
27,
2079,
1021,
437,
1052,
2079,
24072,
489,
291,
14,
981,
63,
493,
8,
66,
63,
29903,
12,
2432,
22622,
4852,
2491,
5981,
14,
21970,
1506,
14,
1637,
396,
27,
2079,
1021,
699,
469,
1169,
437,
282,
27,
2079,
789,
2079,
24072,
489,
291,
14,
981,
63,
493,
8,
67,
63,
29903,
12,
2432,
22622,
4852,
2491,
5981,
14,
21970,
1506,
14,
1637,
396,
27,
2079,
1021,
445,
469,
1169,
437,
282,
27,
2079,
789,
2079,
24072,
2541,
291,
14,
981,
63,
493,
8,
1506,
493,
12,
2432,
22622,
4852,
2079,
12120,
63,
4342,
8,
354,
534,
65,
297,
4318,
5274,
2968,
33,
14,
6138,
418,
2079,
776,
199,
2079,
12120,
63,
4342,
8,
354,
534,
66,
297,
4318,
5274,
2968,
34,
14,
6138,
995,
4318,
5124,
1524,
356,
65,
418,
2079,
776,
199,
2079,
12120,
63,
4342,
8,
354,
534,
67,
297,
4318,
5274,
2968,
35,
14,
6138,
995,
4318,
5124,
1524,
356,
66,
418,
2079,
776,
2079,
24072,
2541,
286,
63,
1650,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
4846,
8,
2164,
63,
694,
395,
283,
1308,
297,
283,
21970,
1506,
297,
2511,
283,
1637,
396,
26,
67,
358,
2541,
543,
291,
14,
13555,
63,
19132,
342,
465,
1736,
694,
26,
267,
291,
14,
1065,
63,
2014,
8,
67,
63,
1650,
12,
1101,
12,
1736,
694,
9,
489,
327,
3633,
1736,
694,
2541,
327,
14267,
2581,
4811,
367,
282,
436,
330,
489,
2581,
63,
694,
63,
3189,
275,
747,
14,
7374,
8,
736,
14,
515,
14,
904,
8,
1637,
63,
694,
430,
489,
1315,
6559,
63,
694,
275,
747,
14,
515,
14,
904,
8,
1637,
63,
694,
12,
2581,
63,
694,
63,
3189,
59,
16,
566,
489,
286,
63,
269,
63,
65,
63,
1637,
63,
3220,
275,
359,
10622,
367,
15488,
315,
747,
14,
7374,
8,
90,
6559,
63,
694,
9,
2574,
340,
15488,
14,
4130,
360,
1637,
396,
14,
65,
358,
503,
15488,
14,
4130,
360,
1637,
396,
14,
67,
5440,
489,
367,
15488,
315,
286,
63,
269,
63,
65,
63,
1637,
63,
3220,
26,
267,
5048,
63,
9242,
8,
736,
14,
515,
14,
904,
8,
90,
6559,
63,
694,
12,
15488,
430,
2541,
327,
1255,
6555,
489,
543,
291,
14,
13555,
63,
19132,
342,
465,
1736,
694,
26,
267,
291,
14,
1065,
63,
2014,
8,
67,
63,
1650,
12,
1101,
12,
1736,
694,
9,
819,
347,
511,
63,
20102,
63,
30129,
63,
82,
1064,
63,
6526,
63,
1637,
63,
2972,
63,
1045,
63,
90,
6559,
8,
277,
304,
272,
543,
7937,
63,
694,
342,
465,
2581,
63,
694,
12,
971,
267,
291,
14,
13555,
63,
19132,
342,
465,
1736,
694,
12,
971,
267,
7937,
63,
694,
8,
1231,
63,
694,
29,
362,
63,
1506,
1231,
1012,
465,
2928,
63,
694,
26,
2541,
1101,
275,
469,
267,
283,
1637,
14,
2014,
14,
90,
6559,
356,
791,
952,
63,
475,
356,
359,
1637,
63,
694,
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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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
] |
40223104/2015cd_0512
|
static/Brython3.1.1-20150328-091302/Lib/browser/local_storage.py
|
617
|
2786
|
# local storage in browser
import sys
from javascript import JSObject
class __UnProvided():
pass
class LocalStorage():
storage_type = "local_storage"
def __init__(self):
if not sys.has_local_storage:
raise EnvironmentError("LocalStorage not available")
self.store = JSObject(__BRYTHON__.local_storage)
def __delitem__(self, key):
if (not isinstance(key, str)):
raise TypeError("key must be string")
if key not in self:
raise KeyError(key)
self.store.removeItem(key)
def __getitem__(self, key):
if (not isinstance(key, str)):
raise TypeError("key must be string")
res = __BRYTHON__.JSObject(self.store.getItem(key))
if res:
return res
raise KeyError(key)
def __setitem__(self, key, value):
if (not isinstance(key, str)):
raise TypeError("key must be string")
if (not isinstance(value, str)):
raise TypeError("value must be string")
self.store.setItem(key, value)
# implement "in" functionality
def __contains__(self, key):
if (not isinstance(key, str)):
raise TypeError("key must be string")
res = __BRYTHON__.JSObject(self.store.getItem(key))
if res is None:
return False
return True
def __iter__(self):
keys = self.keys()
return keys.__iter__()
def get(self, key, default=None):
if (not isinstance(key, str)):
raise TypeError("key must be string")
return __BRYTHON__.JSObject(self.store.getItem(key)) or default
def pop(self, key, default=__UnProvided()):
if (not isinstance(key, str)):
raise TypeError("key must be string")
if type(default) is __UnProvided:
ret = self.get(key)
del self[key] # will throw key error if doesn't exist
return ret
else:
if key in self:
ret = self.get(key)
del self[key]
return ret
else:
return default
# while a real dict provides a view, returning a generator would less helpful than simply returning a list
# and creating a custom iterator is overkill and would likely result in slower performance
def keys(self):
return [__BRYTHON__.JSObject(self.store.key(i)) for i in range(self.store.length)]
def values(self):
return [__BRYTHON__.JSObject(self.__getitem__(k)) for k in self.keys()]
def items(self):
return list(zip(self.keys(), self.values()))
def clear(self):
self.store.clear()
def __len__(self):
return self.store.length
if sys.has_local_storage:
storage = LocalStorage()
|
agpl-3.0
|
[
3,
2257,
4887,
315,
7042,
199,
646,
984,
199,
504,
18910,
492,
18001,
1692,
199,
199,
533,
636,
1358,
919,
11923,
837,
272,
986,
199,
199,
533,
10111,
6408,
837,
272,
4887,
63,
466,
275,
298,
1832,
63,
3494,
2,
339,
347,
636,
826,
721,
277,
304,
267,
340,
440,
984,
14,
1989,
63,
1832,
63,
3494,
26,
288,
746,
25139,
480,
5339,
6408,
440,
2808,
531,
267,
291,
14,
1617,
275,
18001,
1692,
3460,
34,
5782,
8472,
4343,
1832,
63,
3494,
9,
339,
347,
636,
13228,
721,
277,
12,
790,
304,
267,
340,
334,
1397,
1228,
8,
498,
12,
620,
2298,
288,
746,
3146,
480,
498,
1471,
506,
1059,
531,
267,
340,
790,
440,
315,
291,
26,
288,
746,
4067,
8,
498,
9,
267,
291,
14,
1617,
14,
2168,
2081,
8,
498,
9,
339,
347,
636,
6095,
721,
277,
12,
790,
304,
267,
340,
334,
1397,
1228,
8,
498,
12,
620,
2298,
288,
746,
3146,
480,
498,
1471,
506,
1059,
531,
267,
522,
275,
636,
34,
5782,
8472,
4343,
11378,
1692,
8,
277,
14,
1617,
14,
362,
2081,
8,
498,
430,
267,
340,
522,
26,
288,
372,
522,
267,
746,
4067,
8,
498,
9,
339,
347,
636,
8617,
721,
277,
12,
790,
12,
574,
304,
267,
340,
334,
1397,
1228,
8,
498,
12,
620,
2298,
288,
746,
3146,
480,
498,
1471,
506,
1059,
531,
267,
340,
334,
1397,
1228,
8,
585,
12,
620,
2298,
288,
746,
3146,
480,
585,
1471,
506,
1059,
531,
267,
291,
14,
1617,
14,
29135,
8,
498,
12,
574,
9,
339,
327,
5669,
298,
262,
2,
9330,
272,
347,
636,
6134,
721,
277,
12,
790,
304,
267,
340,
334,
1397,
1228,
8,
498,
12,
620,
2298,
288,
746,
3146,
480,
498,
1471,
506,
1059,
531,
267,
522,
275,
636,
34,
5782,
8472,
4343,
11378,
1692,
8,
277,
14,
1617,
14,
362,
2081,
8,
498,
430,
267,
340,
522,
365,
488,
26,
288,
372,
756,
267,
372,
715,
339,
347,
636,
1661,
721,
277,
304,
267,
2883,
275,
291,
14,
1612,
342,
267,
372,
2883,
855,
1661,
4533,
339,
347,
664,
8,
277,
12,
790,
12,
849,
29,
403,
304,
267,
340,
334,
1397,
1228,
8,
498,
12,
620,
2298,
288,
746,
3146,
480,
498,
1471,
506,
1059,
531,
267,
372,
636,
34,
5782,
8472,
4343,
11378,
1692,
8,
277,
14,
1617,
14,
362,
2081,
8,
498,
430,
503,
849,
339,
347,
4560,
8,
277,
12,
790,
12,
849,
18971,
1358,
919,
11923,
5109,
267,
340,
334,
1397,
1228,
8,
498,
12,
620,
2298,
288,
746,
3146,
480,
498,
1471,
506,
1059,
531,
267,
340,
730,
8,
885,
9,
365,
636,
1358,
919,
11923,
26,
288,
2203,
275,
291,
14,
362,
8,
498,
9,
288,
2150,
291,
59,
498,
61,
221,
327,
911,
7978,
790,
1125,
340,
3181,
1133,
2187,
288,
372,
2203,
267,
587,
26,
288,
340,
790,
315,
291,
26,
355,
2203,
275,
291,
14,
362,
8,
498,
9,
355,
2150,
291,
59,
498,
61,
355,
372,
2203,
288,
587,
26,
355,
372,
849,
339,
327,
1830,
282,
3363,
1211,
6571,
282,
2455,
12,
8152,
282,
4306,
3955,
6656,
24606,
2419,
9329,
8152,
282,
769,
272,
327,
436,
6425,
282,
3537,
6122,
365,
1806,
8997,
436,
3955,
12060,
754,
315,
26200,
10238,
272,
347,
2883,
8,
277,
304,
267,
372,
359,
363,
34,
5782,
8472,
4343,
11378,
1692,
8,
277,
14,
1617,
14,
498,
8,
73,
430,
367,
284,
315,
1425,
8,
277,
14,
1617,
14,
1267,
1874,
339,
347,
1338,
8,
277,
304,
267,
372,
359,
363,
34,
5782,
8472,
4343,
11378,
1692,
8,
277,
855,
6095,
721,
75,
430,
367,
1022,
315,
291,
14,
1612,
5106,
339,
347,
2974,
8,
277,
304,
267,
372,
769,
8,
3065,
8,
277,
14,
1612,
1062,
291,
14,
1459,
4059,
339,
347,
5436,
8,
277,
304,
267,
291,
14,
1617,
14,
3584,
342,
339,
347,
636,
552,
721,
277,
304,
267,
372,
291,
14,
1617,
14,
1267,
199,
199,
692,
984,
14,
1989,
63,
1832,
63,
3494,
26,
272,
4887,
275,
10111,
6408,
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
] |
[
2257,
4887,
315,
7042,
199,
646,
984,
199,
504,
18910,
492,
18001,
1692,
199,
199,
533,
636,
1358,
919,
11923,
837,
272,
986,
199,
199,
533,
10111,
6408,
837,
272,
4887,
63,
466,
275,
298,
1832,
63,
3494,
2,
339,
347,
636,
826,
721,
277,
304,
267,
340,
440,
984,
14,
1989,
63,
1832,
63,
3494,
26,
288,
746,
25139,
480,
5339,
6408,
440,
2808,
531,
267,
291,
14,
1617,
275,
18001,
1692,
3460,
34,
5782,
8472,
4343,
1832,
63,
3494,
9,
339,
347,
636,
13228,
721,
277,
12,
790,
304,
267,
340,
334,
1397,
1228,
8,
498,
12,
620,
2298,
288,
746,
3146,
480,
498,
1471,
506,
1059,
531,
267,
340,
790,
440,
315,
291,
26,
288,
746,
4067,
8,
498,
9,
267,
291,
14,
1617,
14,
2168,
2081,
8,
498,
9,
339,
347,
636,
6095,
721,
277,
12,
790,
304,
267,
340,
334,
1397,
1228,
8,
498,
12,
620,
2298,
288,
746,
3146,
480,
498,
1471,
506,
1059,
531,
267,
522,
275,
636,
34,
5782,
8472,
4343,
11378,
1692,
8,
277,
14,
1617,
14,
362,
2081,
8,
498,
430,
267,
340,
522,
26,
288,
372,
522,
267,
746,
4067,
8,
498,
9,
339,
347,
636,
8617,
721,
277,
12,
790,
12,
574,
304,
267,
340,
334,
1397,
1228,
8,
498,
12,
620,
2298,
288,
746,
3146,
480,
498,
1471,
506,
1059,
531,
267,
340,
334,
1397,
1228,
8,
585,
12,
620,
2298,
288,
746,
3146,
480,
585,
1471,
506,
1059,
531,
267,
291,
14,
1617,
14,
29135,
8,
498,
12,
574,
9,
339,
327,
5669,
298,
262,
2,
9330,
272,
347,
636,
6134,
721,
277,
12,
790,
304,
267,
340,
334,
1397,
1228,
8,
498,
12,
620,
2298,
288,
746,
3146,
480,
498,
1471,
506,
1059,
531,
267,
522,
275,
636,
34,
5782,
8472,
4343,
11378,
1692,
8,
277,
14,
1617,
14,
362,
2081,
8,
498,
430,
267,
340,
522,
365,
488,
26,
288,
372,
756,
267,
372,
715,
339,
347,
636,
1661,
721,
277,
304,
267,
2883,
275,
291,
14,
1612,
342,
267,
372,
2883,
855,
1661,
4533,
339,
347,
664,
8,
277,
12,
790,
12,
849,
29,
403,
304,
267,
340,
334,
1397,
1228,
8,
498,
12,
620,
2298,
288,
746,
3146,
480,
498,
1471,
506,
1059,
531,
267,
372,
636,
34,
5782,
8472,
4343,
11378,
1692,
8,
277,
14,
1617,
14,
362,
2081,
8,
498,
430,
503,
849,
339,
347,
4560,
8,
277,
12,
790,
12,
849,
18971,
1358,
919,
11923,
5109,
267,
340,
334,
1397,
1228,
8,
498,
12,
620,
2298,
288,
746,
3146,
480,
498,
1471,
506,
1059,
531,
267,
340,
730,
8,
885,
9,
365,
636,
1358,
919,
11923,
26,
288,
2203,
275,
291,
14,
362,
8,
498,
9,
288,
2150,
291,
59,
498,
61,
221,
327,
911,
7978,
790,
1125,
340,
3181,
1133,
2187,
288,
372,
2203,
267,
587,
26,
288,
340,
790,
315,
291,
26,
355,
2203,
275,
291,
14,
362,
8,
498,
9,
355,
2150,
291,
59,
498,
61,
355,
372,
2203,
288,
587,
26,
355,
372,
849,
339,
327,
1830,
282,
3363,
1211,
6571,
282,
2455,
12,
8152,
282,
4306,
3955,
6656,
24606,
2419,
9329,
8152,
282,
769,
272,
327,
436,
6425,
282,
3537,
6122,
365,
1806,
8997,
436,
3955,
12060,
754,
315,
26200,
10238,
272,
347,
2883,
8,
277,
304,
267,
372,
359,
363,
34,
5782,
8472,
4343,
11378,
1692,
8,
277,
14,
1617,
14,
498,
8,
73,
430,
367,
284,
315,
1425,
8,
277,
14,
1617,
14,
1267,
1874,
339,
347,
1338,
8,
277,
304,
267,
372,
359,
363,
34,
5782,
8472,
4343,
11378,
1692,
8,
277,
855,
6095,
721,
75,
430,
367,
1022,
315,
291,
14,
1612,
5106,
339,
347,
2974,
8,
277,
304,
267,
372,
769,
8,
3065,
8,
277,
14,
1612,
1062,
291,
14,
1459,
4059,
339,
347,
5436,
8,
277,
304,
267,
291,
14,
1617,
14,
3584,
342,
339,
347,
636,
552,
721,
277,
304,
267,
372,
291,
14,
1617,
14,
1267,
199,
199,
692,
984,
14,
1989,
63,
1832,
63,
3494,
26,
272,
4887,
275,
10111,
6408,
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,
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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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
] |
mlperf/training_results_v0.7
|
Google/benchmarks/maskrcnn/implementations/maskrcnn-research-TF-tpu-v4-512/object_detection/preprocessor.py
|
2
|
17746
|
# 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.
# ==============================================================================
"""Preprocess images and bounding boxes for detection.
We perform two sets of operations in preprocessing stage:
(a) operations that are applied to both training and testing data,
(b) operations that are applied only to training data for the purpose of
data augmentation.
A preprocessing function receives a set of inputs,
e.g. an image and bounding boxes,
performs an operation on them, and returns them.
Some examples are: randomly cropping the image, randomly mirroring the image,
randomly changing the brightness, contrast, hue and
randomly jittering the bounding boxes.
The image is a rank 4 tensor: [1, height, width, channels] with
dtype=tf.float32. The groundtruth_boxes is a rank 2 tensor: [N, 4] where
in each row there is a box with [ymin xmin ymax xmax].
Boxes are in normalized coordinates meaning
their coordinate values range in [0, 1]
Important Note: In tensor_dict, images is a rank 4 tensor, but preprocessing
functions receive a rank 3 tensor for processing the image. Thus, inside the
preprocess function we squeeze the image to become a rank 3 tensor and then
we pass it to the functions. At the end of the preprocess we expand the image
back to rank 4.
"""
import tensorflow.compat.v1 as tf
from REDACTED.mask_rcnn.object_detection import box_list
def _flip_boxes_left_right(boxes):
"""Left-right flip the boxes.
Args:
boxes: rank 2 float32 tensor containing the bounding boxes -> [N, 4].
Boxes are in normalized form meaning their coordinates vary
between [0, 1].
Each row is in the form of [ymin, xmin, ymax, xmax].
Returns:
Flipped boxes.
"""
ymin, xmin, ymax, xmax = tf.split(value=boxes, num_or_size_splits=4, axis=1)
flipped_xmin = tf.subtract(1.0, xmax)
flipped_xmax = tf.subtract(1.0, xmin)
flipped_boxes = tf.concat([ymin, flipped_xmin, ymax, flipped_xmax], 1)
return flipped_boxes
def _flip_masks_left_right(masks):
"""Left-right flip masks.
Args:
masks: rank 3 float32 tensor with shape
[num_instances, height, width] representing instance masks.
Returns:
flipped masks: rank 3 float32 tensor with shape
[num_instances, height, width] representing instance masks.
"""
return masks[:, :, ::-1]
def keypoint_flip_horizontal(keypoints, flip_point, flip_permutation,
scope=None):
"""Flips the keypoints horizontally around the flip_point.
This operation flips the x coordinate for each keypoint around the flip_point
and also permutes the keypoints in a manner specified by flip_permutation.
Args:
keypoints: a tensor of shape [num_instances, num_keypoints, 2]
flip_point: (float) scalar tensor representing the x coordinate to flip the
keypoints around.
flip_permutation: rank 1 int32 tensor containing the keypoint flip
permutation. This specifies the mapping from original keypoint indices
to the flipped keypoint indices. This is used primarily for keypoints
that are not reflection invariant. E.g. Suppose there are 3 keypoints
representing ['head', 'right_eye', 'left_eye'], then a logical choice for
flip_permutation might be [0, 2, 1] since we want to swap the 'left_eye'
and 'right_eye' after a horizontal flip.
scope: name scope.
Returns:
new_keypoints: a tensor of shape [num_instances, num_keypoints, 2]
"""
with tf.name_scope(scope, 'FlipHorizontal'):
keypoints = tf.transpose(keypoints, [1, 0, 2])
keypoints = tf.gather(keypoints, flip_permutation)
v, u = tf.split(value=keypoints, num_or_size_splits=2, axis=2)
u = flip_point * 2.0 - u
new_keypoints = tf.concat([v, u], 2)
new_keypoints = tf.transpose(new_keypoints, [1, 0, 2])
return new_keypoints
def random_horizontal_flip(image,
boxes=None,
masks=None,
keypoints=None,
keypoint_flip_permutation=None,
seed=None):
"""Randomly flips the image and detections horizontally.
The probability of flipping the image is 50%.
Args:
image: rank 3 float32 tensor with shape [height, width, channels].
boxes: (optional) rank 2 float32 tensor with shape [N, 4]
containing the bounding boxes.
Boxes are in normalized form meaning their coordinates vary
between [0, 1].
Each row is in the form of [ymin, xmin, ymax, xmax].
masks: (optional) rank 3 float32 tensor with shape
[num_instances, height, width] containing instance masks. The masks
are of the same height, width as the input `image`.
keypoints: (optional) rank 3 float32 tensor with shape
[num_instances, num_keypoints, 2]. The keypoints are in y-x
normalized coordinates.
keypoint_flip_permutation: rank 1 int32 tensor containing the keypoint flip
permutation.
seed: random seed
Returns:
image: image which is the same shape as input image.
If boxes, masks, keypoints, and keypoint_flip_permutation are not None,
the function also returns the following tensors.
boxes: rank 2 float32 tensor containing the bounding boxes -> [N, 4].
Boxes are in normalized form meaning their coordinates vary
between [0, 1].
masks: rank 3 float32 tensor with shape [num_instances, height, width]
containing instance masks.
keypoints: rank 3 float32 tensor with shape
[num_instances, num_keypoints, 2]
Raises:
ValueError: if keypoints are provided but keypoint_flip_permutation is not.
"""
def _flip_image(image):
# flip image
image_flipped = tf.image.flip_left_right(image)
return image_flipped
if keypoints is not None and keypoint_flip_permutation is None:
raise ValueError(
'keypoints are provided but keypoints_flip_permutation is not provided')
with tf.name_scope('RandomHorizontalFlip', values=[image, boxes]):
result = []
# random variable defining whether to do flip or not
do_a_flip_random = tf.greater(tf.random_uniform([], seed=seed), 0.5)
# flip image
image = tf.cond(do_a_flip_random, lambda: _flip_image(image), lambda: image)
result.append(image)
# flip boxes
if boxes is not None:
boxes = tf.cond(do_a_flip_random, lambda: _flip_boxes_left_right(boxes),
lambda: boxes)
result.append(boxes)
# flip masks
if masks is not None:
masks = tf.cond(do_a_flip_random, lambda: _flip_masks_left_right(masks),
lambda: masks)
result.append(masks)
# flip keypoints
if keypoints is not None and keypoint_flip_permutation is not None:
permutation = keypoint_flip_permutation
keypoints = tf.cond(
do_a_flip_random,
lambda: keypoint_flip_horizontal(keypoints, 0.5, permutation),
lambda: keypoints)
result.append(keypoints)
return tuple(result)
def _compute_new_static_size(image, min_dimension, max_dimension):
"""Compute new static shape for resize_to_range method."""
image_shape = image.get_shape().as_list()
orig_height = image_shape[0]
orig_width = image_shape[1]
num_channels = image_shape[2]
orig_min_dim = min(orig_height, orig_width)
# Calculates the larger of the possible sizes
large_scale_factor = min_dimension / float(orig_min_dim)
# Scaling orig_(height|width) by large_scale_factor will make the smaller
# dimension equal to min_dimension, save for floating point rounding errors.
# For reasonably-sized images, taking the nearest integer will reliably
# eliminate this error.
large_height = int(round(orig_height * large_scale_factor))
large_width = int(round(orig_width * large_scale_factor))
large_size = [large_height, large_width]
if max_dimension:
# Calculates the smaller of the possible sizes, use that if the larger
# is too big.
orig_max_dim = max(orig_height, orig_width)
small_scale_factor = max_dimension / float(orig_max_dim)
# Scaling orig_(height|width) by small_scale_factor will make the larger
# dimension equal to max_dimension, save for floating point rounding
# errors. For reasonably-sized images, taking the nearest integer will
# reliably eliminate this error.
small_height = int(round(orig_height * small_scale_factor))
small_width = int(round(orig_width * small_scale_factor))
small_size = [small_height, small_width]
new_size = large_size
if max(large_size) > max_dimension:
new_size = small_size
else:
new_size = large_size
return tf.constant(new_size + [num_channels])
def _compute_new_dynamic_size(image, min_dimension, max_dimension):
"""Compute new dynamic shape for resize_to_range method."""
image_shape = tf.shape(image)
orig_height = tf.to_float(image_shape[0])
orig_width = tf.to_float(image_shape[1])
num_channels = image_shape[2]
orig_min_dim = tf.minimum(orig_height, orig_width)
# Calculates the larger of the possible sizes
min_dimension = tf.constant(min_dimension, dtype=tf.float32)
large_scale_factor = min_dimension / orig_min_dim
# Scaling orig_(height|width) by large_scale_factor will make the smaller
# dimension equal to min_dimension, save for floating point rounding errors.
# For reasonably-sized images, taking the nearest integer will reliably
# eliminate this error.
large_height = tf.to_int32(tf.round(orig_height * large_scale_factor))
large_width = tf.to_int32(tf.round(orig_width * large_scale_factor))
large_size = tf.stack([large_height, large_width])
if max_dimension:
# Calculates the smaller of the possible sizes, use that if the larger
# is too big.
orig_max_dim = tf.maximum(orig_height, orig_width)
max_dimension = tf.constant(max_dimension, dtype=tf.float32)
small_scale_factor = max_dimension / orig_max_dim
# Scaling orig_(height|width) by small_scale_factor will make the larger
# dimension equal to max_dimension, save for floating point rounding
# errors. For reasonably-sized images, taking the nearest integer will
# reliably eliminate this error.
small_height = tf.to_int32(tf.round(orig_height * small_scale_factor))
small_width = tf.to_int32(tf.round(orig_width * small_scale_factor))
small_size = tf.stack([small_height, small_width])
new_size = tf.cond(
tf.to_float(tf.reduce_max(large_size)) > max_dimension,
lambda: small_size, lambda: large_size)
else:
new_size = large_size
return tf.stack(tf.unstack(new_size) + [num_channels])
def resize_to_range(image,
masks=None,
min_dimension=None,
max_dimension=None,
method=tf.image.ResizeMethod.BILINEAR,
align_corners=False,
pad_to_max_dimension=False):
"""Resizes an image so its dimensions are within the provided value.
The output size can be described by two cases:
1. If the image can be rescaled so its minimum dimension is equal to the
provided value without the other dimension exceeding max_dimension,
then do so.
2. Otherwise, resize so the largest dimension is equal to max_dimension.
Args:
image: A 3D tensor of shape [height, width, channels]
masks: (optional) rank 3 float32 tensor with shape
[num_instances, height, width] containing instance masks.
min_dimension: (optional) (scalar) desired size of the smaller image
dimension.
max_dimension: (optional) (scalar) maximum allowed size
of the larger image dimension.
method: (optional) interpolation method used in resizing. Defaults to
BILINEAR.
align_corners: bool. If true, exactly align all 4 corners of the input
and output. Defaults to False.
pad_to_max_dimension: Whether to resize the image and pad it with zeros
so the resulting image is of the spatial size
[max_dimension, max_dimension]. If masks are included they are padded
similarly.
Returns:
Note that the position of the resized_image_shape changes based on whether
masks are present.
resized_image: A 3D tensor of shape [new_height, new_width, channels],
where the image has been resized (with bilinear interpolation) so that
min(new_height, new_width) == min_dimension or
max(new_height, new_width) == max_dimension.
resized_masks: If masks is not None, also outputs masks. A 3D tensor of
shape [num_instances, new_height, new_width].
resized_image_shape: A 1D tensor of shape [3] containing shape of the
resized image.
Raises:
ValueError: if the image is not a 3D tensor.
"""
if len(image.get_shape()) != 3:
raise ValueError('Image should be 3D tensor')
with tf.name_scope('ResizeToRange', values=[image, min_dimension]):
if image.get_shape().is_fully_defined():
new_size = _compute_new_static_size(image, min_dimension, max_dimension)
else:
new_size = _compute_new_dynamic_size(image, min_dimension, max_dimension)
new_image = tf.image.resize_images(
image, new_size[:-1], method=method, align_corners=align_corners)
if pad_to_max_dimension:
new_image = tf.image.pad_to_bounding_box(
new_image, 0, 0, max_dimension, max_dimension)
result = [new_image]
if masks is not None:
new_masks = tf.expand_dims(masks, 3)
new_masks = tf.image.resize_images(
new_masks,
new_size[:-1],
method=tf.image.ResizeMethod.NEAREST_NEIGHBOR,
align_corners=align_corners)
new_masks = tf.squeeze(new_masks, 3)
if pad_to_max_dimension:
new_masks = tf.image.pad_to_bounding_box(
new_masks, 0, 0, max_dimension, max_dimension)
result.append(new_masks)
result.append(new_size)
return result
def _copy_extra_fields(boxlist_to_copy_to, boxlist_to_copy_from):
"""Copies the extra fields of boxlist_to_copy_from to boxlist_to_copy_to.
Args:
boxlist_to_copy_to: BoxList to which extra fields are copied.
boxlist_to_copy_from: BoxList from which fields are copied.
Returns:
boxlist_to_copy_to with extra fields.
"""
for field in boxlist_to_copy_from.get_extra_fields():
boxlist_to_copy_to.add_field(field, boxlist_to_copy_from.get_field(field))
return boxlist_to_copy_to
def box_list_scale(boxlist, y_scale, x_scale, scope=None):
"""scale box coordinates in x and y dimensions.
Args:
boxlist: BoxList holding N boxes
y_scale: (float) scalar tensor
x_scale: (float) scalar tensor
scope: name scope.
Returns:
boxlist: BoxList holding N boxes
"""
with tf.name_scope(scope, 'Scale'):
y_scale = tf.cast(y_scale, tf.float32)
x_scale = tf.cast(x_scale, tf.float32)
y_min, x_min, y_max, x_max = tf.split(
value=boxlist.get(), num_or_size_splits=4, axis=1)
y_min = y_scale * y_min
y_max = y_scale * y_max
x_min = x_scale * x_min
x_max = x_scale * x_max
scaled_boxlist = box_list.BoxList(
tf.concat([y_min, x_min, y_max, x_max], 1))
return _copy_extra_fields(scaled_boxlist, boxlist)
def keypoint_scale(keypoints, y_scale, x_scale, scope=None):
"""Scales keypoint coordinates in x and y dimensions.
Args:
keypoints: a tensor of shape [num_instances, num_keypoints, 2]
y_scale: (float) scalar tensor
x_scale: (float) scalar tensor
scope: name scope.
Returns:
new_keypoints: a tensor of shape [num_instances, num_keypoints, 2]
"""
with tf.name_scope(scope, 'Scale'):
y_scale = tf.cast(y_scale, tf.float32)
x_scale = tf.cast(x_scale, tf.float32)
new_keypoints = keypoints * [[[y_scale, x_scale]]]
return new_keypoints
def scale_boxes_to_pixel_coordinates(image, boxes, keypoints=None):
"""Scales boxes from normalized to pixel coordinates.
Args:
image: A 3D float32 tensor of shape [height, width, channels].
boxes: A 2D float32 tensor of shape [num_boxes, 4] containing the bounding
boxes in normalized coordinates. Each row is of the form
[ymin, xmin, ymax, xmax].
keypoints: (optional) rank 3 float32 tensor with shape
[num_instances, num_keypoints, 2]. The keypoints are in y-x normalized
coordinates.
Returns:
image: unchanged input image.
scaled_boxes: a 2D float32 tensor of shape [num_boxes, 4] containing the
bounding boxes in pixel coordinates.
scaled_keypoints: a 3D float32 tensor with shape
[num_instances, num_keypoints, 2] containing the keypoints in pixel
coordinates.
"""
boxlist = box_list.BoxList(boxes)
image_height = tf.shape(image)[0]
image_width = tf.shape(image)[1]
scaled_boxes = box_list_scale(boxlist, image_height, image_width).get()
result = [image, scaled_boxes]
if keypoints is not None:
scaled_keypoints = keypoint_scale(keypoints, image_height, image_width)
result.append(scaled_keypoints)
return tuple(result)
|
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,
26539,
5935,
436,
16842,
17193,
367,
15212,
14,
199,
199,
6004,
5147,
2877,
5951,
402,
5331,
315,
26471,
9546,
26,
199,
8,
65,
9,
5331,
626,
787,
6781,
370,
3865,
6093,
436,
5343,
666,
12,
199,
8,
66,
9,
5331,
626,
787,
6781,
1454,
370,
6093,
666,
367,
314,
12016,
402,
272,
666,
18336,
3117,
14,
199,
199,
33,
26471,
805,
23192,
282,
663,
402,
4153,
12,
199,
69,
14,
71,
14,
376,
1834,
436,
16842,
17193,
12,
199,
529,
3351,
376,
3439,
641,
3062,
12,
436,
2529,
3062,
14,
199,
7700,
7251,
787,
26,
19311,
286,
20148,
314,
1834,
12,
19311,
15216,
316,
314,
1834,
12,
673,
19311,
13729,
314,
27702,
12,
30347,
12,
28679,
436,
673,
19311,
31292,
351,
316,
314,
16842,
17193,
14,
199,
199,
1918,
1834,
365,
282,
6915,
841,
2345,
26,
359,
17,
12,
4569,
12,
3462,
12,
9245,
61,
543,
199,
2271,
29,
3249,
14,
1609,
708,
14,
710,
19252,
17167,
63,
12922,
365,
282,
6915,
499,
2345,
26,
359,
46,
12,
841,
61,
2382,
199,
262,
1924,
1962,
2337,
365,
282,
5689,
543,
359,
27429,
22036,
21023,
19906,
1055,
199,
3532,
397,
787,
315,
9657,
8983,
11150,
199,
1589,
723,
10021,
1338,
1425,
315,
359,
16,
12,
413,
61,
199,
199,
6295,
867,
3390,
26,
1010,
2345,
63,
807,
12,
5935,
365,
282,
6915,
841,
2345,
12,
1325,
26471,
199,
5777,
9128,
282,
6915,
650,
2345,
367,
6661,
314,
1834,
14,
20227,
12,
6272,
314,
199,
17677,
805,
781,
308,
14167,
314,
1834,
370,
8649,
282,
6915,
650,
2345,
436,
2066,
199,
1129,
986,
652,
370,
314,
3423,
14,
2854,
314,
1284,
402,
314,
23351,
781,
6544,
314,
1834,
199,
894,
370,
6915,
841,
14,
199,
624,
199,
199,
646,
3228,
14,
5819,
14,
86,
17,
465,
2833,
199,
199,
504,
23443,
3036,
1149,
14,
2629,
63,
1195,
4411,
14,
785,
63,
11934,
492,
5689,
63,
513,
421,
199,
318,
485,
16114,
63,
12922,
63,
3039,
63,
1019,
8,
12922,
304,
523,
408,
8185,
13,
1019,
18761,
314,
17193,
14,
819,
3033,
26,
272,
17193,
26,
6915,
499,
2069,
708,
2345,
3035,
314,
16842,
17193,
1035,
359,
46,
12,
841,
1055,
1779,
5088,
12908,
787,
315,
9657,
1824,
11150,
3932,
8983,
17083,
1779,
3382,
359,
16,
12,
413,
1055,
1779,
7048,
1962,
365,
315,
314,
1824,
402,
359,
27429,
12,
22036,
12,
21023,
12,
19906,
1055,
819,
1803,
26,
272,
481,
3587,
1915,
17193,
14,
523,
408,
523,
22506,
12,
22036,
12,
21023,
12,
19906,
275,
2833,
14,
1294,
8,
585,
29,
12922,
12,
1967,
63,
269,
63,
890,
63,
16508,
29,
20,
12,
3114,
29,
17,
9,
523,
18761,
1915,
63,
21601,
275,
2833,
14,
25719,
8,
17,
14,
16,
12,
19906,
9,
523,
18761,
1915,
63,
28961,
275,
2833,
14,
25719,
8,
17,
14,
16,
12,
22036,
9,
523,
18761,
1915,
63,
12922,
275,
2833,
14,
9419,
779,
27429,
12,
18761,
1915,
63,
21601,
12,
21023,
12,
18761,
1915,
63,
28961,
467,
413,
9,
523,
372,
18761,
1915,
63,
12922,
421,
199,
318,
485,
16114,
63,
25768,
63,
3039,
63,
1019,
8,
25768,
304,
523,
408,
8185,
13,
1019,
18761,
27996,
14,
819,
3033,
26,
272,
27996,
26,
6915,
650,
2069,
708,
2345,
543,
2215,
489,
359,
1507,
63,
5990,
12,
4569,
12,
3462,
61,
6144,
1256,
27996,
14,
819,
1803,
26,
272,
18761,
1915,
27996,
26,
6915,
650,
2069,
708,
2345,
543,
2215,
489,
359,
1507,
63,
5990,
12,
4569,
12,
3462,
61,
6144,
1256,
27996,
14,
523,
408,
523,
372,
27996,
3981,
13785,
3800,
13,
17,
61,
421,
199,
318,
790,
1403,
63,
16114,
63,
11392,
8,
498,
3438,
12,
18761,
63,
1403,
12,
18761,
63,
23832,
12,
2490,
4194,
29,
403,
304,
523,
408,
38,
317,
1190,
314,
790,
3438,
394,
7366,
1183,
6818,
314,
18761,
63,
1403,
14,
819,
961,
3439,
289,
317,
1190,
314,
671,
10021,
367,
1924,
790,
1403,
6818,
314,
18761,
63,
1403,
523,
436,
2597,
10869,
3862,
314,
790,
3438,
315,
282,
30800,
2013,
701,
18761,
63,
23832,
14,
819,
3033,
26,
272,
790,
3438,
26,
282,
2345,
402,
2215,
359,
1507,
63,
5990,
12,
1967,
63,
498,
3438,
12,
499,
61,
272,
18761,
63,
1403,
26,
221,
334,
1609,
9,
6917,
2345,
6144,
314,
671,
10021,
370,
18761,
314,
489,
790,
3438,
6818,
14,
272,
18761,
63,
23832,
26,
6915,
413,
1109,
708,
2345,
3035,
314,
790,
1403,
18761,
489,
22966,
14,
961,
9314,
314,
4412,
687,
3379,
790,
1403,
4918,
489,
370,
314,
18761,
1915,
790,
1403,
4918,
14,
961,
365,
1202,
1979,
30468,
367,
790,
3438,
489,
626,
787,
440,
25572,
30326,
14,
662,
14,
71,
14,
6820,
4070,
2337,
787,
650,
790,
3438,
489,
6144,
788,
2993,
297,
283,
1019,
63,
15240,
297,
283,
3039,
63,
15240,
995,
2066,
282,
11461,
7141,
367,
489,
18761,
63,
23832,
5594,
506,
359,
16,
12,
499,
12,
413,
61,
3967,
781,
2934,
370,
11413,
314,
283,
3039,
63,
15240,
7,
489,
436,
283,
1019,
63,
15240,
7,
2410,
282,
17528,
18761,
14,
272,
4194,
26,
536,
4194,
14,
819,
1803,
26,
272,
892,
63,
498,
3438,
26,
282,
2345,
402,
2215,
359,
1507,
63,
5990,
12,
1967,
63,
498,
3438,
12,
499,
61,
523,
408,
523,
543,
2833,
14,
354,
63,
2645,
8,
2645,
12,
283,
38,
3587,
19918
] |
[
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,
26539,
5935,
436,
16842,
17193,
367,
15212,
14,
199,
199,
6004,
5147,
2877,
5951,
402,
5331,
315,
26471,
9546,
26,
199,
8,
65,
9,
5331,
626,
787,
6781,
370,
3865,
6093,
436,
5343,
666,
12,
199,
8,
66,
9,
5331,
626,
787,
6781,
1454,
370,
6093,
666,
367,
314,
12016,
402,
272,
666,
18336,
3117,
14,
199,
199,
33,
26471,
805,
23192,
282,
663,
402,
4153,
12,
199,
69,
14,
71,
14,
376,
1834,
436,
16842,
17193,
12,
199,
529,
3351,
376,
3439,
641,
3062,
12,
436,
2529,
3062,
14,
199,
7700,
7251,
787,
26,
19311,
286,
20148,
314,
1834,
12,
19311,
15216,
316,
314,
1834,
12,
673,
19311,
13729,
314,
27702,
12,
30347,
12,
28679,
436,
673,
19311,
31292,
351,
316,
314,
16842,
17193,
14,
199,
199,
1918,
1834,
365,
282,
6915,
841,
2345,
26,
359,
17,
12,
4569,
12,
3462,
12,
9245,
61,
543,
199,
2271,
29,
3249,
14,
1609,
708,
14,
710,
19252,
17167,
63,
12922,
365,
282,
6915,
499,
2345,
26,
359,
46,
12,
841,
61,
2382,
199,
262,
1924,
1962,
2337,
365,
282,
5689,
543,
359,
27429,
22036,
21023,
19906,
1055,
199,
3532,
397,
787,
315,
9657,
8983,
11150,
199,
1589,
723,
10021,
1338,
1425,
315,
359,
16,
12,
413,
61,
199,
199,
6295,
867,
3390,
26,
1010,
2345,
63,
807,
12,
5935,
365,
282,
6915,
841,
2345,
12,
1325,
26471,
199,
5777,
9128,
282,
6915,
650,
2345,
367,
6661,
314,
1834,
14,
20227,
12,
6272,
314,
199,
17677,
805,
781,
308,
14167,
314,
1834,
370,
8649,
282,
6915,
650,
2345,
436,
2066,
199,
1129,
986,
652,
370,
314,
3423,
14,
2854,
314,
1284,
402,
314,
23351,
781,
6544,
314,
1834,
199,
894,
370,
6915,
841,
14,
199,
624,
199,
199,
646,
3228,
14,
5819,
14,
86,
17,
465,
2833,
199,
199,
504,
23443,
3036,
1149,
14,
2629,
63,
1195,
4411,
14,
785,
63,
11934,
492,
5689,
63,
513,
421,
199,
318,
485,
16114,
63,
12922,
63,
3039,
63,
1019,
8,
12922,
304,
523,
408,
8185,
13,
1019,
18761,
314,
17193,
14,
819,
3033,
26,
272,
17193,
26,
6915,
499,
2069,
708,
2345,
3035,
314,
16842,
17193,
1035,
359,
46,
12,
841,
1055,
1779,
5088,
12908,
787,
315,
9657,
1824,
11150,
3932,
8983,
17083,
1779,
3382,
359,
16,
12,
413,
1055,
1779,
7048,
1962,
365,
315,
314,
1824,
402,
359,
27429,
12,
22036,
12,
21023,
12,
19906,
1055,
819,
1803,
26,
272,
481,
3587,
1915,
17193,
14,
523,
408,
523,
22506,
12,
22036,
12,
21023,
12,
19906,
275,
2833,
14,
1294,
8,
585,
29,
12922,
12,
1967,
63,
269,
63,
890,
63,
16508,
29,
20,
12,
3114,
29,
17,
9,
523,
18761,
1915,
63,
21601,
275,
2833,
14,
25719,
8,
17,
14,
16,
12,
19906,
9,
523,
18761,
1915,
63,
28961,
275,
2833,
14,
25719,
8,
17,
14,
16,
12,
22036,
9,
523,
18761,
1915,
63,
12922,
275,
2833,
14,
9419,
779,
27429,
12,
18761,
1915,
63,
21601,
12,
21023,
12,
18761,
1915,
63,
28961,
467,
413,
9,
523,
372,
18761,
1915,
63,
12922,
421,
199,
318,
485,
16114,
63,
25768,
63,
3039,
63,
1019,
8,
25768,
304,
523,
408,
8185,
13,
1019,
18761,
27996,
14,
819,
3033,
26,
272,
27996,
26,
6915,
650,
2069,
708,
2345,
543,
2215,
489,
359,
1507,
63,
5990,
12,
4569,
12,
3462,
61,
6144,
1256,
27996,
14,
819,
1803,
26,
272,
18761,
1915,
27996,
26,
6915,
650,
2069,
708,
2345,
543,
2215,
489,
359,
1507,
63,
5990,
12,
4569,
12,
3462,
61,
6144,
1256,
27996,
14,
523,
408,
523,
372,
27996,
3981,
13785,
3800,
13,
17,
61,
421,
199,
318,
790,
1403,
63,
16114,
63,
11392,
8,
498,
3438,
12,
18761,
63,
1403,
12,
18761,
63,
23832,
12,
2490,
4194,
29,
403,
304,
523,
408,
38,
317,
1190,
314,
790,
3438,
394,
7366,
1183,
6818,
314,
18761,
63,
1403,
14,
819,
961,
3439,
289,
317,
1190,
314,
671,
10021,
367,
1924,
790,
1403,
6818,
314,
18761,
63,
1403,
523,
436,
2597,
10869,
3862,
314,
790,
3438,
315,
282,
30800,
2013,
701,
18761,
63,
23832,
14,
819,
3033,
26,
272,
790,
3438,
26,
282,
2345,
402,
2215,
359,
1507,
63,
5990,
12,
1967,
63,
498,
3438,
12,
499,
61,
272,
18761,
63,
1403,
26,
221,
334,
1609,
9,
6917,
2345,
6144,
314,
671,
10021,
370,
18761,
314,
489,
790,
3438,
6818,
14,
272,
18761,
63,
23832,
26,
6915,
413,
1109,
708,
2345,
3035,
314,
790,
1403,
18761,
489,
22966,
14,
961,
9314,
314,
4412,
687,
3379,
790,
1403,
4918,
489,
370,
314,
18761,
1915,
790,
1403,
4918,
14,
961,
365,
1202,
1979,
30468,
367,
790,
3438,
489,
626,
787,
440,
25572,
30326,
14,
662,
14,
71,
14,
6820,
4070,
2337,
787,
650,
790,
3438,
489,
6144,
788,
2993,
297,
283,
1019,
63,
15240,
297,
283,
3039,
63,
15240,
995,
2066,
282,
11461,
7141,
367,
489,
18761,
63,
23832,
5594,
506,
359,
16,
12,
499,
12,
413,
61,
3967,
781,
2934,
370,
11413,
314,
283,
3039,
63,
15240,
7,
489,
436,
283,
1019,
63,
15240,
7,
2410,
282,
17528,
18761,
14,
272,
4194,
26,
536,
4194,
14,
819,
1803,
26,
272,
892,
63,
498,
3438,
26,
282,
2345,
402,
2215,
359,
1507,
63,
5990,
12,
1967,
63,
498,
3438,
12,
499,
61,
523,
408,
523,
543,
2833,
14,
354,
63,
2645,
8,
2645,
12,
283,
38,
3587,
19918,
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,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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
] |
krishna-pandey-git/django
|
tests/utils_tests/test_datetime_safe.py
|
207
|
2371
|
import unittest
from datetime import (
date as original_date, datetime as original_datetime,
time as original_time,
)
from django.utils.datetime_safe import date, datetime, time
class DatetimeTests(unittest.TestCase):
def setUp(self):
self.just_safe = (1900, 1, 1)
self.just_unsafe = (1899, 12, 31, 23, 59, 59)
self.just_time = (11, 30, 59)
self.really_old = (20, 1, 1)
self.more_recent = (2006, 1, 1)
def test_compare_datetimes(self):
self.assertEqual(original_datetime(*self.more_recent), datetime(*self.more_recent))
self.assertEqual(original_datetime(*self.really_old), datetime(*self.really_old))
self.assertEqual(original_date(*self.more_recent), date(*self.more_recent))
self.assertEqual(original_date(*self.really_old), date(*self.really_old))
self.assertEqual(original_date(*self.just_safe).strftime('%Y-%m-%d'), date(*self.just_safe).strftime('%Y-%m-%d'))
self.assertEqual(original_datetime(*self.just_safe).strftime('%Y-%m-%d'), datetime(*self.just_safe).strftime('%Y-%m-%d'))
self.assertEqual(original_time(*self.just_time).strftime('%H:%M:%S'), time(*self.just_time).strftime('%H:%M:%S'))
def test_safe_strftime(self):
self.assertEqual(date(*self.just_unsafe[:3]).strftime('%Y-%m-%d (weekday %w)'), '1899-12-31 (weekday 0)')
self.assertEqual(date(*self.just_safe).strftime('%Y-%m-%d (weekday %w)'), '1900-01-01 (weekday 1)')
self.assertEqual(datetime(*self.just_unsafe).strftime('%Y-%m-%d %H:%M:%S (weekday %w)'), '1899-12-31 23:59:59 (weekday 0)')
self.assertEqual(datetime(*self.just_safe).strftime('%Y-%m-%d %H:%M:%S (weekday %w)'), '1900-01-01 00:00:00 (weekday 1)')
self.assertEqual(time(*self.just_time).strftime('%H:%M:%S AM'), '11:30:59 AM')
# %y will error before this date
self.assertEqual(date(*self.just_safe).strftime('%y'), '00')
self.assertEqual(datetime(*self.just_safe).strftime('%y'), '00')
self.assertEqual(date(1850, 8, 2).strftime("%Y/%m/%d was a %A"), '1850/08/02 was a Friday')
def test_zero_padding(self):
"""
Regression for #12524
Check that pre-1000AD dates are padded with zeros if necessary
"""
self.assertEqual(date(1, 1, 1).strftime("%Y/%m/%d was a %A"), '0001/01/01 was a Monday')
|
bsd-3-clause
|
[
646,
2882,
199,
504,
2197,
492,
334,
272,
1434,
465,
3379,
63,
602,
12,
2197,
465,
3379,
63,
2083,
12,
272,
900,
465,
3379,
63,
521,
12,
199,
9,
199,
199,
504,
1639,
14,
1208,
14,
2083,
63,
3489,
492,
1434,
12,
2197,
12,
900,
421,
199,
533,
29825,
2925,
8,
2796,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
4764,
63,
3489,
275,
334,
26631,
12,
413,
12,
413,
9,
267,
291,
14,
4764,
63,
14242,
275,
334,
1085,
1020,
12,
3144,
12,
7105,
12,
6546,
12,
8155,
12,
8155,
9,
267,
291,
14,
4764,
63,
521,
275,
334,
845,
12,
4233,
12,
8155,
9,
267,
291,
14,
29428,
63,
1753,
275,
334,
1165,
12,
413,
12,
413,
9,
267,
291,
14,
6878,
63,
14951,
275,
334,
7968,
12,
413,
12,
413,
9,
339,
347,
511,
63,
5785,
63,
31601,
8,
277,
304,
267,
291,
14,
629,
8,
5043,
63,
2083,
2031,
277,
14,
6878,
63,
14951,
395,
2197,
2031,
277,
14,
6878,
63,
14951,
430,
267,
291,
14,
629,
8,
5043,
63,
2083,
2031,
277,
14,
29428,
63,
1753,
395,
2197,
2031,
277,
14,
29428,
63,
1753,
430,
267,
291,
14,
629,
8,
5043,
63,
602,
2031,
277,
14,
6878,
63,
14951,
395,
1434,
2031,
277,
14,
6878,
63,
14951,
430,
267,
291,
14,
629,
8,
5043,
63,
602,
2031,
277,
14,
29428,
63,
1753,
395,
1434,
2031,
277,
14,
29428,
63,
1753,
430,
398,
291,
14,
629,
8,
5043,
63,
602,
2031,
277,
14,
4764,
63,
3489,
680,
6205,
3508,
57,
3295,
77,
3295,
68,
659,
1434,
2031,
277,
14,
4764,
63,
3489,
680,
6205,
3508,
57,
3295,
77,
3295,
68,
1333,
267,
291,
14,
629,
8,
5043,
63,
2083,
2031,
277,
14,
4764,
63,
3489,
680,
6205,
3508,
57,
3295,
77,
3295,
68,
659,
2197,
2031,
277,
14,
4764,
63,
3489,
680,
6205,
3508,
57,
3295,
77,
3295,
68,
1333,
398,
291,
14,
629,
8,
5043,
63,
521,
2031,
277,
14,
4764,
63,
521,
680,
6205,
3508,
40,
2689,
45,
2689,
51,
659,
900,
2031,
277,
14,
4764,
63,
521,
680,
6205,
3508,
40,
2689,
45,
2689,
51,
1333,
339,
347,
511,
63,
3489,
63,
6205,
8,
277,
304,
267,
291,
14,
629,
8,
602,
2031,
277,
14,
4764,
63,
14242,
1491,
19,
6575,
6205,
3508,
57,
3295,
77,
3295,
68,
334,
12451,
450,
87,
11218,
283,
1085,
1020,
13,
713,
13,
2192,
334,
12451,
378,
5942,
267,
291,
14,
629,
8,
602,
2031,
277,
14,
4764,
63,
3489,
680,
6205,
3508,
57,
3295,
77,
3295,
68,
334,
12451,
450,
87,
11218,
283,
26631,
13,
614,
13,
614,
334,
12451,
413,
5942,
398,
291,
14,
629,
8,
2083,
2031,
277,
14,
4764,
63,
14242,
680,
6205,
3508,
57,
3295,
77,
3295,
68,
450,
40,
2689,
45,
2689,
51,
334,
12451,
450,
87,
11218,
283,
1085,
1020,
13,
713,
13,
2192,
6546,
26,
1427,
26,
1427,
334,
12451,
378,
5942,
267,
291,
14,
629,
8,
2083,
2031,
277,
14,
4764,
63,
3489,
680,
6205,
3508,
57,
3295,
77,
3295,
68,
450,
40,
2689,
45,
2689,
51,
334,
12451,
450,
87,
11218,
283,
26631,
13,
614,
13,
614,
8733,
26,
383,
26,
383,
334,
12451,
413,
5942,
398,
291,
14,
629,
8,
521,
2031,
277,
14,
4764,
63,
521,
680,
6205,
3508,
40,
2689,
45,
2689,
51,
24343,
659,
283,
845,
26,
1216,
26,
1427,
24343,
358,
398,
327,
450,
89,
911,
1125,
2544,
642,
1434,
267,
291,
14,
629,
8,
602,
2031,
277,
14,
4764,
63,
3489,
680,
6205,
3508,
89,
659,
283,
383,
358,
267,
291,
14,
629,
8,
2083,
2031,
277,
14,
4764,
63,
3489,
680,
6205,
3508,
89,
659,
283,
383,
358,
398,
291,
14,
629,
8,
602,
8,
1085,
1400,
12,
1695,
12,
499,
680,
6205,
3647,
57,
3149,
77,
3149,
68,
1990,
282,
450,
33,
1288,
283,
1085,
1400,
15,
2036,
15,
996,
1990,
282,
31712,
2977,
358,
339,
347,
511,
63,
4262,
63,
8358,
8,
277,
304,
267,
408,
267,
13262,
367,
327,
6889,
1194,
398,
2670,
626,
876,
13,
5279,
1554,
10831,
787,
21824,
543,
10136,
340,
5784,
267,
408,
267,
291,
14,
629,
8,
602,
8,
17,
12,
413,
12,
413,
680,
6205,
3647,
57,
3149,
77,
3149,
68,
1990,
282,
450,
33,
1288,
283,
4183,
15,
614,
15,
614,
1990,
282,
32740,
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
] |
[
2882,
199,
504,
2197,
492,
334,
272,
1434,
465,
3379,
63,
602,
12,
2197,
465,
3379,
63,
2083,
12,
272,
900,
465,
3379,
63,
521,
12,
199,
9,
199,
199,
504,
1639,
14,
1208,
14,
2083,
63,
3489,
492,
1434,
12,
2197,
12,
900,
421,
199,
533,
29825,
2925,
8,
2796,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
4764,
63,
3489,
275,
334,
26631,
12,
413,
12,
413,
9,
267,
291,
14,
4764,
63,
14242,
275,
334,
1085,
1020,
12,
3144,
12,
7105,
12,
6546,
12,
8155,
12,
8155,
9,
267,
291,
14,
4764,
63,
521,
275,
334,
845,
12,
4233,
12,
8155,
9,
267,
291,
14,
29428,
63,
1753,
275,
334,
1165,
12,
413,
12,
413,
9,
267,
291,
14,
6878,
63,
14951,
275,
334,
7968,
12,
413,
12,
413,
9,
339,
347,
511,
63,
5785,
63,
31601,
8,
277,
304,
267,
291,
14,
629,
8,
5043,
63,
2083,
2031,
277,
14,
6878,
63,
14951,
395,
2197,
2031,
277,
14,
6878,
63,
14951,
430,
267,
291,
14,
629,
8,
5043,
63,
2083,
2031,
277,
14,
29428,
63,
1753,
395,
2197,
2031,
277,
14,
29428,
63,
1753,
430,
267,
291,
14,
629,
8,
5043,
63,
602,
2031,
277,
14,
6878,
63,
14951,
395,
1434,
2031,
277,
14,
6878,
63,
14951,
430,
267,
291,
14,
629,
8,
5043,
63,
602,
2031,
277,
14,
29428,
63,
1753,
395,
1434,
2031,
277,
14,
29428,
63,
1753,
430,
398,
291,
14,
629,
8,
5043,
63,
602,
2031,
277,
14,
4764,
63,
3489,
680,
6205,
3508,
57,
3295,
77,
3295,
68,
659,
1434,
2031,
277,
14,
4764,
63,
3489,
680,
6205,
3508,
57,
3295,
77,
3295,
68,
1333,
267,
291,
14,
629,
8,
5043,
63,
2083,
2031,
277,
14,
4764,
63,
3489,
680,
6205,
3508,
57,
3295,
77,
3295,
68,
659,
2197,
2031,
277,
14,
4764,
63,
3489,
680,
6205,
3508,
57,
3295,
77,
3295,
68,
1333,
398,
291,
14,
629,
8,
5043,
63,
521,
2031,
277,
14,
4764,
63,
521,
680,
6205,
3508,
40,
2689,
45,
2689,
51,
659,
900,
2031,
277,
14,
4764,
63,
521,
680,
6205,
3508,
40,
2689,
45,
2689,
51,
1333,
339,
347,
511,
63,
3489,
63,
6205,
8,
277,
304,
267,
291,
14,
629,
8,
602,
2031,
277,
14,
4764,
63,
14242,
1491,
19,
6575,
6205,
3508,
57,
3295,
77,
3295,
68,
334,
12451,
450,
87,
11218,
283,
1085,
1020,
13,
713,
13,
2192,
334,
12451,
378,
5942,
267,
291,
14,
629,
8,
602,
2031,
277,
14,
4764,
63,
3489,
680,
6205,
3508,
57,
3295,
77,
3295,
68,
334,
12451,
450,
87,
11218,
283,
26631,
13,
614,
13,
614,
334,
12451,
413,
5942,
398,
291,
14,
629,
8,
2083,
2031,
277,
14,
4764,
63,
14242,
680,
6205,
3508,
57,
3295,
77,
3295,
68,
450,
40,
2689,
45,
2689,
51,
334,
12451,
450,
87,
11218,
283,
1085,
1020,
13,
713,
13,
2192,
6546,
26,
1427,
26,
1427,
334,
12451,
378,
5942,
267,
291,
14,
629,
8,
2083,
2031,
277,
14,
4764,
63,
3489,
680,
6205,
3508,
57,
3295,
77,
3295,
68,
450,
40,
2689,
45,
2689,
51,
334,
12451,
450,
87,
11218,
283,
26631,
13,
614,
13,
614,
8733,
26,
383,
26,
383,
334,
12451,
413,
5942,
398,
291,
14,
629,
8,
521,
2031,
277,
14,
4764,
63,
521,
680,
6205,
3508,
40,
2689,
45,
2689,
51,
24343,
659,
283,
845,
26,
1216,
26,
1427,
24343,
358,
398,
327,
450,
89,
911,
1125,
2544,
642,
1434,
267,
291,
14,
629,
8,
602,
2031,
277,
14,
4764,
63,
3489,
680,
6205,
3508,
89,
659,
283,
383,
358,
267,
291,
14,
629,
8,
2083,
2031,
277,
14,
4764,
63,
3489,
680,
6205,
3508,
89,
659,
283,
383,
358,
398,
291,
14,
629,
8,
602,
8,
1085,
1400,
12,
1695,
12,
499,
680,
6205,
3647,
57,
3149,
77,
3149,
68,
1990,
282,
450,
33,
1288,
283,
1085,
1400,
15,
2036,
15,
996,
1990,
282,
31712,
2977,
358,
339,
347,
511,
63,
4262,
63,
8358,
8,
277,
304,
267,
408,
267,
13262,
367,
327,
6889,
1194,
398,
2670,
626,
876,
13,
5279,
1554,
10831,
787,
21824,
543,
10136,
340,
5784,
267,
408,
267,
291,
14,
629,
8,
602,
8,
17,
12,
413,
12,
413,
680,
6205,
3647,
57,
3149,
77,
3149,
68,
1990,
282,
450,
33,
1288,
283,
4183,
15,
614,
15,
614,
1990,
282,
32740,
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,
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,
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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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
haxoza/django
|
tests/get_or_create/tests.py
|
282
|
15058
|
from __future__ import unicode_literals
import traceback
from datetime import date
from django.db import DatabaseError, IntegrityError
from django.test import TestCase, TransactionTestCase, ignore_warnings
from django.utils.encoding import DjangoUnicodeDecodeError
from .models import (
Author, Book, DefaultPerson, ManualPrimaryKeyTest, Person, Profile,
Publisher, Tag, Thing,
)
class GetOrCreateTests(TestCase):
def setUp(self):
self.lennon = Person.objects.create(
first_name='John', last_name='Lennon', birthday=date(1940, 10, 9)
)
def test_get_or_create_method_with_get(self):
created = Person.objects.get_or_create(
first_name="John", last_name="Lennon", defaults={
"birthday": date(1940, 10, 9)
}
)[1]
self.assertFalse(created)
self.assertEqual(Person.objects.count(), 1)
def test_get_or_create_method_with_create(self):
created = Person.objects.get_or_create(
first_name='George', last_name='Harrison', defaults={
'birthday': date(1943, 2, 25)
}
)[1]
self.assertTrue(created)
self.assertEqual(Person.objects.count(), 2)
def test_get_or_create_redundant_instance(self):
"""
If we execute the exact same statement twice, the second time,
it won't create a Person.
"""
Person.objects.get_or_create(
first_name='George', last_name='Harrison', defaults={
'birthday': date(1943, 2, 25)
}
)
created = Person.objects.get_or_create(
first_name='George', last_name='Harrison', defaults={
'birthday': date(1943, 2, 25)
}
)[1]
self.assertFalse(created)
self.assertEqual(Person.objects.count(), 2)
def test_get_or_create_invalid_params(self):
"""
If you don't specify a value or default value for all required
fields, you will get an error.
"""
self.assertRaises(
IntegrityError,
Person.objects.get_or_create, first_name="Tom", last_name="Smith"
)
def test_get_or_create_on_related_manager(self):
p = Publisher.objects.create(name="Acme Publishing")
# Create a book through the publisher.
book, created = p.books.get_or_create(name="The Book of Ed & Fred")
self.assertTrue(created)
# The publisher should have one book.
self.assertEqual(p.books.count(), 1)
# Try get_or_create again, this time nothing should be created.
book, created = p.books.get_or_create(name="The Book of Ed & Fred")
self.assertFalse(created)
# And the publisher should still have one book.
self.assertEqual(p.books.count(), 1)
# Add an author to the book.
ed, created = book.authors.get_or_create(name="Ed")
self.assertTrue(created)
# The book should have one author.
self.assertEqual(book.authors.count(), 1)
# Try get_or_create again, this time nothing should be created.
ed, created = book.authors.get_or_create(name="Ed")
self.assertFalse(created)
# And the book should still have one author.
self.assertEqual(book.authors.count(), 1)
# Add a second author to the book.
fred, created = book.authors.get_or_create(name="Fred")
self.assertTrue(created)
# The book should have two authors now.
self.assertEqual(book.authors.count(), 2)
# Create an Author not tied to any books.
Author.objects.create(name="Ted")
# There should be three Authors in total. The book object should have two.
self.assertEqual(Author.objects.count(), 3)
self.assertEqual(book.authors.count(), 2)
# Try creating a book through an author.
_, created = ed.books.get_or_create(name="Ed's Recipes", publisher=p)
self.assertTrue(created)
# Now Ed has two Books, Fred just one.
self.assertEqual(ed.books.count(), 2)
self.assertEqual(fred.books.count(), 1)
# Use the publisher's primary key value instead of a model instance.
_, created = ed.books.get_or_create(name='The Great Book of Ed', publisher_id=p.id)
self.assertTrue(created)
# Try get_or_create again, this time nothing should be created.
_, created = ed.books.get_or_create(name='The Great Book of Ed', publisher_id=p.id)
self.assertFalse(created)
# The publisher should have three books.
self.assertEqual(p.books.count(), 3)
def test_defaults_exact(self):
"""
If you have a field named defaults and want to use it as an exact
lookup, you need to use 'defaults__exact'.
"""
obj, created = Person.objects.get_or_create(
first_name='George', last_name='Harrison', defaults__exact='testing', defaults={
'birthday': date(1943, 2, 25),
'defaults': 'testing',
}
)
self.assertTrue(created)
self.assertEqual(obj.defaults, 'testing')
obj2, created = Person.objects.get_or_create(
first_name='George', last_name='Harrison', defaults__exact='testing', defaults={
'birthday': date(1943, 2, 25),
'defaults': 'testing',
}
)
self.assertFalse(created)
self.assertEqual(obj, obj2)
class GetOrCreateTestsWithManualPKs(TestCase):
def setUp(self):
self.first_pk = ManualPrimaryKeyTest.objects.create(id=1, data="Original")
def test_create_with_duplicate_primary_key(self):
"""
If you specify an existing primary key, but different other fields,
then you will get an error and data will not be updated.
"""
self.assertRaises(
IntegrityError,
ManualPrimaryKeyTest.objects.get_or_create, id=1, data="Different"
)
self.assertEqual(ManualPrimaryKeyTest.objects.get(id=1).data, "Original")
def test_get_or_create_raises_IntegrityError_plus_traceback(self):
"""
get_or_create should raise IntegrityErrors with the full traceback.
This is tested by checking that a known method call is in the traceback.
We cannot use assertRaises here because we need to inspect
the actual traceback. Refs #16340.
"""
try:
ManualPrimaryKeyTest.objects.get_or_create(id=1, data="Different")
except IntegrityError:
formatted_traceback = traceback.format_exc()
self.assertIn(str('obj.save'), formatted_traceback)
# MySQL emits a warning when broken data is saved
@ignore_warnings(module='django.db.backends.mysql.base')
def test_savepoint_rollback(self):
"""
Regression test for #20463: the database connection should still be
usable after a DataError or ProgrammingError in .get_or_create().
"""
try:
Person.objects.get_or_create(
birthday=date(1970, 1, 1),
defaults={'first_name': b"\xff", 'last_name': b"\xff"})
except (DatabaseError, DjangoUnicodeDecodeError):
Person.objects.create(
first_name="Bob", last_name="Ross", birthday=date(1950, 1, 1))
else:
self.skipTest("This backend accepts broken utf-8.")
def test_get_or_create_empty(self):
"""
Regression test for #16137: get_or_create does not require kwargs.
"""
try:
DefaultPerson.objects.get_or_create()
except AssertionError:
self.fail("If all the attributes on a model have defaults, we "
"shouldn't need to pass any arguments.")
class GetOrCreateTransactionTests(TransactionTestCase):
available_apps = ['get_or_create']
def test_get_or_create_integrityerror(self):
"""
Regression test for #15117. Requires a TransactionTestCase on
databases that delay integrity checks until the end of transactions,
otherwise the exception is never raised.
"""
try:
Profile.objects.get_or_create(person=Person(id=1))
except IntegrityError:
pass
else:
self.skipTest("This backend does not support integrity checks.")
class GetOrCreateThroughManyToMany(TestCase):
def test_get_get_or_create(self):
tag = Tag.objects.create(text='foo')
a_thing = Thing.objects.create(name='a')
a_thing.tags.add(tag)
obj, created = a_thing.tags.get_or_create(text='foo')
self.assertFalse(created)
self.assertEqual(obj.pk, tag.pk)
def test_create_get_or_create(self):
a_thing = Thing.objects.create(name='a')
obj, created = a_thing.tags.get_or_create(text='foo')
self.assertTrue(created)
self.assertEqual(obj.text, 'foo')
self.assertIn(obj, a_thing.tags.all())
def test_something(self):
Tag.objects.create(text='foo')
a_thing = Thing.objects.create(name='a')
self.assertRaises(IntegrityError, a_thing.tags.get_or_create, text='foo')
class UpdateOrCreateTests(TestCase):
def test_update(self):
Person.objects.create(
first_name='John', last_name='Lennon', birthday=date(1940, 10, 9)
)
p, created = Person.objects.update_or_create(
first_name='John', last_name='Lennon', defaults={
'birthday': date(1940, 10, 10)
}
)
self.assertFalse(created)
self.assertEqual(p.first_name, 'John')
self.assertEqual(p.last_name, 'Lennon')
self.assertEqual(p.birthday, date(1940, 10, 10))
def test_create(self):
p, created = Person.objects.update_or_create(
first_name='John', last_name='Lennon', defaults={
'birthday': date(1940, 10, 10)
}
)
self.assertTrue(created)
self.assertEqual(p.first_name, 'John')
self.assertEqual(p.last_name, 'Lennon')
self.assertEqual(p.birthday, date(1940, 10, 10))
def test_create_twice(self):
params = {
'first_name': 'John',
'last_name': 'Lennon',
'birthday': date(1940, 10, 10),
}
Person.objects.update_or_create(**params)
# If we execute the exact same statement, it won't create a Person.
p, created = Person.objects.update_or_create(**params)
self.assertFalse(created)
def test_integrity(self):
"""
If you don't specify a value or default value for all required
fields, you will get an error.
"""
self.assertRaises(IntegrityError,
Person.objects.update_or_create, first_name="Tom", last_name="Smith")
def test_manual_primary_key_test(self):
"""
If you specify an existing primary key, but different other fields,
then you will get an error and data will not be updated.
"""
ManualPrimaryKeyTest.objects.create(id=1, data="Original")
self.assertRaises(
IntegrityError,
ManualPrimaryKeyTest.objects.update_or_create, id=1, data="Different"
)
self.assertEqual(ManualPrimaryKeyTest.objects.get(id=1).data, "Original")
def test_error_contains_full_traceback(self):
"""
update_or_create should raise IntegrityErrors with the full traceback.
This is tested by checking that a known method call is in the traceback.
We cannot use assertRaises/assertRaises here because we need to inspect
the actual traceback. Refs #16340.
"""
try:
ManualPrimaryKeyTest.objects.update_or_create(id=1, data="Different")
except IntegrityError:
formatted_traceback = traceback.format_exc()
self.assertIn('obj.save', formatted_traceback)
def test_create_with_related_manager(self):
"""
Should be able to use update_or_create from the related manager to
create a book. Refs #23611.
"""
p = Publisher.objects.create(name="Acme Publishing")
book, created = p.books.update_or_create(name="The Book of Ed & Fred")
self.assertTrue(created)
self.assertEqual(p.books.count(), 1)
def test_update_with_related_manager(self):
"""
Should be able to use update_or_create from the related manager to
update a book. Refs #23611.
"""
p = Publisher.objects.create(name="Acme Publishing")
book = Book.objects.create(name="The Book of Ed & Fred", publisher=p)
self.assertEqual(p.books.count(), 1)
name = "The Book of Django"
book, created = p.books.update_or_create(defaults={'name': name}, id=book.id)
self.assertFalse(created)
self.assertEqual(book.name, name)
self.assertEqual(p.books.count(), 1)
def test_create_with_many(self):
"""
Should be able to use update_or_create from the m2m related manager to
create a book. Refs #23611.
"""
p = Publisher.objects.create(name="Acme Publishing")
author = Author.objects.create(name="Ted")
book, created = author.books.update_or_create(name="The Book of Ed & Fred", publisher=p)
self.assertTrue(created)
self.assertEqual(author.books.count(), 1)
def test_update_with_many(self):
"""
Should be able to use update_or_create from the m2m related manager to
update a book. Refs #23611.
"""
p = Publisher.objects.create(name="Acme Publishing")
author = Author.objects.create(name="Ted")
book = Book.objects.create(name="The Book of Ed & Fred", publisher=p)
book.authors.add(author)
self.assertEqual(author.books.count(), 1)
name = "The Book of Django"
book, created = author.books.update_or_create(defaults={'name': name}, id=book.id)
self.assertFalse(created)
self.assertEqual(book.name, name)
self.assertEqual(author.books.count(), 1)
def test_defaults_exact(self):
"""
If you have a field named defaults and want to use it as an exact
lookup, you need to use 'defaults__exact'.
"""
obj, created = Person.objects.update_or_create(
first_name='George', last_name='Harrison', defaults__exact='testing', defaults={
'birthday': date(1943, 2, 25),
'defaults': 'testing',
}
)
self.assertTrue(created)
self.assertEqual(obj.defaults, 'testing')
obj, created = Person.objects.update_or_create(
first_name='George', last_name='Harrison', defaults__exact='testing', defaults={
'birthday': date(1943, 2, 25),
'defaults': 'another testing',
}
)
self.assertFalse(created)
self.assertEqual(obj.defaults, 'another testing')
|
bsd-3-clause
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
5190,
199,
504,
2197,
492,
1434,
199,
199,
504,
1639,
14,
697,
492,
27728,
12,
26864,
199,
504,
1639,
14,
396,
492,
7640,
12,
18244,
1746,
12,
3686,
63,
5451,
199,
504,
1639,
14,
1208,
14,
2991,
492,
5634,
7087,
12620,
199,
199,
504,
1275,
992,
492,
334,
272,
6529,
12,
8944,
12,
3758,
7344,
12,
30247,
29457,
774,
12,
8028,
12,
14386,
12,
272,
19952,
281,
12,
8053,
12,
3868,
316,
12,
199,
9,
421,
199,
533,
2372,
2844,
2499,
2925,
8,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
552,
2865,
275,
8028,
14,
1462,
14,
981,
8,
288,
1642,
63,
354,
534,
12923,
297,
2061,
63,
354,
534,
3166,
2865,
297,
21036,
2977,
29,
602,
8,
30614,
12,
1616,
12,
1749,
9,
267,
776,
339,
347,
511,
63,
362,
63,
269,
63,
981,
63,
765,
63,
1045,
63,
362,
8,
277,
304,
267,
2737,
275,
8028,
14,
1462,
14,
362,
63,
269,
63,
981,
8,
288,
1642,
63,
354,
628,
12923,
401,
2061,
63,
354,
628,
3166,
2865,
401,
4243,
3126,
355,
298,
15881,
582,
1434,
8,
30614,
12,
1616,
12,
1749,
9,
288,
789,
267,
29688,
17,
61,
267,
291,
14,
3334,
8,
3966,
9,
267,
291,
14,
629,
8,
7344,
14,
1462,
14,
835,
1062,
413,
9,
339,
347,
511,
63,
362,
63,
269,
63,
981,
63,
765,
63,
1045,
63,
981,
8,
277,
304,
267,
2737,
275,
8028,
14,
1462,
14,
362,
63,
269,
63,
981,
8,
288,
1642,
63,
354,
534,
4240,
24591,
297,
2061,
63,
354,
534,
18248,
322,
834,
297,
4243,
3126,
355,
283,
15881,
356,
1434,
8,
1167,
2824,
12,
499,
12,
5661,
9,
288,
789,
267,
29688,
17,
61,
267,
291,
14,
1815,
8,
3966,
9,
267,
291,
14,
629,
8,
7344,
14,
1462,
14,
835,
1062,
499,
9,
339,
347,
511,
63,
362,
63,
269,
63,
981,
63,
581,
17013,
63,
842,
8,
277,
304,
267,
408,
267,
982,
781,
5341,
314,
5835,
2011,
5164,
13373,
12,
314,
3499,
900,
12,
267,
652,
7859,
1133,
1218,
282,
8028,
14,
267,
408,
267,
8028,
14,
1462,
14,
362,
63,
269,
63,
981,
8,
288,
1642,
63,
354,
534,
4240,
24591,
297,
2061,
63,
354,
534,
18248,
322,
834,
297,
4243,
3126,
355,
283,
15881,
356,
1434,
8,
1167,
2824,
12,
499,
12,
5661,
9,
288,
789,
267,
776,
267,
2737,
275,
8028,
14,
1462,
14,
362,
63,
269,
63,
981,
8,
288,
1642,
63,
354,
534,
4240,
24591,
297,
2061,
63,
354,
534,
18248,
322,
834,
297,
4243,
3126,
355,
283,
15881,
356,
1434,
8,
1167,
2824,
12,
499,
12,
5661,
9,
288,
789,
267,
29688,
17,
61,
398,
291,
14,
3334,
8,
3966,
9,
267,
291,
14,
629,
8,
7344,
14,
1462,
14,
835,
1062,
499,
9,
339,
347,
511,
63,
362,
63,
269,
63,
981,
63,
3197,
63,
1162,
8,
277,
304,
267,
408,
267,
982,
1265,
2793,
1133,
4165,
282,
574,
503,
849,
574,
367,
1006,
1415,
267,
1504,
12,
1265,
911,
664,
376,
1125,
14,
267,
408,
267,
291,
14,
1855,
8,
288,
26864,
12,
288,
8028,
14,
1462,
14,
362,
63,
269,
63,
981,
12,
1642,
63,
354,
628,
52,
676,
401,
2061,
63,
354,
628,
16782,
448,
2,
267,
776,
339,
347,
511,
63,
362,
63,
269,
63,
981,
63,
265,
63,
2407,
63,
2609,
8,
277,
304,
267,
299,
275,
19952,
281,
14,
1462,
14,
981,
8,
354,
628,
1945,
278,
19952,
316,
531,
267,
327,
2790,
282,
6719,
4012,
314,
19704,
14,
267,
6719,
12,
2737,
275,
299,
14,
8858,
14,
362,
63,
269,
63,
981,
8,
354,
628,
1918,
8944,
402,
17379,
1253,
481,
581,
531,
267,
291,
14,
1815,
8,
3966,
9,
267,
327,
710,
19704,
1077,
1172,
1373,
6719,
14,
267,
291,
14,
629,
8,
80,
14,
8858,
14,
835,
1062,
413,
9,
398,
327,
7649,
664,
63,
269,
63,
981,
4020,
12,
642,
900,
6548,
1077,
506,
2737,
14,
267,
6719,
12,
2737,
275,
299,
14,
8858,
14,
362,
63,
269,
63,
981,
8,
354,
628,
1918,
8944,
402,
17379,
1253,
481,
581,
531,
267,
291,
14,
3334,
8,
3966,
9,
267,
327,
6061,
314,
19704,
1077,
5139,
1172,
1373,
6719,
14,
267,
291,
14,
629,
8,
80,
14,
8858,
14,
835,
1062,
413,
9,
398,
327,
2654,
376,
4132,
370,
314,
6719,
14,
267,
3988,
12,
2737,
275,
6719,
14,
8149,
14,
362,
63,
269,
63,
981,
8,
354,
628,
8751,
531,
267,
291,
14,
1815,
8,
3966,
9,
267,
327,
710,
6719,
1077,
1172,
1373,
4132,
14,
267,
291,
14,
629,
8,
2706,
14,
8149,
14,
835,
1062,
413,
9,
398,
327,
7649,
664,
63,
269,
63,
981,
4020,
12,
642,
900,
6548,
1077,
506,
2737,
14,
267,
3988,
12,
2737,
275,
6719,
14,
8149,
14,
362,
63,
269,
63,
981,
8,
354,
628,
8751,
531,
267,
291,
14,
3334,
8,
3966,
9,
267,
327,
6061,
314,
6719,
1077,
5139,
1172,
1373,
4132,
14,
267,
291,
14,
629,
8,
2706,
14,
8149,
14,
835,
1062,
413,
9,
398,
327,
2654,
282,
3499,
4132,
370,
314,
6719,
14,
267,
289,
581,
12,
2737,
275,
6719,
14,
8149,
14,
362,
63,
269,
63,
981,
8,
354,
628,
38,
581,
531,
267,
291,
14,
1815,
8,
3966,
9,
398,
327,
710,
6719,
1077,
1172,
2877,
11462,
3063,
14,
267,
291,
14,
629,
8,
2706,
14,
8149,
14,
835,
1062,
499,
9,
398,
327,
2790,
376,
6529,
440,
29142,
370,
1263,
19040,
14,
267,
6529,
14,
1462,
14,
981,
8,
354,
628,
52,
379,
531,
398,
327,
6006,
1077,
506,
7795,
6642,
315,
3141,
14,
710,
6719,
909,
1077,
1172,
2877,
14,
267,
291,
14,
629,
8,
5949,
14,
1462,
14,
835,
1062,
650,
9,
267,
291,
14,
629,
8,
2706,
14,
8149,
14,
835,
1062,
499,
9,
398,
327,
7649,
6425,
282,
6719,
4012,
376,
4132,
14,
267,
5501,
2737,
275,
3988,
14,
8858,
14,
362,
63,
269,
63,
981,
8,
354,
628,
8751,
1159,
799,
8233,
83,
401,
19704,
29,
80,
9,
267,
291,
14,
1815,
8,
3966,
9,
398,
327,
7356,
17379,
965,
2877,
8944,
83
] |
[
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
5190,
199,
504,
2197,
492,
1434,
199,
199,
504,
1639,
14,
697,
492,
27728,
12,
26864,
199,
504,
1639,
14,
396,
492,
7640,
12,
18244,
1746,
12,
3686,
63,
5451,
199,
504,
1639,
14,
1208,
14,
2991,
492,
5634,
7087,
12620,
199,
199,
504,
1275,
992,
492,
334,
272,
6529,
12,
8944,
12,
3758,
7344,
12,
30247,
29457,
774,
12,
8028,
12,
14386,
12,
272,
19952,
281,
12,
8053,
12,
3868,
316,
12,
199,
9,
421,
199,
533,
2372,
2844,
2499,
2925,
8,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
552,
2865,
275,
8028,
14,
1462,
14,
981,
8,
288,
1642,
63,
354,
534,
12923,
297,
2061,
63,
354,
534,
3166,
2865,
297,
21036,
2977,
29,
602,
8,
30614,
12,
1616,
12,
1749,
9,
267,
776,
339,
347,
511,
63,
362,
63,
269,
63,
981,
63,
765,
63,
1045,
63,
362,
8,
277,
304,
267,
2737,
275,
8028,
14,
1462,
14,
362,
63,
269,
63,
981,
8,
288,
1642,
63,
354,
628,
12923,
401,
2061,
63,
354,
628,
3166,
2865,
401,
4243,
3126,
355,
298,
15881,
582,
1434,
8,
30614,
12,
1616,
12,
1749,
9,
288,
789,
267,
29688,
17,
61,
267,
291,
14,
3334,
8,
3966,
9,
267,
291,
14,
629,
8,
7344,
14,
1462,
14,
835,
1062,
413,
9,
339,
347,
511,
63,
362,
63,
269,
63,
981,
63,
765,
63,
1045,
63,
981,
8,
277,
304,
267,
2737,
275,
8028,
14,
1462,
14,
362,
63,
269,
63,
981,
8,
288,
1642,
63,
354,
534,
4240,
24591,
297,
2061,
63,
354,
534,
18248,
322,
834,
297,
4243,
3126,
355,
283,
15881,
356,
1434,
8,
1167,
2824,
12,
499,
12,
5661,
9,
288,
789,
267,
29688,
17,
61,
267,
291,
14,
1815,
8,
3966,
9,
267,
291,
14,
629,
8,
7344,
14,
1462,
14,
835,
1062,
499,
9,
339,
347,
511,
63,
362,
63,
269,
63,
981,
63,
581,
17013,
63,
842,
8,
277,
304,
267,
408,
267,
982,
781,
5341,
314,
5835,
2011,
5164,
13373,
12,
314,
3499,
900,
12,
267,
652,
7859,
1133,
1218,
282,
8028,
14,
267,
408,
267,
8028,
14,
1462,
14,
362,
63,
269,
63,
981,
8,
288,
1642,
63,
354,
534,
4240,
24591,
297,
2061,
63,
354,
534,
18248,
322,
834,
297,
4243,
3126,
355,
283,
15881,
356,
1434,
8,
1167,
2824,
12,
499,
12,
5661,
9,
288,
789,
267,
776,
267,
2737,
275,
8028,
14,
1462,
14,
362,
63,
269,
63,
981,
8,
288,
1642,
63,
354,
534,
4240,
24591,
297,
2061,
63,
354,
534,
18248,
322,
834,
297,
4243,
3126,
355,
283,
15881,
356,
1434,
8,
1167,
2824,
12,
499,
12,
5661,
9,
288,
789,
267,
29688,
17,
61,
398,
291,
14,
3334,
8,
3966,
9,
267,
291,
14,
629,
8,
7344,
14,
1462,
14,
835,
1062,
499,
9,
339,
347,
511,
63,
362,
63,
269,
63,
981,
63,
3197,
63,
1162,
8,
277,
304,
267,
408,
267,
982,
1265,
2793,
1133,
4165,
282,
574,
503,
849,
574,
367,
1006,
1415,
267,
1504,
12,
1265,
911,
664,
376,
1125,
14,
267,
408,
267,
291,
14,
1855,
8,
288,
26864,
12,
288,
8028,
14,
1462,
14,
362,
63,
269,
63,
981,
12,
1642,
63,
354,
628,
52,
676,
401,
2061,
63,
354,
628,
16782,
448,
2,
267,
776,
339,
347,
511,
63,
362,
63,
269,
63,
981,
63,
265,
63,
2407,
63,
2609,
8,
277,
304,
267,
299,
275,
19952,
281,
14,
1462,
14,
981,
8,
354,
628,
1945,
278,
19952,
316,
531,
267,
327,
2790,
282,
6719,
4012,
314,
19704,
14,
267,
6719,
12,
2737,
275,
299,
14,
8858,
14,
362,
63,
269,
63,
981,
8,
354,
628,
1918,
8944,
402,
17379,
1253,
481,
581,
531,
267,
291,
14,
1815,
8,
3966,
9,
267,
327,
710,
19704,
1077,
1172,
1373,
6719,
14,
267,
291,
14,
629,
8,
80,
14,
8858,
14,
835,
1062,
413,
9,
398,
327,
7649,
664,
63,
269,
63,
981,
4020,
12,
642,
900,
6548,
1077,
506,
2737,
14,
267,
6719,
12,
2737,
275,
299,
14,
8858,
14,
362,
63,
269,
63,
981,
8,
354,
628,
1918,
8944,
402,
17379,
1253,
481,
581,
531,
267,
291,
14,
3334,
8,
3966,
9,
267,
327,
6061,
314,
19704,
1077,
5139,
1172,
1373,
6719,
14,
267,
291,
14,
629,
8,
80,
14,
8858,
14,
835,
1062,
413,
9,
398,
327,
2654,
376,
4132,
370,
314,
6719,
14,
267,
3988,
12,
2737,
275,
6719,
14,
8149,
14,
362,
63,
269,
63,
981,
8,
354,
628,
8751,
531,
267,
291,
14,
1815,
8,
3966,
9,
267,
327,
710,
6719,
1077,
1172,
1373,
4132,
14,
267,
291,
14,
629,
8,
2706,
14,
8149,
14,
835,
1062,
413,
9,
398,
327,
7649,
664,
63,
269,
63,
981,
4020,
12,
642,
900,
6548,
1077,
506,
2737,
14,
267,
3988,
12,
2737,
275,
6719,
14,
8149,
14,
362,
63,
269,
63,
981,
8,
354,
628,
8751,
531,
267,
291,
14,
3334,
8,
3966,
9,
267,
327,
6061,
314,
6719,
1077,
5139,
1172,
1373,
4132,
14,
267,
291,
14,
629,
8,
2706,
14,
8149,
14,
835,
1062,
413,
9,
398,
327,
2654,
282,
3499,
4132,
370,
314,
6719,
14,
267,
289,
581,
12,
2737,
275,
6719,
14,
8149,
14,
362,
63,
269,
63,
981,
8,
354,
628,
38,
581,
531,
267,
291,
14,
1815,
8,
3966,
9,
398,
327,
710,
6719,
1077,
1172,
2877,
11462,
3063,
14,
267,
291,
14,
629,
8,
2706,
14,
8149,
14,
835,
1062,
499,
9,
398,
327,
2790,
376,
6529,
440,
29142,
370,
1263,
19040,
14,
267,
6529,
14,
1462,
14,
981,
8,
354,
628,
52,
379,
531,
398,
327,
6006,
1077,
506,
7795,
6642,
315,
3141,
14,
710,
6719,
909,
1077,
1172,
2877,
14,
267,
291,
14,
629,
8,
5949,
14,
1462,
14,
835,
1062,
650,
9,
267,
291,
14,
629,
8,
2706,
14,
8149,
14,
835,
1062,
499,
9,
398,
327,
7649,
6425,
282,
6719,
4012,
376,
4132,
14,
267,
5501,
2737,
275,
3988,
14,
8858,
14,
362,
63,
269,
63,
981,
8,
354,
628,
8751,
1159,
799,
8233,
83,
401,
19704,
29,
80,
9,
267,
291,
14,
1815,
8,
3966,
9,
398,
327,
7356,
17379,
965,
2877,
8944,
83,
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
] |
btabibian/scikit-learn
|
examples/linear_model/plot_multi_task_lasso_support.py
|
102
|
2319
|
#!/usr/bin/env python
"""
=============================================
Joint feature selection with multi-task Lasso
=============================================
The multi-task lasso allows to fit multiple regression problems
jointly enforcing the selected features to be the same across
tasks. This example simulates sequential measurements, each task
is a time instant, and the relevant features vary in amplitude
over time while being the same. The multi-task lasso imposes that
features that are selected at one time point are select for all time
point. This makes feature selection by the Lasso more stable.
"""
print(__doc__)
# Author: Alexandre Gramfort <alexandre.gramfort@inria.fr>
# License: BSD 3 clause
import matplotlib.pyplot as plt
import numpy as np
from sklearn.linear_model import MultiTaskLasso, Lasso
rng = np.random.RandomState(42)
# Generate some 2D coefficients with sine waves with random frequency and phase
n_samples, n_features, n_tasks = 100, 30, 40
n_relevant_features = 5
coef = np.zeros((n_tasks, n_features))
times = np.linspace(0, 2 * np.pi, n_tasks)
for k in range(n_relevant_features):
coef[:, k] = np.sin((1. + rng.randn(1)) * times + 3 * rng.randn(1))
X = rng.randn(n_samples, n_features)
Y = np.dot(X, coef.T) + rng.randn(n_samples, n_tasks)
coef_lasso_ = np.array([Lasso(alpha=0.5).fit(X, y).coef_ for y in Y.T])
coef_multi_task_lasso_ = MultiTaskLasso(alpha=1.).fit(X, Y).coef_
###############################################################################
# Plot support and time series
fig = plt.figure(figsize=(8, 5))
plt.subplot(1, 2, 1)
plt.spy(coef_lasso_)
plt.xlabel('Feature')
plt.ylabel('Time (or Task)')
plt.text(10, 5, 'Lasso')
plt.subplot(1, 2, 2)
plt.spy(coef_multi_task_lasso_)
plt.xlabel('Feature')
plt.ylabel('Time (or Task)')
plt.text(10, 5, 'MultiTaskLasso')
fig.suptitle('Coefficient non-zero location')
feature_to_plot = 0
plt.figure()
lw = 2
plt.plot(coef[:, feature_to_plot], color='seagreen', linewidth=lw,
label='Ground truth')
plt.plot(coef_lasso_[:, feature_to_plot], color='cornflowerblue', linewidth=lw,
label='Lasso')
plt.plot(coef_multi_task_lasso_[:, feature_to_plot], color='gold', linewidth=lw,
label='MultiTaskLasso')
plt.legend(loc='upper center')
plt.axis('tight')
plt.ylim([-1.1, 1.1])
plt.show()
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
624,
199,
2486,
9152,
199,
30219,
3878,
7267,
543,
3510,
13,
1765,
29029,
199,
2486,
9152,
199,
199,
1918,
3510,
13,
1765,
634,
15923,
6127,
370,
5542,
3663,
10864,
8826,
199,
10153,
590,
655,
509,
4477,
314,
4895,
4534,
370,
506,
314,
2011,
9371,
199,
5054,
14,
961,
2893,
4389,
15409,
23381,
32619,
12,
1924,
2120,
199,
374,
282,
900,
2727,
867,
12,
436,
314,
12082,
4534,
17083,
315,
30727,
199,
1883,
900,
1830,
3769,
314,
2011,
14,
710,
3510,
13,
1765,
634,
15923,
1742,
32128,
626,
199,
3179,
626,
787,
4895,
737,
1373,
900,
2376,
787,
3504,
367,
1006,
900,
199,
1403,
14,
961,
7704,
3878,
7267,
701,
314,
29029,
1655,
17830,
14,
199,
199,
624,
199,
1361,
3460,
1301,
3368,
199,
199,
3,
6529,
26,
22986,
28547,
27211,
10279,
665,
24421,
28547,
14,
1679,
10279,
32,
262,
23714,
14,
4391,
30,
199,
3,
844,
26,
6289,
650,
8502,
199,
199,
646,
8027,
14,
13563,
465,
4488,
199,
646,
2680,
465,
980,
199,
199,
504,
6357,
14,
6676,
63,
1238,
492,
6879,
4476,
27537,
12,
29029,
199,
199,
12686,
275,
980,
14,
2355,
14,
15726,
8,
2260,
9,
199,
199,
3,
7958,
2005,
499,
36,
12343,
543,
308,
1132,
336,
7047,
543,
2196,
9857,
436,
7669,
199,
78,
63,
3356,
12,
302,
63,
3179,
12,
302,
63,
5054,
275,
2948,
12,
4233,
12,
6335,
199,
78,
63,
21906,
63,
3179,
275,
959,
199,
8009,
275,
980,
14,
4250,
1332,
78,
63,
5054,
12,
302,
63,
3179,
430,
199,
4508,
275,
980,
14,
11649,
8,
16,
12,
499,
627,
980,
14,
1038,
12,
302,
63,
5054,
9,
199,
509,
1022,
315,
1425,
8,
78,
63,
21906,
63,
3179,
304,
272,
7355,
3981,
1022,
61,
275,
980,
14,
5911,
1332,
17,
14,
435,
9038,
14,
10843,
8,
17,
430,
627,
5431,
435,
650,
627,
9038,
14,
10843,
8,
17,
430,
199,
199,
56,
275,
9038,
14,
10843,
8,
78,
63,
3356,
12,
302,
63,
3179,
9,
199,
57,
275,
980,
14,
3287,
8,
56,
12,
7355,
14,
52,
9,
435,
9038,
14,
10843,
8,
78,
63,
3356,
12,
302,
63,
5054,
9,
199,
199,
8009,
63,
18412,
63,
275,
980,
14,
1144,
779,
27537,
8,
4468,
29,
16,
14,
21,
680,
3269,
8,
56,
12,
612,
680,
8009,
63,
367,
612,
315,
1488,
14,
52,
566,
199,
8009,
63,
3029,
63,
1765,
63,
18412,
63,
275,
6879,
4476,
27537,
8,
4468,
29,
17,
25860,
3269,
8,
56,
12,
1488,
680,
8009,
63,
199,
199,
11490,
199,
3,
14794,
2291,
436,
900,
6779,
199,
592,
275,
4488,
14,
8941,
8,
23899,
2687,
24,
12,
959,
430,
199,
6003,
14,
13334,
8,
17,
12,
499,
12,
413,
9,
199,
6003,
14,
15252,
8,
8009,
63,
18412,
4602,
199,
6003,
14,
14168,
360,
5968,
358,
199,
6003,
14,
13849,
360,
1366,
334,
269,
8495,
5942,
199,
6003,
14,
505,
8,
709,
12,
959,
12,
283,
27537,
358,
199,
6003,
14,
13334,
8,
17,
12,
499,
12,
499,
9,
199,
6003,
14,
15252,
8,
8009,
63,
3029,
63,
1765,
63,
18412,
4602,
199,
6003,
14,
14168,
360,
5968,
358,
199,
6003,
14,
13849,
360,
1366,
334,
269,
8495,
5942,
199,
6003,
14,
505,
8,
709,
12,
959,
12,
283,
3947,
4476,
27537,
358,
199,
592,
14,
1961,
1213,
360,
967,
21069,
2222,
13,
4262,
2909,
358,
199,
199,
4445,
63,
475,
63,
2798,
275,
378,
199,
6003,
14,
8941,
342,
199,
20692,
275,
499,
199,
6003,
14,
2798,
8,
8009,
3981,
3878,
63,
475,
63,
2798,
467,
3164,
534,
261,
643,
3441,
297,
21213,
29,
20692,
12,
268,
1768,
534,
39,
2363,
16865,
358,
199,
6003,
14,
2798,
8,
8009,
63,
18412,
63,
3981,
3878,
63,
475,
63,
2798,
467,
3164,
534,
989,
78,
1659,
281,
6304,
297,
21213,
29,
20692,
12,
268,
1768,
534,
27537,
358,
199,
6003,
14,
2798,
8,
8009,
63,
3029,
63,
1765,
63,
18412,
63,
3981,
3878,
63,
475,
63,
2798,
467,
3164,
534,
23628,
297,
21213,
29,
20692,
12,
268,
1768,
534,
3947,
4476,
27537,
358,
199,
6003,
14,
10231,
8,
2102,
534,
4142,
8126,
358,
199,
6003,
14,
3127,
360,
23787,
358,
199,
6003,
14,
18123,
11468,
17,
14,
17,
12,
413,
14,
17,
566,
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
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
624,
199,
2486,
9152,
199,
30219,
3878,
7267,
543,
3510,
13,
1765,
29029,
199,
2486,
9152,
199,
199,
1918,
3510,
13,
1765,
634,
15923,
6127,
370,
5542,
3663,
10864,
8826,
199,
10153,
590,
655,
509,
4477,
314,
4895,
4534,
370,
506,
314,
2011,
9371,
199,
5054,
14,
961,
2893,
4389,
15409,
23381,
32619,
12,
1924,
2120,
199,
374,
282,
900,
2727,
867,
12,
436,
314,
12082,
4534,
17083,
315,
30727,
199,
1883,
900,
1830,
3769,
314,
2011,
14,
710,
3510,
13,
1765,
634,
15923,
1742,
32128,
626,
199,
3179,
626,
787,
4895,
737,
1373,
900,
2376,
787,
3504,
367,
1006,
900,
199,
1403,
14,
961,
7704,
3878,
7267,
701,
314,
29029,
1655,
17830,
14,
199,
199,
624,
199,
1361,
3460,
1301,
3368,
199,
199,
3,
6529,
26,
22986,
28547,
27211,
10279,
665,
24421,
28547,
14,
1679,
10279,
32,
262,
23714,
14,
4391,
30,
199,
3,
844,
26,
6289,
650,
8502,
199,
199,
646,
8027,
14,
13563,
465,
4488,
199,
646,
2680,
465,
980,
199,
199,
504,
6357,
14,
6676,
63,
1238,
492,
6879,
4476,
27537,
12,
29029,
199,
199,
12686,
275,
980,
14,
2355,
14,
15726,
8,
2260,
9,
199,
199,
3,
7958,
2005,
499,
36,
12343,
543,
308,
1132,
336,
7047,
543,
2196,
9857,
436,
7669,
199,
78,
63,
3356,
12,
302,
63,
3179,
12,
302,
63,
5054,
275,
2948,
12,
4233,
12,
6335,
199,
78,
63,
21906,
63,
3179,
275,
959,
199,
8009,
275,
980,
14,
4250,
1332,
78,
63,
5054,
12,
302,
63,
3179,
430,
199,
4508,
275,
980,
14,
11649,
8,
16,
12,
499,
627,
980,
14,
1038,
12,
302,
63,
5054,
9,
199,
509,
1022,
315,
1425,
8,
78,
63,
21906,
63,
3179,
304,
272,
7355,
3981,
1022,
61,
275,
980,
14,
5911,
1332,
17,
14,
435,
9038,
14,
10843,
8,
17,
430,
627,
5431,
435,
650,
627,
9038,
14,
10843,
8,
17,
430,
199,
199,
56,
275,
9038,
14,
10843,
8,
78,
63,
3356,
12,
302,
63,
3179,
9,
199,
57,
275,
980,
14,
3287,
8,
56,
12,
7355,
14,
52,
9,
435,
9038,
14,
10843,
8,
78,
63,
3356,
12,
302,
63,
5054,
9,
199,
199,
8009,
63,
18412,
63,
275,
980,
14,
1144,
779,
27537,
8,
4468,
29,
16,
14,
21,
680,
3269,
8,
56,
12,
612,
680,
8009,
63,
367,
612,
315,
1488,
14,
52,
566,
199,
8009,
63,
3029,
63,
1765,
63,
18412,
63,
275,
6879,
4476,
27537,
8,
4468,
29,
17,
25860,
3269,
8,
56,
12,
1488,
680,
8009,
63,
199,
199,
11490,
199,
3,
14794,
2291,
436,
900,
6779,
199,
592,
275,
4488,
14,
8941,
8,
23899,
2687,
24,
12,
959,
430,
199,
6003,
14,
13334,
8,
17,
12,
499,
12,
413,
9,
199,
6003,
14,
15252,
8,
8009,
63,
18412,
4602,
199,
6003,
14,
14168,
360,
5968,
358,
199,
6003,
14,
13849,
360,
1366,
334,
269,
8495,
5942,
199,
6003,
14,
505,
8,
709,
12,
959,
12,
283,
27537,
358,
199,
6003,
14,
13334,
8,
17,
12,
499,
12,
499,
9,
199,
6003,
14,
15252,
8,
8009,
63,
3029,
63,
1765,
63,
18412,
4602,
199,
6003,
14,
14168,
360,
5968,
358,
199,
6003,
14,
13849,
360,
1366,
334,
269,
8495,
5942,
199,
6003,
14,
505,
8,
709,
12,
959,
12,
283,
3947,
4476,
27537,
358,
199,
592,
14,
1961,
1213,
360,
967,
21069,
2222,
13,
4262,
2909,
358,
199,
199,
4445,
63,
475,
63,
2798,
275,
378,
199,
6003,
14,
8941,
342,
199,
20692,
275,
499,
199,
6003,
14,
2798,
8,
8009,
3981,
3878,
63,
475,
63,
2798,
467,
3164,
534,
261,
643,
3441,
297,
21213,
29,
20692,
12,
268,
1768,
534,
39,
2363,
16865,
358,
199,
6003,
14,
2798,
8,
8009,
63,
18412,
63,
3981,
3878,
63,
475,
63,
2798,
467,
3164,
534,
989,
78,
1659,
281,
6304,
297,
21213,
29,
20692,
12,
268,
1768,
534,
27537,
358,
199,
6003,
14,
2798,
8,
8009,
63,
3029,
63,
1765,
63,
18412,
63,
3981,
3878,
63,
475,
63,
2798,
467,
3164,
534,
23628,
297,
21213,
29,
20692,
12,
268,
1768,
534,
3947,
4476,
27537,
358,
199,
6003,
14,
10231,
8,
2102,
534,
4142,
8126,
358,
199,
6003,
14,
3127,
360,
23787,
358,
199,
6003,
14,
18123,
11468,
17,
14,
17,
12,
413,
14,
17,
566,
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,
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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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
genehuangtaiwan/common
|
tools/perf/tests/attr.py
|
3174
|
9441
|
#! /usr/bin/python
import os
import sys
import glob
import optparse
import tempfile
import logging
import shutil
import ConfigParser
class Fail(Exception):
def __init__(self, test, msg):
self.msg = msg
self.test = test
def getMsg(self):
return '\'%s\' - %s' % (self.test.path, self.msg)
class Unsup(Exception):
def __init__(self, test):
self.test = test
def getMsg(self):
return '\'%s\'' % self.test.path
class Event(dict):
terms = [
'cpu',
'flags',
'type',
'size',
'config',
'sample_period',
'sample_type',
'read_format',
'disabled',
'inherit',
'pinned',
'exclusive',
'exclude_user',
'exclude_kernel',
'exclude_hv',
'exclude_idle',
'mmap',
'comm',
'freq',
'inherit_stat',
'enable_on_exec',
'task',
'watermark',
'precise_ip',
'mmap_data',
'sample_id_all',
'exclude_host',
'exclude_guest',
'exclude_callchain_kernel',
'exclude_callchain_user',
'wakeup_events',
'bp_type',
'config1',
'config2',
'branch_sample_type',
'sample_regs_user',
'sample_stack_user',
]
def add(self, data):
for key, val in data:
log.debug(" %s = %s" % (key, val))
self[key] = val
def __init__(self, name, data, base):
log.debug(" Event %s" % name);
self.name = name;
self.group = ''
self.add(base)
self.add(data)
def compare_data(self, a, b):
# Allow multiple values in assignment separated by '|'
a_list = a.split('|')
b_list = b.split('|')
for a_item in a_list:
for b_item in b_list:
if (a_item == b_item):
return True
elif (a_item == '*') or (b_item == '*'):
return True
return False
def equal(self, other):
for t in Event.terms:
log.debug(" [%s] %s %s" % (t, self[t], other[t]));
if not self.has_key(t) or not other.has_key(t):
return False
if not self.compare_data(self[t], other[t]):
return False
return True
def diff(self, other):
for t in Event.terms:
if not self.has_key(t) or not other.has_key(t):
continue
if not self.compare_data(self[t], other[t]):
log.warning("expected %s=%s, got %s" % (t, self[t], other[t]))
# Test file description needs to have following sections:
# [config]
# - just single instance in file
# - needs to specify:
# 'command' - perf command name
# 'args' - special command arguments
# 'ret' - expected command return value (0 by default)
#
# [eventX:base]
# - one or multiple instances in file
# - expected values assignments
class Test(object):
def __init__(self, path, options):
parser = ConfigParser.SafeConfigParser()
parser.read(path)
log.warning("running '%s'" % path)
self.path = path
self.test_dir = options.test_dir
self.perf = options.perf
self.command = parser.get('config', 'command')
self.args = parser.get('config', 'args')
try:
self.ret = parser.get('config', 'ret')
except:
self.ret = 0
self.expect = {}
self.result = {}
log.debug(" loading expected events");
self.load_events(path, self.expect)
def is_event(self, name):
if name.find("event") == -1:
return False
else:
return True
def load_events(self, path, events):
parser_event = ConfigParser.SafeConfigParser()
parser_event.read(path)
# The event record section header contains 'event' word,
# optionaly followed by ':' allowing to load 'parent
# event' first as a base
for section in filter(self.is_event, parser_event.sections()):
parser_items = parser_event.items(section);
base_items = {}
# Read parent event if there's any
if (':' in section):
base = section[section.index(':') + 1:]
parser_base = ConfigParser.SafeConfigParser()
parser_base.read(self.test_dir + '/' + base)
base_items = parser_base.items('event')
e = Event(section, parser_items, base_items)
events[section] = e
def run_cmd(self, tempdir):
cmd = "PERF_TEST_ATTR=%s %s %s -o %s/perf.data %s" % (tempdir,
self.perf, self.command, tempdir, self.args)
ret = os.WEXITSTATUS(os.system(cmd))
log.info(" '%s' ret %d " % (cmd, ret))
if ret != int(self.ret):
raise Unsup(self)
def compare(self, expect, result):
match = {}
log.debug(" compare");
# For each expected event find all matching
# events in result. Fail if there's not any.
for exp_name, exp_event in expect.items():
exp_list = []
log.debug(" matching [%s]" % exp_name)
for res_name, res_event in result.items():
log.debug(" to [%s]" % res_name)
if (exp_event.equal(res_event)):
exp_list.append(res_name)
log.debug(" ->OK")
else:
log.debug(" ->FAIL");
log.debug(" match: [%s] matches %s" % (exp_name, str(exp_list)))
# we did not any matching event - fail
if (not exp_list):
exp_event.diff(res_event)
raise Fail(self, 'match failure');
match[exp_name] = exp_list
# For each defined group in the expected events
# check we match the same group in the result.
for exp_name, exp_event in expect.items():
group = exp_event.group
if (group == ''):
continue
for res_name in match[exp_name]:
res_group = result[res_name].group
if res_group not in match[group]:
raise Fail(self, 'group failure')
log.debug(" group: [%s] matches group leader %s" %
(exp_name, str(match[group])))
log.debug(" matched")
def resolve_groups(self, events):
for name, event in events.items():
group_fd = event['group_fd'];
if group_fd == '-1':
continue;
for iname, ievent in events.items():
if (ievent['fd'] == group_fd):
event.group = iname
log.debug('[%s] has group leader [%s]' % (name, iname))
break;
def run(self):
tempdir = tempfile.mkdtemp();
try:
# run the test script
self.run_cmd(tempdir);
# load events expectation for the test
log.debug(" loading result events");
for f in glob.glob(tempdir + '/event*'):
self.load_events(f, self.result);
# resolve group_fd to event names
self.resolve_groups(self.expect);
self.resolve_groups(self.result);
# do the expectation - results matching - both ways
self.compare(self.expect, self.result)
self.compare(self.result, self.expect)
finally:
# cleanup
shutil.rmtree(tempdir)
def run_tests(options):
for f in glob.glob(options.test_dir + '/' + options.test):
try:
Test(f, options).run()
except Unsup, obj:
log.warning("unsupp %s" % obj.getMsg())
def setup_log(verbose):
global log
level = logging.CRITICAL
if verbose == 1:
level = logging.WARNING
if verbose == 2:
level = logging.INFO
if verbose >= 3:
level = logging.DEBUG
log = logging.getLogger('test')
log.setLevel(level)
ch = logging.StreamHandler()
ch.setLevel(level)
formatter = logging.Formatter('%(message)s')
ch.setFormatter(formatter)
log.addHandler(ch)
USAGE = '''%s [OPTIONS]
-d dir # tests dir
-p path # perf binary
-t test # single test
-v # verbose level
''' % sys.argv[0]
def main():
parser = optparse.OptionParser(usage=USAGE)
parser.add_option("-t", "--test",
action="store", type="string", dest="test")
parser.add_option("-d", "--test-dir",
action="store", type="string", dest="test_dir")
parser.add_option("-p", "--perf",
action="store", type="string", dest="perf")
parser.add_option("-v", "--verbose",
action="count", dest="verbose")
options, args = parser.parse_args()
if args:
parser.error('FAILED wrong arguments %s' % ' '.join(args))
return -1
setup_log(options.verbose)
if not options.test_dir:
print 'FAILED no -d option specified'
sys.exit(-1)
if not options.test:
options.test = 'test*'
try:
run_tests(options)
except Fail, obj:
print "FAILED %s" % obj.getMsg();
sys.exit(-1)
sys.exit(0)
if __name__ == '__main__':
main()
|
gpl-2.0
|
[
3168,
1182,
2647,
15,
1393,
15,
1548,
199,
199,
646,
747,
199,
646,
984,
199,
646,
5739,
199,
646,
8691,
199,
646,
5549,
199,
646,
2050,
199,
646,
5145,
199,
646,
14196,
199,
199,
533,
12176,
8,
1726,
304,
272,
347,
636,
826,
721,
277,
12,
511,
12,
1499,
304,
267,
291,
14,
1328,
275,
1499,
267,
291,
14,
396,
275,
511,
272,
347,
664,
6173,
8,
277,
304,
267,
372,
1557,
5956,
83,
3985,
446,
450,
83,
7,
450,
334,
277,
14,
396,
14,
515,
12,
291,
14,
1328,
9,
199,
199,
533,
15254,
384,
8,
1726,
304,
272,
347,
636,
826,
721,
277,
12,
511,
304,
267,
291,
14,
396,
275,
511,
272,
347,
664,
6173,
8,
277,
304,
267,
372,
1557,
5956,
83,
60,
891,
450,
291,
14,
396,
14,
515,
199,
199,
533,
6763,
8,
807,
304,
272,
2895,
275,
359,
267,
283,
3541,
297,
267,
283,
2469,
297,
267,
283,
466,
297,
267,
283,
890,
297,
267,
283,
888,
297,
267,
283,
3271,
63,
5191,
297,
267,
283,
3271,
63,
466,
297,
267,
283,
739,
63,
908,
297,
267,
283,
7011,
297,
267,
283,
6486,
297,
267,
283,
7751,
7439,
297,
267,
283,
12730,
297,
267,
283,
5473,
63,
751,
297,
267,
283,
5473,
63,
4989,
297,
267,
283,
5473,
63,
22926,
297,
267,
283,
5473,
63,
12000,
297,
267,
283,
20671,
297,
267,
283,
1404,
297,
267,
283,
5646,
297,
267,
283,
6486,
63,
3736,
297,
267,
283,
4296,
63,
265,
63,
1628,
297,
267,
283,
1765,
297,
267,
283,
17217,
1657,
297,
267,
283,
657,
11900,
63,
711,
297,
267,
283,
20671,
63,
576,
297,
267,
283,
3271,
63,
344,
63,
452,
297,
267,
283,
5473,
63,
1102,
297,
267,
283,
5473,
63,
10409,
297,
267,
283,
5473,
63,
1250,
4429,
63,
4989,
297,
267,
283,
5473,
63,
1250,
4429,
63,
751,
297,
267,
283,
28715,
63,
4368,
297,
267,
283,
10913,
63,
466,
297,
267,
283,
888,
17,
297,
267,
283,
888,
18,
297,
267,
283,
4694,
63,
3271,
63,
466,
297,
267,
283,
3271,
63,
23957,
63,
751,
297,
267,
283,
3271,
63,
2340,
63,
751,
297,
272,
1622,
339,
347,
1050,
8,
277,
12,
666,
304,
267,
367,
790,
12,
1139,
315,
666,
26,
288,
943,
14,
1757,
480,
420,
450,
83,
275,
450,
83,
2,
450,
334,
498,
12,
1139,
430,
288,
291,
59,
498,
61,
275,
1139,
339,
347,
636,
826,
721,
277,
12,
536,
12,
666,
12,
1300,
304,
267,
943,
14,
1757,
480,
259,
6763,
450,
83,
2,
450,
536,
2736,
267,
291,
14,
354,
221,
275,
536,
27,
267,
291,
14,
923,
275,
2125,
267,
291,
14,
525,
8,
1095,
9,
267,
291,
14,
525,
8,
576,
9,
339,
347,
6540,
63,
576,
8,
277,
12,
282,
12,
330,
304,
267,
327,
9812,
3663,
1338,
315,
9801,
11673,
701,
24628,
267,
282,
63,
513,
275,
282,
14,
1294,
20137,
358,
267,
330,
63,
513,
275,
330,
14,
1294,
20137,
358,
398,
367,
282,
63,
1053,
315,
282,
63,
513,
26,
288,
367,
330,
63,
1053,
315,
330,
63,
513,
26,
355,
340,
334,
65,
63,
1053,
508,
330,
63,
1053,
304,
490,
372,
715,
355,
916,
334,
65,
63,
1053,
508,
6438,
358,
503,
334,
66,
63,
1053,
508,
6438,
735,
490,
372,
715,
398,
372,
756,
339,
347,
4472,
8,
277,
12,
1163,
304,
267,
367,
307,
315,
6763,
14,
9187,
26,
288,
943,
14,
1757,
480,
420,
8978,
83,
61,
450,
83,
450,
83,
2,
450,
334,
84,
12,
291,
59,
84,
467,
1163,
59,
84,
2459,
27,
288,
340,
440,
291,
14,
1989,
63,
498,
8,
84,
9,
503,
440,
1163,
14,
1989,
63,
498,
8,
84,
304,
355,
372,
756,
288,
340,
440,
291,
14,
5785,
63,
576,
8,
277,
59,
84,
467,
1163,
59,
84,
4682,
355,
372,
756,
267,
372,
715,
339,
347,
3915,
8,
277,
12,
1163,
304,
267,
367,
307,
315,
6763,
14,
9187,
26,
288,
340,
440,
291,
14,
1989,
63,
498,
8,
84,
9,
503,
440,
1163,
14,
1989,
63,
498,
8,
84,
304,
355,
1980,
288,
340,
440,
291,
14,
5785,
63,
576,
8,
277,
59,
84,
467,
1163,
59,
84,
4682,
507,
198,
793,
14,
3764,
480,
2062,
450,
83,
2458,
83,
12,
4788,
450,
83,
2,
450,
334,
84,
12,
291,
59,
84,
467,
1163,
59,
84,
2459,
326,
199,
199,
3,
1379,
570,
1369,
4839,
370,
1172,
2569,
10189,
26,
199,
3,
359,
888,
61,
199,
3,
257,
446,
2951,
2849,
1256,
315,
570,
199,
3,
257,
446,
4839,
370,
4165,
26,
199,
3,
258,
283,
1531,
7,
446,
8582,
1414,
536,
199,
3,
258,
283,
589,
7,
259,
446,
4539,
1414,
2368,
199,
3,
258,
283,
3292,
7,
258,
446,
1420,
1414,
372,
574,
334,
16,
701,
849,
9,
199,
3,
199,
3,
359,
1430,
56,
26,
1095,
61,
199,
3,
257,
446,
1373,
503,
3663,
4454,
315,
570,
199,
3,
257,
446,
1420,
1338,
18121,
199,
533,
1379,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
931,
12,
1511,
304,
267,
1798,
275,
14196,
14,
11090,
15218,
342,
267,
1798,
14,
739,
8,
515,
9,
398,
943,
14,
3764,
480,
5720,
1543,
83,
4065,
450,
931,
9,
398,
291,
14,
515,
258,
275,
931,
267,
291,
14,
396,
63,
694,
275,
1511,
14,
396,
63,
694,
267,
291,
14,
9452,
258,
275,
1511,
14,
9452,
267,
291,
14,
1531,
221,
275,
1798,
14,
362,
360,
888,
297,
283,
1531,
358,
267,
291,
14,
589,
258,
275,
1798,
14,
362,
360,
888,
297,
283,
589,
358,
398,
862,
26,
288,
291,
14,
3292,
221,
275,
1798,
14,
362,
360,
888,
297,
283,
3292,
358,
267,
871,
26,
288,
291,
14,
3292,
221,
275,
378,
398,
291,
14,
4921,
257,
275,
1052,
267,
291,
14,
1099,
257,
275,
1052,
267,
943,
14,
1757,
480,
221,
8697,
1420,
4474,
3547,
267,
291,
14,
912,
63,
4368,
8,
515,
12,
291,
14,
4921,
9,
339,
347,
365,
63,
1430,
8,
277,
12,
536,
304,
267,
340,
536,
14,
1623,
480,
1430,
531,
508,
446,
17,
26,
288,
372,
756,
267,
587,
26,
288,
372,
715
] |
[
1182,
2647,
15,
1393,
15,
1548,
199,
199,
646,
747,
199,
646,
984,
199,
646,
5739,
199,
646,
8691,
199,
646,
5549,
199,
646,
2050,
199,
646,
5145,
199,
646,
14196,
199,
199,
533,
12176,
8,
1726,
304,
272,
347,
636,
826,
721,
277,
12,
511,
12,
1499,
304,
267,
291,
14,
1328,
275,
1499,
267,
291,
14,
396,
275,
511,
272,
347,
664,
6173,
8,
277,
304,
267,
372,
1557,
5956,
83,
3985,
446,
450,
83,
7,
450,
334,
277,
14,
396,
14,
515,
12,
291,
14,
1328,
9,
199,
199,
533,
15254,
384,
8,
1726,
304,
272,
347,
636,
826,
721,
277,
12,
511,
304,
267,
291,
14,
396,
275,
511,
272,
347,
664,
6173,
8,
277,
304,
267,
372,
1557,
5956,
83,
60,
891,
450,
291,
14,
396,
14,
515,
199,
199,
533,
6763,
8,
807,
304,
272,
2895,
275,
359,
267,
283,
3541,
297,
267,
283,
2469,
297,
267,
283,
466,
297,
267,
283,
890,
297,
267,
283,
888,
297,
267,
283,
3271,
63,
5191,
297,
267,
283,
3271,
63,
466,
297,
267,
283,
739,
63,
908,
297,
267,
283,
7011,
297,
267,
283,
6486,
297,
267,
283,
7751,
7439,
297,
267,
283,
12730,
297,
267,
283,
5473,
63,
751,
297,
267,
283,
5473,
63,
4989,
297,
267,
283,
5473,
63,
22926,
297,
267,
283,
5473,
63,
12000,
297,
267,
283,
20671,
297,
267,
283,
1404,
297,
267,
283,
5646,
297,
267,
283,
6486,
63,
3736,
297,
267,
283,
4296,
63,
265,
63,
1628,
297,
267,
283,
1765,
297,
267,
283,
17217,
1657,
297,
267,
283,
657,
11900,
63,
711,
297,
267,
283,
20671,
63,
576,
297,
267,
283,
3271,
63,
344,
63,
452,
297,
267,
283,
5473,
63,
1102,
297,
267,
283,
5473,
63,
10409,
297,
267,
283,
5473,
63,
1250,
4429,
63,
4989,
297,
267,
283,
5473,
63,
1250,
4429,
63,
751,
297,
267,
283,
28715,
63,
4368,
297,
267,
283,
10913,
63,
466,
297,
267,
283,
888,
17,
297,
267,
283,
888,
18,
297,
267,
283,
4694,
63,
3271,
63,
466,
297,
267,
283,
3271,
63,
23957,
63,
751,
297,
267,
283,
3271,
63,
2340,
63,
751,
297,
272,
1622,
339,
347,
1050,
8,
277,
12,
666,
304,
267,
367,
790,
12,
1139,
315,
666,
26,
288,
943,
14,
1757,
480,
420,
450,
83,
275,
450,
83,
2,
450,
334,
498,
12,
1139,
430,
288,
291,
59,
498,
61,
275,
1139,
339,
347,
636,
826,
721,
277,
12,
536,
12,
666,
12,
1300,
304,
267,
943,
14,
1757,
480,
259,
6763,
450,
83,
2,
450,
536,
2736,
267,
291,
14,
354,
221,
275,
536,
27,
267,
291,
14,
923,
275,
2125,
267,
291,
14,
525,
8,
1095,
9,
267,
291,
14,
525,
8,
576,
9,
339,
347,
6540,
63,
576,
8,
277,
12,
282,
12,
330,
304,
267,
327,
9812,
3663,
1338,
315,
9801,
11673,
701,
24628,
267,
282,
63,
513,
275,
282,
14,
1294,
20137,
358,
267,
330,
63,
513,
275,
330,
14,
1294,
20137,
358,
398,
367,
282,
63,
1053,
315,
282,
63,
513,
26,
288,
367,
330,
63,
1053,
315,
330,
63,
513,
26,
355,
340,
334,
65,
63,
1053,
508,
330,
63,
1053,
304,
490,
372,
715,
355,
916,
334,
65,
63,
1053,
508,
6438,
358,
503,
334,
66,
63,
1053,
508,
6438,
735,
490,
372,
715,
398,
372,
756,
339,
347,
4472,
8,
277,
12,
1163,
304,
267,
367,
307,
315,
6763,
14,
9187,
26,
288,
943,
14,
1757,
480,
420,
8978,
83,
61,
450,
83,
450,
83,
2,
450,
334,
84,
12,
291,
59,
84,
467,
1163,
59,
84,
2459,
27,
288,
340,
440,
291,
14,
1989,
63,
498,
8,
84,
9,
503,
440,
1163,
14,
1989,
63,
498,
8,
84,
304,
355,
372,
756,
288,
340,
440,
291,
14,
5785,
63,
576,
8,
277,
59,
84,
467,
1163,
59,
84,
4682,
355,
372,
756,
267,
372,
715,
339,
347,
3915,
8,
277,
12,
1163,
304,
267,
367,
307,
315,
6763,
14,
9187,
26,
288,
340,
440,
291,
14,
1989,
63,
498,
8,
84,
9,
503,
440,
1163,
14,
1989,
63,
498,
8,
84,
304,
355,
1980,
288,
340,
440,
291,
14,
5785,
63,
576,
8,
277,
59,
84,
467,
1163,
59,
84,
4682,
507,
198,
793,
14,
3764,
480,
2062,
450,
83,
2458,
83,
12,
4788,
450,
83,
2,
450,
334,
84,
12,
291,
59,
84,
467,
1163,
59,
84,
2459,
326,
199,
199,
3,
1379,
570,
1369,
4839,
370,
1172,
2569,
10189,
26,
199,
3,
359,
888,
61,
199,
3,
257,
446,
2951,
2849,
1256,
315,
570,
199,
3,
257,
446,
4839,
370,
4165,
26,
199,
3,
258,
283,
1531,
7,
446,
8582,
1414,
536,
199,
3,
258,
283,
589,
7,
259,
446,
4539,
1414,
2368,
199,
3,
258,
283,
3292,
7,
258,
446,
1420,
1414,
372,
574,
334,
16,
701,
849,
9,
199,
3,
199,
3,
359,
1430,
56,
26,
1095,
61,
199,
3,
257,
446,
1373,
503,
3663,
4454,
315,
570,
199,
3,
257,
446,
1420,
1338,
18121,
199,
533,
1379,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
931,
12,
1511,
304,
267,
1798,
275,
14196,
14,
11090,
15218,
342,
267,
1798,
14,
739,
8,
515,
9,
398,
943,
14,
3764,
480,
5720,
1543,
83,
4065,
450,
931,
9,
398,
291,
14,
515,
258,
275,
931,
267,
291,
14,
396,
63,
694,
275,
1511,
14,
396,
63,
694,
267,
291,
14,
9452,
258,
275,
1511,
14,
9452,
267,
291,
14,
1531,
221,
275,
1798,
14,
362,
360,
888,
297,
283,
1531,
358,
267,
291,
14,
589,
258,
275,
1798,
14,
362,
360,
888,
297,
283,
589,
358,
398,
862,
26,
288,
291,
14,
3292,
221,
275,
1798,
14,
362,
360,
888,
297,
283,
3292,
358,
267,
871,
26,
288,
291,
14,
3292,
221,
275,
378,
398,
291,
14,
4921,
257,
275,
1052,
267,
291,
14,
1099,
257,
275,
1052,
267,
943,
14,
1757,
480,
221,
8697,
1420,
4474,
3547,
267,
291,
14,
912,
63,
4368,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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
] |
pyecs/servo
|
tests/wpt/web-platform-tests/2dcontext/tools/specextract.py
|
132
|
2100
|
import html5lib
import html5lib.treebuilders.dom
# Expected use:
# curl --compressed http://www.whatwg.org/specs/web-apps/current-work/ >current-work
# python specextract.py
#
# Generates current-work-canvas.xhtml, for use by gentest.py to create the annotated spec document
def extract():
parser = html5lib.html5parser.HTMLParser(tree=html5lib.treebuilders.dom.TreeBuilder)
doc = parser.parse(open('current-work'), encoding='utf-8')
head = doc.getElementsByTagName('head')[0]
for n in head.childNodes:
if n.tagName == 'script':
head.removeChild(n)
header = doc.getElementsByTagName('header')[0]
#thecanvas = doc.getElementById('the-canvas') # doesn't work (?!)
thecanvas = [ n for n in doc.getElementsByTagName('h4') if n.getAttribute('id') == 'the-canvas-element' ][0]
keep = [header, thecanvas]
node = thecanvas.nextSibling
while node.nodeName != 'h4':
keep.append(node)
node = node.nextSibling
p = thecanvas.parentNode
for n in p.childNodes[:]:
if n not in keep:
p.removeChild(n)
for n in header.childNodes[3:-4]:
header.removeChild(n)
def make_absolute(uri):
if uri.startswith('data:'):
return uri
elif uri[0] == '/':
return 'http://www.whatwg.org' + uri
else:
return 'http://www.whatwg.org/specs/web-apps/current-work/' + uri
# Fix the stylesheet, icon and image references
for e in doc.getElementsByTagName('link'):
e.setAttribute('href', make_absolute(e.getAttribute('href')))
for img in doc.getElementsByTagName('img'):
img.setAttribute('src', make_absolute(img.getAttribute('src')))
# Convert to XHTML, because it's quicker to re-parse than HTML5
doc.documentElement.setAttribute('xmlns', 'http://www.w3.org/1999/xhtml')
doc.documentElement.setAttribute('xml:lang', doc.documentElement.getAttribute('lang'))
doc.removeChild(doc.firstChild) # remove the DOCTYPE
open('current-work-canvas.xhtml', 'w').write(doc.toxml(encoding = 'UTF-8'))
extract()
|
mpl-2.0
|
[
646,
3517,
21,
773,
199,
646,
3517,
21,
773,
14,
2350,
20968,
14,
4556,
199,
199,
3,
13796,
675,
26,
199,
3,
257,
26145,
1553,
10895,
1455,
921,
1544,
14,
10058,
23596,
14,
1308,
15,
7273,
15,
2520,
13,
5181,
15,
1818,
13,
800,
15,
690,
1818,
13,
800,
199,
3,
257,
2366,
14475,
301,
400,
1957,
14,
647,
199,
3,
199,
3,
21687,
1453,
13,
800,
13,
7682,
14,
12909,
12,
367,
675,
701,
3805,
396,
14,
647,
370,
1218,
314,
27526,
3158,
2213,
199,
199,
318,
5536,
837,
272,
1798,
275,
3517,
21,
773,
14,
1360,
21,
2087,
14,
27375,
8,
2350,
29,
1360,
21,
773,
14,
2350,
20968,
14,
4556,
14,
20437,
9,
272,
1382,
275,
1798,
14,
1122,
8,
1490,
360,
1818,
13,
800,
659,
2644,
534,
1624,
13,
24,
358,
339,
4854,
275,
1382,
14,
15045,
360,
2993,
5832,
16,
61,
272,
367,
302,
315,
4854,
14,
10626,
26,
267,
340,
302,
14,
20183,
508,
283,
1579,
356,
288,
4854,
14,
2168,
3493,
8,
78,
9,
339,
1406,
275,
1382,
14,
15045,
360,
1291,
5832,
16,
61,
272,
327,
273,
825,
290,
4755,
275,
1382,
14,
26215,
360,
1589,
13,
7682,
358,
327,
3181,
1133,
1736,
7558,
21866,
272,
314,
7682,
275,
359,
302,
367,
302,
315,
1382,
14,
15045,
360,
72,
20,
358,
340,
302,
14,
12956,
360,
344,
358,
508,
283,
1589,
13,
7682,
13,
2108,
7,
30479,
16,
61,
339,
4215,
275,
359,
1291,
12,
314,
7682,
61,
272,
1031,
275,
314,
7682,
14,
30336,
272,
1830,
1031,
14,
13777,
1137,
283,
72,
20,
356,
267,
4215,
14,
740,
8,
932,
9,
267,
1031,
275,
1031,
14,
30336,
272,
299,
275,
314,
7682,
14,
24899,
272,
367,
302,
315,
299,
14,
10626,
32734,
267,
340,
302,
440,
315,
4215,
26,
288,
299,
14,
2168,
3493,
8,
78,
9,
339,
367,
302,
315,
1406,
14,
10626,
59,
19,
6809,
20,
2189,
267,
1406,
14,
2168,
3493,
8,
78,
9,
339,
347,
1852,
63,
6116,
8,
2302,
304,
267,
340,
5108,
14,
2460,
360,
576,
23117,
288,
372,
5108,
267,
916,
5108,
59,
16,
61,
508,
20549,
288,
372,
283,
1014,
921,
1544,
14,
10058,
23596,
14,
1308,
7,
435,
5108,
267,
587,
26,
288,
372,
283,
1014,
921,
1544,
14,
10058,
23596,
14,
1308,
15,
7273,
15,
2520,
13,
5181,
15,
1818,
13,
800,
4805,
435,
5108,
339,
327,
14811,
314,
3449,
5069,
12,
7016,
436,
1834,
6941,
272,
367,
325,
315,
1382,
14,
15045,
360,
1073,
735,
267,
325,
14,
17618,
360,
6399,
297,
1852,
63,
6116,
8,
69,
14,
12956,
360,
6399,
7058,
272,
367,
6050,
315,
1382,
14,
15045,
360,
4060,
735,
267,
6050,
14,
17618,
360,
2164,
297,
1852,
63,
6116,
8,
4060,
14,
12956,
360,
2164,
7058,
339,
327,
7905,
370,
26223,
12,
2952,
652,
1159,
12530,
281,
370,
295,
13,
1122,
2419,
4163,
21,
272,
1382,
14,
22464,
14,
17618,
360,
13991,
297,
283,
1014,
921,
1544,
14,
87,
19,
14,
1308,
15,
16278,
15,
12909,
358,
272,
1382,
14,
22464,
14,
17618,
360,
1652,
26,
4159,
297,
1382,
14,
22464,
14,
12956,
360,
4159,
1333,
272,
1382,
14,
2168,
3493,
8,
1301,
14,
22262,
9,
327,
2813,
314,
3506,
7540,
339,
1551,
360,
1818,
13,
800,
13,
7682,
14,
12909,
297,
283,
87,
1959,
952,
8,
1301,
14,
475,
1652,
8,
2991,
275,
283,
6610,
13,
24,
1333,
199,
199,
5005,
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
] |
[
3517,
21,
773,
199,
646,
3517,
21,
773,
14,
2350,
20968,
14,
4556,
199,
199,
3,
13796,
675,
26,
199,
3,
257,
26145,
1553,
10895,
1455,
921,
1544,
14,
10058,
23596,
14,
1308,
15,
7273,
15,
2520,
13,
5181,
15,
1818,
13,
800,
15,
690,
1818,
13,
800,
199,
3,
257,
2366,
14475,
301,
400,
1957,
14,
647,
199,
3,
199,
3,
21687,
1453,
13,
800,
13,
7682,
14,
12909,
12,
367,
675,
701,
3805,
396,
14,
647,
370,
1218,
314,
27526,
3158,
2213,
199,
199,
318,
5536,
837,
272,
1798,
275,
3517,
21,
773,
14,
1360,
21,
2087,
14,
27375,
8,
2350,
29,
1360,
21,
773,
14,
2350,
20968,
14,
4556,
14,
20437,
9,
272,
1382,
275,
1798,
14,
1122,
8,
1490,
360,
1818,
13,
800,
659,
2644,
534,
1624,
13,
24,
358,
339,
4854,
275,
1382,
14,
15045,
360,
2993,
5832,
16,
61,
272,
367,
302,
315,
4854,
14,
10626,
26,
267,
340,
302,
14,
20183,
508,
283,
1579,
356,
288,
4854,
14,
2168,
3493,
8,
78,
9,
339,
1406,
275,
1382,
14,
15045,
360,
1291,
5832,
16,
61,
272,
327,
273,
825,
290,
4755,
275,
1382,
14,
26215,
360,
1589,
13,
7682,
358,
327,
3181,
1133,
1736,
7558,
21866,
272,
314,
7682,
275,
359,
302,
367,
302,
315,
1382,
14,
15045,
360,
72,
20,
358,
340,
302,
14,
12956,
360,
344,
358,
508,
283,
1589,
13,
7682,
13,
2108,
7,
30479,
16,
61,
339,
4215,
275,
359,
1291,
12,
314,
7682,
61,
272,
1031,
275,
314,
7682,
14,
30336,
272,
1830,
1031,
14,
13777,
1137,
283,
72,
20,
356,
267,
4215,
14,
740,
8,
932,
9,
267,
1031,
275,
1031,
14,
30336,
272,
299,
275,
314,
7682,
14,
24899,
272,
367,
302,
315,
299,
14,
10626,
32734,
267,
340,
302,
440,
315,
4215,
26,
288,
299,
14,
2168,
3493,
8,
78,
9,
339,
367,
302,
315,
1406,
14,
10626,
59,
19,
6809,
20,
2189,
267,
1406,
14,
2168,
3493,
8,
78,
9,
339,
347,
1852,
63,
6116,
8,
2302,
304,
267,
340,
5108,
14,
2460,
360,
576,
23117,
288,
372,
5108,
267,
916,
5108,
59,
16,
61,
508,
20549,
288,
372,
283,
1014,
921,
1544,
14,
10058,
23596,
14,
1308,
7,
435,
5108,
267,
587,
26,
288,
372,
283,
1014,
921,
1544,
14,
10058,
23596,
14,
1308,
15,
7273,
15,
2520,
13,
5181,
15,
1818,
13,
800,
4805,
435,
5108,
339,
327,
14811,
314,
3449,
5069,
12,
7016,
436,
1834,
6941,
272,
367,
325,
315,
1382,
14,
15045,
360,
1073,
735,
267,
325,
14,
17618,
360,
6399,
297,
1852,
63,
6116,
8,
69,
14,
12956,
360,
6399,
7058,
272,
367,
6050,
315,
1382,
14,
15045,
360,
4060,
735,
267,
6050,
14,
17618,
360,
2164,
297,
1852,
63,
6116,
8,
4060,
14,
12956,
360,
2164,
7058,
339,
327,
7905,
370,
26223,
12,
2952,
652,
1159,
12530,
281,
370,
295,
13,
1122,
2419,
4163,
21,
272,
1382,
14,
22464,
14,
17618,
360,
13991,
297,
283,
1014,
921,
1544,
14,
87,
19,
14,
1308,
15,
16278,
15,
12909,
358,
272,
1382,
14,
22464,
14,
17618,
360,
1652,
26,
4159,
297,
1382,
14,
22464,
14,
12956,
360,
4159,
1333,
272,
1382,
14,
2168,
3493,
8,
1301,
14,
22262,
9,
327,
2813,
314,
3506,
7540,
339,
1551,
360,
1818,
13,
800,
13,
7682,
14,
12909,
297,
283,
87,
1959,
952,
8,
1301,
14,
475,
1652,
8,
2991,
275,
283,
6610,
13,
24,
1333,
199,
199,
5005,
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,
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,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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
] |
gaolichuang/py-task-framework
|
nova/api/openstack/compute/plugins/__init__.py
|
13
|
2060
|
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2013 IBM Corp.
#
# 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 nova import exception
from nova.openstack.common.gettextutils import _
from nova.openstack.common import log as logging
LOG = logging.getLogger(__name__)
class LoadedExtensionInfo(object):
"""Keep track of all loaded API extensions."""
def __init__(self):
self.extensions = {}
def register_extension(self, ext):
if not self._check_extension(ext):
return False
alias = ext.alias
LOG.audit(_("Loaded extension %s"), alias)
if alias in self.extensions:
raise exception.NovaException("Found duplicate extension: %s"
% alias)
self.extensions[alias] = ext
return True
def _check_extension(self, extension):
"""Checks for required methods in extension objects."""
try:
LOG.debug(_('Ext name: %s'), extension.name)
LOG.debug(_('Ext alias: %s'), extension.alias)
LOG.debug(_('Ext description: %s'),
' '.join(extension.__doc__.strip().split()))
LOG.debug(_('Ext namespace: %s'), extension.namespace)
LOG.debug(_('Ext version: %i'), extension.version)
except AttributeError as ex:
LOG.exception(_("Exception loading extension: %s"), unicode(ex))
return False
return True
def get_extensions(self):
return self.extensions
|
apache-2.0
|
[
3,
6695,
26,
20849,
29,
20,
20105,
29,
20,
25966,
29,
20,
199,
199,
3,
1898,
6171,
26202,
22304,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
421,
199,
504,
5913,
492,
1919,
199,
504,
5913,
14,
8512,
14,
2330,
14,
5152,
1208,
492,
485,
199,
504,
5913,
14,
8512,
14,
2330,
492,
943,
465,
2050,
199,
199,
4947,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
3835,
3074,
6382,
2354,
8,
785,
304,
272,
408,
18567,
4426,
402,
1006,
6511,
3261,
5478,
1041,
339,
347,
636,
826,
721,
277,
304,
267,
291,
14,
5359,
275,
1052,
339,
347,
2274,
63,
3435,
8,
277,
12,
1599,
304,
267,
340,
440,
291,
423,
1074,
63,
3435,
8,
832,
304,
288,
372,
756,
398,
5162,
275,
1599,
14,
3620,
267,
5051,
14,
14274,
6115,
19757,
3329,
450,
83,
1288,
5162,
9,
398,
340,
5162,
315,
291,
14,
5359,
26,
288,
746,
1919,
14,
19884,
1726,
480,
3601,
9250,
3329,
26,
450,
83,
2,
5101,
450,
5162,
9,
267,
291,
14,
5359,
59,
3620,
61,
275,
1599,
267,
372,
715,
339,
347,
485,
1074,
63,
3435,
8,
277,
12,
3329,
304,
267,
408,
11834,
367,
1415,
3102,
315,
3329,
2251,
1041,
267,
862,
26,
288,
5051,
14,
1757,
6723,
4942,
536,
26,
450,
83,
659,
3329,
14,
354,
9,
288,
5051,
14,
1757,
6723,
4942,
5162,
26,
450,
83,
659,
3329,
14,
3620,
9,
288,
5051,
14,
1757,
6723,
4942,
1369,
26,
450,
83,
659,
1993,
283,
1987,
904,
8,
3435,
855,
1301,
4343,
1913,
1252,
1294,
4059,
288,
5051,
14,
1757,
6723,
4942,
3231,
26,
450,
83,
659,
3329,
14,
3251,
9,
288,
5051,
14,
1757,
6723,
4942,
1015,
26,
450,
73,
659,
3329,
14,
1023,
9,
267,
871,
4281,
465,
444,
26,
288,
5051,
14,
1971,
6115,
1726,
8697,
3329,
26,
450,
83,
1288,
2649,
8,
476,
430,
288,
372,
756,
398,
372,
715,
339,
347,
664,
63,
5359,
8,
277,
304,
267,
372,
291,
14,
5359,
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
] |
[
6695,
26,
20849,
29,
20,
20105,
29,
20,
25966,
29,
20,
199,
199,
3,
1898,
6171,
26202,
22304,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
421,
199,
504,
5913,
492,
1919,
199,
504,
5913,
14,
8512,
14,
2330,
14,
5152,
1208,
492,
485,
199,
504,
5913,
14,
8512,
14,
2330,
492,
943,
465,
2050,
199,
199,
4947,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
3835,
3074,
6382,
2354,
8,
785,
304,
272,
408,
18567,
4426,
402,
1006,
6511,
3261,
5478,
1041,
339,
347,
636,
826,
721,
277,
304,
267,
291,
14,
5359,
275,
1052,
339,
347,
2274,
63,
3435,
8,
277,
12,
1599,
304,
267,
340,
440,
291,
423,
1074,
63,
3435,
8,
832,
304,
288,
372,
756,
398,
5162,
275,
1599,
14,
3620,
267,
5051,
14,
14274,
6115,
19757,
3329,
450,
83,
1288,
5162,
9,
398,
340,
5162,
315,
291,
14,
5359,
26,
288,
746,
1919,
14,
19884,
1726,
480,
3601,
9250,
3329,
26,
450,
83,
2,
5101,
450,
5162,
9,
267,
291,
14,
5359,
59,
3620,
61,
275,
1599,
267,
372,
715,
339,
347,
485,
1074,
63,
3435,
8,
277,
12,
3329,
304,
267,
408,
11834,
367,
1415,
3102,
315,
3329,
2251,
1041,
267,
862,
26,
288,
5051,
14,
1757,
6723,
4942,
536,
26,
450,
83,
659,
3329,
14,
354,
9,
288,
5051,
14,
1757,
6723,
4942,
5162,
26,
450,
83,
659,
3329,
14,
3620,
9,
288,
5051,
14,
1757,
6723,
4942,
1369,
26,
450,
83,
659,
1993,
283,
1987,
904,
8,
3435,
855,
1301,
4343,
1913,
1252,
1294,
4059,
288,
5051,
14,
1757,
6723,
4942,
3231,
26,
450,
83,
659,
3329,
14,
3251,
9,
288,
5051,
14,
1757,
6723,
4942,
1015,
26,
450,
73,
659,
3329,
14,
1023,
9,
267,
871,
4281,
465,
444,
26,
288,
5051,
14,
1971,
6115,
1726,
8697,
3329,
26,
450,
83,
1288,
2649,
8,
476,
430,
288,
372,
756,
398,
372,
715,
339,
347,
664,
63,
5359,
8,
277,
304,
267,
372,
291,
14,
5359,
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,
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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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
] |
nickBumgarner/wwf
|
node_modules/node-gyp/gyp/pylib/gyp/xcode_ninja.py
|
1789
|
10585
|
# Copyright (c) 2014 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.
"""Xcode-ninja wrapper project file generator.
This updates the data structures passed to the Xcode gyp generator to build
with ninja instead. The Xcode project itself is transformed into a list of
executable targets, each with a build step to build with ninja, and a target
with every source and resource file. This appears to sidestep some of the
major performance headaches experienced using complex projects and large number
of targets within Xcode.
"""
import errno
import gyp.generator.ninja
import os
import re
import xml.sax.saxutils
def _WriteWorkspace(main_gyp, sources_gyp, params):
""" Create a workspace to wrap main and sources gyp paths. """
(build_file_root, build_file_ext) = os.path.splitext(main_gyp)
workspace_path = build_file_root + '.xcworkspace'
options = params['options']
if options.generator_output:
workspace_path = os.path.join(options.generator_output, workspace_path)
try:
os.makedirs(workspace_path)
except OSError, e:
if e.errno != errno.EEXIST:
raise
output_string = '<?xml version="1.0" encoding="UTF-8"?>\n' + \
'<Workspace version = "1.0">\n'
for gyp_name in [main_gyp, sources_gyp]:
name = os.path.splitext(os.path.basename(gyp_name))[0] + '.xcodeproj'
name = xml.sax.saxutils.quoteattr("group:" + name)
output_string += ' <FileRef location = %s></FileRef>\n' % name
output_string += '</Workspace>\n'
workspace_file = os.path.join(workspace_path, "contents.xcworkspacedata")
try:
with open(workspace_file, 'r') as input_file:
input_string = input_file.read()
if input_string == output_string:
return
except IOError:
# Ignore errors if the file doesn't exist.
pass
with open(workspace_file, 'w') as output_file:
output_file.write(output_string)
def _TargetFromSpec(old_spec, params):
""" Create fake target for xcode-ninja wrapper. """
# Determine ninja top level build dir (e.g. /path/to/out).
ninja_toplevel = None
jobs = 0
if params:
options = params['options']
ninja_toplevel = \
os.path.join(options.toplevel_dir,
gyp.generator.ninja.ComputeOutputDir(params))
jobs = params.get('generator_flags', {}).get('xcode_ninja_jobs', 0)
target_name = old_spec.get('target_name')
product_name = old_spec.get('product_name', target_name)
product_extension = old_spec.get('product_extension')
ninja_target = {}
ninja_target['target_name'] = target_name
ninja_target['product_name'] = product_name
if product_extension:
ninja_target['product_extension'] = product_extension
ninja_target['toolset'] = old_spec.get('toolset')
ninja_target['default_configuration'] = old_spec.get('default_configuration')
ninja_target['configurations'] = {}
# Tell Xcode to look in |ninja_toplevel| for build products.
new_xcode_settings = {}
if ninja_toplevel:
new_xcode_settings['CONFIGURATION_BUILD_DIR'] = \
"%s/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)" % ninja_toplevel
if 'configurations' in old_spec:
for config in old_spec['configurations'].iterkeys():
old_xcode_settings = \
old_spec['configurations'][config].get('xcode_settings', {})
if 'IPHONEOS_DEPLOYMENT_TARGET' in old_xcode_settings:
new_xcode_settings['CODE_SIGNING_REQUIRED'] = "NO"
new_xcode_settings['IPHONEOS_DEPLOYMENT_TARGET'] = \
old_xcode_settings['IPHONEOS_DEPLOYMENT_TARGET']
ninja_target['configurations'][config] = {}
ninja_target['configurations'][config]['xcode_settings'] = \
new_xcode_settings
ninja_target['mac_bundle'] = old_spec.get('mac_bundle', 0)
ninja_target['ios_app_extension'] = old_spec.get('ios_app_extension', 0)
ninja_target['ios_watchkit_extension'] = \
old_spec.get('ios_watchkit_extension', 0)
ninja_target['ios_watchkit_app'] = old_spec.get('ios_watchkit_app', 0)
ninja_target['type'] = old_spec['type']
if ninja_toplevel:
ninja_target['actions'] = [
{
'action_name': 'Compile and copy %s via ninja' % target_name,
'inputs': [],
'outputs': [],
'action': [
'env',
'PATH=%s' % os.environ['PATH'],
'ninja',
'-C',
new_xcode_settings['CONFIGURATION_BUILD_DIR'],
target_name,
],
'message': 'Compile and copy %s via ninja' % target_name,
},
]
if jobs > 0:
ninja_target['actions'][0]['action'].extend(('-j', jobs))
return ninja_target
def IsValidTargetForWrapper(target_extras, executable_target_pattern, spec):
"""Limit targets for Xcode wrapper.
Xcode sometimes performs poorly with too many targets, so only include
proper executable targets, with filters to customize.
Arguments:
target_extras: Regular expression to always add, matching any target.
executable_target_pattern: Regular expression limiting executable targets.
spec: Specifications for target.
"""
target_name = spec.get('target_name')
# Always include targets matching target_extras.
if target_extras is not None and re.search(target_extras, target_name):
return True
# Otherwise just show executable targets.
if spec.get('type', '') == 'executable' and \
spec.get('product_extension', '') != 'bundle':
# If there is a filter and the target does not match, exclude the target.
if executable_target_pattern is not None:
if not re.search(executable_target_pattern, target_name):
return False
return True
return False
def CreateWrapper(target_list, target_dicts, data, params):
"""Initialize targets for the ninja wrapper.
This sets up the necessary variables in the targets to generate Xcode projects
that use ninja as an external builder.
Arguments:
target_list: List of target pairs: 'base/base.gyp:base'.
target_dicts: Dict of target properties keyed on target pair.
data: Dict of flattened build files keyed on gyp path.
params: Dict of global options for gyp.
"""
orig_gyp = params['build_files'][0]
for gyp_name, gyp_dict in data.iteritems():
if gyp_name == orig_gyp:
depth = gyp_dict['_DEPTH']
# Check for custom main gyp name, otherwise use the default CHROMIUM_GYP_FILE
# and prepend .ninja before the .gyp extension.
generator_flags = params.get('generator_flags', {})
main_gyp = generator_flags.get('xcode_ninja_main_gyp', None)
if main_gyp is None:
(build_file_root, build_file_ext) = os.path.splitext(orig_gyp)
main_gyp = build_file_root + ".ninja" + build_file_ext
# Create new |target_list|, |target_dicts| and |data| data structures.
new_target_list = []
new_target_dicts = {}
new_data = {}
# Set base keys needed for |data|.
new_data[main_gyp] = {}
new_data[main_gyp]['included_files'] = []
new_data[main_gyp]['targets'] = []
new_data[main_gyp]['xcode_settings'] = \
data[orig_gyp].get('xcode_settings', {})
# Normally the xcode-ninja generator includes only valid executable targets.
# If |xcode_ninja_executable_target_pattern| is set, that list is reduced to
# executable targets that match the pattern. (Default all)
executable_target_pattern = \
generator_flags.get('xcode_ninja_executable_target_pattern', None)
# For including other non-executable targets, add the matching target name
# to the |xcode_ninja_target_pattern| regular expression. (Default none)
target_extras = generator_flags.get('xcode_ninja_target_pattern', None)
for old_qualified_target in target_list:
spec = target_dicts[old_qualified_target]
if IsValidTargetForWrapper(target_extras, executable_target_pattern, spec):
# Add to new_target_list.
target_name = spec.get('target_name')
new_target_name = '%s:%s#target' % (main_gyp, target_name)
new_target_list.append(new_target_name)
# Add to new_target_dicts.
new_target_dicts[new_target_name] = _TargetFromSpec(spec, params)
# Add to new_data.
for old_target in data[old_qualified_target.split(':')[0]]['targets']:
if old_target['target_name'] == target_name:
new_data_target = {}
new_data_target['target_name'] = old_target['target_name']
new_data_target['toolset'] = old_target['toolset']
new_data[main_gyp]['targets'].append(new_data_target)
# Create sources target.
sources_target_name = 'sources_for_indexing'
sources_target = _TargetFromSpec(
{ 'target_name' : sources_target_name,
'toolset': 'target',
'default_configuration': 'Default',
'mac_bundle': '0',
'type': 'executable'
}, None)
# Tell Xcode to look everywhere for headers.
sources_target['configurations'] = {'Default': { 'include_dirs': [ depth ] } }
sources = []
for target, target_dict in target_dicts.iteritems():
base = os.path.dirname(target)
files = target_dict.get('sources', []) + \
target_dict.get('mac_bundle_resources', [])
for action in target_dict.get('actions', []):
files.extend(action.get('inputs', []))
# Remove files starting with $. These are mostly intermediate files for the
# build system.
files = [ file for file in files if not file.startswith('$')]
# Make sources relative to root build file.
relative_path = os.path.dirname(main_gyp)
sources += [ os.path.relpath(os.path.join(base, file), relative_path)
for file in files ]
sources_target['sources'] = sorted(set(sources))
# Put sources_to_index in it's own gyp.
sources_gyp = \
os.path.join(os.path.dirname(main_gyp), sources_target_name + ".gyp")
fully_qualified_target_name = \
'%s:%s#target' % (sources_gyp, sources_target_name)
# Add to new_target_list, new_target_dicts and new_data.
new_target_list.append(fully_qualified_target_name)
new_target_dicts[fully_qualified_target_name] = sources_target
new_data_target = {}
new_data_target['target_name'] = sources_target['target_name']
new_data_target['_DEPTH'] = depth
new_data_target['toolset'] = "target"
new_data[sources_gyp] = {}
new_data[sources_gyp]['targets'] = []
new_data[sources_gyp]['included_files'] = []
new_data[sources_gyp]['xcode_settings'] = \
data[orig_gyp].get('xcode_settings', {})
new_data[sources_gyp]['targets'].append(new_data_target)
# Write workspace to file.
_WriteWorkspace(main_gyp, sources_gyp, params)
return (new_target_list, new_target_dicts, new_data)
|
gpl-2.0
|
[
3,
1898,
334,
67,
9,
6927,
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,
18442,
13,
8675,
4975,
2199,
570,
4306,
14,
199,
199,
2765,
7029,
314,
666,
13955,
3032,
370,
314,
10602,
4902,
4306,
370,
1900,
199,
1045,
14822,
3140,
14,
710,
10602,
2199,
6337,
365,
14834,
1901,
282,
769,
402,
199,
5904,
4545,
12,
1924,
543,
282,
1900,
3650,
370,
1900,
543,
14822,
12,
436,
282,
1347,
199,
1045,
4036,
1350,
436,
2073,
570,
14,
221,
961,
11337,
370,
5366,
2926,
2005,
402,
314,
199,
8452,
10238,
4854,
1225,
397,
444,
24242,
68,
1808,
6114,
11336,
436,
7031,
1329,
199,
1618,
4545,
4453,
10602,
14,
199,
624,
199,
199,
646,
7554,
199,
646,
4902,
14,
4679,
14,
8675,
199,
646,
747,
199,
646,
295,
199,
646,
2748,
14,
14338,
14,
14338,
1208,
421,
199,
318,
485,
3534,
21058,
8,
973,
63,
6179,
12,
5274,
63,
6179,
12,
1862,
304,
523,
408,
2790,
282,
14466,
370,
4816,
2446,
436,
5274,
4902,
3792,
14,
408,
523,
334,
1506,
63,
493,
63,
1231,
12,
1900,
63,
493,
63,
832,
9,
275,
747,
14,
515,
14,
7973,
8,
973,
63,
6179,
9,
523,
14466,
63,
515,
275,
1900,
63,
493,
63,
1231,
435,
1987,
1812,
13249,
7,
523,
1511,
275,
1862,
459,
1419,
418,
523,
340,
1511,
14,
4679,
63,
1199,
26,
272,
14466,
63,
515,
275,
747,
14,
515,
14,
904,
8,
1419,
14,
4679,
63,
1199,
12,
14466,
63,
515,
9,
523,
862,
26,
272,
747,
14,
8347,
8,
13249,
63,
515,
9,
523,
871,
6440,
12,
325,
26,
272,
340,
325,
14,
7931,
1137,
7554,
14,
28596,
26,
489,
746,
523,
1072,
63,
875,
275,
2650,
31,
1652,
1015,
628,
17,
14,
16,
2,
2644,
628,
6610,
13,
24,
14863,
3072,
78,
7,
435,
971,
2116,
2650,
21058,
1015,
275,
298,
17,
14,
16,
14559,
78,
7,
523,
367,
4902,
63,
354,
315,
359,
973,
63,
6179,
12,
5274,
63,
6179,
2189,
272,
536,
275,
747,
14,
515,
14,
7973,
8,
736,
14,
515,
14,
4846,
8,
6179,
63,
354,
11515,
16,
61,
435,
1987,
29286,
7,
272,
536,
275,
2748,
14,
14338,
14,
14338,
1208,
14,
3513,
962,
480,
923,
5424,
435,
536,
9,
272,
1072,
63,
875,
847,
283,
221,
665,
1173,
2891,
2909,
275,
450,
83,
2957,
1173,
2891,
3072,
78,
7,
450,
536,
523,
1072,
63,
875,
847,
11936,
21058,
3072,
78,
7,
819,
14466,
63,
493,
275,
747,
14,
515,
14,
904,
8,
13249,
63,
515,
12,
298,
4407,
14,
1812,
13249,
576,
531,
819,
862,
26,
272,
543,
1551,
8,
13249,
63,
493,
12,
283,
82,
358,
465,
1324,
63,
493,
26,
489,
1324,
63,
875,
275,
1324,
63,
493,
14,
739,
342,
489,
340,
1324,
63,
875,
508,
1072,
63,
875,
26,
267,
372,
523,
871,
5925,
26,
272,
327,
14092,
2552,
340,
314,
570,
3181,
1133,
2187,
14,
272,
986,
819,
543,
1551,
8,
13249,
63,
493,
12,
283,
87,
358,
465,
1072,
63,
493,
26,
272,
1072,
63,
493,
14,
952,
8,
1199,
63,
875,
9,
199,
199,
318,
485,
4277,
2532,
5307,
8,
1753,
63,
1650,
12,
1862,
304,
523,
408,
2790,
4026,
1347,
367,
13592,
13,
8675,
4975,
14,
408,
523,
327,
14703,
14822,
2746,
2166,
1900,
2935,
334,
69,
14,
71,
14,
1182,
515,
15,
475,
15,
548,
680,
523,
14822,
63,
13517,
275,
488,
523,
9643,
275,
378,
523,
340,
1862,
26,
272,
1511,
275,
1862,
459,
1419,
418,
272,
14822,
63,
13517,
275,
971,
267,
747,
14,
515,
14,
904,
8,
1419,
14,
13517,
63,
694,
12,
2151,
4902,
14,
4679,
14,
8675,
14,
8564,
2959,
3567,
8,
1162,
430,
272,
9643,
275,
1862,
14,
362,
360,
4679,
63,
2469,
297,
13056,
362,
360,
8701,
63,
8675,
63,
6920,
297,
378,
9,
819,
1347,
63,
354,
275,
2269,
63,
1650,
14,
362,
360,
1375,
63,
354,
358,
523,
3336,
63,
354,
275,
2269,
63,
1650,
14,
362,
360,
2558,
63,
354,
297,
1347,
63,
354,
9,
523,
3336,
63,
3435,
275,
2269,
63,
1650,
14,
362,
360,
2558,
63,
3435,
358,
819,
14822,
63,
1375,
275,
1052,
523,
14822,
63,
1375,
459,
1375,
63,
354,
418,
275,
1347,
63,
354,
523,
14822,
63,
1375,
459,
2558,
63,
354,
418,
275,
3336,
63,
354,
523,
340,
3336,
63,
3435,
26,
272,
14822,
63,
1375,
459,
2558,
63,
3435,
418,
275,
3336,
63,
3435,
523,
14822,
63,
1375,
459,
12081,
418,
275,
2269,
63,
1650,
14,
362,
360,
12081,
358,
523,
14822,
63,
1375,
459,
885,
63,
4758,
418,
275,
2269,
63,
1650,
14,
362,
360,
885,
63,
4758,
358,
523,
14822,
63,
1375,
459,
10057,
418,
275,
1052,
819,
327,
30528,
10602,
370,
3648,
315,
1204,
8675,
63,
13517,
92,
367,
1900,
7585,
14,
523,
892,
63,
8701,
63,
1751,
275,
1052,
523,
340,
14822,
63,
13517,
26,
272,
892,
63,
8701,
63,
1751,
459,
22212,
63,
8248,
63,
3022,
418,
275,
971,
267,
2071,
83,
15,
6629,
22212,
9,
6629,
29512,
3582,
5399,
63,
17805,
63,
2339,
2924,
450,
14822,
63,
13517,
819,
340,
283,
10057,
7,
315,
2269,
63,
1650,
26,
272,
367,
1101,
315,
2269,
63,
1650,
459,
10057,
2278,
16007,
837,
489,
2269,
63,
8701,
63,
1751,
275,
971,
267,
2269,
63,
1650,
459,
10057,
3488,
888,
1055,
362,
360,
8701,
63,
1751,
297,
5009,
489,
340,
283,
1772,
40,
4817,
3100,
63,
32304,
63,
9268,
7,
315,
2269,
63,
8701,
63,
1751,
26,
267,
892,
63,
8701,
63,
1751,
459,
6012,
63,
9396,
1206,
63,
12496,
418,
275,
298,
2826,
2,
267,
892,
63,
8701,
63,
1751,
459,
1772,
40,
4817,
3100,
63,
32304,
63,
9268,
418,
275,
971,
288,
2269,
63,
8701,
63,
1751,
459,
1772,
40,
4817,
3100,
63,
32304,
63,
9268,
418,
489,
14822,
63,
1375,
459,
10057,
3488,
888,
61,
275,
1052,
489,
14822,
63,
1375,
459,
10057,
3488,
888,
2733,
8701,
63,
1751,
418,
275,
971,
881,
892,
63,
8701,
63,
1751,
819,
14822,
63,
1375,
459,
3088,
63,
6469,
418,
275
] |
[
1898,
334,
67,
9,
6927,
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,
18442,
13,
8675,
4975,
2199,
570,
4306,
14,
199,
199,
2765,
7029,
314,
666,
13955,
3032,
370,
314,
10602,
4902,
4306,
370,
1900,
199,
1045,
14822,
3140,
14,
710,
10602,
2199,
6337,
365,
14834,
1901,
282,
769,
402,
199,
5904,
4545,
12,
1924,
543,
282,
1900,
3650,
370,
1900,
543,
14822,
12,
436,
282,
1347,
199,
1045,
4036,
1350,
436,
2073,
570,
14,
221,
961,
11337,
370,
5366,
2926,
2005,
402,
314,
199,
8452,
10238,
4854,
1225,
397,
444,
24242,
68,
1808,
6114,
11336,
436,
7031,
1329,
199,
1618,
4545,
4453,
10602,
14,
199,
624,
199,
199,
646,
7554,
199,
646,
4902,
14,
4679,
14,
8675,
199,
646,
747,
199,
646,
295,
199,
646,
2748,
14,
14338,
14,
14338,
1208,
421,
199,
318,
485,
3534,
21058,
8,
973,
63,
6179,
12,
5274,
63,
6179,
12,
1862,
304,
523,
408,
2790,
282,
14466,
370,
4816,
2446,
436,
5274,
4902,
3792,
14,
408,
523,
334,
1506,
63,
493,
63,
1231,
12,
1900,
63,
493,
63,
832,
9,
275,
747,
14,
515,
14,
7973,
8,
973,
63,
6179,
9,
523,
14466,
63,
515,
275,
1900,
63,
493,
63,
1231,
435,
1987,
1812,
13249,
7,
523,
1511,
275,
1862,
459,
1419,
418,
523,
340,
1511,
14,
4679,
63,
1199,
26,
272,
14466,
63,
515,
275,
747,
14,
515,
14,
904,
8,
1419,
14,
4679,
63,
1199,
12,
14466,
63,
515,
9,
523,
862,
26,
272,
747,
14,
8347,
8,
13249,
63,
515,
9,
523,
871,
6440,
12,
325,
26,
272,
340,
325,
14,
7931,
1137,
7554,
14,
28596,
26,
489,
746,
523,
1072,
63,
875,
275,
2650,
31,
1652,
1015,
628,
17,
14,
16,
2,
2644,
628,
6610,
13,
24,
14863,
3072,
78,
7,
435,
971,
2116,
2650,
21058,
1015,
275,
298,
17,
14,
16,
14559,
78,
7,
523,
367,
4902,
63,
354,
315,
359,
973,
63,
6179,
12,
5274,
63,
6179,
2189,
272,
536,
275,
747,
14,
515,
14,
7973,
8,
736,
14,
515,
14,
4846,
8,
6179,
63,
354,
11515,
16,
61,
435,
1987,
29286,
7,
272,
536,
275,
2748,
14,
14338,
14,
14338,
1208,
14,
3513,
962,
480,
923,
5424,
435,
536,
9,
272,
1072,
63,
875,
847,
283,
221,
665,
1173,
2891,
2909,
275,
450,
83,
2957,
1173,
2891,
3072,
78,
7,
450,
536,
523,
1072,
63,
875,
847,
11936,
21058,
3072,
78,
7,
819,
14466,
63,
493,
275,
747,
14,
515,
14,
904,
8,
13249,
63,
515,
12,
298,
4407,
14,
1812,
13249,
576,
531,
819,
862,
26,
272,
543,
1551,
8,
13249,
63,
493,
12,
283,
82,
358,
465,
1324,
63,
493,
26,
489,
1324,
63,
875,
275,
1324,
63,
493,
14,
739,
342,
489,
340,
1324,
63,
875,
508,
1072,
63,
875,
26,
267,
372,
523,
871,
5925,
26,
272,
327,
14092,
2552,
340,
314,
570,
3181,
1133,
2187,
14,
272,
986,
819,
543,
1551,
8,
13249,
63,
493,
12,
283,
87,
358,
465,
1072,
63,
493,
26,
272,
1072,
63,
493,
14,
952,
8,
1199,
63,
875,
9,
199,
199,
318,
485,
4277,
2532,
5307,
8,
1753,
63,
1650,
12,
1862,
304,
523,
408,
2790,
4026,
1347,
367,
13592,
13,
8675,
4975,
14,
408,
523,
327,
14703,
14822,
2746,
2166,
1900,
2935,
334,
69,
14,
71,
14,
1182,
515,
15,
475,
15,
548,
680,
523,
14822,
63,
13517,
275,
488,
523,
9643,
275,
378,
523,
340,
1862,
26,
272,
1511,
275,
1862,
459,
1419,
418,
272,
14822,
63,
13517,
275,
971,
267,
747,
14,
515,
14,
904,
8,
1419,
14,
13517,
63,
694,
12,
2151,
4902,
14,
4679,
14,
8675,
14,
8564,
2959,
3567,
8,
1162,
430,
272,
9643,
275,
1862,
14,
362,
360,
4679,
63,
2469,
297,
13056,
362,
360,
8701,
63,
8675,
63,
6920,
297,
378,
9,
819,
1347,
63,
354,
275,
2269,
63,
1650,
14,
362,
360,
1375,
63,
354,
358,
523,
3336,
63,
354,
275,
2269,
63,
1650,
14,
362,
360,
2558,
63,
354,
297,
1347,
63,
354,
9,
523,
3336,
63,
3435,
275,
2269,
63,
1650,
14,
362,
360,
2558,
63,
3435,
358,
819,
14822,
63,
1375,
275,
1052,
523,
14822,
63,
1375,
459,
1375,
63,
354,
418,
275,
1347,
63,
354,
523,
14822,
63,
1375,
459,
2558,
63,
354,
418,
275,
3336,
63,
354,
523,
340,
3336,
63,
3435,
26,
272,
14822,
63,
1375,
459,
2558,
63,
3435,
418,
275,
3336,
63,
3435,
523,
14822,
63,
1375,
459,
12081,
418,
275,
2269,
63,
1650,
14,
362,
360,
12081,
358,
523,
14822,
63,
1375,
459,
885,
63,
4758,
418,
275,
2269,
63,
1650,
14,
362,
360,
885,
63,
4758,
358,
523,
14822,
63,
1375,
459,
10057,
418,
275,
1052,
819,
327,
30528,
10602,
370,
3648,
315,
1204,
8675,
63,
13517,
92,
367,
1900,
7585,
14,
523,
892,
63,
8701,
63,
1751,
275,
1052,
523,
340,
14822,
63,
13517,
26,
272,
892,
63,
8701,
63,
1751,
459,
22212,
63,
8248,
63,
3022,
418,
275,
971,
267,
2071,
83,
15,
6629,
22212,
9,
6629,
29512,
3582,
5399,
63,
17805,
63,
2339,
2924,
450,
14822,
63,
13517,
819,
340,
283,
10057,
7,
315,
2269,
63,
1650,
26,
272,
367,
1101,
315,
2269,
63,
1650,
459,
10057,
2278,
16007,
837,
489,
2269,
63,
8701,
63,
1751,
275,
971,
267,
2269,
63,
1650,
459,
10057,
3488,
888,
1055,
362,
360,
8701,
63,
1751,
297,
5009,
489,
340,
283,
1772,
40,
4817,
3100,
63,
32304,
63,
9268,
7,
315,
2269,
63,
8701,
63,
1751,
26,
267,
892,
63,
8701,
63,
1751,
459,
6012,
63,
9396,
1206,
63,
12496,
418,
275,
298,
2826,
2,
267,
892,
63,
8701,
63,
1751,
459,
1772,
40,
4817,
3100,
63,
32304,
63,
9268,
418,
275,
971,
288,
2269,
63,
8701,
63,
1751,
459,
1772,
40,
4817,
3100,
63,
32304,
63,
9268,
418,
489,
14822,
63,
1375,
459,
10057,
3488,
888,
61,
275,
1052,
489,
14822,
63,
1375,
459,
10057,
3488,
888,
2733,
8701,
63,
1751,
418,
275,
971,
881,
892,
63,
8701,
63,
1751,
819,
14822,
63,
1375,
459,
3088,
63,
6469,
418,
275,
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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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
] |
odejesush/tensorflow
|
tensorflow/contrib/layers/python/layers/utils.py
|
71
|
10875
|
# 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.
# ==============================================================================
"""Common util functions used by layers.
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from collections import namedtuple
from collections import OrderedDict
from tensorflow.python.framework import ops
from tensorflow.python.framework import tensor_shape
from tensorflow.python.framework import tensor_util
from tensorflow.python.ops import control_flow_ops
from tensorflow.python.ops import variables
__all__ = ['collect_named_outputs',
'constant_value',
'static_cond',
'smart_cond',
'get_variable_collections',
'two_element_tuple',
'n_positive_integers',
'last_dimension',
'first_dimension']
NamedOutputs = namedtuple('NamedOutputs', ['name', 'outputs'])
def collect_named_outputs(collections, alias, outputs):
"""Add `Tensor` outputs tagged with alias to collections.
It is useful to collect end-points or tags for summaries. Example of usage:
logits = collect_named_outputs('end_points', 'inception_v3/logits', logits)
assert 'inception_v3/logits' in logits.aliases
Args:
collections: A collection or list of collections. If None skip collection.
alias: String to append to the list of aliases of outputs, for example,
'inception_v3/conv1'.
outputs: Tensor, an output tensor to collect
Returns:
The outputs Tensor to allow inline call.
"""
if collections:
append_tensor_alias(outputs, alias)
ops.add_to_collections(collections, outputs)
return outputs
def append_tensor_alias(tensor, alias):
"""Append an alias to the list of aliases of the tensor.
Args:
tensor: A `Tensor`.
alias: String, to add to the list of aliases of the tensor.
Returns:
The tensor with a new alias appended to its list of aliases.
"""
# Remove ending '/' if present.
if alias[-1] == '/':
alias = alias[:-1]
if hasattr(tensor, 'aliases'):
tensor.aliases.append(alias)
else:
tensor.aliases = [alias]
return tensor
def gather_tensors_aliases(tensors):
"""Given a list of tensors, gather their aliases.
Args:
tensors: A list of `Tensors`.
Returns:
A list of strings with the aliases of all tensors.
"""
aliases = []
for tensor in tensors:
aliases += get_tensor_aliases(tensor)
return aliases
def get_tensor_aliases(tensor):
"""Get a list with the aliases of the input tensor.
If the tensor does not have any alias, it would default to its its op.name or
its name.
Args:
tensor: A `Tensor`.
Returns:
A list of strings with the aliases of the tensor.
"""
if hasattr(tensor, 'aliases'):
aliases = tensor.aliases
else:
if tensor.name[-2:] == ':0':
# Use op.name for tensor ending in :0
aliases = [tensor.op.name]
else:
aliases = [tensor.name]
return aliases
def convert_collection_to_dict(collection):
"""Returns an OrderedDict of Tensors with their aliases as keys.
Args:
collection: A collection.
Returns:
An OrderedDict of {alias: tensor}
"""
return OrderedDict((alias, tensor)
for tensor in ops.get_collection(collection)
for alias in get_tensor_aliases(tensor))
def constant_value(value_or_tensor_or_var, dtype=None):
"""Returns value if value_or_tensor_or_var has a constant value.
Args:
value_or_tensor_or_var: A value, a `Tensor` or a `Variable`.
dtype: Optional `tf.dtype`, if set it would check it has the right
dtype.
Returns:
The constant value or None if it not constant.
Raises:
ValueError: if value_or_tensor_or_var is None or the tensor_variable has the
wrong dtype.
"""
if value_or_tensor_or_var is None:
raise ValueError('value_or_tensor_or_var cannot be None')
value = value_or_tensor_or_var
if isinstance(value_or_tensor_or_var, (ops.Tensor, variables.Variable)):
if dtype and value_or_tensor_or_var.dtype != dtype:
raise ValueError('It has the wrong type %s instead of %s' % (
value_or_tensor_or_var.dtype, dtype))
if isinstance(value_or_tensor_or_var, variables.Variable):
value = None
else:
value = tensor_util.constant_value(value_or_tensor_or_var)
return value
def static_cond(pred, fn1, fn2):
"""Return either fn1() or fn2() based on the boolean value of `pred`.
Same signature as `control_flow_ops.cond()` but requires pred to be a bool.
Args:
pred: A value determining whether to return the result of `fn1` or `fn2`.
fn1: The callable to be performed if pred is true.
fn2: The callable to be performed if pred is false.
Returns:
Tensors returned by the call to either `fn1` or `fn2`.
Raises:
TypeError: if `fn1` or `fn2` is not callable.
"""
if not callable(fn1):
raise TypeError('fn1 must be callable.')
if not callable(fn2):
raise TypeError('fn2 must be callable.')
if pred:
return fn1()
else:
return fn2()
def smart_cond(pred, fn1, fn2, name=None):
"""Return either fn1() or fn2() based on the boolean predicate/value `pred`.
If `pred` is bool or has a constant value it would use `static_cond`,
otherwise it would use `tf.cond`.
Args:
pred: A scalar determining whether to return the result of `fn1` or `fn2`.
fn1: The callable to be performed if pred is true.
fn2: The callable to be performed if pred is false.
name: Optional name prefix when using tf.cond
Returns:
Tensors returned by the call to either `fn1` or `fn2`.
"""
pred_value = constant_value(pred)
if pred_value is not None:
# Use static_cond if pred has a constant value.
return static_cond(pred_value, fn1, fn2)
else:
# Use dynamic cond otherwise.
return control_flow_ops.cond(pred, fn1, fn2, name)
def get_variable_collections(variables_collections, name):
if isinstance(variables_collections, dict):
variable_collections = variables_collections.get(name, None)
else:
variable_collections = variables_collections
return variable_collections
def first_dimension(shape, min_rank=1):
"""Returns the first dimension of shape while checking it has min_rank.
Args:
shape: A `TensorShape`.
min_rank: Integer, minimum rank of shape.
Returns:
The value of the first dimension.
Raises:
ValueError: if inputs don't have at least min_rank dimensions, or if the
first dimension value is not defined.
"""
dims = shape.dims
if dims is None:
raise ValueError('dims of shape must be known but is None')
if len(dims) < min_rank:
raise ValueError('rank of shape must be at least %d not: %d' % (min_rank,
len(dims)))
value = dims[0].value
if value is None:
raise ValueError('first dimension shape must be known but is None')
return value
def last_dimension(shape, min_rank=1):
"""Returns the last dimension of shape while checking it has min_rank.
Args:
shape: A `TensorShape`.
min_rank: Integer, minimum rank of shape.
Returns:
The value of the last dimension.
Raises:
ValueError: if inputs don't have at least min_rank dimensions, or if the
last dimension value is not defined.
"""
dims = shape.dims
if dims is None:
raise ValueError('dims of shape must be known but is None')
if len(dims) < min_rank:
raise ValueError('rank of shape must be at least %d not: %d' % (min_rank,
len(dims)))
value = dims[-1].value
if value is None:
raise ValueError('last dimension shape must be known but is None')
return value
def two_element_tuple(int_or_tuple):
"""Converts `int_or_tuple` to height, width.
Several of the functions that follow accept arguments as either
a tuple of 2 integers or a single integer. A single integer
indicates that the 2 values of the tuple are the same.
This functions normalizes the input value by always returning a tuple.
Args:
int_or_tuple: A list of 2 ints, a single int or a `TensorShape`.
Returns:
A tuple with 2 values.
Raises:
ValueError: If `int_or_tuple` it not well formed.
"""
if isinstance(int_or_tuple, (list, tuple)):
if len(int_or_tuple) != 2:
raise ValueError('Must be a list with 2 elements: %s' % int_or_tuple)
return int(int_or_tuple[0]), int(int_or_tuple[1])
if isinstance(int_or_tuple, int):
return int(int_or_tuple), int(int_or_tuple)
if isinstance(int_or_tuple, tensor_shape.TensorShape):
if len(int_or_tuple) == 2:
return int_or_tuple[0], int_or_tuple[1]
raise ValueError('Must be an int, a list with 2 elements or a TensorShape of '
'length 2')
def n_positive_integers(n, value):
"""Converts `value` to a sequence of `n` positive integers.
`value` may be either be a sequence of values convertible to `int`, or a
single value convertible to `int`, in which case the resulting integer is
duplicated `n` times. It may also be a TensorShape of rank `n`.
Args:
n: Length of sequence to return.
value: Either a single value convertible to a positive `int` or an
`n`-element sequence of values convertible to a positive `int`.
Returns:
A tuple of `n` positive integers.
Raises:
TypeError: If `n` is not convertible to an integer.
ValueError: If `n` or `value` are invalid.
"""
n_orig = n
n = int(n)
if n < 1 or n != n_orig:
raise ValueError('n must be a positive integer')
try:
value = int(value)
except (TypeError, ValueError):
sequence_len = len(value)
if sequence_len != n:
raise ValueError(
'Expected sequence of %d positive integers, but received %r' %
(n, value))
try:
values = tuple(int(x) for x in value)
except:
raise ValueError(
'Expected sequence of %d positive integers, but received %r' %
(n, value))
for x in values:
if x < 1:
raise ValueError('expected positive integer, but received %d' % x)
return values
if value < 1:
raise ValueError('expected positive integer, but received %d' % value)
return (value,) * n
|
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,
7844,
4884,
3423,
1202,
701,
9393,
14,
199,
624,
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,
5055,
492,
12863,
199,
504,
5055,
492,
8773,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
4857,
492,
2345,
63,
1392,
199,
504,
3228,
14,
1548,
14,
4857,
492,
2345,
63,
1974,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3304,
63,
1659,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
2860,
199,
199,
363,
452,
363,
275,
788,
7112,
63,
4579,
63,
4467,
297,
1779,
283,
4083,
63,
585,
297,
1779,
283,
1986,
63,
2067,
297,
1779,
283,
7853,
63,
2067,
297,
1779,
283,
362,
63,
1975,
63,
7882,
297,
1779,
283,
5601,
63,
2108,
63,
2960,
297,
1779,
283,
78,
63,
8965,
63,
23931,
297,
1779,
283,
2019,
63,
7430,
297,
1779,
283,
2246,
63,
7430,
418,
199,
199,
7989,
18669,
275,
12863,
360,
7989,
18669,
297,
788,
354,
297,
283,
4467,
1105,
421,
199,
318,
8775,
63,
4579,
63,
4467,
8,
7882,
12,
5162,
12,
4704,
304,
523,
408,
1123,
658,
3861,
64,
4704,
20018,
543,
5162,
370,
5055,
14,
819,
2779,
365,
2997,
370,
8775,
1284,
13,
3438,
503,
3762,
367,
23747,
14,
5679,
402,
4503,
26,
819,
11051,
275,
8775,
63,
4579,
63,
4467,
360,
500,
63,
3438,
297,
283,
262,
814,
63,
86,
19,
15,
10492,
297,
11051,
9,
523,
702,
283,
262,
814,
63,
86,
19,
15,
10492,
7,
315,
11051,
14,
8602,
819,
3033,
26,
272,
5055,
26,
437,
3245,
503,
769,
402,
5055,
14,
982,
488,
3372,
3245,
14,
272,
5162,
26,
2624,
370,
5666,
370,
314,
769,
402,
5481,
402,
4704,
12,
367,
2893,
12,
1779,
283,
262,
814,
63,
86,
19,
15,
5598,
17,
1370,
272,
4704,
26,
5878,
12,
376,
1072,
2345,
370,
8775,
819,
1803,
26,
272,
710,
4704,
5878,
370,
2040,
8308,
1240,
14,
523,
408,
523,
340,
5055,
26,
272,
5666,
63,
3128,
63,
3620,
8,
4467,
12,
5162,
9,
272,
4156,
14,
525,
63,
475,
63,
7882,
8,
7882,
12,
4704,
9,
523,
372,
4704,
421,
199,
318,
5666,
63,
3128,
63,
3620,
8,
3128,
12,
5162,
304,
523,
408,
8310,
376,
5162,
370,
314,
769,
402,
5481,
402,
314,
2345,
14,
819,
3033,
26,
272,
2345,
26,
437,
658,
3861,
2313,
272,
5162,
26,
2624,
12,
370,
1050,
370,
314,
769,
402,
5481,
402,
314,
2345,
14,
819,
1803,
26,
272,
710,
2345,
543,
282,
892,
5162,
11544,
370,
2399,
769,
402,
5481,
14,
523,
408,
523,
327,
5852,
13401,
7324,
340,
3451,
14,
523,
340,
5162,
1988,
17,
61,
508,
20549,
272,
5162,
275,
5162,
4439,
17,
61,
523,
340,
2688,
8,
3128,
12,
283,
8602,
735,
272,
2345,
14,
8602,
14,
740,
8,
3620,
9,
523,
587,
26,
272,
2345,
14,
8602,
275,
359,
3620,
61,
523,
372,
2345,
421,
199,
318,
13082,
63,
10206,
63,
8602,
8,
10206,
304,
523,
408,
13735,
282,
769,
402,
10519,
12,
13082,
3932,
5481,
14,
819,
3033,
26,
272,
10519,
26,
437,
769,
402,
658,
29212,
2313,
819,
1803,
26,
272,
437,
769,
402,
3326,
543,
314,
5481,
402,
1006,
10519,
14,
523,
408,
523,
5481,
275,
942,
523,
367,
2345,
315,
10519,
26,
272,
5481,
847,
664,
63,
3128,
63,
8602,
8,
3128,
9,
523,
372,
5481,
421,
199,
318,
664,
63,
3128,
63,
8602,
8,
3128,
304,
523,
408,
1002,
282,
769,
543,
314,
5481,
402,
314,
1324,
2345,
14,
819,
982,
314,
2345,
1630,
440,
1172,
1263,
5162,
12,
652,
3955,
849,
370,
2399,
2399,
1687,
14,
354,
503,
523,
2399,
536,
14,
819,
3033,
26,
272,
2345,
26,
437,
658,
3861,
2313,
819,
1803,
26,
272,
437,
769,
402,
3326,
543,
314,
5481,
402,
314,
2345,
14,
523,
408,
523,
340,
2688,
8,
3128,
12,
283,
8602,
735,
272,
5481,
275,
2345,
14,
8602,
523,
587,
26,
272,
340,
2345,
14,
354,
1988,
18,
2938,
508,
7596,
16,
356,
489,
327,
3645,
1687,
14,
354,
367,
2345,
13401,
315,
520,
16,
489,
5481,
275,
359,
3128,
14,
411,
14,
354,
61,
272,
587,
26,
489,
5481,
275,
359,
3128,
14,
354,
61,
523,
372,
5481,
421,
199,
318,
3957,
63,
3627,
63,
475,
63,
807,
8,
3627,
304,
523,
408,
3407,
376,
8773,
402,
28373,
543,
3932,
5481,
465,
2883,
14,
819,
3033,
26,
272,
3245,
26,
437,
3245,
14,
819,
1803,
26,
272,
1626,
8773,
402,
469,
3620,
26,
2345,
93,
523,
408,
523,
372,
8773,
1332,
3620,
12,
2345,
9,
2151,
367,
2345,
315,
4156,
14,
362,
63,
3627,
8,
3627,
9,
2151,
367,
5162,
315,
664,
63,
3128,
63,
8602,
8,
3128,
430,
421,
199,
318,
4413,
63,
585,
8,
585,
63,
269,
63,
3128,
63,
269,
63,
1391,
12,
2152,
29,
403,
304,
523,
408,
3407,
574,
340,
574,
63,
269,
63,
3128,
63,
269,
63,
1391,
965,
282,
4413,
574,
14,
819,
3033,
26,
272,
574,
63,
269,
63,
3128,
63,
269,
63,
1391,
26,
437,
574,
12,
282,
658,
3861,
64,
503,
282,
658,
2773,
2313,
272,
2152,
26,
4879,
658,
3249,
14,
2271,
3559,
340,
663,
652,
3955,
1104,
652,
965,
314,
2451,
489
] |
[
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,
7844,
4884,
3423,
1202,
701,
9393,
14,
199,
624,
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,
5055,
492,
12863,
199,
504,
5055,
492,
8773,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
4857,
492,
2345,
63,
1392,
199,
504,
3228,
14,
1548,
14,
4857,
492,
2345,
63,
1974,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3304,
63,
1659,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
2860,
199,
199,
363,
452,
363,
275,
788,
7112,
63,
4579,
63,
4467,
297,
1779,
283,
4083,
63,
585,
297,
1779,
283,
1986,
63,
2067,
297,
1779,
283,
7853,
63,
2067,
297,
1779,
283,
362,
63,
1975,
63,
7882,
297,
1779,
283,
5601,
63,
2108,
63,
2960,
297,
1779,
283,
78,
63,
8965,
63,
23931,
297,
1779,
283,
2019,
63,
7430,
297,
1779,
283,
2246,
63,
7430,
418,
199,
199,
7989,
18669,
275,
12863,
360,
7989,
18669,
297,
788,
354,
297,
283,
4467,
1105,
421,
199,
318,
8775,
63,
4579,
63,
4467,
8,
7882,
12,
5162,
12,
4704,
304,
523,
408,
1123,
658,
3861,
64,
4704,
20018,
543,
5162,
370,
5055,
14,
819,
2779,
365,
2997,
370,
8775,
1284,
13,
3438,
503,
3762,
367,
23747,
14,
5679,
402,
4503,
26,
819,
11051,
275,
8775,
63,
4579,
63,
4467,
360,
500,
63,
3438,
297,
283,
262,
814,
63,
86,
19,
15,
10492,
297,
11051,
9,
523,
702,
283,
262,
814,
63,
86,
19,
15,
10492,
7,
315,
11051,
14,
8602,
819,
3033,
26,
272,
5055,
26,
437,
3245,
503,
769,
402,
5055,
14,
982,
488,
3372,
3245,
14,
272,
5162,
26,
2624,
370,
5666,
370,
314,
769,
402,
5481,
402,
4704,
12,
367,
2893,
12,
1779,
283,
262,
814,
63,
86,
19,
15,
5598,
17,
1370,
272,
4704,
26,
5878,
12,
376,
1072,
2345,
370,
8775,
819,
1803,
26,
272,
710,
4704,
5878,
370,
2040,
8308,
1240,
14,
523,
408,
523,
340,
5055,
26,
272,
5666,
63,
3128,
63,
3620,
8,
4467,
12,
5162,
9,
272,
4156,
14,
525,
63,
475,
63,
7882,
8,
7882,
12,
4704,
9,
523,
372,
4704,
421,
199,
318,
5666,
63,
3128,
63,
3620,
8,
3128,
12,
5162,
304,
523,
408,
8310,
376,
5162,
370,
314,
769,
402,
5481,
402,
314,
2345,
14,
819,
3033,
26,
272,
2345,
26,
437,
658,
3861,
2313,
272,
5162,
26,
2624,
12,
370,
1050,
370,
314,
769,
402,
5481,
402,
314,
2345,
14,
819,
1803,
26,
272,
710,
2345,
543,
282,
892,
5162,
11544,
370,
2399,
769,
402,
5481,
14,
523,
408,
523,
327,
5852,
13401,
7324,
340,
3451,
14,
523,
340,
5162,
1988,
17,
61,
508,
20549,
272,
5162,
275,
5162,
4439,
17,
61,
523,
340,
2688,
8,
3128,
12,
283,
8602,
735,
272,
2345,
14,
8602,
14,
740,
8,
3620,
9,
523,
587,
26,
272,
2345,
14,
8602,
275,
359,
3620,
61,
523,
372,
2345,
421,
199,
318,
13082,
63,
10206,
63,
8602,
8,
10206,
304,
523,
408,
13735,
282,
769,
402,
10519,
12,
13082,
3932,
5481,
14,
819,
3033,
26,
272,
10519,
26,
437,
769,
402,
658,
29212,
2313,
819,
1803,
26,
272,
437,
769,
402,
3326,
543,
314,
5481,
402,
1006,
10519,
14,
523,
408,
523,
5481,
275,
942,
523,
367,
2345,
315,
10519,
26,
272,
5481,
847,
664,
63,
3128,
63,
8602,
8,
3128,
9,
523,
372,
5481,
421,
199,
318,
664,
63,
3128,
63,
8602,
8,
3128,
304,
523,
408,
1002,
282,
769,
543,
314,
5481,
402,
314,
1324,
2345,
14,
819,
982,
314,
2345,
1630,
440,
1172,
1263,
5162,
12,
652,
3955,
849,
370,
2399,
2399,
1687,
14,
354,
503,
523,
2399,
536,
14,
819,
3033,
26,
272,
2345,
26,
437,
658,
3861,
2313,
819,
1803,
26,
272,
437,
769,
402,
3326,
543,
314,
5481,
402,
314,
2345,
14,
523,
408,
523,
340,
2688,
8,
3128,
12,
283,
8602,
735,
272,
5481,
275,
2345,
14,
8602,
523,
587,
26,
272,
340,
2345,
14,
354,
1988,
18,
2938,
508,
7596,
16,
356,
489,
327,
3645,
1687,
14,
354,
367,
2345,
13401,
315,
520,
16,
489,
5481,
275,
359,
3128,
14,
411,
14,
354,
61,
272,
587,
26,
489,
5481,
275,
359,
3128,
14,
354,
61,
523,
372,
5481,
421,
199,
318,
3957,
63,
3627,
63,
475,
63,
807,
8,
3627,
304,
523,
408,
3407,
376,
8773,
402,
28373,
543,
3932,
5481,
465,
2883,
14,
819,
3033,
26,
272,
3245,
26,
437,
3245,
14,
819,
1803,
26,
272,
1626,
8773,
402,
469,
3620,
26,
2345,
93,
523,
408,
523,
372,
8773,
1332,
3620,
12,
2345,
9,
2151,
367,
2345,
315,
4156,
14,
362,
63,
3627,
8,
3627,
9,
2151,
367,
5162,
315,
664,
63,
3128,
63,
8602,
8,
3128,
430,
421,
199,
318,
4413,
63,
585,
8,
585,
63,
269,
63,
3128,
63,
269,
63,
1391,
12,
2152,
29,
403,
304,
523,
408,
3407,
574,
340,
574,
63,
269,
63,
3128,
63,
269,
63,
1391,
965,
282,
4413,
574,
14,
819,
3033,
26,
272,
574,
63,
269,
63,
3128,
63,
269,
63,
1391,
26,
437,
574,
12,
282,
658,
3861,
64,
503,
282,
658,
2773,
2313,
272,
2152,
26,
4879,
658,
3249,
14,
2271,
3559,
340,
663,
652,
3955,
1104,
652,
965,
314,
2451,
489,
0
] |
[
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|
jasonyaw/SFrame
|
oss_src/unity/python/sframe/util/file_util.py
|
8
|
27988
|
'''
Copyright (C) 2015 Dato, Inc.
All rights reserved.
This software may be modified and distributed under the terms
of the BSD license. See the LICENSE file for details.
'''
'''
This package provides commonly used methods for dealing with file operation,
including working with network file system like S3, http, etc.
'''
import os
import sys
import time
import boto
import boto.s3
import tarfile
import logging
import shutil
import tempfile
import subprocess
from subprocess import PIPE
from boto.exception import S3ResponseError
__logger__ = logging.getLogger(__name__)
__RETRY_TIMES = 5
__SLEEP_SECONDS_BETWEEN_RETRIES = 2
__GRAPHLAB_S3_USE_BOTO = "GRAPHLAB_UNIT_TEST"
def _use_boto():
return __GRAPHLAB_S3_USE_BOTO in os.environ and \
os.environ[__GRAPHLAB_S3_USE_BOTO] == 'PredictiveService'
def get_protocol(path):
'''Given a path, returns the protocol the path uses
For example,
's3://a/b/c/' returns 's3'
'http://a/b/c' returns 'http'
'tmp/a/bc/' returns ''
'''
pos = path.find('://')
if pos < 0:
return ''
return path[0:pos].lower()
def is_path(string):
if not isinstance(string, str):
return False
return is_local_path(string) or is_s3_path(string)
def mkdir(path):
if is_local_path(path):
os.makedirs(path)
elif is_hdfs_path(path):
hdfs_mkdir(path)
elif is_s3_path(path):
# no need to make any directory
pass
else:
raise ValueError('Unsupported protocol %s' % path)
def exists(path, aws_credentials = {}):
if is_local_path(path):
return os.path.exists(path)
elif is_hdfs_path(path):
return hdfs_test_url(path)
elif is_s3_path(path):
return s3_test_url(path, aws_credentials = aws_credentials)
else:
raise ValueError('Unsupported protocol %s' % path)
def touch(path):
if is_local_path(path):
with open(path, 'a'):
os.utime(path, None)
elif is_hdfs_path(path):
hdfs_touch(path)
elif is_s3_path(path):
s3_touch(path)
else:
raise ValueError('Unsupported protocol %s' % path)
def read(path):
if is_local_path(path):
return open(path).read()
elif is_hdfs_path(path):
return read_file_to_string_hdfs(path)
elif is_s3_path(path):
return read_file_to_string_s3(path)
else:
raise ValueError('Unsupported protocol %s' % path)
def copy_from_local(localpath, remotepath):
if is_hdfs_path(remotepath):
upload_to_hdfs(localpath, remotepath)
elif is_s3_path(remotepath):
upload_to_s3(localpath, remotepath)
elif is_local_path(remotepath):
shutil.copy(localpath, remotepath)
else:
raise ValueError('Unsupported protocol %s' % remotepath)
def is_local_path(path):
'''Returns True if the path indicates a local path, otherwise False'''
protocol = get_protocol(path)
return protocol != 'hdfs' and protocol != 's3' and \
protocol != 'http' and protocol != 'https'
def is_s3_path(path):
'''Returns True if the path indicates a s3 path, otherwise False'''
protocol = get_protocol(path)
return protocol == 's3'
def is_hdfs_path(path):
'''Returns True if the path indicates a s3 path, otherwise False'''
protocol = get_protocol(path)
return protocol == 'hdfs'
def upload_to_local(src_path, dst_path, is_dir=False, silent=False):
'''Copies a file/dir to a local path'''
if not silent:
__logger__.info('Uploading local path %s to path: %s' % (src_path, dst_path))
if not os.path.exists(src_path):
raise RuntimeError("Cannot find file/path: %s" % src_path)
if not is_dir and not os.path.isfile(src_path):
raise RuntimeError("Path %s is not a file" % src_path)
if is_dir and not os.path.isdir(src_path):
raise RuntimeError("Path %s is not a directory" % src_path)
if not is_local_path(dst_path):
raise RuntimeError("Path %s is not a valid dest path" % dst_path)
# now upload
num_retries = 0
while num_retries < __RETRY_TIMES:
try:
if is_dir:
shutil.copytree(src_path, dst_path)
else:
shutil.copy(src_path, dst_path)
# We are done
if not silent:
__logger__.info("Successfully uploaded to path %s" % dst_path)
break
except Exception as e:
num_retries = num_retries + 1
__logger__.info("Error hit while copying file: %s" % e)
__logger__.info("Retrying %s out of %s" % (num_retries, __RETRY_TIMES))
if num_retries == __RETRY_TIMES:
raise e
time.sleep(__SLEEP_SECONDS_BETWEEN_RETRIES)
def read_file_to_string_s3(s3_path, max_size=None, aws_credentials={}):
''' Read a file in s3 to a string
'''
if not is_s3_path(s3_path):
raise RuntimeError("Path %s is not a valid s3 path" % s3_path)
k = _get_s3_key(s3_path, aws_credentials=aws_credentials)
if k:
k.open_read()
if max_size and long(k.size) > max_size:
raise RuntimeError("Cannot read file greater than max size %s." % str(max_size))
return k.get_contents_as_string()
return None
def list_s3(s3_path, aws_credentials={}):
''' List a directory in s3
'''
if not is_s3_path(s3_path):
raise RuntimeError("Path %s is not a valid s3 path" % s3_path)
(s3_bucket_name, s3_key_prefix) = parse_s3_path(s3_path)
conn = boto.connect_s3(**aws_credentials)
bucket = conn.get_bucket(s3_bucket_name)
# get list of keys with the prefix as the s3_path, in other words,
# this returns the keys to all the files under this s3_path dir.
k_list = list(bucket.list(s3_key_prefix))
key_list = []
for k in k_list:
if k.size:
s3_full_path = os.path.join("s3://", bucket.name, k.name)
key_list.append({"path":s3_full_path, "size":str(k.size)})
return key_list
def upload_to_s3(local_path, s3_path, is_dir=False, aws_credentials={}, silent=False):
'''Upload a local file to s3
'''
if not silent:
__logger__.info('Uploading local path %s to s3 path: %s' % (local_path, s3_path))
if not os.path.exists(local_path):
raise RuntimeError("Cannot find file: %s" % local_path)
if not is_dir and not os.path.isfile(local_path):
raise RuntimeError("Path %s is not a file" % local_path)
if is_dir and not os.path.isdir(local_path):
raise RuntimeError("Path %s is not a directory" % local_path)
if not is_s3_path(s3_path):
raise RuntimeError("Path %s is not a valid s3 path" % s3_path)
# now upload
num_retries = 0
while num_retries < __RETRY_TIMES:
try:
# Use BOTO
if _use_boto():
# Relative and absolute paths. S3 paths are relative while
# file paths on the local machine are not.
abs_path = os.path.abspath(local_path)
# Remove files that are already there.
s3_recursive_delete(s3_path)
# Get all the files.
uploadFileNames = {}
if os.path.isdir(abs_path):
for (source_dir, sub_dirs, files) in os.walk(abs_path):
for f in files:
path = os.path.join(source_dir, f)
key = '%s/%s' % (s3_path, os.path.relpath(path, abs_path))
uploadFileNames[key] = path
else:
key = s3_path
uploadFileNames[key] = abs_path
# Upload each file
for key, path in uploadFileNames.items():
k = _get_s3_key(key, aws_credentials)
__logger__.info("Uploading %s to %s." % (path, key))
k.set_contents_from_filename(
path,
num_cb=10)
# Use awscli
else:
_awscli_s3_op('cp', local_path, s3_path, recursive=is_dir,
silent = silent, aws_credentials=aws_credentials)
# We are done
if not silent:
__logger__.info("Successfully uploaded to s3 path %s" % s3_path)
break
except Exception as e:
num_retries = num_retries + 1
__logger__.info("Error hit while uploading to S3: %s" % e)
__logger__.info("Retrying %s out of %s" % (num_retries, __RETRY_TIMES))
if num_retries == __RETRY_TIMES:
raise e
time.sleep(__SLEEP_SECONDS_BETWEEN_RETRIES)
def get_s3_bucket_region(s3_bucket_name, aws_credentials={}):
conn = boto.connect_s3(**aws_credentials)
bucket = conn.get_bucket(s3_bucket_name)
return bucket.get_location() or "us-east-1" # default=us-standard
def _is_valid_s3_key(s3_path, aws_credentials={}):
key_prefix = _get_s3_key(s3_path)
return key_prefix.exists()
def download_from_s3(s3_path, local_path, is_dir=False, aws_credentials={}, silent=False):
'''Download a file from S3'''
local_file = expand_full_path(local_path)
if not silent:
__logger__.info('Downloading %s from s3 to local path %s' % (s3_path, local_path))
if not is_local_path(local_path):
raise RuntimeError("Invalid path: %s" % local_path)
if os.path.exists(local_path):
__logger__.debug("Overwriting file/path %s" % local_path)
if not is_s3_path(s3_path):
raise RuntimeError("Path %s is not a valid S3 path" % s3_path)
# now download
num_retries = 0
while num_retries < __RETRY_TIMES:
try:
# check if should use boto
if _use_boto():
key_prefix = _get_s3_key(s3_path)
bucket = key_prefix.bucket
abs_path = os.path.abspath(local_path)
# Download to a file
if not is_dir:
if not key_prefix.exists():
raise RuntimeError("Key %s does not exist." % s3_path)
key_prefix.get_contents_to_filename(
abs_path,
cb = _s3_callback,
num_cb = 10)
# Download to a directory.
else:
# Get all the keys with the same prefix.
keys = []
for k in bucket.list(prefix = key_prefix.key):
keys.append(k)
if len(keys) == 0:
raise RuntimeError("Key %s does not exist." % s3_path)
# Make a new directory.
if os.path.exists(local_path):
shutil.rmtree(local_path)
os.makedirs(local_path)
for k in keys:
# Key-name relative to directory name.
s3_key = 's3://%s/%s' % (k.bucket.name, k.key)
rel_file = os.path.relpath(s3_key, s3_path)
path = '/'.join([abs_path, rel_file])
dirname = os.path.dirname(path)
# This is a directory. Make it.
if not os.path.exists(dirname):
os.makedirs(dirname)
k.get_contents_to_filename(
path,
cb = _s3_callback,
num_cb = 10)
else:
# use awscli
_awscli_s3_op('cp', s3_path, local_path, recursive=is_dir, aws_credentials=aws_credentials,
silent=silent)
__logger__.debug("Successfully downloaded file %s from s3" % s3_path)
break
except Exception as e:
num_retries = num_retries + 1
if not silent:
__logger__.info("Error hit while download from S3: %s" % e)
__logger__.info("Retrying %s out of %s" % (num_retries, __RETRY_TIMES))
if num_retries == __RETRY_TIMES:
raise e
time.sleep(__SLEEP_SECONDS_BETWEEN_RETRIES)
def parse_s3_path(path):
'''Parse a s3 path to bucket name and path name
Parameters
-----------
path : str
s3 path like: s3://bucket_name/path/to/somewhere
Returns
--------
out : (bucket_name, path_name)
'''
if not is_s3_path(path):
raise ValueError('path is not a s3 path: %s' % path)
tokens = path.split('/')
bucket_name = tokens[2]
s3_directory = '/'.join(tokens[3:])
# remove trailing '/' if exists
if s3_directory and s3_directory[-1] == '/':
s3_directory = s3_directory[0:-1]
return (bucket_name, s3_directory)
def s3_delete_key(s3_bucket_name, s3_key_name, aws_credentials = {}):
conn = boto.connect_s3(**aws_credentials)
bucket = conn.get_bucket(s3_bucket_name, validate=False)
bucket.delete_key(s3_key_name)
def s3_touch(path, aws_credentials = {}):
"""
Create an empty file in s3
"""
with tempfile.NamedTemporaryFile() as f:
upload_to_s3(f.name, path, aws_credentials=aws_credentials, silent=True)
def read_file_to_string_hdfs(hdfs_path, max_size=None, hadoop_conf_dir=None):
''' Read a file from hdfs and return the string content
'''
# list the file first, should be a single file
file_info = list_hdfs(hdfs_path, hadoop_conf_dir=hadoop_conf_dir)
if not file_info or len(file_info) != 1:
return None
if max_size and long(file_info[0]['size']) > max_size:
raise RuntimeError("Cannot read file larger than max size %s." % str(max_size))
base_command = 'hadoop fs -cat '
if hadoop_conf_dir:
base_command = 'hadoop --config %s fs -cat ' % hadoop_conf_dir
base_command += '\"%s\" ' % hdfs_path
exit_code, stdo, stde = _hdfs_exec_command(base_command)
if exit_code == 0:
return stdo
return None
def remove_hdfs(hdfs_path, hadoop_conf_dir=None, recursive=False):
base_command = 'hadoop fs -rm -f '
'''
Remove all file/files in the given path, recursively.
'''
if hadoop_conf_dir:
base_command = 'hadoop --config %s fs -rm -f ' % hadoop_conf_dir
if recursive:
base_command += '-r '
base_command += '\"%s\" ' % hdfs_path
exit_code, stdo, stde = _hdfs_exec_command(base_command)
if exit_code != 0:
raise RuntimeError('Error encounted trying to run the following command: \n%s\n, '
'Output from the command: \n%s' % (base_command, stdo))
def list_hdfs(hdfs_path, hadoop_conf_dir=None):
base_command = 'hadoop fs -ls '
if hadoop_conf_dir:
base_command = 'hadoop --config %s fs -ls ' % hadoop_conf_dir
base_command += '\"%s\" ' % hdfs_path
exit_code, stdo, stde = _hdfs_exec_command(base_command)
if exit_code == 0:
files = []
lines = stdo.split("\n")
for l in lines:
if len(l) == 0 or l.startswith("Found"):
continue
file_line = l.split(hdfs_path)
file_info = file_line[0].split() # split file info string
file_name = file_line[1] # file name
file_size = file_info[4] # file size
files.append({"path": hdfs_path + file_name, "size":file_size})
return files
return None
def copy_to_hdfs(src_hdfs_path, dst_hdfs_path, hadoop_conf_dir=None, force=False):
base_command= 'hadoop fs -cp '
if hadoop_conf_dir:
base_command='hadoop --config %s fs -cp ' % hadoop_conf_dir
if force:
base_command += ' -f'
base_command += ' %s %s ' % (src_hdfs_path, dst_hdfs_path)
exit_code, stdo, stde = _hdfs_exec_command(base_command)
if exit_code != 0:
raise RuntimeError("Failed to copy hdfs %s -> hdfs %s: %s" % (src_hdfs_path,dst_hdfs_path, stde))
def upload_to_hdfs(local_path, hdfs_path, hadoop_conf_dir=None, force=False):
base_command= 'hadoop fs -put '
if hadoop_conf_dir:
base_command='hadoop --config %s fs -put ' % hadoop_conf_dir
if force:
base_command += ' -f'
base_command += ' %s %s ' % (local_path, hdfs_path)
exit_code, stdo, stde = _hdfs_exec_command(base_command)
if exit_code != 0:
raise RuntimeError("Failed to copy %s -> hdfs %s: %s" % (local_path, hdfs_path, stde))
def upload_folder_to_hdfs(local_path, hdfs_path, hadoop_conf_dir=None):
if not os.path.isdir(local_path):
raise RuntimeError("'%s' has to be a directory" % local_path)
base_command= 'hadoop fs '
if hadoop_conf_dir:
base_command='hadoop --config %s fs ' % hadoop_conf_dir
cp_command = '%s -copyFromLocal %s %s ' % (base_command, local_path, hdfs_path)
exit_code, stdo, stde = _hdfs_exec_command(cp_command)
if exit_code != 0:
raise RuntimeError("Failed to copy directory %s -> hdfs %s: %s" % (local_path, hdfs_path, stde))
# change folder permission
chang_permission_cmd = base_command + '-chmod -R a+rwx \"%s\"' % hdfs_path
exit_code, stdo, stde = _hdfs_exec_command(chang_permission_cmd)
if exit_code != 0:
raise RuntimeError("error changing permissions %s" % stde)
# Todo -- maybe use copyToLocal instead /*
def download_from_hdfs(hdfs_path, local_path, hadoop_conf_dir=None, is_dir = False):
if is_dir:
hdfs_path = '%s/*' % hdfs_path
if hadoop_conf_dir:
base_command = 'hadoop --config %s fs -get \"%s\" \"%s\" ' % (hadoop_conf_dir, hdfs_path, local_path)
else:
base_command = 'hadoop fs -get \"%s\" \"%s\" ' % (hdfs_path, local_path)
exit_code, stdo, stde = _hdfs_exec_command(base_command)
if exit_code != 0:
raise RuntimeError("Failed to get %s -> %s: %s" % (hdfs_path, local_path, stde))
if not os.path.exists(local_path):
raise RuntimeError('local file %s not found' % local_path)
def hdfs_touch(path, hadoop_conf_dir=None):
"""
Create an empty file in HDFS
"""
base_command = 'hadoop'
if hadoop_conf_dir:
base_command += ' --config %s' % hadoop_conf_dir
touchz_cmd = base_command + ' fs -touchz \"%s\"' % path
exit_code, stdo, stde = _hdfs_exec_command(touchz_cmd)
if exit_code != 0:
raise RuntimeError("error creating file '%s', error: %s" % (path, stde))
def hdfs_mkdir(dirname, hadoop_conf_dir=None):
'''
Create a new directory in HDFS
'''
if isinstance(dirname,list):
dirname = " ".join(dirname)
base_command = 'hadoop'
if hadoop_conf_dir:
base_command += ' --config %s' % hadoop_conf_dir
mkdir_cmd = base_command + ' fs -mkdir -p \"%s\"' % dirname
exit_code, stdo, stde = _hdfs_exec_command(mkdir_cmd)
if exit_code != 0:
raise RuntimeError("error making dir '%s', error: %s" % (dirname, stde))
chang_permission_cmd = base_command + ' fs -chmod a+rwx \"%s\"' % dirname
exit_code, stdo, stde = _hdfs_exec_command(chang_permission_cmd)
if exit_code != 0:
raise RuntimeError("error changing permissions %s" % stde)
def _intra_s3_copy_model(s3_src_path, s3_dest_path, aws_credentials = {}):
assert(is_s3_path(s3_src_path) and is_s3_path(s3_dest_path))
s3_src_bucket_name, s3_src_dir_name = parse_s3_path(s3_src_path)
s3_dest_bucket_name, s3_dest_dir_name = parse_s3_path(s3_dest_path)
conn = boto.connect_s3(**aws_credentials)
s3_src_bucket = conn.get_bucket(s3_src_bucket_name, validate=False)
s3_dest_bucket = conn.get_bucket(s3_dest_bucket_name, validate=False)
# Get a list of all keys to copy
num_retries = 0
while num_retries < __RETRY_TIMES:
try:
keys_to_copy = s3_src_bucket.list(prefix=s3_src_dir_name)
break
except Exception as e:
num_retries = num_retries + 1
__logger__.info("Error hit while listing keys to S3: %s" % e)
__logger__.info("Retrying %s out of %s" % (num_retries, __RETRY_TIMES))
if num_retries == __RETRY_TIMES:
raise e
time.sleep(__SLEEP_SECONDS_BETWEEN_RETRIES)
for k in keys_to_copy:
k = k.name
file_name = os.path.basename(k)
new_key_name = s3_dest_dir_name + '/' + file_name
# Do the actual copy
num_retries = 0
while num_retries < __RETRY_TIMES:
try:
s3_dest_bucket.copy_key(new_key_name, s3_src_bucket_name, k)
break
except Exception as e:
num_retries = num_retries + 1
__logger__.info("Error hit while listing keys to S3: %s" % e)
__logger__.info("Retrying %s out of %s" % (num_retries, __RETRY_TIMES))
if num_retries == __RETRY_TIMES:
raise e
time.sleep(__SLEEP_SECONDS_BETWEEN_RETRIES)
def intra_s3_copy_model(s3_src_path, s3_dest_path, is_dir=False, aws_credentials = {}):
'''
copy model from a source s3 path to the target s3 path. set 'is_dir' to True if you plan
to copy the directory. set 'is_dir' to False if you only plan to copy a single file.
the default value for 'is_dir' is False.
'''
assert(is_s3_path(s3_src_path) and is_s3_path(s3_dest_path))
# check if should use boto
if _use_boto():
_intra_s3_copy_model(s3_src_path, s3_dest_path, aws_credentials)
return
__logger__.info('Copying s3 path %s to s3 path %s' % (s3_src_path, s3_dest_path))
# Get a list of all keys to copy
num_retries = 0
while num_retries < __RETRY_TIMES:
try:
_awscli_s3_op('cp', s3_src_path, s3_dest_path, recursive=is_dir, aws_credentials=aws_credentials)
__logger__.info("Successfully copied from s3 path %s to s3 path %s" % (s3_src_path, s3_dest_path))
break
except Exception as e:
num_retries = num_retries + 1
__logger__.info("Error hit while copying model from %s to %s: %s" % (s3_src_path, s3_dest_path, e))
__logger__.info("Retrying %s out of %s" % (num_retries, __RETRY_TIMES))
if num_retries == __RETRY_TIMES:
raise e
time.sleep(__SLEEP_SECONDS_BETWEEN_RETRIES)
def s3_copy_model(src_path, s3_dest_path, aws_credentials = {}):
assert(is_local_path(src_path) and is_s3_path(s3_dest_path))
# check if should use boto
if _use_boto():
for base_file_name in os.listdir(src_path):
source_file = os.path.join(src_path, base_file_name)
file_dest = s3_dest_path + '/' + base_file_name
upload_to_s3(source_file, file_dest, aws_credentials=aws_credentials)
else:
upload_to_s3(src_path, s3_dest_path, is_dir=True, aws_credentials=aws_credentials)
def s3_recursive_delete(s3_path, aws_credentials = {}):
(s3_bucket_name, s3_key_prefix) = parse_s3_path(s3_path)
conn = boto.connect_s3(**aws_credentials)
bucket = conn.get_bucket(s3_bucket_name, validate=False)
matches = bucket.list(prefix=s3_key_prefix)
bucket.delete_keys([key.name for key in matches])
def expand_full_path(path):
'''Expand a relative path to a full path
For example,
'~/tmp' may be expanded to '/Users/username/tmp'
'abc/def' may be expanded to '/pwd/abc/def'
'''
return os.path.abspath(os.path.expanduser(path))
def _get_s3_key(s3_path, aws_credentials = {}):
'''Given S3 path, get the key object that represents the path'''
conn = boto.connect_s3(**aws_credentials)
(bucket_name, path) = parse_s3_path(s3_path)
bucket = conn.get_bucket(bucket_name, validate=False)
k = boto.s3.key.Key(bucket)
k.key = path
return k
def _s3_callback(complete, total):
if complete > 0:
__logger__.info('%d%% completed.' % int(1.0 * complete/total * 100))
def _awscli_s3_op(op, src, dst=None, recursive=False, silent=False, is_test=False,
aws_credentials = {}):
''' use AWS command line interface for any operations to s3 '''
# get aws credentials from input or environment variables
aws_access_key_id = None
aws_secret_access_key = None
if 'aws_access_key_id' in aws_credentials and 'aws_secret_access_key' in aws_credentials:
aws_access_key_id = aws_credentials['aws_access_key_id']
aws_secret_access_key = aws_credentials['aws_secret_access_key']
elif 'AWS_ACCESS_KEY_ID' in os.environ and 'AWS_SECRET_ACCESS_KEY' in os.environ:
aws_access_key_id = os.environ['AWS_ACCESS_KEY_ID']
aws_secret_access_key = os.environ['AWS_SECRET_ACCESS_KEY']
# use subprocess to perform aws s3 ops
# "acl" grants the bucket owner full permission regardless of the uploader's account
arglist = ['aws', 's3']
if sys.platform == 'win32':
arglist[0] = arglist[0] + ".cmd"
if op == 'cp':
arglist.extend(['cp', src, dst, '--acl', 'bucket-owner-full-control'])
elif op == 'rm':
arglist.extend(['rm', src])
if recursive:
arglist.append('--recursive')
if is_test:
arglist.append('--dryrun')
if silent:
arglist.append('--quiet')
env = os.environ.copy()
if aws_access_key_id is not None and aws_secret_access_key is not None:
env['AWS_ACCESS_KEY_ID'] = aws_access_key_id
env['AWS_SECRET_ACCESS_KEY'] = aws_secret_access_key
if 'PYTHONEXECUTABLE' in env: # remove PYTHONEXECUTABLE for anaconda
del env['PYTHONEXECUTABLE']
# open subprocess
proc = subprocess.Popen(arglist, env=env, stderr=subprocess.PIPE, stdout=subprocess.PIPE, bufsize=-1)
# read stdout/stderr and wait for subprocess to finish
prev = ''
while True:
line = proc.stdout.read(100)
if line != '':
# parse stdout from subprocess
line = line.replace('\r\n', '\n').replace('\r', '\n')
lines = line.split('\n')
if len(lines) == 1:
prev = prev + lines[0]
continue
else:
# print status for each file, and total progress
for index, l in enumerate(lines):
print_str = None
if index == 0:
print_str = prev + l
elif index == (len(lines) - 1):
prev = l
else:
print_str = l
if print_str:
_awscli_print(print_str)
else:
break
proc.wait()
# check for error
if proc.returncode != 0: # error
raise RuntimeError('AWS S3 operation failed')
def _awscli_print(line):
if line.startswith('Completed'): # progress bar
sys.stdout.write("\r%s" % line)
sys.stdout.flush()
else: # file path
sys.stdout.write('\r'+line+'\n')
def s3_test_url(s3_path, aws_credentials={}):
"""
Test if a given key exist in S3. Return True if exists, otherwise False
"""
conn = boto.connect_s3(**aws_credentials)
(bucket_name, path) = parse_s3_path(s3_path)
try:
bucket = conn.get_bucket(bucket_name, validate=True)
k = bucket.get_key(path, validate=True)
return k is not None
except S3ResponseError as e:
return False
def hdfs_test_url(hdfs_url,test='e',hadoop_conf_dir=None):
"""
Test the url.
parameters
----------
hdfs_url: string
The hdfs url
test: string, optional
'e': existence
'd': is a directory
'z': zero length
Default is an existence test, 'e'
"""
if hadoop_conf_dir == None:
command = "hadoop fs -test -%s %s" % (test, hdfs_url)
else:
command = "hadoop --config %s fs -test -%s %s" % (hadoop_conf_dir,test, hdfs_url)
exit_code, stdo, stde = _hdfs_exec_command(command)
return exit_code == 0
def _hdfs_exec_command(command, silent = True):
"""
Execute HDFS command. and return the exit status.
"""
if not silent:
__logger__.info("Running hdfs command: \n%s" % command)
pobj = subprocess.Popen(command, stdout=PIPE, stderr=PIPE, shell=True)
stdo, stde = pobj.communicate()
exit_code = pobj.returncode
return exit_code, stdo, stde
def retry(tries=3, delay=1, backoff=1, retry_exception=None):
'''
Retries a function or method until it has reached the maximum retries
Parameters
-----------
tries : int, optional
the number of times this function will retry
delay : int, optional
the number of seconds in delay to retry
backoff : int, optional
the number of factors by which the delay should increase after a retry
retry_exception: Error, optional
the type of error that only will trigger retries. Defaults to None so
all types of error will trigger retries.
This is derived from the original implementation of retry at:
https://wiki.python.org/moin/PythonDecoratorLibrary#Retry
'''
def deco_retry(f):
def f_retry(*args, **kargs):
mtries, mdelay = tries, delay # mutables
while mtries > 1:
try:
return f(*args, **kargs) # run function
except Exception as e:
if retry_exception and not isinstance(e, retry_exception):
break # break and return f if exception caught is not expected
mtries -= 1 # decrease retry
time.sleep(mdelay) # delay to next retry
mdelay *= backoff # increase delay
return f(*args, **kargs) # last retry
return f_retry
return deco_retry
|
bsd-3-clause
|
[
2344,
199,
7384,
334,
35,
9,
6900,
577,
11318,
12,
3277,
14,
199,
2422,
4481,
4644,
14,
199,
199,
2765,
2032,
1443,
506,
6042,
436,
1854,
1334,
314,
2895,
199,
1618,
314,
6289,
4190,
14,
1666,
314,
5113,
570,
367,
2436,
14,
199,
2344,
199,
199,
2344,
199,
199,
2765,
2559,
6571,
28829,
1202,
3102,
367,
23654,
543,
570,
3439,
12,
199,
15768,
6449,
543,
2784,
570,
2656,
2839,
428,
19,
12,
1455,
12,
5423,
14,
199,
199,
2344,
199,
646,
747,
199,
646,
984,
199,
646,
900,
199,
646,
6055,
199,
646,
6055,
14,
83,
19,
199,
646,
13608,
199,
646,
2050,
199,
646,
5145,
199,
646,
5549,
199,
646,
3873,
199,
504,
3873,
492,
22773,
199,
504,
6055,
14,
1971,
492,
428,
19,
19712,
199,
199,
363,
2921,
363,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
363,
27778,
63,
11342,
654,
275,
959,
199,
363,
51,
906,
6102,
63,
23319,
63,
34,
29056,
63,
32528,
275,
499,
199,
363,
25302,
12019,
63,
51,
19,
63,
4701,
63,
21373,
275,
298,
25302,
12019,
63,
15505,
63,
2864,
2,
199,
199,
318,
485,
1180,
63,
10914,
837,
523,
372,
221,
636,
25302,
12019,
63,
51,
19,
63,
4701,
63,
21373,
315,
747,
14,
2314,
436,
971,
272,
747,
14,
2314,
28894,
25302,
12019,
63,
51,
19,
63,
4701,
63,
21373,
61,
508,
283,
2398,
5000,
857,
3167,
7,
199,
199,
318,
664,
63,
3922,
8,
515,
304,
523,
1449,
13735,
282,
931,
12,
2529,
314,
4113,
314,
931,
4440,
819,
2104,
2893,
12,
272,
283,
83,
19,
921,
65,
15,
66,
15,
67,
4805,
221,
2529,
283,
83,
19,
7,
272,
283,
1014,
921,
65,
15,
66,
15,
67,
7,
2529,
283,
1014,
7,
272,
283,
2791,
15,
65,
15,
3776,
4805,
259,
2529,
2125,
819,
1449,
523,
2086,
275,
931,
14,
1623,
6176,
501,
358,
523,
340,
2086,
665,
378,
26,
272,
372,
2125,
523,
372,
931,
59,
16,
26,
1712,
1055,
2325,
342,
421,
199,
318,
365,
63,
515,
8,
875,
304,
523,
340,
440,
1228,
8,
875,
12,
620,
304,
272,
372,
756,
523,
372,
365,
63,
1832,
63,
515,
8,
875,
9,
503,
365,
63,
83,
19,
63,
515,
8,
875,
9,
421,
199,
318,
20366,
8,
515,
304,
272,
340,
365,
63,
1832,
63,
515,
8,
515,
304,
267,
747,
14,
8347,
8,
515,
9,
272,
916,
365,
63,
19055,
63,
515,
8,
515,
304,
267,
394,
10434,
63,
8215,
8,
515,
9,
272,
916,
365,
63,
83,
19,
63,
515,
8,
515,
304,
267,
327,
949,
1929,
370,
1852,
1263,
2082,
267,
986,
272,
587,
26,
267,
746,
1722,
360,
12647,
4113,
450,
83,
7,
450,
931,
9,
199,
199,
318,
3495,
8,
515,
12,
11488,
63,
6942,
275,
1052,
304,
272,
340,
365,
63,
1832,
63,
515,
8,
515,
304,
267,
372,
747,
14,
515,
14,
2444,
8,
515,
9,
272,
916,
365,
63,
19055,
63,
515,
8,
515,
304,
267,
372,
394,
10434,
63,
396,
63,
633,
8,
515,
9,
272,
916,
365,
63,
83,
19,
63,
515,
8,
515,
304,
267,
372,
308,
19,
63,
396,
63,
633,
8,
515,
12,
11488,
63,
6942,
275,
11488,
63,
6942,
9,
272,
587,
26,
267,
746,
1722,
360,
12647,
4113,
450,
83,
7,
450,
931,
9,
421,
199,
318,
12943,
8,
515,
304,
272,
340,
365,
63,
1832,
63,
515,
8,
515,
304,
267,
543,
1551,
8,
515,
12,
283,
65,
735,
288,
747,
14,
24043,
8,
515,
12,
488,
9,
272,
916,
365,
63,
19055,
63,
515,
8,
515,
304,
267,
394,
10434,
63,
12376,
8,
515,
9,
272,
916,
365,
63,
83,
19,
63,
515,
8,
515,
304,
267,
308,
19,
63,
12376,
8,
515,
9,
272,
587,
26,
267,
746,
1722,
360,
12647,
4113,
450,
83,
7,
450,
931,
9,
421,
199,
318,
1586,
8,
515,
304,
272,
340,
365,
63,
1832,
63,
515,
8,
515,
304,
267,
372,
1551,
8,
515,
680,
739,
342,
272,
916,
365,
63,
19055,
63,
515,
8,
515,
304,
267,
372,
1586,
63,
493,
63,
475,
63,
875,
63,
19055,
8,
515,
9,
272,
916,
365,
63,
83,
19,
63,
515,
8,
515,
304,
267,
372,
1586,
63,
493,
63,
475,
63,
875,
63,
83,
19,
8,
515,
9,
272,
587,
26,
267,
746,
1722,
360,
12647,
4113,
450,
83,
7,
450,
931,
9,
421,
199,
318,
1331,
63,
504,
63,
1832,
8,
1832,
515,
12,
3982,
515,
304,
272,
340,
365,
63,
19055,
63,
515,
8,
3846,
515,
304,
267,
5802,
63,
475,
63,
19055,
8,
1832,
515,
12,
3982,
515,
9,
272,
916,
365,
63,
83,
19,
63,
515,
8,
3846,
515,
304,
267,
5802,
63,
475,
63,
83,
19,
8,
1832,
515,
12,
3982,
515,
9,
272,
916,
365,
63,
1832,
63,
515,
8,
3846,
515,
304,
267,
5145,
14,
1574,
8,
1832,
515,
12,
3982,
515,
9,
272,
587,
26,
267,
746,
1722,
360,
12647,
4113,
450,
83,
7,
450,
3982,
515,
9,
199,
199,
318,
365,
63,
1832,
63,
515,
8,
515,
304,
523,
1449,
3407,
715,
340,
314,
931,
9126,
282,
2257,
931,
12,
4257,
756,
2344,
523,
4113,
275,
664,
63,
3922,
8,
515,
9,
523,
372,
4113,
1137,
283,
19055,
7,
436,
4113,
1137,
283,
83,
19,
7,
436,
971,
267,
4113,
1137,
283,
1014,
7,
436,
4113,
1137,
283,
2859,
7,
199,
199,
318,
365,
63,
83,
19,
63,
515,
8,
515,
304,
523,
1449,
3407,
715,
340,
314,
931,
9126,
282,
308,
19,
931,
12,
4257,
756,
2344,
523,
4113,
275,
664,
63,
3922,
8,
515,
9,
523,
372,
4113,
508,
283,
83,
19,
7,
199,
199,
318,
365,
63,
19055,
63,
515,
8,
515,
304,
523,
1449,
3407,
715,
340,
314,
931,
9126,
282,
308,
19,
931,
12,
4257,
756,
2344,
523,
4113,
275,
664,
63,
3922,
8,
515,
9,
523,
372,
4113,
508,
283,
19055,
7,
199,
199,
318,
5802,
63,
475,
63,
1832,
8,
2164,
63,
515,
12,
5042,
63,
515,
12,
365,
63,
694,
29,
797,
12,
10866,
29,
797,
304,
523,
1449,
29042,
282,
570,
15,
694,
370,
282,
2257,
931,
2344,
523,
340,
440,
10866,
26,
272,
636,
2921,
4343
] |
[
199,
7384,
334,
35,
9,
6900,
577,
11318,
12,
3277,
14,
199,
2422,
4481,
4644,
14,
199,
199,
2765,
2032,
1443,
506,
6042,
436,
1854,
1334,
314,
2895,
199,
1618,
314,
6289,
4190,
14,
1666,
314,
5113,
570,
367,
2436,
14,
199,
2344,
199,
199,
2344,
199,
199,
2765,
2559,
6571,
28829,
1202,
3102,
367,
23654,
543,
570,
3439,
12,
199,
15768,
6449,
543,
2784,
570,
2656,
2839,
428,
19,
12,
1455,
12,
5423,
14,
199,
199,
2344,
199,
646,
747,
199,
646,
984,
199,
646,
900,
199,
646,
6055,
199,
646,
6055,
14,
83,
19,
199,
646,
13608,
199,
646,
2050,
199,
646,
5145,
199,
646,
5549,
199,
646,
3873,
199,
504,
3873,
492,
22773,
199,
504,
6055,
14,
1971,
492,
428,
19,
19712,
199,
199,
363,
2921,
363,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
363,
27778,
63,
11342,
654,
275,
959,
199,
363,
51,
906,
6102,
63,
23319,
63,
34,
29056,
63,
32528,
275,
499,
199,
363,
25302,
12019,
63,
51,
19,
63,
4701,
63,
21373,
275,
298,
25302,
12019,
63,
15505,
63,
2864,
2,
199,
199,
318,
485,
1180,
63,
10914,
837,
523,
372,
221,
636,
25302,
12019,
63,
51,
19,
63,
4701,
63,
21373,
315,
747,
14,
2314,
436,
971,
272,
747,
14,
2314,
28894,
25302,
12019,
63,
51,
19,
63,
4701,
63,
21373,
61,
508,
283,
2398,
5000,
857,
3167,
7,
199,
199,
318,
664,
63,
3922,
8,
515,
304,
523,
1449,
13735,
282,
931,
12,
2529,
314,
4113,
314,
931,
4440,
819,
2104,
2893,
12,
272,
283,
83,
19,
921,
65,
15,
66,
15,
67,
4805,
221,
2529,
283,
83,
19,
7,
272,
283,
1014,
921,
65,
15,
66,
15,
67,
7,
2529,
283,
1014,
7,
272,
283,
2791,
15,
65,
15,
3776,
4805,
259,
2529,
2125,
819,
1449,
523,
2086,
275,
931,
14,
1623,
6176,
501,
358,
523,
340,
2086,
665,
378,
26,
272,
372,
2125,
523,
372,
931,
59,
16,
26,
1712,
1055,
2325,
342,
421,
199,
318,
365,
63,
515,
8,
875,
304,
523,
340,
440,
1228,
8,
875,
12,
620,
304,
272,
372,
756,
523,
372,
365,
63,
1832,
63,
515,
8,
875,
9,
503,
365,
63,
83,
19,
63,
515,
8,
875,
9,
421,
199,
318,
20366,
8,
515,
304,
272,
340,
365,
63,
1832,
63,
515,
8,
515,
304,
267,
747,
14,
8347,
8,
515,
9,
272,
916,
365,
63,
19055,
63,
515,
8,
515,
304,
267,
394,
10434,
63,
8215,
8,
515,
9,
272,
916,
365,
63,
83,
19,
63,
515,
8,
515,
304,
267,
327,
949,
1929,
370,
1852,
1263,
2082,
267,
986,
272,
587,
26,
267,
746,
1722,
360,
12647,
4113,
450,
83,
7,
450,
931,
9,
199,
199,
318,
3495,
8,
515,
12,
11488,
63,
6942,
275,
1052,
304,
272,
340,
365,
63,
1832,
63,
515,
8,
515,
304,
267,
372,
747,
14,
515,
14,
2444,
8,
515,
9,
272,
916,
365,
63,
19055,
63,
515,
8,
515,
304,
267,
372,
394,
10434,
63,
396,
63,
633,
8,
515,
9,
272,
916,
365,
63,
83,
19,
63,
515,
8,
515,
304,
267,
372,
308,
19,
63,
396,
63,
633,
8,
515,
12,
11488,
63,
6942,
275,
11488,
63,
6942,
9,
272,
587,
26,
267,
746,
1722,
360,
12647,
4113,
450,
83,
7,
450,
931,
9,
421,
199,
318,
12943,
8,
515,
304,
272,
340,
365,
63,
1832,
63,
515,
8,
515,
304,
267,
543,
1551,
8,
515,
12,
283,
65,
735,
288,
747,
14,
24043,
8,
515,
12,
488,
9,
272,
916,
365,
63,
19055,
63,
515,
8,
515,
304,
267,
394,
10434,
63,
12376,
8,
515,
9,
272,
916,
365,
63,
83,
19,
63,
515,
8,
515,
304,
267,
308,
19,
63,
12376,
8,
515,
9,
272,
587,
26,
267,
746,
1722,
360,
12647,
4113,
450,
83,
7,
450,
931,
9,
421,
199,
318,
1586,
8,
515,
304,
272,
340,
365,
63,
1832,
63,
515,
8,
515,
304,
267,
372,
1551,
8,
515,
680,
739,
342,
272,
916,
365,
63,
19055,
63,
515,
8,
515,
304,
267,
372,
1586,
63,
493,
63,
475,
63,
875,
63,
19055,
8,
515,
9,
272,
916,
365,
63,
83,
19,
63,
515,
8,
515,
304,
267,
372,
1586,
63,
493,
63,
475,
63,
875,
63,
83,
19,
8,
515,
9,
272,
587,
26,
267,
746,
1722,
360,
12647,
4113,
450,
83,
7,
450,
931,
9,
421,
199,
318,
1331,
63,
504,
63,
1832,
8,
1832,
515,
12,
3982,
515,
304,
272,
340,
365,
63,
19055,
63,
515,
8,
3846,
515,
304,
267,
5802,
63,
475,
63,
19055,
8,
1832,
515,
12,
3982,
515,
9,
272,
916,
365,
63,
83,
19,
63,
515,
8,
3846,
515,
304,
267,
5802,
63,
475,
63,
83,
19,
8,
1832,
515,
12,
3982,
515,
9,
272,
916,
365,
63,
1832,
63,
515,
8,
3846,
515,
304,
267,
5145,
14,
1574,
8,
1832,
515,
12,
3982,
515,
9,
272,
587,
26,
267,
746,
1722,
360,
12647,
4113,
450,
83,
7,
450,
3982,
515,
9,
199,
199,
318,
365,
63,
1832,
63,
515,
8,
515,
304,
523,
1449,
3407,
715,
340,
314,
931,
9126,
282,
2257,
931,
12,
4257,
756,
2344,
523,
4113,
275,
664,
63,
3922,
8,
515,
9,
523,
372,
4113,
1137,
283,
19055,
7,
436,
4113,
1137,
283,
83,
19,
7,
436,
971,
267,
4113,
1137,
283,
1014,
7,
436,
4113,
1137,
283,
2859,
7,
199,
199,
318,
365,
63,
83,
19,
63,
515,
8,
515,
304,
523,
1449,
3407,
715,
340,
314,
931,
9126,
282,
308,
19,
931,
12,
4257,
756,
2344,
523,
4113,
275,
664,
63,
3922,
8,
515,
9,
523,
372,
4113,
508,
283,
83,
19,
7,
199,
199,
318,
365,
63,
19055,
63,
515,
8,
515,
304,
523,
1449,
3407,
715,
340,
314,
931,
9126,
282,
308,
19,
931,
12,
4257,
756,
2344,
523,
4113,
275,
664,
63,
3922,
8,
515,
9,
523,
372,
4113,
508,
283,
19055,
7,
199,
199,
318,
5802,
63,
475,
63,
1832,
8,
2164,
63,
515,
12,
5042,
63,
515,
12,
365,
63,
694,
29,
797,
12,
10866,
29,
797,
304,
523,
1449,
29042,
282,
570,
15,
694,
370,
282,
2257,
931,
2344,
523,
340,
440,
10866,
26,
272,
636,
2921,
4343,
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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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
] |
haoyuchen1992/osf.io
|
scripts/box/connect_external_accounts.py
|
31
|
1562
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
First run
rm -rf website/addons/box/views/
to remove old .pyc files that would interfere.
"""
import sys
import logging
from modularodm import Q
from website.app import init_app
from scripts import utils as script_utils
from framework.transactions.context import TokuTransaction
from website.addons.box.model import BoxNodeSettings
logger = logging.getLogger(__name__)
def do_migration():
for node_addon in BoxNodeSettings.find(Q('foreign_user_settings', 'ne', None)):
user_addon = node_addon.foreign_user_settings
user = user_addon.owner
if not user_addon.external_accounts:
logger.warning('User {0} has no box external account'.format(user._id))
continue
account = user_addon.external_accounts[0]
node_addon.set_auth(account, user_addon.owner)
user_addon.grant_oauth_access(
node=node_addon.owner,
external_account=account,
metadata={'folder': node_addon.folder_id}
)
logger.info('Added external account {0} to node {1}'.format(
account._id, node_addon.owner._id,
))
def main(dry=True):
init_app(set_backends=True, routes=False) # Sets the storage backends on all models
with TokuTransaction():
do_migration()
if dry:
raise Exception('Abort Transaction - Dry Run')
if __name__ == '__main__':
dry = 'dry' in sys.argv
if not dry:
script_utils.add_file_logger(logger, __file__)
main(dry=dry)
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
7147,
1255,
5591,
14267,
446,
3941,
10691,
15,
10788,
15,
1977,
15,
4196,
15,
199,
475,
2813,
2269,
1275,
11357,
1584,
626,
3955,
1640,
771,
264,
14,
199,
624,
199,
646,
984,
199,
646,
2050,
199,
504,
3413,
2238,
364,
77,
492,
1413,
199,
199,
504,
10691,
14,
571,
492,
4205,
63,
571,
199,
504,
10554,
492,
3778,
465,
2884,
63,
1208,
199,
504,
10059,
14,
13754,
14,
1100,
492,
377,
745,
85,
10161,
199,
199,
504,
10691,
14,
10788,
14,
1977,
14,
1238,
492,
20783,
1716,
5268,
199,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
318,
886,
63,
8998,
837,
272,
367,
1031,
63,
9291,
315,
20783,
1716,
5268,
14,
1623,
8,
49,
360,
6846,
63,
751,
63,
1751,
297,
283,
685,
297,
488,
2298,
267,
922,
63,
9291,
275,
1031,
63,
9291,
14,
6846,
63,
751,
63,
1751,
267,
922,
275,
922,
63,
9291,
14,
4597,
267,
340,
440,
922,
63,
9291,
14,
5159,
63,
8370,
26,
288,
2512,
14,
3764,
360,
1899,
469,
16,
93,
965,
949,
5689,
5957,
2933,
1370,
908,
8,
751,
423,
344,
430,
288,
1980,
267,
2933,
275,
922,
63,
9291,
14,
5159,
63,
8370,
59,
16,
61,
267,
1031,
63,
9291,
14,
409,
63,
1178,
8,
2048,
12,
922,
63,
9291,
14,
4597,
9,
398,
922,
63,
9291,
14,
17362,
63,
6126,
63,
2732,
8,
288,
1031,
29,
932,
63,
9291,
14,
4597,
12,
288,
5957,
63,
2048,
29,
2048,
12,
288,
3341,
3713,
3741,
356,
1031,
63,
9291,
14,
3741,
63,
344,
93,
267,
776,
398,
2512,
14,
815,
360,
20201,
5957,
2933,
469,
16,
93,
370,
1031,
469,
17,
5285,
908,
8,
288,
2933,
423,
344,
12,
1031,
63,
9291,
14,
4597,
423,
344,
12,
267,
5082,
421,
199,
318,
2446,
8,
10481,
29,
549,
304,
272,
4205,
63,
571,
8,
409,
63,
7765,
29,
549,
12,
15777,
29,
797,
9,
221,
327,
10729,
314,
4887,
14745,
641,
1006,
1709,
272,
543,
377,
745,
85,
10161,
837,
267,
886,
63,
8998,
342,
267,
340,
9951,
26,
288,
746,
2186,
360,
16682,
18244,
446,
577,
651,
3378,
358,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
9951,
275,
283,
10481,
7,
315,
984,
14,
3020,
272,
340,
440,
9951,
26,
267,
2884,
63,
1208,
14,
525,
63,
493,
63,
2921,
8,
2921,
12,
636,
493,
3368,
272,
2446,
8,
10481,
29,
10481,
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
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
7147,
1255,
5591,
14267,
446,
3941,
10691,
15,
10788,
15,
1977,
15,
4196,
15,
199,
475,
2813,
2269,
1275,
11357,
1584,
626,
3955,
1640,
771,
264,
14,
199,
624,
199,
646,
984,
199,
646,
2050,
199,
504,
3413,
2238,
364,
77,
492,
1413,
199,
199,
504,
10691,
14,
571,
492,
4205,
63,
571,
199,
504,
10554,
492,
3778,
465,
2884,
63,
1208,
199,
504,
10059,
14,
13754,
14,
1100,
492,
377,
745,
85,
10161,
199,
199,
504,
10691,
14,
10788,
14,
1977,
14,
1238,
492,
20783,
1716,
5268,
199,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
318,
886,
63,
8998,
837,
272,
367,
1031,
63,
9291,
315,
20783,
1716,
5268,
14,
1623,
8,
49,
360,
6846,
63,
751,
63,
1751,
297,
283,
685,
297,
488,
2298,
267,
922,
63,
9291,
275,
1031,
63,
9291,
14,
6846,
63,
751,
63,
1751,
267,
922,
275,
922,
63,
9291,
14,
4597,
267,
340,
440,
922,
63,
9291,
14,
5159,
63,
8370,
26,
288,
2512,
14,
3764,
360,
1899,
469,
16,
93,
965,
949,
5689,
5957,
2933,
1370,
908,
8,
751,
423,
344,
430,
288,
1980,
267,
2933,
275,
922,
63,
9291,
14,
5159,
63,
8370,
59,
16,
61,
267,
1031,
63,
9291,
14,
409,
63,
1178,
8,
2048,
12,
922,
63,
9291,
14,
4597,
9,
398,
922,
63,
9291,
14,
17362,
63,
6126,
63,
2732,
8,
288,
1031,
29,
932,
63,
9291,
14,
4597,
12,
288,
5957,
63,
2048,
29,
2048,
12,
288,
3341,
3713,
3741,
356,
1031,
63,
9291,
14,
3741,
63,
344,
93,
267,
776,
398,
2512,
14,
815,
360,
20201,
5957,
2933,
469,
16,
93,
370,
1031,
469,
17,
5285,
908,
8,
288,
2933,
423,
344,
12,
1031,
63,
9291,
14,
4597,
423,
344,
12,
267,
5082,
421,
199,
318,
2446,
8,
10481,
29,
549,
304,
272,
4205,
63,
571,
8,
409,
63,
7765,
29,
549,
12,
15777,
29,
797,
9,
221,
327,
10729,
314,
4887,
14745,
641,
1006,
1709,
272,
543,
377,
745,
85,
10161,
837,
267,
886,
63,
8998,
342,
267,
340,
9951,
26,
288,
746,
2186,
360,
16682,
18244,
446,
577,
651,
3378,
358,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
9951,
275,
283,
10481,
7,
315,
984,
14,
3020,
272,
340,
440,
9951,
26,
267,
2884,
63,
1208,
14,
525,
63,
493,
63,
2921,
8,
2921,
12,
636,
493,
3368,
272,
2446,
8,
10481,
29,
10481,
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,
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,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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,
0,
0,
0,
0
] |
ypcs/avoin
|
src/avoin/core.py
|
1
|
1173
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import argparse
from avoin.scraper.scraper import DefaultScraper, xpath_parser, ScraperMissingElementError
from avoin.data.utils import read, write
def main(args):
if args.command == 'xpath':
scraper = DefaultScraper()
xpath = args.xpath
url = args.url
format = args.format.lower()
try:
result = scraper.parse(url, parser=xpath_parser, format=format, xpath=xpath)
if args.outfile:
write(args.outfile, result)
else:
print result
except ScraperMissingElementError:
print "Element w/ XPath %s not found" % xpath
return 0
def run():
parser = argparse.ArgumentParser()
parser.add_argument('command')
parser.add_argument('--xpath', dest='xpath')
parser.add_argument('--url', dest='url')
parser.add_argument('--format', dest='format', default='text')
parser.add_argument('--outfile', dest='outfile')
parser.add_argument('--infile', dest='infile')
args = parser.parse_args()
sys.exit(main(args) or 0)
if __name__ == "__main__":
run()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
646,
984,
199,
646,
7534,
199,
199,
504,
2289,
79,
262,
14,
12865,
529,
14,
12865,
529,
492,
3758,
7181,
345,
529,
12,
14462,
63,
2087,
12,
13916,
345,
529,
7718,
2162,
547,
199,
504,
2289,
79,
262,
14,
576,
14,
1208,
492,
1586,
12,
2218,
199,
199,
318,
2446,
8,
589,
304,
272,
340,
1249,
14,
1531,
508,
283,
8006,
356,
267,
21435,
275,
3758,
7181,
345,
529,
342,
267,
14462,
275,
1249,
14,
8006,
267,
1166,
275,
1249,
14,
633,
398,
1475,
275,
1249,
14,
908,
14,
2325,
342,
398,
862,
26,
288,
754,
275,
21435,
14,
1122,
8,
633,
12,
1798,
29,
8006,
63,
2087,
12,
1475,
29,
908,
12,
14462,
29,
8006,
9,
953,
340,
1249,
14,
4984,
26,
355,
2218,
8,
589,
14,
4984,
12,
754,
9,
288,
587,
26,
355,
870,
754,
398,
871,
13916,
345,
529,
7718,
2162,
547,
26,
288,
870,
298,
2162,
336,
15,
1323,
2042,
450,
83,
440,
1911,
2,
450,
14462,
16478,
372,
378,
199,
199,
318,
1255,
837,
272,
1798,
275,
7534,
14,
10730,
342,
339,
1798,
14,
525,
63,
2094,
360,
1531,
358,
272,
1798,
14,
525,
63,
2094,
4517,
8006,
297,
2053,
534,
8006,
358,
272,
1798,
14,
525,
63,
2094,
4517,
633,
297,
2053,
534,
633,
358,
272,
1798,
14,
525,
63,
2094,
4517,
908,
297,
2053,
534,
908,
297,
849,
534,
505,
358,
272,
1798,
14,
525,
63,
2094,
4517,
4984,
297,
2053,
534,
4984,
358,
272,
1798,
14,
525,
63,
2094,
4517,
13880,
297,
2053,
534,
13880,
358,
339,
1249,
275,
1798,
14,
1122,
63,
589,
342,
272,
984,
14,
2224,
8,
973,
8,
589,
9,
503,
378,
9,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
1255,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
646,
984,
199,
646,
7534,
199,
199,
504,
2289,
79,
262,
14,
12865,
529,
14,
12865,
529,
492,
3758,
7181,
345,
529,
12,
14462,
63,
2087,
12,
13916,
345,
529,
7718,
2162,
547,
199,
504,
2289,
79,
262,
14,
576,
14,
1208,
492,
1586,
12,
2218,
199,
199,
318,
2446,
8,
589,
304,
272,
340,
1249,
14,
1531,
508,
283,
8006,
356,
267,
21435,
275,
3758,
7181,
345,
529,
342,
267,
14462,
275,
1249,
14,
8006,
267,
1166,
275,
1249,
14,
633,
398,
1475,
275,
1249,
14,
908,
14,
2325,
342,
398,
862,
26,
288,
754,
275,
21435,
14,
1122,
8,
633,
12,
1798,
29,
8006,
63,
2087,
12,
1475,
29,
908,
12,
14462,
29,
8006,
9,
953,
340,
1249,
14,
4984,
26,
355,
2218,
8,
589,
14,
4984,
12,
754,
9,
288,
587,
26,
355,
870,
754,
398,
871,
13916,
345,
529,
7718,
2162,
547,
26,
288,
870,
298,
2162,
336,
15,
1323,
2042,
450,
83,
440,
1911,
2,
450,
14462,
16478,
372,
378,
199,
199,
318,
1255,
837,
272,
1798,
275,
7534,
14,
10730,
342,
339,
1798,
14,
525,
63,
2094,
360,
1531,
358,
272,
1798,
14,
525,
63,
2094,
4517,
8006,
297,
2053,
534,
8006,
358,
272,
1798,
14,
525,
63,
2094,
4517,
633,
297,
2053,
534,
633,
358,
272,
1798,
14,
525,
63,
2094,
4517,
908,
297,
2053,
534,
908,
297,
849,
534,
505,
358,
272,
1798,
14,
525,
63,
2094,
4517,
4984,
297,
2053,
534,
4984,
358,
272,
1798,
14,
525,
63,
2094,
4517,
13880,
297,
2053,
534,
13880,
358,
339,
1249,
275,
1798,
14,
1122,
63,
589,
342,
272,
984,
14,
2224,
8,
973,
8,
589,
9,
503,
378,
9,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
1255,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
marcel-dancak/QGIS
|
python/plugins/processing/algs/gdal/hillshade.py
|
4
|
8475
|
# -*- coding: utf-8 -*-
"""
***************************************************************************
hillshade.py
---------------------
Date : October 2013
Copyright : (C) 2013 by Alexander Bruy
Email : alexander dot bruy 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__ = 'Alexander Bruy'
__date__ = 'October 2013'
__copyright__ = '(C) 2013, Alexander Bruy'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'
import os
from qgis.core import (QgsRasterFileWriter,
QgsProcessingException,
QgsProcessingParameterDefinition,
QgsProcessingParameterRasterLayer,
QgsProcessingParameterBand,
QgsProcessingParameterBoolean,
QgsProcessingParameterNumber,
QgsProcessingParameterString,
QgsProcessingParameterRasterDestination)
from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
from processing.algs.gdal.GdalUtils import GdalUtils
pluginPath = os.path.split(os.path.split(os.path.dirname(__file__))[0])[0]
class hillshade(GdalAlgorithm):
INPUT = 'INPUT'
BAND = 'BAND'
COMPUTE_EDGES = 'COMPUTE_EDGES'
ZEVENBERGEN = 'ZEVENBERGEN'
Z_FACTOR = 'Z_FACTOR'
SCALE = 'SCALE'
AZIMUTH = 'AZIMUTH'
ALTITUDE = 'ALTITUDE'
COMBINED = 'COMBINED'
MULTIDIRECTIONAL = 'MULTIDIRECTIONAL'
OPTIONS = 'OPTIONS'
OUTPUT = 'OUTPUT'
def __init__(self):
super().__init__()
def initAlgorithm(self, config=None):
self.addParameter(QgsProcessingParameterRasterLayer(self.INPUT, self.tr('Input layer')))
self.addParameter(QgsProcessingParameterBand(self.BAND,
self.tr('Band number'),
1,
parentLayerParameterName=self.INPUT))
self.addParameter(QgsProcessingParameterNumber(self.Z_FACTOR,
self.tr('Z factor (vertical exaggeration)'),
type=QgsProcessingParameterNumber.Double,
minValue=0.0,
defaultValue=1.0))
self.addParameter(QgsProcessingParameterNumber(self.SCALE,
self.tr('Scale (ratio of vertical units to horizontal)'),
type=QgsProcessingParameterNumber.Double,
minValue=0.0,
defaultValue=1.0))
self.addParameter(QgsProcessingParameterNumber(self.AZIMUTH,
self.tr('Azimuth of the light'),
type=QgsProcessingParameterNumber.Double,
minValue=0.0,
maxValue=360,
defaultValue=315.0))
self.addParameter(QgsProcessingParameterNumber(self.ALTITUDE,
self.tr('Altitude of the light'),
type=QgsProcessingParameterNumber.Double,
minValue=0.0,
defaultValue=45.0))
self.addParameter(QgsProcessingParameterBoolean(self.COMPUTE_EDGES,
self.tr('Compute edges'),
defaultValue=False))
self.addParameter(QgsProcessingParameterBoolean(self.ZEVENBERGEN,
self.tr("Use Zevenbergen&Thorne formula instead of the Horn's one"),
defaultValue=False))
self.addParameter(QgsProcessingParameterBoolean(self.COMBINED,
self.tr("Combined shading"),
defaultValue=False))
self.addParameter(QgsProcessingParameterBoolean(self.MULTIDIRECTIONAL,
self.tr("Multidirectional shading"),
defaultValue=False))
options_param = QgsProcessingParameterString(self.OPTIONS,
self.tr('Additional creation options'),
defaultValue='',
optional=True)
options_param.setFlags(options_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
options_param.setMetadata({
'widget_wrapper': {
'class': 'processing.algs.gdal.ui.RasterOptionsWidget.RasterOptionsWidgetWrapper'}})
self.addParameter(options_param)
self.addParameter(QgsProcessingParameterRasterDestination(self.OUTPUT, self.tr('Hillshade')))
def name(self):
return 'hillshade'
def displayName(self):
return self.tr('Hillshade')
def group(self):
return self.tr('Raster analysis')
def groupId(self):
return 'rasteranalysis'
def commandName(self):
return 'gdaldem'
def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments = ['hillshade']
inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
if inLayer is None:
raise QgsProcessingException(self.invalidRasterError(parameters, self.INPUT))
arguments.append(inLayer.source())
out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
self.setOutputValue(self.OUTPUT, out)
arguments.append(out)
arguments.append('-of')
arguments.append(QgsRasterFileWriter.driverForExtension(os.path.splitext(out)[1]))
arguments.append('-b')
arguments.append(str(self.parameterAsInt(parameters, self.BAND, context)))
arguments.append('-z')
arguments.append(str(self.parameterAsDouble(parameters, self.Z_FACTOR, context)))
arguments.append('-s')
arguments.append(str(self.parameterAsDouble(parameters, self.SCALE, context)))
multidirectional = self.parameterAsBoolean(parameters, self.MULTIDIRECTIONAL, context)
# azimuth and multidirectional are mutually exclusive
if not multidirectional:
arguments.append('-az')
arguments.append(str(self.parameterAsDouble(parameters, self.AZIMUTH, context)))
arguments.append('-alt')
arguments.append(str(self.parameterAsDouble(parameters, self.ALTITUDE, context)))
if self.parameterAsBoolean(parameters, self.COMPUTE_EDGES, context):
arguments.append('-compute_edges')
if self.parameterAsBoolean(parameters, self.ZEVENBERGEN, context):
arguments.append('-alg')
arguments.append('ZevenbergenThorne')
if self.parameterAsBoolean(parameters, self.COMBINED, context):
arguments.append('-combined')
if multidirectional:
arguments.append('-multidirectional')
options = self.parameterAsString(parameters, self.OPTIONS, context)
if options:
arguments.extend(GdalUtils.parseCreationOptions(options))
return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
199,
17623,
272,
394,
15350,
2411,
271,
14,
647,
272,
10652,
9858,
272,
6148,
463,
520,
18365,
22459,
6171,
272,
1898,
3322,
520,
334,
35,
9,
6171,
701,
22986,
11438,
699,
6558,
89,
272,
11426,
4483,
520,
282,
3113,
11438,
6308,
330,
6558,
89,
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,
33,
3113,
11438,
699,
6558,
89,
7,
199,
363,
602,
363,
275,
283,
17584,
22459,
6171,
7,
199,
363,
7307,
363,
275,
8189,
35,
9,
6171,
12,
22986,
11438,
699,
6558,
89,
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,
421,
199,
646,
747,
199,
199,
504,
15640,
14,
1018,
492,
334,
7350,
13284,
28199,
12,
2432,
17214,
1726,
12,
2432,
23764,
10701,
12,
2432,
23764,
13284,
5003,
12,
2432,
23764,
11675,
12,
2432,
23764,
4082,
12,
2432,
23764,
3259,
12,
2432,
23764,
1558,
12,
2432,
23764,
13284,
13151,
9,
199,
504,
6661,
14,
31128,
14,
11600,
14,
39,
12390,
11570,
492,
598,
12390,
11570,
199,
504,
6661,
14,
31128,
14,
11600,
14,
39,
12390,
7535,
492,
598,
12390,
7535,
199,
199,
2718,
2042,
275,
747,
14,
515,
14,
1294,
8,
736,
14,
515,
14,
1294,
8,
736,
14,
515,
14,
3475,
3460,
493,
8964,
59,
16,
11057,
16,
61,
421,
199,
533,
394,
15350,
2411,
271,
8,
39,
12390,
11570,
304,
339,
21955,
275,
283,
7321,
7,
272,
699,
3649,
275,
283,
23297,
7,
272,
16503,
4586,
63,
1149,
39,
654,
275,
283,
6790,
4586,
63,
1149,
39,
654,
7,
272,
3107,
37,
8253,
12003,
9289,
275,
283,
3687,
8253,
12003,
9289,
7,
272,
3107,
63,
26393,
275,
283,
58,
63,
26393,
7,
272,
12075,
28553,
275,
283,
24333,
7,
272,
437,
58,
1469,
4138,
275,
283,
17613,
1469,
4138,
7,
272,
12112,
52,
28742,
275,
283,
19600,
28742,
7,
272,
5099,
4567,
568,
1149,
275,
283,
1439,
4567,
568,
1149,
7,
272,
24895,
28904,
4168,
21518,
275,
283,
8203,
28904,
4168,
21518,
7,
272,
23860,
275,
283,
8808,
7,
272,
18746,
275,
283,
8414,
7,
339,
347,
636,
826,
721,
277,
304,
267,
1613,
11027,
826,
4533,
339,
347,
4205,
11570,
8,
277,
12,
1101,
29,
403,
304,
267,
291,
14,
26895,
8,
28559,
4720,
13284,
5003,
8,
277,
14,
7321,
12,
291,
14,
454,
360,
3205,
4045,
7058,
267,
291,
14,
26895,
8,
28559,
4720,
11675,
8,
277,
14,
23297,
12,
9349,
291,
14,
454,
360,
11675,
1329,
659,
9349,
413,
12,
9349,
1676,
5003,
4720,
985,
29,
277,
14,
7321,
430,
267,
291,
14,
26895,
8,
28559,
4720,
3259,
8,
277,
14,
58,
63,
26393,
12,
10940,
291,
14,
454,
360,
58,
6535,
334,
7870,
444,
16267,
425,
11218,
10940,
730,
29,
28559,
4720,
3259,
14,
7281,
12,
10940,
1748,
1110,
29,
16,
14,
16,
12,
10940,
31617,
29,
17,
14,
16,
430,
267,
291,
14,
26895,
8,
28559,
4720,
3259,
8,
277,
14,
24333,
12,
10940,
291,
14,
454,
360,
9944,
334,
6884,
402,
13763,
6204,
370,
17528,
11218,
10940,
730,
29,
28559,
4720,
3259,
14,
7281,
12,
10940,
1748,
1110,
29,
16,
14,
16,
12,
10940,
31617,
29,
17,
14,
16,
430,
267,
291,
14,
26895,
8,
28559,
4720,
3259,
8,
277,
14,
17613,
1469,
4138,
12,
10940,
291,
14,
454,
360,
32171,
26720,
402,
314,
10540,
659,
10940,
730,
29,
28559,
4720,
3259,
14,
7281,
12,
10940,
1748,
1110,
29,
16,
14,
16,
12,
10940,
1390,
1110,
29,
11197,
12,
10940,
31617,
29,
9927,
14,
16,
430,
267,
291,
14,
26895,
8,
28559,
4720,
3259,
8,
277,
14,
19600,
28742,
12,
10940,
291,
14,
454,
360,
2439,
7951,
402,
314,
10540,
659,
10940,
730,
29,
28559,
4720,
3259,
14,
7281,
12,
10940,
1748,
1110,
29,
16,
14,
16,
12,
10940,
31617,
29,
2322,
14,
16,
430,
267,
291,
14,
26895,
8,
28559,
4720,
4082,
8,
277,
14,
6790,
4586,
63,
1149,
39,
654,
12,
9144,
291,
14,
454,
360,
8564,
8207,
659,
9144,
31617,
29,
797,
430,
267,
291,
14,
26895,
8,
28559,
4720,
4082,
8,
277,
14,
3687,
8253,
12003,
9289,
12,
9144,
291,
14,
454,
480,
6119,
3107,
12056,
605,
2268,
6,
2719,
269,
685,
15723,
3140,
402,
314,
869,
6161,
1159,
1373,
1288,
9144,
31617,
29,
797,
430,
267,
291,
14,
26895,
8,
28559,
4720,
4082,
8,
277,
14,
1439,
4567,
568,
1149,
12,
9144,
291,
14,
454,
480,
26444,
1033,
5384,
1288,
9144,
31617,
29,
797,
430,
267,
291,
14,
26895,
8,
28559,
4720,
4082,
8,
277,
14,
8203,
28904,
4168,
21518,
12,
9144,
291,
14,
454,
480,
3947,
21360,
1033,
5384,
1288,
9144,
31617,
29,
797,
430,
398,
1511,
63,
635,
275,
23764,
1558,
8,
277,
14,
8808,
12,
9349,
291,
14,
454,
360,
8824,
7143,
1511,
659,
9349,
31617,
4581,
9349,
2716,
29,
549,
9,
267,
1511,
63,
635,
14,
409,
6381,
8,
1419,
63,
635,
14,
2469,
342,
1204,
23764,
10701,
14,
5318,
23613,
9,
267,
1511,
63,
635,
14,
409,
5142,
2561,
288,
283,
3440,
63,
5029,
356,
469,
355,
283,
533,
356,
283,
6338,
14,
31128,
14,
11600,
14,
1907,
14,
13284,
4558,
3339,
14,
13284,
4558,
32276,
936,
1552,
267,
291,
14,
26895,
8,
1419,
63,
635,
9,
398,
291,
14,
26895,
8,
28559,
4720,
13284,
13151,
8,
277,
14,
8414,
12,
291,
14,
454,
360,
40,
15350,
2411,
271,
7058,
339,
347,
536,
8,
277,
304,
267,
372,
283,
72,
15350,
2411,
271,
7,
339,
347,
2929,
985,
8,
277,
304,
267,
372,
291,
14,
454,
360,
40,
15350,
2411,
271,
358,
339,
347,
1572
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
199,
17623,
272,
394,
15350,
2411,
271,
14,
647,
272,
10652,
9858,
272,
6148,
463,
520,
18365,
22459,
6171,
272,
1898,
3322,
520,
334,
35,
9,
6171,
701,
22986,
11438,
699,
6558,
89,
272,
11426,
4483,
520,
282,
3113,
11438,
6308,
330,
6558,
89,
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,
33,
3113,
11438,
699,
6558,
89,
7,
199,
363,
602,
363,
275,
283,
17584,
22459,
6171,
7,
199,
363,
7307,
363,
275,
8189,
35,
9,
6171,
12,
22986,
11438,
699,
6558,
89,
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,
421,
199,
646,
747,
199,
199,
504,
15640,
14,
1018,
492,
334,
7350,
13284,
28199,
12,
2432,
17214,
1726,
12,
2432,
23764,
10701,
12,
2432,
23764,
13284,
5003,
12,
2432,
23764,
11675,
12,
2432,
23764,
4082,
12,
2432,
23764,
3259,
12,
2432,
23764,
1558,
12,
2432,
23764,
13284,
13151,
9,
199,
504,
6661,
14,
31128,
14,
11600,
14,
39,
12390,
11570,
492,
598,
12390,
11570,
199,
504,
6661,
14,
31128,
14,
11600,
14,
39,
12390,
7535,
492,
598,
12390,
7535,
199,
199,
2718,
2042,
275,
747,
14,
515,
14,
1294,
8,
736,
14,
515,
14,
1294,
8,
736,
14,
515,
14,
3475,
3460,
493,
8964,
59,
16,
11057,
16,
61,
421,
199,
533,
394,
15350,
2411,
271,
8,
39,
12390,
11570,
304,
339,
21955,
275,
283,
7321,
7,
272,
699,
3649,
275,
283,
23297,
7,
272,
16503,
4586,
63,
1149,
39,
654,
275,
283,
6790,
4586,
63,
1149,
39,
654,
7,
272,
3107,
37,
8253,
12003,
9289,
275,
283,
3687,
8253,
12003,
9289,
7,
272,
3107,
63,
26393,
275,
283,
58,
63,
26393,
7,
272,
12075,
28553,
275,
283,
24333,
7,
272,
437,
58,
1469,
4138,
275,
283,
17613,
1469,
4138,
7,
272,
12112,
52,
28742,
275,
283,
19600,
28742,
7,
272,
5099,
4567,
568,
1149,
275,
283,
1439,
4567,
568,
1149,
7,
272,
24895,
28904,
4168,
21518,
275,
283,
8203,
28904,
4168,
21518,
7,
272,
23860,
275,
283,
8808,
7,
272,
18746,
275,
283,
8414,
7,
339,
347,
636,
826,
721,
277,
304,
267,
1613,
11027,
826,
4533,
339,
347,
4205,
11570,
8,
277,
12,
1101,
29,
403,
304,
267,
291,
14,
26895,
8,
28559,
4720,
13284,
5003,
8,
277,
14,
7321,
12,
291,
14,
454,
360,
3205,
4045,
7058,
267,
291,
14,
26895,
8,
28559,
4720,
11675,
8,
277,
14,
23297,
12,
9349,
291,
14,
454,
360,
11675,
1329,
659,
9349,
413,
12,
9349,
1676,
5003,
4720,
985,
29,
277,
14,
7321,
430,
267,
291,
14,
26895,
8,
28559,
4720,
3259,
8,
277,
14,
58,
63,
26393,
12,
10940,
291,
14,
454,
360,
58,
6535,
334,
7870,
444,
16267,
425,
11218,
10940,
730,
29,
28559,
4720,
3259,
14,
7281,
12,
10940,
1748,
1110,
29,
16,
14,
16,
12,
10940,
31617,
29,
17,
14,
16,
430,
267,
291,
14,
26895,
8,
28559,
4720,
3259,
8,
277,
14,
24333,
12,
10940,
291,
14,
454,
360,
9944,
334,
6884,
402,
13763,
6204,
370,
17528,
11218,
10940,
730,
29,
28559,
4720,
3259,
14,
7281,
12,
10940,
1748,
1110,
29,
16,
14,
16,
12,
10940,
31617,
29,
17,
14,
16,
430,
267,
291,
14,
26895,
8,
28559,
4720,
3259,
8,
277,
14,
17613,
1469,
4138,
12,
10940,
291,
14,
454,
360,
32171,
26720,
402,
314,
10540,
659,
10940,
730,
29,
28559,
4720,
3259,
14,
7281,
12,
10940,
1748,
1110,
29,
16,
14,
16,
12,
10940,
1390,
1110,
29,
11197,
12,
10940,
31617,
29,
9927,
14,
16,
430,
267,
291,
14,
26895,
8,
28559,
4720,
3259,
8,
277,
14,
19600,
28742,
12,
10940,
291,
14,
454,
360,
2439,
7951,
402,
314,
10540,
659,
10940,
730,
29,
28559,
4720,
3259,
14,
7281,
12,
10940,
1748,
1110,
29,
16,
14,
16,
12,
10940,
31617,
29,
2322,
14,
16,
430,
267,
291,
14,
26895,
8,
28559,
4720,
4082,
8,
277,
14,
6790,
4586,
63,
1149,
39,
654,
12,
9144,
291,
14,
454,
360,
8564,
8207,
659,
9144,
31617,
29,
797,
430,
267,
291,
14,
26895,
8,
28559,
4720,
4082,
8,
277,
14,
3687,
8253,
12003,
9289,
12,
9144,
291,
14,
454,
480,
6119,
3107,
12056,
605,
2268,
6,
2719,
269,
685,
15723,
3140,
402,
314,
869,
6161,
1159,
1373,
1288,
9144,
31617,
29,
797,
430,
267,
291,
14,
26895,
8,
28559,
4720,
4082,
8,
277,
14,
1439,
4567,
568,
1149,
12,
9144,
291,
14,
454,
480,
26444,
1033,
5384,
1288,
9144,
31617,
29,
797,
430,
267,
291,
14,
26895,
8,
28559,
4720,
4082,
8,
277,
14,
8203,
28904,
4168,
21518,
12,
9144,
291,
14,
454,
480,
3947,
21360,
1033,
5384,
1288,
9144,
31617,
29,
797,
430,
398,
1511,
63,
635,
275,
23764,
1558,
8,
277,
14,
8808,
12,
9349,
291,
14,
454,
360,
8824,
7143,
1511,
659,
9349,
31617,
4581,
9349,
2716,
29,
549,
9,
267,
1511,
63,
635,
14,
409,
6381,
8,
1419,
63,
635,
14,
2469,
342,
1204,
23764,
10701,
14,
5318,
23613,
9,
267,
1511,
63,
635,
14,
409,
5142,
2561,
288,
283,
3440,
63,
5029,
356,
469,
355,
283,
533,
356,
283,
6338,
14,
31128,
14,
11600,
14,
1907,
14,
13284,
4558,
3339,
14,
13284,
4558,
32276,
936,
1552,
267,
291,
14,
26895,
8,
1419,
63,
635,
9,
398,
291,
14,
26895,
8,
28559,
4720,
13284,
13151,
8,
277,
14,
8414,
12,
291,
14,
454,
360,
40,
15350,
2411,
271,
7058,
339,
347,
536,
8,
277,
304,
267,
372,
283,
72,
15350,
2411,
271,
7,
339,
347,
2929,
985,
8,
277,
304,
267,
372,
291,
14,
454,
360,
40,
15350,
2411,
271,
358,
339,
347,
1572,
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,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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
] |
40223114/w16
|
static/Brython3.1.1-20150328-091302/Lib/site-packages/pygame/image.py
|
603
|
19603
|
#!/usr/bin/env python
'''Pygame module for image transfer.
The image module contains functions for loading and saving pictures, as
well as transferring Surfaces to formats usable by other packages.
Note that there is no Image class; an image is loaded as a
Surface object. The Surface class allows manipulation (drawing lines,
setting pixels, capturing regions, etc.).
The image module is a required dependency of Pygame, but it only optionally
supports any extended file formats. By default it can only load uncompressed
BMP images. When built with full image support, the pygame.image.load()
function can support the following formats.
* JPG
* PNG
* GIF (non animated)
* BMP
* PCX
* TGA (uncompressed)
* TIF
* LBM (and PBM)
* PBM (and PGM, PPM)
* XPM
Saving images only supports a limited set of formats. You can save
to the following formats.
* BMP
* TGA
* PNG
* JPEG
PNG, JPEG saving new in pygame 1.8.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id$'
from browser import html, window
from javascript import JSConstructor, console
#import os.path
import os
import re
#from SDL import *
import pygame.surface
#try:
# #from SDL.image import *
# #_have_SDL_image = True
#except ImportError:
_have_SDL_image = False
def load_extended(file, namehint=''):
'''Load new image from a file, using SDL.image.
:see: `load`
:Parameters:
`file` : str or file-like object
Image file or filename to load.
`namehint` : str
Optional file extension.
:rtype: `Surface`
'''
if not _have_SDL_image:
raise NotImplementedError('load_extended requires SDL.image')
if not hasattr(file, 'read'):
surf = IMG_Load(file)
else:
if not namehint and hasattr(file, 'name'):
namehint = file.name
namehint = os.path.splitext(namehint)[1]
rw = SDL_RWFromObject(file)
# XXX Differ from pygame: don't freesrc when we didn't allocate it
surf = IMG_LoadTyped_RW(rw, 0, namehint)
return pygame.surface.Surface(surf=surf)
def load_basic(file, namehint=''):
'''Load BMP image from a file.
:see: `load`
:Parameters:
`file` : str or file-like object
Image file or filename to load.
`namehint` : str
Ignored, for compatibility.
:rtype: `Surface`
'''
#if not hasattr(file, 'read'):
# surf = SDL_LoadBMP(file)
#else:
# rw = SDL_RWFromObject(file)
# # XXX Differ from pygame: don't freesrc when we didn't allocate it
# surf = SDL_LoadBMP_RW(rw, 0)
_img=JSConstructor(window.Image)()
_img.src=file
_img.canvas=html.CANVAS()
def img_onload(*args):
#http://www.jaypan.com/tutorial/javascript-passing-arguments-anonymous-functions-without-firing-function
#the onload files very slow so variables get messed up so we have
#to use args[0].path[0] to figure out the correct image
console.log(args)
if hasattr(args[0], 'target'): # Firefox
this=args[0].target
else: #chrome
this=args[0].path[0]
this.canvas.width=this.width
this.canvas.height=this.height
this.canvas.getContext('2d').drawImage(this,0,0)
#this.loaded=True
_img.onload=img_onload
return pygame.surface.Surface(surf=_img.canvas)
def load(file, namehint=''):
'''Load a new image from a file.
Pygame will automatically determine the image type (e.g., GIF or bitmap)
and create a new Surface object from the data. In some cases it will need
to know the file extension (e.g., GIF images should end in ".gif"). If
you pass a raw file-like object, you may also want to pass the original
filename as the namehint argument.
The returned Surface will contain the same color format, colorkey and
alpha transparency as the file it came from. You will often want to call
Surface.convert() with no arguments, to create a copy that will draw more
quickly on the screen.
For alpha transparency, like in .png images use the convert_alpha() method
after loading so that the image has per pixel transparency.
Pygame may not always be built to support all image formats. At minimum it
will support uncompressed BMP. If pygame.image.get_extended() returns
'True', you should be able to load most images (including png, jpg and gif).
You should use os.path.join() for compatibility, e.g.::
asurf = pygame.image.load(os.path.join('data', 'bla.png'))
This function calls `load_extended` if SDL.image is available, otherwise
`load_basic`.
:Parameters:
`file` : str or file-like object
Image file or filename to load.
`namehint` : str
Optional file extension.
:rtype: `Surface`
'''
#if _have_SDL_image:
# return load_extended(file, namehint)
#else:
return load_basic(file, namehint)
def save(surface, file):
'''Save an image to disk.
This will save your Surface as either a BMP, TGA, PNG, or JPEG image. If
the filename extension is unrecognized it will default to TGA. Both TGA,
and BMP file formats create uncompressed files.
:note: Only BMP is currently implemented.
:Parameters:
`surface` : `Surface`
Surface containing image data to save.
`file` : str or file-like object
File or filename to save to.
'''
#todo brython..
#for now, lets just pass
pass
if surface._surf.flags & SDL_OPENGL:
surf = _get_opengl_surface(surface._surf)
else:
surface._prep()
surf = surface._surf
if hasattr(file, 'write'):
# TODO TGA not BMP save
rw = SDL_RWFromObject(file)
# XXX Differ from pygame: don't freesrc when we didn't allocate it
SDL_SaveBMP_RW(surf, rw, 0)
else:
fileext = os.path.splitext(file)[1].lower()
if fileext == '.bmp':
SDL_SaveBMP(surf, file)
elif fileext in ('.jpg', '.jpeg'):
raise pygame.base.error('No support for jpg compiled in.') # TODO
elif fileext == '.png':
raise pygame.base.error('No support for png compiled in.') # TODO
else:
raise NotImplementedError('TODO: TGA support')
if surface._surf.flags & SDL_OPENGL:
SDL_FreeSurface(surf)
else:
surface._unprep()
def get_extended():
'''Test if extended image formats can be loaded.
If pygame is built with extended image formats this function will return
True. It is still not possible to determine which formats will be
available, but generally you will be able to load them all.
:rtype: bool
'''
return _have_SDL_image
def tostring(surface, format, flipped=False):
'''Transfer image to string buffer.
Creates a string that can be transferred with the 'fromstring' method in
other Python imaging packages. Some Python image packages prefer their
images in bottom-to-top format (PyOpenGL for example). If you pass True
for the flipped argument, the string buffer will be vertically flipped.
The format argument is a string of one of the following values. Note that
only 8bit Surfaces can use the "P" format. The other formats will work for
any Surface. Also note that other Python image packages support more
formats than Pygame.
* P, 8bit palettized Surfaces
* RGB, 24bit image
* RGBX, 32bit image with alpha channel derived from color key
* RGBA, 32bit image with an alpha channel
* ARGB, 32bit image with alpha channel first
:Parameters:
`surface` : `Surface`
Surface containing data to convert.
`format` : str
One of 'P', 'RGB', 'RGBX', 'RGBA' or 'ARGB'
`flipped` : bool
If True, data is ordered from bottom row to top.
:rtype: str
'''
#brython
return pygame.surface.Surface.toDataURL('image/%s' % format)
surf = surface._surf
if surf.flags & SDL_OPENGL:
surf = _get_opengl_surface(surf)
result = None
rows = []
pitch = surf.pitch
w = surf.w
h = surf.h
if flipped:
h_range = range(surf.h - 1, -1, -1)
else:
h_range = range(surf.h)
if format == 'P':
# The only case for creating palette data.
if surf.format.BytesPerPixel != 1:
raise ValueError('Can only create "P" format data with 8bit Surfaces')
surface.lock()
pixels = surf.pixels.to_string()
surface.unlock()
if pitch == w:
result = pixels # easy exit
else:
flipped = False # Flipping taken care of by h_range
for y in h_range:
rows.append(pixels[y*pitch:y*pitch + w])
elif surf.format.BytesPerPixel == len(format) and format != 'RGBX':
# No conversion required?
# This is an optimisation; could also use the default case.
if format == 'RGBA':
Rmask = SDL_SwapLE32(0x000000ff)
Gmask = SDL_SwapLE32(0x0000ff00)
Bmask = SDL_SwapLE32(0x00ff0000)
Amask = SDL_SwapLE32(0xff000000)
elif format == 'ARGB':
Amask = SDL_SwapLE32(0x000000ff)
Rmask = SDL_SwapLE32(0x0000ff00)
Gmask = SDL_SwapLE32(0x00ff0000)
Bmask = SDL_SwapLE32(0xff000000)
elif format == 'RGB':
if SDL_BYTEORDER == SDL_LIL_ENDIAN:
Rmask = 0x000000ff
Gmask = 0x0000ff00
Bmask = 0x00ff0000
else:
Rmask = 0x00ff0000
Gmask = 0x0000ff00
Bmask = 0x000000ff
Amask = surf.format.Amask # ignore
if surf.format.Rmask == Rmask and \
surf.format.Gmask == Gmask and \
surf.format.Bmask == Bmask and \
surf.format.Amask == Amask and \
pitch == w * surf.format.BytesPerPixel:
# Pixel data is already in required format, simply memcpy will
# work fast.
surface.lock()
result = surf.pixels.to_string()
surface.unlock()
elif surf.format.BytesPerPixel == 3 and \
(format in ('RGBA', 'ARGB') or \
format == 'RGBX' and not surf.flags & SDL_SRCCOLORKEY):
# Optimised conversion from RGB to RGBA or ARGB.
if surf.format.Rmask == SDL_SwapLE32(0x000000ff) and \
surf.format.Gmask == SDL_SwapLE32(0x0000ff00) and \
surf.format.Bmask == SDL_SwapLE32(0x00ff0000) and \
pitch == w * surf.format.BytesPerPixel:
surface.lock()
result = surf.pixels.to_string()
surface.unlock()
# Insert in empty alpha byte
alpha = chr(0xff)
result = alpha.join(re.findall('...', result, re.DOTALL))
if format == 'ARGB':
result = alpha + result
else:
result += alpha
elif surf.format.BytesPerPixel == 4 and format == 'RGB':
# Optimised conversion from RGBA or ARGB to RGB.
# This is an optimisation; could also use the default case.
if surf.format.Rmask == SDL_SwapLE32(0x000000ff):
# Internal format is RGBA
Gmask = SDL_SwapLE32(0x0000ff00)
Bmask = SDL_SwapLE32(0x00ff0000)
pattern = '(...).'
elif surf.format.Rmask == SDL_SwapLE32(0x0000ff00):
# Internal format is ARGB
Gmask = SDL_SwapLE32(0x00ff0000)
Bmask = SDL_SwapLE32(0xff000000)
pattern = '.(...)'
else:
# Internal format is something else, give up.
pattern = None
if pattern and \
surf.format.Gmask == Gmask and \
surf.format.Bmask == Bmask and \
pitch == w * surf.format.BytesPerPixel:
surface.lock()
result = surf.pixels.to_string()
surface.unlock()
# Squeeze out the alpha byte
result = ''.join(re.findall(pattern, result, re.DOTALL))
if not result and not rows:
# Default case, works for any conversion, but is slow.
surface.lock()
if surf.format.BytesPerPixel == 1:
palette = surf.format.palette.colors
if surf.flags & SDL_SRCCOLORKEY and not Amask and format == 'RGBX':
colorkey = surf.format.colorkey
pixels = [(palette[c].r, palette[c].g, palette[c].b,
(c != colorkey) * 0xff) \
for c in surf.pixels]
else:
pixels = [(palette[c].r, palette[c].g, palette[c].b, 255) \
for c in surf.pixels]
elif surf.format.BytesPerPixel == 3:
raise NotImplementedError('TODO')
else:
Rmask = surf.format.Rmask
Gmask = surf.format.Gmask
Bmask = surf.format.Bmask
Amask = surf.format.Amask
Rshift = surf.format.Rshift
Gshift = surf.format.Gshift
Bshift = surf.format.Bshift
Ashift = surf.format.Ashift
Rloss = surf.format.Rloss
Gloss = surf.format.Gloss
Bloss = surf.format.Bloss
Aloss = surf.format.Aloss
if surf.flags & SDL_SRCCOLORKEY and not Amask and format == 'RGBX':
colorkey = surf.format.colorkey
pixels = [( ((c & Rmask) >> Rshift) << Rloss,
((c & Gmask) >> Gshift) << Gloss,
((c & Bmask) >> Bshift) << Bloss,
(c != colorkey) * 0xff ) \
for c in surf.pixels]
else:
pixels = [( ((c & Rmask) >> Rshift) << Rloss,
((c & Gmask) >> Gshift) << Gloss,
((c & Bmask) >> Bshift) << Bloss,
((c & Amask) >> Ashift) << Aloss ) \
for c in surf.pixels]
surface.unlock()
pitch /= surf.format.BytesPerPixel
flipped = False # Flipping taken care of by h_range
if format == 'RGB':
for y in h_range:
rows.append(''.join([ chr(c[0]) + chr(c[1]) + chr(c[2]) \
for c in pixels[y*pitch:y*pitch + w] ]))
elif format in ('RGBA', 'RGBX'):
for y in h_range:
rows.append(''.join([ chr(c[0]) + chr(c[1]) + chr(c[2]) + \
chr(c[3]) \
for c in pixels[y*pitch:y*pitch + w] ]))
elif format == 'ARGB':
for y in h_range:
rows.append(''.join([ chr(c[3]) + chr(c[1]) + chr(c[2]) + \
chr(c[0]) \
for c in pixels[y*pitch:y*pitch + w] ]))
if surface._surf.flags & SDL_OPENGL:
SDL_FreeSurface(surf)
# Is pixel data already one big string?
if result:
if flipped:
# Split it into rows so it can be flipped vertically.
rows = re.findall('.' * w * len(format), result, re.DOTALL)
else:
return result
if flipped:
rows.reverse()
return ''.join(rows)
def fromstring(string, size, format, flipped=False):
'''Create new Surface from a string buffer.
This function takes arguments similar to pygame.image.tostring(). The size
argument is a pair of numbers representing the width and height. Once the
new Surface is created you can destroy the string buffer.
The size and format image must compute the exact same size as the passed
string buffer. Otherwise an exception will be raised.
:Parameters:
`string` : str
String containing image data.
`size` : (int, int)
Width, height of the image.
`format` : str
One of 'P', 'RGB', 'RGBA' or 'ARGB'
`flipped` : bool
If True, data is ordered from bottom row to top.
:rtype: `Surface`
'''
_img = html.IMG(width=size[0], height=size[1])
_img.src=string
_canvas=html.CANVAS(width=size[0], height=size[1])
_ctx=_canvas.getContext('2d')
_ctx.drawImage(_img,0,0)
return pygame.surface.Surface(surf=_canvas)
width, height = size
if format == 'P':
Rmask = 0
Gmask = 0
Bmask = 0
Amask = 0
depth = 8
pitch = width
elif format == 'RGB':
if SDL_BYTEORDER == SDL_LIL_ENDIAN:
Rmask = 0x000000ff
Gmask = 0x0000ff00
Bmask = 0x00ff0000
else:
Rmask = 0x00ff0000
Gmask = 0x0000ff00
Bmask = 0x000000ff
Amask = 0x00000000
depth = 24
pitch = width * 3
elif format in ('RGBA', 'RGBX'):
if SDL_BYTEORDER == SDL_LIL_ENDIAN:
Rmask = 0x000000ff
Gmask = 0x0000ff00
Bmask = 0x00ff0000
Amask = 0xff000000
else:
Rmask = 0xff000000
Gmask = 0x00ff0000
Bmask = 0x0000ff00
Amask = 0x000000ff
if format == 'RGBX':
Amask = 0x00000000
depth = 32
pitch = width * 4
elif format == 'ARGB':
if SDL_BYTEORDER == SDL_LIL_ENDIAN:
Rmask = 0x0000ff00
Gmask = 0x00ff0000
Bmask = 0xff000000
Amask = 0x000000ff
else:
Rmask = 0x00ff0000
Gmask = 0x0000ff00
Bmask = 0x000000ff
Amask = 0xff000000
depth = 32
pitch = width * 4
if len(string) != pitch * height:
raise ValueError('String length does not equal format and resolution size')
if flipped:
string = ''.join([string[y*pitch:y*pitch+pitch] \
for y in range(height - 1, -1, -1)])
surf = SDL_CreateRGBSurfaceFrom(string, width, height, depth, pitch,
Rmask, Gmask, Bmask, Amask)
return pygame.surface.Surface(surf=surf)
def frombuffer(string, size, format):
'''Create a new Surface that shares data inside a string buffer.
Create a new Surface that shares pixel data directly from the string buffer.
This method takes the same arguments as pygame.image.fromstring(), but is
unable to vertically flip the source data.
:note: In pygame-ctypes, this function is identical to `fromstring`.
:Parameters:
`string` : str
String containing image data.
`size` : (int, int)
Width, height of the image.
`format` : str
One of 'P', 'RGB', 'RGBA', 'RGBX' or 'ARGB'
:rtype: `Surface`
'''
return fromstring(string, size, format)
def _get_opengl_surface(surf):
import OpenGL.GL
data = OpenGL.GL.glReadPixels(0, 0, surf.w, surf.h,
OpenGL.GL.GL_RGB, OpenGL.GL.GL_UNSIGNED_BYTE)
if SDL_BYTEORDER == SDL_LIL_ENDIAN:
Rmask = 0x000000ff
Gmask = 0x0000ff00
Bmask = 0x00ff0000
else:
Rmask = 0x00ff0000
Gmask = 0x0000ff00
Bmask = 0x000000ff
# Flip vertically
pitch = surf.w * 3
data = ''.join([data[y*pitch:y*pitch+pitch] \
for y in range(surf.h - 1, -1, -1)])
newsurf = SDL_CreateRGBSurfaceFrom(data, surf.w, surf.h, 24, pitch,
Rmask, Gmask, Bmask, 0)
return newsurf
|
agpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
2344,
2713,
5097,
859,
367,
1834,
9307,
14,
199,
199,
1918,
1834,
859,
3509,
3423,
367,
8697,
436,
13369,
6682,
22004,
12,
465,
199,
20501,
465,
28183,
17756,
17079,
4309,
370,
6752,
18025,
701,
1163,
6117,
14,
199,
199,
7443,
626,
2337,
365,
949,
6047,
1021,
27,
376,
1834,
365,
6511,
465,
282,
199,
16923,
909,
14,
710,
29564,
1021,
6127,
26212,
334,
25195,
2385,
12,
199,
6031,
11094,
12,
12162,
4039,
16150,
12,
5423,
25860,
199,
199,
1918,
1834,
859,
365,
282,
1415,
5936,
402,
1611,
5097,
12,
1325,
652,
1454,
14190,
199,
9823,
1263,
9243,
570,
6752,
14,
221,
4885,
849,
652,
883,
1454,
2248,
25904,
199,
34,
1658,
5935,
14,
3979,
6137,
543,
2615,
1834,
2291,
12,
314,
9193,
14,
1569,
14,
912,
342,
199,
1593,
883,
2291,
314,
2569,
6752,
14,
199,
199,
10,
1603,
11115,
199,
10,
26951,
199,
10,
598,
4656,
334,
2865,
376,
12754,
9,
199,
10,
699,
1658,
199,
10,
510,
26001,
199,
10,
377,
9741,
334,
324,
10895,
9,
199,
10,
377,
4656,
199,
10,
491,
15225,
334,
460,
510,
15225,
9,
199,
10,
510,
15225,
334,
460,
510,
22636,
12,
510,
10793,
9,
199,
10,
1323,
10793,
199,
199,
30125,
5935,
1454,
5171,
282,
13988,
663,
402,
6752,
14,
2047,
883,
3354,
199,
475,
314,
2569,
6752,
14,
199,
199,
10,
699,
1658,
199,
10,
377,
9741,
199,
10,
26951,
199,
10,
1603,
17557,
199,
199,
24454,
12,
1603,
17557,
13369,
892,
315,
9193,
413,
14,
24,
14,
199,
2344,
199,
199,
363,
21841,
363,
275,
283,
26854,
7,
199,
363,
1023,
363,
275,
4505,
1304,
12913,
199,
199,
504,
7042,
492,
3517,
12,
4353,
199,
504,
18910,
492,
18001,
11447,
12,
8559,
199,
199,
3,
646,
747,
14,
515,
199,
646,
747,
199,
646,
295,
199,
199,
3,
504,
14314,
492,
627,
199,
199,
646,
9193,
14,
10992,
199,
199,
3,
893,
26,
199,
3,
259,
327,
504,
14314,
14,
1569,
492,
627,
199,
3,
259,
327,
63,
7804,
63,
14029,
63,
1569,
275,
715,
199,
3,
2590,
3545,
26,
199,
63,
7804,
63,
14029,
63,
1569,
275,
756,
199,
199,
318,
2248,
63,
10525,
8,
493,
12,
536,
6479,
9280,
272,
1449,
6200,
892,
1834,
687,
282,
570,
12,
1808,
14314,
14,
1569,
14,
339,
520,
3239,
26,
658,
912,
64,
339,
520,
5976,
26,
267,
658,
493,
64,
520,
620,
503,
570,
13,
2930,
909,
288,
6047,
570,
503,
1788,
370,
2248,
14,
267,
658,
354,
6479,
64,
520,
620,
288,
4879,
570,
3329,
14,
339,
520,
4500,
26,
658,
16923,
64,
272,
1449,
272,
340,
440,
485,
7804,
63,
14029,
63,
1569,
26,
267,
746,
4279,
360,
912,
63,
10525,
5074,
14314,
14,
1569,
358,
339,
340,
440,
2688,
8,
493,
12,
283,
739,
735,
267,
24802,
275,
18211,
39,
63,
6200,
8,
493,
9,
272,
587,
26,
267,
340,
440,
536,
6479,
436,
2688,
8,
493,
12,
283,
354,
735,
288,
536,
6479,
275,
570,
14,
354,
267,
536,
6479,
275,
747,
14,
515,
14,
7973,
8,
354,
6479,
2788,
17,
61,
267,
29329,
275,
14314,
63,
25438,
2532,
1692,
8,
493,
9,
267,
327,
5787,
3757,
1260,
687,
9193,
26,
2793,
1133,
289,
5710,
1195,
1380,
781,
9980,
1133,
18310,
652,
267,
24802,
275,
18211,
39,
63,
6200,
22193,
63,
25438,
8,
13057,
12,
378,
12,
536,
6479,
9,
272,
372,
9193,
14,
10992,
14,
16923,
8,
21579,
29,
21579,
9,
199,
199,
318,
2248,
63,
4316,
8,
493,
12,
536,
6479,
9280,
272,
1449,
6200,
699,
1658,
1834,
687,
282,
570,
14,
339,
520,
3239,
26,
658,
912,
64,
339,
520,
5976,
26,
267,
658,
493,
64,
520,
620,
503,
570,
13,
2930,
909,
288,
6047,
570,
503,
1788,
370,
2248,
14,
267,
658,
354,
6479,
64,
520,
620,
288,
27662,
12,
367,
7163,
14,
339,
520,
4500,
26,
658,
16923,
64,
272,
1449,
272,
327,
692,
440,
2688,
8,
493,
12,
283,
739,
735,
272,
327,
259,
24802,
275,
14314,
63,
6200,
34,
1658,
8,
493,
9,
272,
327,
2836,
26,
272,
327,
259,
29329,
275,
14314,
63,
25438,
2532,
1692,
8,
493,
9,
272,
327,
259,
327,
5787,
3757,
1260,
687,
9193,
26,
2793,
1133,
289,
5710,
1195,
1380,
781,
9980,
1133,
18310,
652,
272,
327,
259,
24802,
275,
14314,
63,
6200,
34,
1658,
63,
25438,
8,
13057,
12,
378,
9,
2378,
485,
4060,
29,
11378,
11447,
8,
3806,
14,
3491,
16315,
272,
485,
4060,
14,
2164,
29,
493,
339,
485,
4060,
14,
7682,
29,
1360,
14,
18988,
54,
1179,
342,
272,
347,
6050,
63,
265,
912,
2031,
589,
304,
267,
327,
1014,
921,
1544,
14,
74,
1187,
10384,
14,
957,
15,
23561,
15,
9554,
13,
29436,
13,
4958,
13,
12628,
13,
5777,
13,
7395,
13,
1795,
316,
13,
1593,
267,
327,
1589,
641,
912,
1584,
7437,
11999,
880,
2860,
664,
26560,
939,
1536,
880,
781,
1172,
267,
327,
475,
675,
1249,
59,
16,
1055,
515,
59,
16,
61,
370,
9658,
734,
314,
3211,
1834,
267,
8559,
14,
793,
8,
589,
9,
267,
340,
2688,
8,
589,
59,
16,
467,
283,
1375,
735,
257,
327,
24584,
1779,
642,
29,
589,
59,
16,
1055,
1375,
267,
587,
26,
14960,
327,
9887,
1779,
642,
29,
589,
59,
16,
1055,
515,
59,
16,
61,
398,
642,
14,
7682,
14,
2063,
29,
3749,
14,
2063,
267,
642,
14,
7682,
14,
3333,
29,
3749,
14,
3333,
267,
642,
14,
7682,
14,
32160,
360,
18,
68,
1959,
5485,
3491,
8,
3749,
12,
16,
12,
16,
9,
267,
327,
3749,
14,
4591,
29,
549,
339,
485,
4060,
14,
265,
912,
29,
4060,
63,
265,
912,
272,
372,
9193,
14,
10992,
14,
16923,
8,
21579,
3699,
4060,
14,
7682,
9,
421,
199,
318,
2248,
8,
493,
12,
536,
6479,
9280,
272,
1449,
6200,
282,
892,
1834,
687,
282,
570,
14,
339,
1611,
5097,
911,
5847,
6705,
314,
1834,
730,
334,
69,
14,
71,
2020,
598,
4656,
503,
20810,
9,
272,
436,
1218,
282,
892,
29564,
909,
687,
314,
666,
14,
1010,
2005,
5560,
652,
911,
1929,
272,
370,
5715,
314,
570,
3329,
334,
69,
14,
71,
2020,
598,
4656,
5935,
1077,
1284,
315,
3680
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
2344,
2713,
5097,
859,
367,
1834,
9307,
14,
199,
199,
1918,
1834,
859,
3509,
3423,
367,
8697,
436,
13369,
6682,
22004,
12,
465,
199,
20501,
465,
28183,
17756,
17079,
4309,
370,
6752,
18025,
701,
1163,
6117,
14,
199,
199,
7443,
626,
2337,
365,
949,
6047,
1021,
27,
376,
1834,
365,
6511,
465,
282,
199,
16923,
909,
14,
710,
29564,
1021,
6127,
26212,
334,
25195,
2385,
12,
199,
6031,
11094,
12,
12162,
4039,
16150,
12,
5423,
25860,
199,
199,
1918,
1834,
859,
365,
282,
1415,
5936,
402,
1611,
5097,
12,
1325,
652,
1454,
14190,
199,
9823,
1263,
9243,
570,
6752,
14,
221,
4885,
849,
652,
883,
1454,
2248,
25904,
199,
34,
1658,
5935,
14,
3979,
6137,
543,
2615,
1834,
2291,
12,
314,
9193,
14,
1569,
14,
912,
342,
199,
1593,
883,
2291,
314,
2569,
6752,
14,
199,
199,
10,
1603,
11115,
199,
10,
26951,
199,
10,
598,
4656,
334,
2865,
376,
12754,
9,
199,
10,
699,
1658,
199,
10,
510,
26001,
199,
10,
377,
9741,
334,
324,
10895,
9,
199,
10,
377,
4656,
199,
10,
491,
15225,
334,
460,
510,
15225,
9,
199,
10,
510,
15225,
334,
460,
510,
22636,
12,
510,
10793,
9,
199,
10,
1323,
10793,
199,
199,
30125,
5935,
1454,
5171,
282,
13988,
663,
402,
6752,
14,
2047,
883,
3354,
199,
475,
314,
2569,
6752,
14,
199,
199,
10,
699,
1658,
199,
10,
377,
9741,
199,
10,
26951,
199,
10,
1603,
17557,
199,
199,
24454,
12,
1603,
17557,
13369,
892,
315,
9193,
413,
14,
24,
14,
199,
2344,
199,
199,
363,
21841,
363,
275,
283,
26854,
7,
199,
363,
1023,
363,
275,
4505,
1304,
12913,
199,
199,
504,
7042,
492,
3517,
12,
4353,
199,
504,
18910,
492,
18001,
11447,
12,
8559,
199,
199,
3,
646,
747,
14,
515,
199,
646,
747,
199,
646,
295,
199,
199,
3,
504,
14314,
492,
627,
199,
199,
646,
9193,
14,
10992,
199,
199,
3,
893,
26,
199,
3,
259,
327,
504,
14314,
14,
1569,
492,
627,
199,
3,
259,
327,
63,
7804,
63,
14029,
63,
1569,
275,
715,
199,
3,
2590,
3545,
26,
199,
63,
7804,
63,
14029,
63,
1569,
275,
756,
199,
199,
318,
2248,
63,
10525,
8,
493,
12,
536,
6479,
9280,
272,
1449,
6200,
892,
1834,
687,
282,
570,
12,
1808,
14314,
14,
1569,
14,
339,
520,
3239,
26,
658,
912,
64,
339,
520,
5976,
26,
267,
658,
493,
64,
520,
620,
503,
570,
13,
2930,
909,
288,
6047,
570,
503,
1788,
370,
2248,
14,
267,
658,
354,
6479,
64,
520,
620,
288,
4879,
570,
3329,
14,
339,
520,
4500,
26,
658,
16923,
64,
272,
1449,
272,
340,
440,
485,
7804,
63,
14029,
63,
1569,
26,
267,
746,
4279,
360,
912,
63,
10525,
5074,
14314,
14,
1569,
358,
339,
340,
440,
2688,
8,
493,
12,
283,
739,
735,
267,
24802,
275,
18211,
39,
63,
6200,
8,
493,
9,
272,
587,
26,
267,
340,
440,
536,
6479,
436,
2688,
8,
493,
12,
283,
354,
735,
288,
536,
6479,
275,
570,
14,
354,
267,
536,
6479,
275,
747,
14,
515,
14,
7973,
8,
354,
6479,
2788,
17,
61,
267,
29329,
275,
14314,
63,
25438,
2532,
1692,
8,
493,
9,
267,
327,
5787,
3757,
1260,
687,
9193,
26,
2793,
1133,
289,
5710,
1195,
1380,
781,
9980,
1133,
18310,
652,
267,
24802,
275,
18211,
39,
63,
6200,
22193,
63,
25438,
8,
13057,
12,
378,
12,
536,
6479,
9,
272,
372,
9193,
14,
10992,
14,
16923,
8,
21579,
29,
21579,
9,
199,
199,
318,
2248,
63,
4316,
8,
493,
12,
536,
6479,
9280,
272,
1449,
6200,
699,
1658,
1834,
687,
282,
570,
14,
339,
520,
3239,
26,
658,
912,
64,
339,
520,
5976,
26,
267,
658,
493,
64,
520,
620,
503,
570,
13,
2930,
909,
288,
6047,
570,
503,
1788,
370,
2248,
14,
267,
658,
354,
6479,
64,
520,
620,
288,
27662,
12,
367,
7163,
14,
339,
520,
4500,
26,
658,
16923,
64,
272,
1449,
272,
327,
692,
440,
2688,
8,
493,
12,
283,
739,
735,
272,
327,
259,
24802,
275,
14314,
63,
6200,
34,
1658,
8,
493,
9,
272,
327,
2836,
26,
272,
327,
259,
29329,
275,
14314,
63,
25438,
2532,
1692,
8,
493,
9,
272,
327,
259,
327,
5787,
3757,
1260,
687,
9193,
26,
2793,
1133,
289,
5710,
1195,
1380,
781,
9980,
1133,
18310,
652,
272,
327,
259,
24802,
275,
14314,
63,
6200,
34,
1658,
63,
25438,
8,
13057,
12,
378,
9,
2378,
485,
4060,
29,
11378,
11447,
8,
3806,
14,
3491,
16315,
272,
485,
4060,
14,
2164,
29,
493,
339,
485,
4060,
14,
7682,
29,
1360,
14,
18988,
54,
1179,
342,
272,
347,
6050,
63,
265,
912,
2031,
589,
304,
267,
327,
1014,
921,
1544,
14,
74,
1187,
10384,
14,
957,
15,
23561,
15,
9554,
13,
29436,
13,
4958,
13,
12628,
13,
5777,
13,
7395,
13,
1795,
316,
13,
1593,
267,
327,
1589,
641,
912,
1584,
7437,
11999,
880,
2860,
664,
26560,
939,
1536,
880,
781,
1172,
267,
327,
475,
675,
1249,
59,
16,
1055,
515,
59,
16,
61,
370,
9658,
734,
314,
3211,
1834,
267,
8559,
14,
793,
8,
589,
9,
267,
340,
2688,
8,
589,
59,
16,
467,
283,
1375,
735,
257,
327,
24584,
1779,
642,
29,
589,
59,
16,
1055,
1375,
267,
587,
26,
14960,
327,
9887,
1779,
642,
29,
589,
59,
16,
1055,
515,
59,
16,
61,
398,
642,
14,
7682,
14,
2063,
29,
3749,
14,
2063,
267,
642,
14,
7682,
14,
3333,
29,
3749,
14,
3333,
267,
642,
14,
7682,
14,
32160,
360,
18,
68,
1959,
5485,
3491,
8,
3749,
12,
16,
12,
16,
9,
267,
327,
3749,
14,
4591,
29,
549,
339,
485,
4060,
14,
265,
912,
29,
4060,
63,
265,
912,
272,
372,
9193,
14,
10992,
14,
16923,
8,
21579,
3699,
4060,
14,
7682,
9,
421,
199,
318,
2248,
8,
493,
12,
536,
6479,
9280,
272,
1449,
6200,
282,
892,
1834,
687,
282,
570,
14,
339,
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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
] |
ssaeger/scikit-learn
|
sklearn/covariance/__init__.py
|
389
|
1157
|
"""
The :mod:`sklearn.covariance` module includes methods and algorithms to
robustly estimate the covariance of features given a set of points. The
precision matrix defined as the inverse of the covariance is also estimated.
Covariance estimation is closely related to the theory of Gaussian Graphical
Models.
"""
from .empirical_covariance_ import empirical_covariance, EmpiricalCovariance, \
log_likelihood
from .shrunk_covariance_ import shrunk_covariance, ShrunkCovariance, \
ledoit_wolf, ledoit_wolf_shrinkage, \
LedoitWolf, oas, OAS
from .robust_covariance import fast_mcd, MinCovDet
from .graph_lasso_ import graph_lasso, GraphLasso, GraphLassoCV
from .outlier_detection import EllipticEnvelope
__all__ = ['EllipticEnvelope',
'EmpiricalCovariance',
'GraphLasso',
'GraphLassoCV',
'LedoitWolf',
'MinCovDet',
'OAS',
'ShrunkCovariance',
'empirical_covariance',
'fast_mcd',
'graph_lasso',
'ledoit_wolf',
'ledoit_wolf_shrinkage',
'log_likelihood',
'oas',
'shrunk_covariance']
|
bsd-3-clause
|
[
624,
199,
1918,
520,
1494,
1705,
27993,
14,
15024,
64,
859,
6952,
3102,
436,
18036,
370,
199,
293,
15549,
590,
14497,
314,
13263,
402,
4534,
1627,
282,
663,
402,
4501,
14,
710,
199,
6833,
3634,
3247,
465,
314,
11484,
402,
314,
13263,
365,
2597,
20077,
14,
199,
967,
6221,
27156,
365,
4002,
590,
4048,
370,
314,
30629,
402,
17131,
11513,
2652,
199,
20474,
14,
199,
624,
199,
199,
504,
1275,
2109,
73,
8825,
63,
15024,
63,
492,
9052,
73,
8825,
63,
15024,
12,
662,
22575,
967,
6221,
12,
971,
272,
943,
63,
20704,
199,
504,
1275,
609,
1065,
75,
63,
15024,
63,
492,
1033,
1065,
75,
63,
15024,
12,
5244,
1065,
75,
967,
6221,
12,
971,
272,
1026,
19014,
63,
28070,
12,
1026,
19014,
63,
28070,
63,
23733,
474,
12,
971,
272,
491,
379,
79,
390,
26724,
276,
12,
312,
305,
12,
593,
1179,
199,
504,
1275,
293,
15549,
63,
15024,
492,
7377,
63,
77,
2866,
12,
10195,
967,
86,
21097,
199,
504,
1275,
2180,
63,
18412,
63,
492,
3343,
63,
18412,
12,
11513,
27537,
12,
11513,
27537,
12847,
199,
504,
1275,
548,
5697,
63,
11934,
492,
27761,
764,
28278,
421,
199,
363,
452,
363,
275,
788,
23525,
764,
28278,
297,
1779,
283,
24949,
967,
6221,
297,
1779,
283,
4578,
27537,
297,
1779,
283,
4578,
27537,
12847,
297,
1779,
283,
44,
379,
79,
390,
26724,
276,
297,
1779,
283,
4649,
967,
86,
21097,
297,
1779,
283,
47,
1179,
297,
1779,
283,
2662,
1065,
75,
967,
6221,
297,
1779,
283,
2109,
73,
8825,
63,
15024,
297,
1779,
283,
7015,
63,
77,
2866,
297,
1779,
283,
2180,
63,
18412,
297,
1779,
283,
274,
19014,
63,
28070,
297,
1779,
283,
274,
19014,
63,
28070,
63,
23733,
474,
297,
1779,
283,
793,
63,
20704,
297,
1779,
283,
79,
305,
297,
1779,
283,
609,
1065,
75,
63,
15024,
418,
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
] |
[
199,
1918,
520,
1494,
1705,
27993,
14,
15024,
64,
859,
6952,
3102,
436,
18036,
370,
199,
293,
15549,
590,
14497,
314,
13263,
402,
4534,
1627,
282,
663,
402,
4501,
14,
710,
199,
6833,
3634,
3247,
465,
314,
11484,
402,
314,
13263,
365,
2597,
20077,
14,
199,
967,
6221,
27156,
365,
4002,
590,
4048,
370,
314,
30629,
402,
17131,
11513,
2652,
199,
20474,
14,
199,
624,
199,
199,
504,
1275,
2109,
73,
8825,
63,
15024,
63,
492,
9052,
73,
8825,
63,
15024,
12,
662,
22575,
967,
6221,
12,
971,
272,
943,
63,
20704,
199,
504,
1275,
609,
1065,
75,
63,
15024,
63,
492,
1033,
1065,
75,
63,
15024,
12,
5244,
1065,
75,
967,
6221,
12,
971,
272,
1026,
19014,
63,
28070,
12,
1026,
19014,
63,
28070,
63,
23733,
474,
12,
971,
272,
491,
379,
79,
390,
26724,
276,
12,
312,
305,
12,
593,
1179,
199,
504,
1275,
293,
15549,
63,
15024,
492,
7377,
63,
77,
2866,
12,
10195,
967,
86,
21097,
199,
504,
1275,
2180,
63,
18412,
63,
492,
3343,
63,
18412,
12,
11513,
27537,
12,
11513,
27537,
12847,
199,
504,
1275,
548,
5697,
63,
11934,
492,
27761,
764,
28278,
421,
199,
363,
452,
363,
275,
788,
23525,
764,
28278,
297,
1779,
283,
24949,
967,
6221,
297,
1779,
283,
4578,
27537,
297,
1779,
283,
4578,
27537,
12847,
297,
1779,
283,
44,
379,
79,
390,
26724,
276,
297,
1779,
283,
4649,
967,
86,
21097,
297,
1779,
283,
47,
1179,
297,
1779,
283,
2662,
1065,
75,
967,
6221,
297,
1779,
283,
2109,
73,
8825,
63,
15024,
297,
1779,
283,
7015,
63,
77,
2866,
297,
1779,
283,
2180,
63,
18412,
297,
1779,
283,
274,
19014,
63,
28070,
297,
1779,
283,
274,
19014,
63,
28070,
63,
23733,
474,
297,
1779,
283,
793,
63,
20704,
297,
1779,
283,
79,
305,
297,
1779,
283,
609,
1065,
75,
63,
15024,
418,
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,
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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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
] |
kylerbrown/scikit-learn
|
sklearn/cross_decomposition/cca_.py
|
209
|
3150
|
from .pls_ import _PLS
__all__ = ['CCA']
class CCA(_PLS):
"""CCA Canonical Correlation Analysis.
CCA inherits from PLS with mode="B" and deflation_mode="canonical".
Read more in the :ref:`User Guide <cross_decomposition>`.
Parameters
----------
n_components : int, (default 2).
number of components to keep.
scale : boolean, (default True)
whether to scale the data?
max_iter : an integer, (default 500)
the maximum number of iterations of the NIPALS inner loop
tol : non-negative real, default 1e-06.
the tolerance used in the iterative algorithm
copy : boolean
Whether the deflation be done on a copy. Let the default value
to True unless you don't care about side effects
Attributes
----------
x_weights_ : array, [p, n_components]
X block weights vectors.
y_weights_ : array, [q, n_components]
Y block weights vectors.
x_loadings_ : array, [p, n_components]
X block loadings vectors.
y_loadings_ : array, [q, n_components]
Y block loadings vectors.
x_scores_ : array, [n_samples, n_components]
X scores.
y_scores_ : array, [n_samples, n_components]
Y scores.
x_rotations_ : array, [p, n_components]
X block to latents rotations.
y_rotations_ : array, [q, n_components]
Y block to latents rotations.
n_iter_ : array-like
Number of iterations of the NIPALS inner loop for each
component.
Notes
-----
For each component k, find the weights u, v that maximizes
max corr(Xk u, Yk v), such that ``|u| = |v| = 1``
Note that it maximizes only the correlations between the scores.
The residual matrix of X (Xk+1) block is obtained by the deflation on the
current X score: x_score.
The residual matrix of Y (Yk+1) block is obtained by deflation on the
current Y score.
Examples
--------
>>> from sklearn.cross_decomposition import CCA
>>> X = [[0., 0., 1.], [1.,0.,0.], [2.,2.,2.], [3.,5.,4.]]
>>> Y = [[0.1, -0.2], [0.9, 1.1], [6.2, 5.9], [11.9, 12.3]]
>>> cca = CCA(n_components=1)
>>> cca.fit(X, Y)
... # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
CCA(copy=True, max_iter=500, n_components=1, scale=True, tol=1e-06)
>>> X_c, Y_c = cca.transform(X, Y)
References
----------
Jacob A. Wegelin. A survey of Partial Least Squares (PLS) methods, with
emphasis on the two-block case. Technical Report 371, Department of
Statistics, University of Washington, Seattle, 2000.
In french but still a reference:
Tenenhaus, M. (1998). La regression PLS: theorie et pratique. Paris:
Editions Technic.
See also
--------
PLSCanonical
PLSSVD
"""
def __init__(self, n_components=2, scale=True,
max_iter=500, tol=1e-06, copy=True):
_PLS.__init__(self, n_components=n_components, scale=scale,
deflation_mode="canonical", mode="B",
norm_y_weights=True, algorithm="nipals",
max_iter=max_iter, tol=tol, copy=copy)
|
bsd-3-clause
|
[
504,
1275,
80,
478,
63,
492,
485,
2749,
51,
199,
199,
363,
452,
363,
275,
788,
2571,
33,
418,
421,
199,
533,
445,
3263,
1547,
2749,
51,
304,
272,
408,
2571,
33,
6855,
7174,
7499,
5690,
21916,
14,
339,
445,
3263,
21592,
687,
510,
5296,
543,
818,
628,
34,
2,
436,
347,
2212,
63,
632,
628,
13109,
1674,
339,
5574,
1655,
315,
314,
520,
1121,
1705,
1899,
15423,
665,
7925,
63,
31384,
14943,
339,
3897,
272,
4143,
272,
302,
63,
4608,
520,
1109,
12,
334,
885,
499,
680,
267,
1329,
402,
7323,
370,
4215,
14,
339,
4666,
520,
5046,
12,
334,
885,
715,
9,
267,
3775,
370,
4666,
314,
666,
31,
339,
1390,
63,
1661,
520,
376,
3000,
12,
334,
885,
6891,
9,
267,
314,
5696,
1329,
402,
10615,
402,
314,
653,
1772,
748,
51,
6506,
4438,
339,
9561,
520,
2222,
13,
7371,
3363,
12,
849,
413,
69,
13,
1690,
14,
267,
314,
13464,
1202,
315,
314,
4826,
857,
5563,
339,
1331,
520,
5046,
267,
7480,
314,
347,
2212,
506,
4224,
641,
282,
1331,
14,
12230,
314,
849,
574,
267,
370,
715,
7444,
1265,
2793,
1133,
10296,
3595,
5366,
22414,
339,
9382,
272,
4143,
272,
671,
63,
4916,
63,
520,
1625,
12,
359,
80,
12,
302,
63,
4608,
61,
267,
1323,
1853,
4931,
11102,
14,
339,
612,
63,
4916,
63,
520,
1625,
12,
359,
81,
12,
302,
63,
4608,
61,
267,
1488,
1853,
4931,
11102,
14,
339,
671,
63,
912,
780,
63,
520,
1625,
12,
359,
80,
12,
302,
63,
4608,
61,
267,
1323,
1853,
2248,
780,
11102,
14,
339,
612,
63,
912,
780,
63,
520,
1625,
12,
359,
81,
12,
302,
63,
4608,
61,
267,
1488,
1853,
2248,
780,
11102,
14,
339,
671,
63,
7107,
63,
520,
1625,
12,
359,
78,
63,
3356,
12,
302,
63,
4608,
61,
267,
1323,
9342,
14,
339,
612,
63,
7107,
63,
520,
1625,
12,
359,
78,
63,
3356,
12,
302,
63,
4608,
61,
267,
1488,
9342,
14,
339,
671,
63,
4571,
1298,
63,
520,
1625,
12,
359,
80,
12,
302,
63,
4608,
61,
267,
1323,
1853,
370,
2465,
343,
83,
7513,
1298,
14,
339,
612,
63,
4571,
1298,
63,
520,
1625,
12,
359,
81,
12,
302,
63,
4608,
61,
267,
1488,
1853,
370,
2465,
343,
83,
7513,
1298,
14,
339,
302,
63,
1661,
63,
520,
1625,
13,
2930,
267,
4860,
402,
10615,
402,
314,
653,
1772,
748,
51,
6506,
4438,
367,
1924,
267,
3931,
14,
339,
8144,
272,
9063,
272,
2104,
1924,
3931,
1022,
12,
2342,
314,
4931,
399,
12,
373,
626,
1390,
1017,
6491,
272,
1390,
25948,
8,
56,
75,
399,
12,
1488,
75,
373,
395,
4066,
626,
1124,
92,
85,
92,
275,
1204,
86,
92,
275,
413,
1040,
339,
3390,
626,
652,
1390,
1017,
6491,
1454,
314,
1970,
15741,
3382,
314,
9342,
14,
339,
710,
16731,
3634,
402,
1323,
334,
56,
75,
11,
17,
9,
1853,
365,
15884,
701,
314,
347,
2212,
641,
314,
272,
1453,
1323,
5396,
26,
671,
63,
3397,
14,
339,
710,
16731,
3634,
402,
1488,
334,
57,
75,
11,
17,
9,
1853,
365,
15884,
701,
347,
2212,
641,
314,
272,
1453,
1488,
5396,
14,
339,
6058,
272,
3001,
272,
1306,
687,
6357,
14,
7925,
63,
31384,
492,
445,
3263,
272,
1306,
1323,
275,
3474,
16,
2020,
378,
2020,
413,
8333,
359,
17,
2020,
16,
2020,
16,
8333,
359,
18,
2020,
18,
2020,
18,
8333,
359,
19,
2020,
21,
2020,
20,
28132,
272,
1306,
1488,
275,
3474,
16,
14,
17,
12,
446,
16,
14,
18,
467,
359,
16,
14,
25,
12,
413,
14,
17,
467,
359,
22,
14,
18,
12,
959,
14,
25,
467,
359,
845,
14,
25,
12,
3144,
14,
19,
2677,
272,
1306,
286,
696,
275,
445,
3263,
8,
78,
63,
4608,
29,
17,
9,
272,
1306,
286,
696,
14,
3269,
8,
56,
12,
1488,
9,
272,
2263,
327,
8868,
26,
435,
21677,
12,
435,
10765,
11025,
63,
20620,
272,
445,
3263,
8,
1574,
29,
549,
12,
1390,
63,
1661,
29,
5783,
12,
302,
63,
4608,
29,
17,
12,
4666,
29,
549,
12,
9561,
29,
17,
69,
13,
1690,
9,
272,
1306,
1323,
63,
67,
12,
1488,
63,
67,
275,
286,
696,
14,
4711,
8,
56,
12,
1488,
9,
339,
14504,
272,
4143,
339,
1603,
13286,
66,
437,
14,
2136,
303,
472,
14,
437,
16576,
402,
2235,
1009,
7005,
1810,
428,
392,
11044,
334,
2749,
51,
9,
3102,
12,
543,
272,
9052,
24059,
641,
314,
2877,
13,
1457,
1930,
14,
5773,
28836,
11774,
650,
3172,
12,
1487,
12493,
402,
272,
28365,
12,
15904,
402,
644,
1119,
31673,
12,
3240,
29274,
12,
12293,
14,
339,
1010,
289,
15148,
1325,
5139,
282,
3659,
26,
272,
377,
287,
287,
2411,
527,
12,
603,
14,
334,
23756,
680,
7964,
10864,
510,
5296,
26,
314,
269,
1873,
10844,
299,
345,
280,
544,
14,
2235,
374,
26,
272,
662,
3138,
5773,
11019,
530,
14,
339,
1666,
2597,
272,
3001,
272,
10092,
5153,
290,
7174,
272,
10092,
2300,
26197,
272,
408,
339,
347,
636,
826,
721,
277,
12,
302,
63,
4608,
29,
18,
12,
4666,
29,
549,
12,
326,
1390,
63,
1661,
29,
5783,
12,
9561,
29,
17,
69,
13,
1690,
12,
1331,
29,
549,
304,
267,
485,
2749,
51,
855,
826,
721,
277,
12,
302,
63,
4608,
29,
78,
63,
4608,
12,
4666,
29,
3467,
12,
1993,
347,
2212,
63,
632,
628,
13109,
401,
818,
628,
34,
401,
1993,
6316,
63,
89,
63,
4916,
29,
549,
12,
5563,
628,
78,
711,
2551,
401,
1993,
1390,
63,
1661,
29,
988,
63,
1661,
12,
9561,
29,
6896,
12,
1331,
29,
1574,
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
] |
[
1275,
80,
478,
63,
492,
485,
2749,
51,
199,
199,
363,
452,
363,
275,
788,
2571,
33,
418,
421,
199,
533,
445,
3263,
1547,
2749,
51,
304,
272,
408,
2571,
33,
6855,
7174,
7499,
5690,
21916,
14,
339,
445,
3263,
21592,
687,
510,
5296,
543,
818,
628,
34,
2,
436,
347,
2212,
63,
632,
628,
13109,
1674,
339,
5574,
1655,
315,
314,
520,
1121,
1705,
1899,
15423,
665,
7925,
63,
31384,
14943,
339,
3897,
272,
4143,
272,
302,
63,
4608,
520,
1109,
12,
334,
885,
499,
680,
267,
1329,
402,
7323,
370,
4215,
14,
339,
4666,
520,
5046,
12,
334,
885,
715,
9,
267,
3775,
370,
4666,
314,
666,
31,
339,
1390,
63,
1661,
520,
376,
3000,
12,
334,
885,
6891,
9,
267,
314,
5696,
1329,
402,
10615,
402,
314,
653,
1772,
748,
51,
6506,
4438,
339,
9561,
520,
2222,
13,
7371,
3363,
12,
849,
413,
69,
13,
1690,
14,
267,
314,
13464,
1202,
315,
314,
4826,
857,
5563,
339,
1331,
520,
5046,
267,
7480,
314,
347,
2212,
506,
4224,
641,
282,
1331,
14,
12230,
314,
849,
574,
267,
370,
715,
7444,
1265,
2793,
1133,
10296,
3595,
5366,
22414,
339,
9382,
272,
4143,
272,
671,
63,
4916,
63,
520,
1625,
12,
359,
80,
12,
302,
63,
4608,
61,
267,
1323,
1853,
4931,
11102,
14,
339,
612,
63,
4916,
63,
520,
1625,
12,
359,
81,
12,
302,
63,
4608,
61,
267,
1488,
1853,
4931,
11102,
14,
339,
671,
63,
912,
780,
63,
520,
1625,
12,
359,
80,
12,
302,
63,
4608,
61,
267,
1323,
1853,
2248,
780,
11102,
14,
339,
612,
63,
912,
780,
63,
520,
1625,
12,
359,
81,
12,
302,
63,
4608,
61,
267,
1488,
1853,
2248,
780,
11102,
14,
339,
671,
63,
7107,
63,
520,
1625,
12,
359,
78,
63,
3356,
12,
302,
63,
4608,
61,
267,
1323,
9342,
14,
339,
612,
63,
7107,
63,
520,
1625,
12,
359,
78,
63,
3356,
12,
302,
63,
4608,
61,
267,
1488,
9342,
14,
339,
671,
63,
4571,
1298,
63,
520,
1625,
12,
359,
80,
12,
302,
63,
4608,
61,
267,
1323,
1853,
370,
2465,
343,
83,
7513,
1298,
14,
339,
612,
63,
4571,
1298,
63,
520,
1625,
12,
359,
81,
12,
302,
63,
4608,
61,
267,
1488,
1853,
370,
2465,
343,
83,
7513,
1298,
14,
339,
302,
63,
1661,
63,
520,
1625,
13,
2930,
267,
4860,
402,
10615,
402,
314,
653,
1772,
748,
51,
6506,
4438,
367,
1924,
267,
3931,
14,
339,
8144,
272,
9063,
272,
2104,
1924,
3931,
1022,
12,
2342,
314,
4931,
399,
12,
373,
626,
1390,
1017,
6491,
272,
1390,
25948,
8,
56,
75,
399,
12,
1488,
75,
373,
395,
4066,
626,
1124,
92,
85,
92,
275,
1204,
86,
92,
275,
413,
1040,
339,
3390,
626,
652,
1390,
1017,
6491,
1454,
314,
1970,
15741,
3382,
314,
9342,
14,
339,
710,
16731,
3634,
402,
1323,
334,
56,
75,
11,
17,
9,
1853,
365,
15884,
701,
314,
347,
2212,
641,
314,
272,
1453,
1323,
5396,
26,
671,
63,
3397,
14,
339,
710,
16731,
3634,
402,
1488,
334,
57,
75,
11,
17,
9,
1853,
365,
15884,
701,
347,
2212,
641,
314,
272,
1453,
1488,
5396,
14,
339,
6058,
272,
3001,
272,
1306,
687,
6357,
14,
7925,
63,
31384,
492,
445,
3263,
272,
1306,
1323,
275,
3474,
16,
2020,
378,
2020,
413,
8333,
359,
17,
2020,
16,
2020,
16,
8333,
359,
18,
2020,
18,
2020,
18,
8333,
359,
19,
2020,
21,
2020,
20,
28132,
272,
1306,
1488,
275,
3474,
16,
14,
17,
12,
446,
16,
14,
18,
467,
359,
16,
14,
25,
12,
413,
14,
17,
467,
359,
22,
14,
18,
12,
959,
14,
25,
467,
359,
845,
14,
25,
12,
3144,
14,
19,
2677,
272,
1306,
286,
696,
275,
445,
3263,
8,
78,
63,
4608,
29,
17,
9,
272,
1306,
286,
696,
14,
3269,
8,
56,
12,
1488,
9,
272,
2263,
327,
8868,
26,
435,
21677,
12,
435,
10765,
11025,
63,
20620,
272,
445,
3263,
8,
1574,
29,
549,
12,
1390,
63,
1661,
29,
5783,
12,
302,
63,
4608,
29,
17,
12,
4666,
29,
549,
12,
9561,
29,
17,
69,
13,
1690,
9,
272,
1306,
1323,
63,
67,
12,
1488,
63,
67,
275,
286,
696,
14,
4711,
8,
56,
12,
1488,
9,
339,
14504,
272,
4143,
339,
1603,
13286,
66,
437,
14,
2136,
303,
472,
14,
437,
16576,
402,
2235,
1009,
7005,
1810,
428,
392,
11044,
334,
2749,
51,
9,
3102,
12,
543,
272,
9052,
24059,
641,
314,
2877,
13,
1457,
1930,
14,
5773,
28836,
11774,
650,
3172,
12,
1487,
12493,
402,
272,
28365,
12,
15904,
402,
644,
1119,
31673,
12,
3240,
29274,
12,
12293,
14,
339,
1010,
289,
15148,
1325,
5139,
282,
3659,
26,
272,
377,
287,
287,
2411,
527,
12,
603,
14,
334,
23756,
680,
7964,
10864,
510,
5296,
26,
314,
269,
1873,
10844,
299,
345,
280,
544,
14,
2235,
374,
26,
272,
662,
3138,
5773,
11019,
530,
14,
339,
1666,
2597,
272,
3001,
272,
10092,
5153,
290,
7174,
272,
10092,
2300,
26197,
272,
408,
339,
347,
636,
826,
721,
277,
12,
302,
63,
4608,
29,
18,
12,
4666,
29,
549,
12,
326,
1390,
63,
1661,
29,
5783,
12,
9561,
29,
17,
69,
13,
1690,
12,
1331,
29,
549,
304,
267,
485,
2749,
51,
855,
826,
721,
277,
12,
302,
63,
4608,
29,
78,
63,
4608,
12,
4666,
29,
3467,
12,
1993,
347,
2212,
63,
632,
628,
13109,
401,
818,
628,
34,
401,
1993,
6316,
63,
89,
63,
4916,
29,
549,
12,
5563,
628,
78,
711,
2551,
401,
1993,
1390,
63,
1661,
29,
988,
63,
1661,
12,
9561,
29,
6896,
12,
1331,
29,
1574,
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,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
PythonMilano/pillole-di-python-01
|
pdb_in_action/sources/estimate.py
|
1
|
1274
|
#!/usr/bin/env python3
""" Estimator 1.0
The estimator helps you find those hard estimations they ask you.
Just call the script, it will ask you a brief feature descrition,
then it will show you the estimation.
Press CTRL-C when you're done.
"""
import sys
from random import randrange
fib_n = [1, 1, 2, 3, 5, 8, 13, 21, 54, 75]
def get_estimate(feature):
" Gets a string input and with a comlpext AI calculates the get_estimation "
feature_hash = hash(feature)
feature_hash = int(feature_hash / 10 + 2)
return fib_n[reduce(feature_hash)]
def reduce(number):
""" Reduces a number with multiple digits to a single digit
i.e. 135 -> 1 + 3 + 5 = 9
"""
#if number < 0:
# number *= -1
while number > 9:
number = sum([int(char) for char in str(number)])
return number
def test_reduce():
assert reduce(2) == 2
assert reduce(1) == 1
assert reduce(10) == 1
assert reduce(1000000) == 1
assert reduce(123456) == reduce(21) == reduce(3) == 3
assert reduce(-9) == reduce(9) == 9
assert reduce(-123) == reduce(123) == 6
if __name__ == "__main__":
while True:
feature = input("Write the description of a feature: ")
print(get_estimate(feature))
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
19,
199,
199,
624,
28992,
413,
14,
16,
272,
710,
8943,
22577,
1265,
2342,
5204,
7508,
4347,
11744,
852,
2985,
7198,
1265,
14,
272,
13870,
1240,
314,
2884,
12,
652,
911,
7198,
1265,
282,
29226,
3878,
7039,
296,
12,
272,
2066,
652,
911,
2498,
1265,
314,
27156,
14,
272,
23583,
445,
1766,
44,
13,
35,
1380,
1265,
3984,
4224,
14,
199,
624,
199,
199,
646,
984,
199,
504,
2196,
492,
10261,
1842,
421,
199,
329,
66,
63,
78,
275,
359,
17,
12,
413,
12,
499,
12,
650,
12,
959,
12,
1695,
12,
4944,
12,
7829,
12,
13470,
12,
13098,
61,
421,
199,
318,
664,
63,
21196,
8,
4445,
304,
272,
298,
14509,
282,
1059,
1324,
436,
543,
282,
512,
757,
321,
400,
437,
41,
6966,
2335,
314,
664,
63,
597,
8182,
298,
339,
3878,
63,
2227,
275,
2631,
8,
4445,
9,
272,
3878,
63,
2227,
275,
1109,
8,
4445,
63,
2227,
1182,
1616,
435,
499,
9,
272,
372,
289,
1892,
63,
78,
59,
5270,
8,
4445,
63,
2227,
1874,
421,
199,
318,
7114,
8,
1955,
304,
272,
408,
820,
8654,
823,
282,
1329,
543,
3663,
7576,
370,
282,
2849,
10964,
267,
284,
14,
69,
14,
23051,
1035,
413,
435,
650,
435,
959,
275,
1749,
272,
408,
339,
327,
692,
1329,
665,
378,
26,
272,
327,
259,
1329,
9000,
446,
17,
339,
1830,
1329,
690,
1749,
26,
267,
1329,
275,
3089,
779,
442,
8,
1560,
9,
367,
1495,
315,
620,
8,
1955,
3948,
2286,
372,
1329,
421,
199,
318,
511,
63,
5270,
837,
272,
702,
7114,
8,
18,
9,
508,
499,
272,
702,
7114,
8,
17,
9,
508,
413,
272,
702,
7114,
8,
709,
9,
508,
413,
272,
702,
7114,
8,
22589,
9,
508,
413,
272,
702,
7114,
8,
19060,
9,
508,
7114,
8,
2025,
9,
508,
7114,
8,
19,
9,
508,
650,
272,
702,
7114,
2801,
25,
9,
508,
7114,
8,
25,
9,
508,
1749,
272,
702,
7114,
2801,
4288,
9,
508,
7114,
8,
4288,
9,
508,
1227,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
1830,
715,
26,
267,
3878,
275,
1324,
480,
3534,
314,
1369,
402,
282,
3878,
26,
6099,
267,
870,
8,
362,
63,
21196,
8,
4445,
430,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
19,
199,
199,
624,
28992,
413,
14,
16,
272,
710,
8943,
22577,
1265,
2342,
5204,
7508,
4347,
11744,
852,
2985,
7198,
1265,
14,
272,
13870,
1240,
314,
2884,
12,
652,
911,
7198,
1265,
282,
29226,
3878,
7039,
296,
12,
272,
2066,
652,
911,
2498,
1265,
314,
27156,
14,
272,
23583,
445,
1766,
44,
13,
35,
1380,
1265,
3984,
4224,
14,
199,
624,
199,
199,
646,
984,
199,
504,
2196,
492,
10261,
1842,
421,
199,
329,
66,
63,
78,
275,
359,
17,
12,
413,
12,
499,
12,
650,
12,
959,
12,
1695,
12,
4944,
12,
7829,
12,
13470,
12,
13098,
61,
421,
199,
318,
664,
63,
21196,
8,
4445,
304,
272,
298,
14509,
282,
1059,
1324,
436,
543,
282,
512,
757,
321,
400,
437,
41,
6966,
2335,
314,
664,
63,
597,
8182,
298,
339,
3878,
63,
2227,
275,
2631,
8,
4445,
9,
272,
3878,
63,
2227,
275,
1109,
8,
4445,
63,
2227,
1182,
1616,
435,
499,
9,
272,
372,
289,
1892,
63,
78,
59,
5270,
8,
4445,
63,
2227,
1874,
421,
199,
318,
7114,
8,
1955,
304,
272,
408,
820,
8654,
823,
282,
1329,
543,
3663,
7576,
370,
282,
2849,
10964,
267,
284,
14,
69,
14,
23051,
1035,
413,
435,
650,
435,
959,
275,
1749,
272,
408,
339,
327,
692,
1329,
665,
378,
26,
272,
327,
259,
1329,
9000,
446,
17,
339,
1830,
1329,
690,
1749,
26,
267,
1329,
275,
3089,
779,
442,
8,
1560,
9,
367,
1495,
315,
620,
8,
1955,
3948,
2286,
372,
1329,
421,
199,
318,
511,
63,
5270,
837,
272,
702,
7114,
8,
18,
9,
508,
499,
272,
702,
7114,
8,
17,
9,
508,
413,
272,
702,
7114,
8,
709,
9,
508,
413,
272,
702,
7114,
8,
22589,
9,
508,
413,
272,
702,
7114,
8,
19060,
9,
508,
7114,
8,
2025,
9,
508,
7114,
8,
19,
9,
508,
650,
272,
702,
7114,
2801,
25,
9,
508,
7114,
8,
25,
9,
508,
1749,
272,
702,
7114,
2801,
4288,
9,
508,
7114,
8,
4288,
9,
508,
1227,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
1830,
715,
26,
267,
3878,
275,
1324,
480,
3534,
314,
1369,
402,
282,
3878,
26,
6099,
267,
870,
8,
362,
63,
21196,
8,
4445,
430,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
djtotten/workbench
|
workbench/clients/pcap_meta_indexer.py
|
2
|
1303
|
"""This client pushes PCAPs -> MetaDaa -> ELS Indexer."""
import zerorpc
import os
import client_helper
def run():
"""This client pushes PCAPs -> MetaDaa -> ELS Indexer."""
# Grab server args
args = client_helper.grab_server_args()
# Start up workbench connection
workbench = zerorpc.Client(timeout=300, heartbeat=60)
workbench.connect('tcp://'+args['server']+':'+args['port'])
# Test out PCAP data
data_path = os.path.join(os.path.dirname(os.path.realpath(__file__)),'../data/pcap')
file_list = [os.path.join(data_path, child) for child in os.listdir(data_path)]
for filename in file_list:
# Skip OS generated files
if '.DS_Store' in filename: continue
with open(filename,'rb') as pcap_file:
base_name = os.path.basename(filename)
md5 = workbench.store_sample(pcap_file.read(), base_name, 'pcap')
# Index the view_pcap output (notice we can ask for any worker output)
# Also (super important) it all happens on the server side.
workbench.index_worker_output('view_pcap', md5, 'view_pcap', None)
print '\n\n<<< PCAP Data: %s Indexed>>>' % (base_name)
def test():
"""Executes pcap_meta_indexer test."""
run()
if __name__ == '__main__':
run()
|
mit
|
[
624,
2765,
1890,
6675,
397,
510,
8549,
83,
1035,
6288,
36,
2158,
1035,
662,
5296,
5499,
281,
1041,
199,
646,
8043,
30786,
199,
646,
747,
199,
646,
1890,
63,
3676,
199,
199,
318,
1255,
837,
272,
408,
2765,
1890,
6675,
397,
510,
8549,
83,
1035,
6288,
36,
2158,
1035,
662,
5296,
5499,
281,
1041,
2286,
327,
29225,
1654,
1249,
272,
1249,
275,
1890,
63,
3676,
14,
22090,
63,
1000,
63,
589,
342,
339,
327,
7707,
1536,
1736,
16571,
1950,
272,
1736,
16571,
275,
8043,
30786,
14,
3041,
8,
2593,
29,
5863,
12,
32015,
29,
2259,
9,
272,
1736,
16571,
14,
2242,
360,
8815,
921,
6828,
589,
459,
1000,
21899,
5242,
11,
589,
459,
719,
1105,
339,
327,
1379,
734,
510,
8549,
666,
272,
666,
63,
515,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
11091,
3460,
493,
22159,
7,
5093,
576,
15,
2352,
439,
358,
272,
570,
63,
513,
275,
359,
736,
14,
515,
14,
904,
8,
576,
63,
515,
12,
1982,
9,
367,
1982,
315,
747,
14,
7374,
8,
576,
63,
515,
1874,
272,
367,
1788,
315,
570,
63,
513,
26,
398,
327,
8232,
4403,
4046,
1584,
267,
340,
1987,
3177,
63,
5502,
7,
315,
1788,
26,
1980,
398,
543,
1551,
8,
1501,
2584,
4848,
358,
465,
18606,
63,
493,
26,
288,
1300,
63,
354,
275,
747,
14,
515,
14,
4846,
8,
1501,
9,
288,
6128,
21,
275,
1736,
16571,
14,
1617,
63,
3271,
8,
2352,
439,
63,
493,
14,
739,
1062,
1300,
63,
354,
12,
283,
2352,
439,
358,
953,
327,
5499,
314,
2455,
63,
2352,
439,
1072,
334,
20556,
781,
883,
7198,
367,
1263,
7239,
1072,
9,
288,
327,
6121,
334,
4792,
11012,
9,
652,
1006,
10986,
641,
314,
1654,
5366,
14,
288,
1736,
16571,
14,
1080,
63,
6599,
63,
1199,
360,
1345,
63,
2352,
439,
297,
6128,
21,
12,
283,
1345,
63,
2352,
439,
297,
488,
9,
288,
870,
1557,
78,
60,
78,
8999,
28,
510,
8549,
3918,
26,
450,
83,
26437,
1140,
3524,
450,
334,
1095,
63,
354,
9,
199,
199,
318,
511,
837,
272,
408,
4858,
3862,
18606,
63,
2024,
63,
15615,
511,
1041,
272,
1255,
342,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
1255,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2765,
1890,
6675,
397,
510,
8549,
83,
1035,
6288,
36,
2158,
1035,
662,
5296,
5499,
281,
1041,
199,
646,
8043,
30786,
199,
646,
747,
199,
646,
1890,
63,
3676,
199,
199,
318,
1255,
837,
272,
408,
2765,
1890,
6675,
397,
510,
8549,
83,
1035,
6288,
36,
2158,
1035,
662,
5296,
5499,
281,
1041,
2286,
327,
29225,
1654,
1249,
272,
1249,
275,
1890,
63,
3676,
14,
22090,
63,
1000,
63,
589,
342,
339,
327,
7707,
1536,
1736,
16571,
1950,
272,
1736,
16571,
275,
8043,
30786,
14,
3041,
8,
2593,
29,
5863,
12,
32015,
29,
2259,
9,
272,
1736,
16571,
14,
2242,
360,
8815,
921,
6828,
589,
459,
1000,
21899,
5242,
11,
589,
459,
719,
1105,
339,
327,
1379,
734,
510,
8549,
666,
272,
666,
63,
515,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
11091,
3460,
493,
22159,
7,
5093,
576,
15,
2352,
439,
358,
272,
570,
63,
513,
275,
359,
736,
14,
515,
14,
904,
8,
576,
63,
515,
12,
1982,
9,
367,
1982,
315,
747,
14,
7374,
8,
576,
63,
515,
1874,
272,
367,
1788,
315,
570,
63,
513,
26,
398,
327,
8232,
4403,
4046,
1584,
267,
340,
1987,
3177,
63,
5502,
7,
315,
1788,
26,
1980,
398,
543,
1551,
8,
1501,
2584,
4848,
358,
465,
18606,
63,
493,
26,
288,
1300,
63,
354,
275,
747,
14,
515,
14,
4846,
8,
1501,
9,
288,
6128,
21,
275,
1736,
16571,
14,
1617,
63,
3271,
8,
2352,
439,
63,
493,
14,
739,
1062,
1300,
63,
354,
12,
283,
2352,
439,
358,
953,
327,
5499,
314,
2455,
63,
2352,
439,
1072,
334,
20556,
781,
883,
7198,
367,
1263,
7239,
1072,
9,
288,
327,
6121,
334,
4792,
11012,
9,
652,
1006,
10986,
641,
314,
1654,
5366,
14,
288,
1736,
16571,
14,
1080,
63,
6599,
63,
1199,
360,
1345,
63,
2352,
439,
297,
6128,
21,
12,
283,
1345,
63,
2352,
439,
297,
488,
9,
288,
870,
1557,
78,
60,
78,
8999,
28,
510,
8549,
3918,
26,
450,
83,
26437,
1140,
3524,
450,
334,
1095,
63,
354,
9,
199,
199,
318,
511,
837,
272,
408,
4858,
3862,
18606,
63,
2024,
63,
15615,
511,
1041,
272,
1255,
342,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
1255,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
sgmap/openfisca-france
|
openfisca_france/model/prestations/minima_sociaux/aah.py
|
1
|
21212
|
# -*- coding: utf-8 -*-
from openfisca_france.model.base import *
from numpy import datetime64
# Références juridiques - Code de la sécurité sociale
#
# Article L821-1 / 821-8
# https://www.legifrance.gouv.fr/affichCode.do;jsessionid=0E604431776A4B1ED8D2F8EB55A1A99C.tplgfr35s_1?idSectionTA=LEGISCTA000006141693&cidTexte=LEGITEXT000006073189&dateTexte=20180412
#
# Article R821-1 / 821-9
# https://www.legifrance.gouv.fr/affichCode.do;jsessionid=0E604431776A4B1ED8D2F8EB55A1A99C.tplgfr35s_1?idSectionTA=LEGISCTA000006142017&cidTexte=LEGITEXT000006073189&dateTexte=20181010
#
# Article D821-1 / 821-11
# https://www.legifrance.gouv.fr/affichCode.do;jsessionid=157287C570B3AE9450A0BD88AA902970.tplgfr38s_1?idSectionTA=LEGISCTA000006141593&cidTexte=LEGITEXT000006073189&dateTexte=20180731
class aah_date_debut_incarceration(Variable):
value_type = date
default_value = date.max
label = u"La date de début d'incarcération"
entity = Individu
definition_period = MONTH
class aah_date_debut_hospitalisation(Variable):
value_type = date
default_value = date.max
label = u"La date de début d'hospitalisation"
entity = Individu
definition_period = MONTH
class aah_base_ressources(Variable):
value_type = float
label = u"Base ressources de l'allocation adulte handicapé"
entity = Famille
definition_period = MONTH
def formula(famille, period, parameters):
law = parameters(period)
demandeur_en_activite = famille.demandeur('salaire_imposable', period) > 0
def assiette_conjoint(revenus_conjoint):
return 0.9 * (1 - 0.2) * revenus_conjoint
def assiette_revenu_activite_demandeur(revenus_demandeur):
smic_brut_annuel = 12 * law.cotsoc.gen.smic_h_b * law.cotsoc.gen.nb_heure_travail_mensuel
tranche1 = min_(0.3 * smic_brut_annuel, revenus_demandeur)
tranche2 = revenus_demandeur - tranche1
return (1 - 0.8) * tranche1 + (1 - 0.4) * tranche2
def base_ressource_eval_trim():
three_previous_months = period.first_month.start.period('month', 3).offset(-3)
base_ressource_activite_demandeur = famille.demandeur('aah_base_ressources_activite_eval_trimestrielle', period) - famille.demandeur('aah_base_ressources_activite_milieu_protege', three_previous_months, options = [ADD])
base_ressource_hors_activite_demandeur = famille.demandeur('aah_base_ressources_hors_activite_eval_trimestrielle', period) + famille.demandeur('aah_base_ressources_activite_milieu_protege', three_previous_months, options = [ADD])
base_ressource_demandeur = assiette_revenu_activite_demandeur(base_ressource_activite_demandeur) + base_ressource_hors_activite_demandeur
base_ressource_conjoint = famille.conjoint('aah_base_ressources_activite_eval_trimestrielle', period) + famille.conjoint('aah_base_ressources_hors_activite_eval_trimestrielle', period)
return base_ressource_demandeur + assiette_conjoint(base_ressource_conjoint)
def base_ressource_eval_annuelle():
base_ressource_demandeur = assiette_revenu_activite_demandeur(famille.demandeur('salaire_imposable', period.n_2, options = [ADD]) + famille.demandeur('rpns_individu', period.n_2)) + famille.demandeur('revenu_assimile_pension', period.n_2)
base_ressource_conjoint = famille.conjoint('aah_base_ressources_eval_annuelle', period)
return base_ressource_demandeur + assiette_conjoint(base_ressource_conjoint)
return where(
demandeur_en_activite,
base_ressource_eval_trim(),
base_ressource_eval_annuelle()
)
class aah_base_ressources_activite_eval_trimestrielle(Variable):
value_type = float
label = u"Base de ressources des revenus d'activité de l'AAH pour un individu, évaluation trimestrielle"
entity = Individu
definition_period = MONTH
'''
N'entrent pas en compte dans les ressources :
L'allocation compensatrice tierce personne, les allocations familiales,
l'allocation de logement, la retraite du combattant, les rentes viagères
constituées en faveur d'une personne handicapée ou dans la limite d'un
montant fixé à l'article D.821-6 du code de la sécurité sociale (1 830 €/an),
lorsqu'elles ont été constituées par une personne handicapée pour elle-même.
Le RMI (article R 531-10 du code de la sécurité sociale).
A partir du 1er juillet 2007, votre Caf, pour le calcul de votre Aah,
continue à prendre en compte les ressources de votre foyer diminuées de 20%.
Notez, dans certaines situations, la Caf évalue forfaitairement vos
ressources à partir de votre revenu mensuel.
'''
def formula(individu, period):
period = period.first_month
three_previous_months = period.start.period('month', 3).offset(-3)
last_year = period.last_year
ressources_a_inclure = [
'chomage_net',
'indemnites_chomage_partiel',
'indemnites_journalieres_imposables',
'indemnites_stage',
'revenus_stage_formation_pro',
'salaire_net',
]
ressources = sum(
[individu(ressource, three_previous_months, options = [ADD]) for ressource in ressources_a_inclure]
)
def revenus_tns():
revenus_auto_entrepreneur = individu('tns_auto_entrepreneur_benefice', three_previous_months, options = [ADD])
# Les revenus TNS hors AE sont estimés en se basant sur le revenu N-1
tns_micro_entreprise_benefice = individu('tns_micro_entreprise_benefice', last_year) * 3 / 12
tns_benefice_exploitant_agricole = individu('tns_benefice_exploitant_agricole', last_year) * 3 / 12
tns_autres_revenus = individu('tns_autres_revenus', last_year) * 3 / 12
return revenus_auto_entrepreneur + tns_micro_entreprise_benefice + tns_benefice_exploitant_agricole + tns_autres_revenus
return (ressources + revenus_tns()) * 4
class aah_base_ressources_activite_milieu_protege(Variable):
value_type = float
label = u"Base de ressources de l'AAH des revenus d'activité en milieu protégé pour un individu"
entity = Individu
definition_period = MONTH
class aah_base_ressources_hors_activite_eval_trimestrielle(Variable):
value_type = float
label = u"Base de ressources hors revenus d'activité de l'AAH pour un individu, évaluation trimestrielle"
entity = Individu
definition_period = MONTH
'''
N'entrent pas en compte dans les ressources :
L'allocation compensatrice tierce personne, les allocations familiales,
l'allocation de logement, la retraite du combattant, les rentes viagères
constituées en faveur d'une personne handicapée ou dans la limite d'un
montant fixé à l'article D.821-6 du code de la sécurité sociale (1 830 €/an),
lorsqu'elles ont été constituées par une personne handicapée pour elle-même.
Le RMI (article R 531-10 du code de la sécurité sociale).
A partir du 1er juillet 2007, votre Caf, pour le calcul de votre Aah,
continue à prendre en compte les ressources de votre foyer diminuées de 20%.
Notez, dans certaines situations, la Caf évalue forfaitairement vos
ressources à partir de votre revenu mensuel.
'''
def formula(individu, period):
period = period.first_month
three_previous_months = period.start.period('month', 3).offset(-3)
ressources_a_inclure = [
'asi',
'allocation_securisation_professionnelle',
'bourse_recherche',
'gains_exceptionnels',
'pensions_alimentaires_percues',
'pensions_alimentaires_versees_individu',
'pensions_invalidite',
'prestation_compensatoire',
'retraite_nette',
'rsa_base_ressources_patrimoine_individu',
]
ressources = sum(
[individu(ressource, three_previous_months, options = [ADD]) for ressource in ressources_a_inclure]
)
return ressources * 4
class aah_base_ressources_eval_annuelle(Variable):
value_type = float
label = u"Base de ressources de l'AAH pour un individu, évaluation annuelle"
entity = Individu
definition_period = MONTH
def formula(individu, period, parameters):
return (
individu('salaire_imposable', period.n_2, options = [ADD])
+ individu('rpns_individu', period.n_2)
+ individu('revenu_assimile_pension', period.n_2)
)
class aah_restriction_substantielle_durable_acces_emploi(Variable):
value_type = bool
default_value = True
entity = Individu
label = u"Restriction substantielle et durable pour l'accès à l'emploi reconnue par la commission des droits et de l'autonomie des personnes handicapées"
reference = [
u"Article L821-2 du Code de la sécurité sociale",
u"https://www.legifrance.gouv.fr/affichCodeArticle.do;jsessionid=17BE3036A19374AA1C8C7A4169702CD7.tplgfr24s_2?idArticle=LEGIARTI000020039305&cidTexte=LEGITEXT000006073189&dateTexte=20180731"
]
definition_period = MONTH
class aah_eligible(Variable):
value_type = bool
label = u"Eligibilité à l'Allocation adulte handicapé"
entity = Individu
definition_period = MONTH
'''
Allocation adulte handicapé
Conditions liées au handicap
La personne doit être atteinte d’un taux d’incapacité permanente :
- d’au moins 80 %,
- ou compris entre 50 et 79 %. Dans ce cas, elle doit remplir deux conditions
supplémentaires : être dans l’impossibilité de se procurer un emploi compte
tenu de son handicap et ne pas avoir travaillé depuis au moins 1 an
Condition de résidence
L'AAH peut être versée aux personnes résidant en France métropolitaine ou
dans les départements d'outre-mer ou à Saint-Pierre et Miquelon de façon permanente.
Les personnes de nationalité étrangère doivent être en possession d'un titre de séjour
régulier ou être titulaire d'un récépissé de renouvellement de titre de séjour.
Condition d'âge
Age minimum : Le demandeur ne doit plus avoir l'âge de bénéficier de l'allocation d'éducation de l'enfant
handicapé, c'est-à-dire qu'il doit être âgé :
- de plus de vingt ans,
- ou de plus de seize ans, s'il ne remplit plus les conditions pour ouvrir droit aux allocations familiales.
Pour les montants http://www.handipole.org/spip.php?article666
Âge max_
Le versement de l'AAH prend fin à partir de l'âge minimum légal de départ à la retraite en cas d'incapacité
de 50 % à 79 %. À cet âge, le bénéficiaire bascule dans le régime de retraite pour inaptitude.
En cas d'incapacité d'au moins 80 %, une AAH différentielle (c'est-à-dire une allocation mensuelle réduite)
peut être versée au-delà de l'âge minimum légal de départ à la retraite en complément d'une retraite inférieure
au minimum vieillesse.
'''
def formula(individu, period, parameters):
law = parameters(period).prestations.minima_sociaux.aah
taux_incapacite = individu('taux_incapacite', period)
rsdae = individu('aah_restriction_substantielle_durable_acces_emploi', period)
age = individu('age', period)
autonomie_financiere = individu('autonomie_financiere', period)
eligible_aah = (
((taux_incapacite >= law.taux_incapacite) + (taux_incapacite >= 0.5) * rsdae)
* (age <= law.age_legal_retraite)
* ((age >= law.age_minimal) + ((age >= 16) * (autonomie_financiere)))
)
return eligible_aah
# TODO: dated_function : avant 2008, il fallait ne pas avoir travaillé pendant les 12 mois précédant la demande.
class aah_base_non_cumulable(Variable):
value_type = float
label = u"Montant de l'Allocation adulte handicapé (hors complément) pour un individu, mensualisée"
entity = Individu
definition_period = MONTH
def formula(individu, period):
return individu('pensions_invalidite', period) + individu('asi', period.last_month)
class aah_plafond_ressources(Variable):
value_type = float
label = u"Montant plafond des ressources pour bénéficier de l'Allocation adulte handicapé (hors complément)"
entity = Individu
reference = [
u"Article D821-2 du Code de la sécurité sociale",
u"https://www.legifrance.gouv.fr/affichCodeArticle.do;jsessionid=4B54EC7065520E4812F84677B918A48E.tplgfr28s_2?idArticle=LEGIARTI000019077584&cidTexte=LEGITEXT000006073189&dateTexte=20081218"
]
definition_period = MONTH
def formula(individu, period, parameters):
law = parameters(period).prestations
en_couple = individu.famille('en_couple', period)
af_nbenf = individu.famille('af_nbenf', period)
montant_max = law.minima_sociaux.aah.montant
return montant_max * (1 +
en_couple * law.minima_sociaux.aah.majoration_du_plafond_pour_un_couple +
law.minima_sociaux.aah.tx_plaf_supp * af_nbenf)
class aah_base(Variable):
calculate_output = calculate_output_add
value_type = float
label = u"Montant de l'Allocation adulte handicapé (hors complément) pour un individu, mensualisée"
entity = Individu
reference = [
u"Article L821-1 du Code de la sécurité sociale",
u"https://www.legifrance.gouv.fr/affichCodeArticle.do;jsessionid=53AFF5AA4010B01F0539052A33180B39.tplgfr35s_1?idArticle=LEGIARTI000033813790&cidTexte=LEGITEXT000006073189&dateTexte=20180412"
]
definition_period = MONTH
def formula(individu, period, parameters):
law = parameters(period).prestations
aah_eligible = individu('aah_eligible', period)
aah_base_ressources = individu.famille('aah_base_ressources', period) / 12
plaf_ress_aah = individu('aah_plafond_ressources', period)
# Le montant de l'AAH est plafonné au montant de base.
montant_max = law.minima_sociaux.aah.montant
montant_aah = min_(montant_max, max_(0, plaf_ress_aah - aah_base_ressources))
aah_base_non_cumulable = individu('aah_base_non_cumulable', period)
return aah_eligible * min_(montant_aah, max_(0, montant_max - aah_base_non_cumulable))
class aah(Variable):
calculate_output = calculate_output_add
value_type = float
label = u"Allocation adulte handicapé mensualisée"
reference = u"https://www.legifrance.gouv.fr/affichCodeArticle.do?cidTexte=LEGITEXT000006073189&idArticle=LEGIARTI000006754198"
entity = Individu
definition_period = MONTH
set_input = set_input_divide_by_period
def formula(individu, period, parameters):
aah_base = individu('aah_base', period)
aah_parameters = parameters(period).prestations.minima_sociaux.aah
m_2 = datetime64(period.offset(-60, 'day').start)
aah_date_debut_hospitalisation = individu("aah_date_debut_hospitalisation", period)
aah_date_debut_incarceration = individu("aah_date_debut_incarceration", period)
aah_reduction = (aah_date_debut_hospitalisation <= m_2) + (aah_date_debut_incarceration <= m_2)
return where(aah_reduction, aah_base * aah_parameters.taux_aah_hospitalise_ou_incarcere, aah_base)
class eligibilite_caah(Variable):
entity = Individu
value_type = float
label = u"Eligibilité aux compléments à l'aah"
definition_period = MONTH
def formula_2015_07_01(individu, period, parameters):
annee_precedente = period.start.period('year').offset(-1)
prestations = parameters(period).prestations
taux_incapacite_min = prestations.minima_sociaux.aah.taux_incapacite
aah = individu('aah', period)
asi_eligibilite = individu('asi_eligibilite', period)
asi = individu('asi', period) # montant asi de la famille
benef_asi = (asi_eligibilite * (asi > 0))
taux_incapacite = individu('taux_incapacite', period)
locataire_foyer = (individu.menage('statut_occupation_logement', period) == TypesStatutOccupationLogement.locataire_foyer)
salaire_net = individu('salaire_net', annee_precedente, options=[ADD])
return ((taux_incapacite >= taux_incapacite_min) *
((aah > 0) | (benef_asi > 0)) *
not_(locataire_foyer) *
(salaire_net == 0)
)
class caah(Variable):
calculate_output = calculate_output_add
value_type = float
label = u"Complément d'allocation adulte handicapé (mensualisé)"
entity = Individu
set_input = set_input_divide_by_period
definition_period = MONTH
def formula_2015_07_01(individu, period, parameters):
eligibilite_caah = individu('eligibilite_caah', period)
complement_ressources_aah = individu('complement_ressources_aah', period)
mva = individu('mva', period)
return max_(complement_ressources_aah, mva) * eligibilite_caah
def formula_2005_07_01(individu, period, parameters):
law = parameters(period).prestations
garantie_ressources = law.minima_sociaux.caah.garantie_ressources
aah_montant = law.minima_sociaux.aah.montant
aah = individu('aah', period)
asi_eligibilite = individu('asi_eligibilite', period)
asi = individu('asi', period)
benef_asi = (asi_eligibilite * (asi > 0))
# montant allocs logement de la famille
al = individu.famille('aide_logement_montant', period)
taux_incapacite = individu('taux_incapacite', period)
elig_cpl = ((aah > 0) | (benef_asi > 0)) * (taux_incapacite >= law.minima_sociaux.aah.taux_incapacite)
# TODO: & logement indépendant & inactif 12 derniers mois
# & capa de travail < 5%
compl_ress = elig_cpl * max_(garantie_ressources - aah_montant, 0)
elig_mva = (al > 0) * ((aah > 0) | (benef_asi > 0))
# TODO: & logement indépendant & pas de revenus professionnels
# propres & capa de travail < 5% & taux d'incapacité >= 80%
# TODO: rentrer mva dans paramètres. mva (mensuelle) = 104,77 en 2015, était de 101,80 en 2006, et de 119,72 en 2007
mva = 0.0 * elig_mva
return max_(compl_ress, mva)
# TODO FIXME start date
def formula_2002_01_01(individu, period, parameters):
law = parameters(period).prestations
cpltx = law.minima_sociaux.caah.cpltx
aah_montant = law.minima_sociaux.aah.montant
aah = individu('aah', period)
asi_eligibilite = individu('asi_eligibilite', period)
asi = individu('asi', period)
benef_asi = (asi_eligibilite * (asi > 0))
# montant allocs logement de la famille
al = individu.famille('aide_logement_montant', period)
taux_incapacite = individu('taux_incapacite', period)
# TODO: & logement indépendant
elig_ancien_caah = (al > 0) * ((aah > 0) | (benef_asi > 0)) * (taux_incapacite >= law.minima_sociaux.aah.taux_incapacite)
ancien_caah = cpltx * aah_montant * elig_ancien_caah
# En fait le taux cpltx perdure jusqu'en 2008
return ancien_caah
class complement_ressources_aah(Variable):
entity = Individu
value_type = float
label = u"Le complément de ressources"
reference = u"https://www.legifrance.gouv.fr/affichCodeArticle.do?cidTexte=LEGITEXT000006073189&idArticle=LEGIARTI000006745305&dateTexte=&categorieLien=cid"
definition_period = MONTH
def formula_2015_07_01(individu, period, parameters):
prestations = parameters(period).prestations
garantie_ressources = prestations.minima_sociaux.caah.garantie_ressources
aah_montant = prestations.minima_sociaux.aah.montant
taux_capacite_travail_max = prestations.minima_sociaux.aah.taux_capacite_travail
taux_capacite_travail = individu('taux_capacite_travail', period)
return (taux_capacite_travail < taux_capacite_travail_max) * max_(garantie_ressources - aah_montant, 0)
class mva(Variable):
entity = Individu
value_type = float
label = u"Majoration pour la vie autonome"
reference = u"https://www.legifrance.gouv.fr/affichCodeArticle.do;jsessionid=6E5B97C7E6C7E06666BCFFA11871E70B.tplgfr43s_2?idArticle=LEGIARTI000006745350&cidTexte=LEGITEXT000006073189&dateTexte=20190124"
definition_period = MONTH
def formula_2015_07_01(individu, period, parameters):
prestations = parameters(period).prestations
al = individu.famille('aide_logement_montant', period) # montant allocs logement de la famille
mva_montant = prestations.minima_sociaux.aah.mva
return mva_montant * (al > 0)
class pch(Variable):
entity = Individu
value_type = float
label = u"Prestation de compensation du handicap"
definition_period = MONTH
|
agpl-3.0
|
[
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
1551,
329,
7101,
63,
4391,
554,
14,
1238,
14,
1095,
492,
627,
199,
199,
504,
2680,
492,
2197,
772,
199,
199,
3,
820,
5741,
70,
5741,
10056,
1335,
2302,
328,
19658,
446,
5495,
477,
1127,
308,
5741,
895,
390,
5741,
880,
559,
1895,
199,
3,
199,
3,
8281,
491,
24,
2025,
13,
17,
1182,
1695,
2025,
13,
24,
199,
3,
4178,
921,
1544,
14,
4170,
692,
31331,
14,
71,
810,
86,
14,
4391,
15,
27054,
335,
3034,
14,
1117,
27,
74,
1730,
344,
29,
16,
37,
22,
9111,
2192,
14626,
33,
20,
34,
17,
1149,
24,
36,
18,
38,
24,
14138,
1229,
33,
17,
33,
1020,
35,
14,
683,
9783,
4391,
1276,
83,
63,
17,
31,
344,
8660,
6166,
29,
906,
11092,
1028,
33,
993,
1690,
1079,
975,
3129,
6,
7504,
13999,
266,
29,
906,
20072,
2472,
993,
1690,
26010,
11370,
6,
602,
13999,
266,
29,
12682,
31720,
199,
3,
199,
3,
8281,
820,
24,
2025,
13,
17,
1182,
1695,
2025,
13,
25,
199,
3,
4178,
921,
1544,
14,
4170,
692,
31331,
14,
71,
810,
86,
14,
4391,
15,
27054,
335,
3034,
14,
1117,
27,
74,
1730,
344,
29,
16,
37,
22,
9111,
2192,
14626,
33,
20,
34,
17,
1149,
24,
36,
18,
38,
24,
14138,
1229,
33,
17,
33,
1020,
35,
14,
683,
9783,
4391,
1276,
83,
63,
17,
31,
344,
8660,
6166,
29,
906,
11092,
1028,
33,
993,
1690,
1079,
10680,
6,
7504,
13999,
266,
29,
906,
20072,
2472,
993,
1690,
26010,
11370,
6,
602,
13999,
266,
29,
1797,
2835,
9523,
199,
3,
199,
3,
8281,
577,
24,
2025,
13,
17,
1182,
1695,
2025,
13,
845,
199,
3,
4178,
921,
1544,
14,
4170,
692,
31331,
14,
71,
810,
86,
14,
4391,
15,
27054,
335,
3034,
14,
1117,
27,
74,
1730,
344,
29,
1046,
2819,
1555,
35,
15986,
34,
19,
12500,
2635,
1400,
33,
16,
11156,
1299,
2276,
29929,
20598,
14,
683,
9783,
4391,
1703,
83,
63,
17,
31,
344,
8660,
6166,
29,
906,
11092,
1028,
33,
993,
1690,
32689,
3129,
6,
7504,
13999,
266,
29,
906,
20072,
2472,
993,
1690,
26010,
11370,
6,
602,
13999,
266,
29,
1797,
11369,
2192,
421,
199,
533,
282,
11326,
63,
602,
63,
271,
7911,
63,
6559,
285,
2247,
425,
8,
2773,
304,
272,
574,
63,
466,
275,
1434,
272,
849,
63,
585,
275,
1434,
14,
988,
272,
1768,
275,
399,
2,
7833,
1434,
477,
366,
5741,
7911,
366,
7,
6559,
9912,
5741,
1754,
2,
272,
4642,
275,
1010,
14715,
85,
272,
5492,
63,
5191,
275,
603,
615,
2080,
421,
199,
533,
282,
11326,
63,
602,
63,
271,
7911,
63,
526,
681,
6910,
19914,
8,
2773,
304,
272,
574,
63,
466,
275,
1434,
272,
849,
63,
585,
275,
1434,
14,
988,
272,
1768,
275,
399,
2,
7833,
1434,
477,
366,
5741,
7911,
366,
7,
526,
681,
6910,
19914,
2,
272,
4642,
275,
1010,
14715,
85,
272,
5492,
63,
5191,
275,
603,
615,
2080,
421,
199,
533,
282,
11326,
63,
1095,
63,
753,
616,
83,
8,
2773,
304,
272,
574,
63,
466,
275,
2069,
272,
1768,
275,
399,
2,
1563,
295,
385,
616,
83,
477,
634,
7,
14940,
1503,
348,
266,
394,
290,
328,
2874,
5741,
2,
272,
4642,
275,
481,
455,
17142,
272,
5492,
63,
5191,
275,
603,
615,
2080,
339,
347,
15723,
8,
18493,
17142,
12,
6247,
12,
2633,
304,
267,
4179,
275,
2633,
8,
5191,
9,
398,
477,
1237,
271,
300,
63,
287,
63,
645,
3804,
266,
275,
21450,
17142,
14,
271,
1237,
271,
300,
360,
6327,
65,
3621,
63,
3236,
736,
461,
297,
6247,
9,
690,
378,
398,
347,
465,
338,
386,
266,
63,
388,
10153,
8,
264,
1856,
527,
63,
388,
10153,
304,
288,
372,
378,
14,
25,
627,
334,
17,
446,
378,
14,
18,
9,
627,
295,
1856,
527,
63,
388,
10153,
398,
347,
465,
338,
386,
266,
63,
264,
1856,
85,
63,
645,
3804,
266,
63,
271,
1237,
271,
300,
8,
264,
1856,
527,
63,
271,
1237,
271,
300,
304,
288,
4383,
530,
63,
3289,
337,
63,
1189,
13086,
275,
3144,
627,
4179,
14,
331,
1086,
679,
14,
2268,
14,
3300,
530,
63,
72,
63,
66,
627,
4179,
14,
331,
1086,
679,
14,
2268,
14,
4994,
63,
426,
608,
63,
1239,
86,
1054,
63,
278,
561,
13086,
288,
7115,
595,
17,
275,
1748,
2531,
16,
14,
19,
627,
4383,
530,
63,
3289,
337,
63,
1189,
13086,
12,
295,
1856,
527,
63,
271,
1237,
271,
300,
9,
288,
7115,
595,
18,
275,
295,
1856,
527,
63,
271,
1237,
271,
300,
446,
7115,
595,
17,
288,
372,
334,
17,
446,
378,
14,
24,
9,
627,
7115,
595,
17,
435,
334,
17,
446,
378,
14,
20,
9,
627,
7115,
595,
18,
398,
347,
1300,
63,
753,
616,
63,
2579,
63,
12263,
837,
288,
7795,
63,
6352,
63,
16745,
275,
6247,
14,
2246,
63,
4482,
14,
928,
14,
5191,
360,
4482,
297,
650,
680,
2743,
2801,
19,
9,
288,
1300,
63,
753,
616,
63,
645,
3804,
266,
63,
271,
1237,
271,
300,
275,
21450,
17142,
14,
271,
1237,
271,
300,
360,
2158,
72,
63,
1095,
63,
753,
616,
83,
63,
645,
3804,
266,
63,
2579,
63,
599,
278,
816,
352,
274,
297,
6247,
9,
446,
21450,
17142,
14,
271,
1237,
271,
300,
360,
2158,
72,
63,
1095,
63,
753,
616,
83,
63,
645,
3804,
266,
63,
77,
1638,
16913,
63,
496,
266,
303,
297,
7795,
63,
6352,
63,
16745,
12,
1511,
275,
359,
9732,
566,
288,
1300,
63,
753,
616,
63,
72,
1384,
63,
645,
3804,
266,
63,
271,
1237,
271,
300,
275,
21450,
17142,
14,
271,
1237,
271,
300,
360,
2158,
72,
63,
1095,
63,
753,
616,
83,
63,
72,
1384,
63,
645,
3804,
266,
63,
2579,
63,
599,
278,
816,
352,
274,
297,
6247,
9,
435,
21450,
17142,
14,
271,
1237,
271,
300,
360,
2158,
72,
63,
1095,
63,
753,
616,
83,
63,
645,
3804,
266,
63,
77,
1638,
16913,
63,
496,
266,
303,
297,
7795,
63,
6352,
63,
16745,
12,
1511,
275,
359,
9732,
566,
288,
1300,
63,
753,
616,
63,
271,
1237,
271,
300,
275,
465,
338,
386,
266,
63,
264,
1856,
85,
63,
645,
3804,
266,
63,
271,
1237
] |
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
1551,
329,
7101,
63,
4391,
554,
14,
1238,
14,
1095,
492,
627,
199,
199,
504,
2680,
492,
2197,
772,
199,
199,
3,
820,
5741,
70,
5741,
10056,
1335,
2302,
328,
19658,
446,
5495,
477,
1127,
308,
5741,
895,
390,
5741,
880,
559,
1895,
199,
3,
199,
3,
8281,
491,
24,
2025,
13,
17,
1182,
1695,
2025,
13,
24,
199,
3,
4178,
921,
1544,
14,
4170,
692,
31331,
14,
71,
810,
86,
14,
4391,
15,
27054,
335,
3034,
14,
1117,
27,
74,
1730,
344,
29,
16,
37,
22,
9111,
2192,
14626,
33,
20,
34,
17,
1149,
24,
36,
18,
38,
24,
14138,
1229,
33,
17,
33,
1020,
35,
14,
683,
9783,
4391,
1276,
83,
63,
17,
31,
344,
8660,
6166,
29,
906,
11092,
1028,
33,
993,
1690,
1079,
975,
3129,
6,
7504,
13999,
266,
29,
906,
20072,
2472,
993,
1690,
26010,
11370,
6,
602,
13999,
266,
29,
12682,
31720,
199,
3,
199,
3,
8281,
820,
24,
2025,
13,
17,
1182,
1695,
2025,
13,
25,
199,
3,
4178,
921,
1544,
14,
4170,
692,
31331,
14,
71,
810,
86,
14,
4391,
15,
27054,
335,
3034,
14,
1117,
27,
74,
1730,
344,
29,
16,
37,
22,
9111,
2192,
14626,
33,
20,
34,
17,
1149,
24,
36,
18,
38,
24,
14138,
1229,
33,
17,
33,
1020,
35,
14,
683,
9783,
4391,
1276,
83,
63,
17,
31,
344,
8660,
6166,
29,
906,
11092,
1028,
33,
993,
1690,
1079,
10680,
6,
7504,
13999,
266,
29,
906,
20072,
2472,
993,
1690,
26010,
11370,
6,
602,
13999,
266,
29,
1797,
2835,
9523,
199,
3,
199,
3,
8281,
577,
24,
2025,
13,
17,
1182,
1695,
2025,
13,
845,
199,
3,
4178,
921,
1544,
14,
4170,
692,
31331,
14,
71,
810,
86,
14,
4391,
15,
27054,
335,
3034,
14,
1117,
27,
74,
1730,
344,
29,
1046,
2819,
1555,
35,
15986,
34,
19,
12500,
2635,
1400,
33,
16,
11156,
1299,
2276,
29929,
20598,
14,
683,
9783,
4391,
1703,
83,
63,
17,
31,
344,
8660,
6166,
29,
906,
11092,
1028,
33,
993,
1690,
32689,
3129,
6,
7504,
13999,
266,
29,
906,
20072,
2472,
993,
1690,
26010,
11370,
6,
602,
13999,
266,
29,
1797,
11369,
2192,
421,
199,
533,
282,
11326,
63,
602,
63,
271,
7911,
63,
6559,
285,
2247,
425,
8,
2773,
304,
272,
574,
63,
466,
275,
1434,
272,
849,
63,
585,
275,
1434,
14,
988,
272,
1768,
275,
399,
2,
7833,
1434,
477,
366,
5741,
7911,
366,
7,
6559,
9912,
5741,
1754,
2,
272,
4642,
275,
1010,
14715,
85,
272,
5492,
63,
5191,
275,
603,
615,
2080,
421,
199,
533,
282,
11326,
63,
602,
63,
271,
7911,
63,
526,
681,
6910,
19914,
8,
2773,
304,
272,
574,
63,
466,
275,
1434,
272,
849,
63,
585,
275,
1434,
14,
988,
272,
1768,
275,
399,
2,
7833,
1434,
477,
366,
5741,
7911,
366,
7,
526,
681,
6910,
19914,
2,
272,
4642,
275,
1010,
14715,
85,
272,
5492,
63,
5191,
275,
603,
615,
2080,
421,
199,
533,
282,
11326,
63,
1095,
63,
753,
616,
83,
8,
2773,
304,
272,
574,
63,
466,
275,
2069,
272,
1768,
275,
399,
2,
1563,
295,
385,
616,
83,
477,
634,
7,
14940,
1503,
348,
266,
394,
290,
328,
2874,
5741,
2,
272,
4642,
275,
481,
455,
17142,
272,
5492,
63,
5191,
275,
603,
615,
2080,
339,
347,
15723,
8,
18493,
17142,
12,
6247,
12,
2633,
304,
267,
4179,
275,
2633,
8,
5191,
9,
398,
477,
1237,
271,
300,
63,
287,
63,
645,
3804,
266,
275,
21450,
17142,
14,
271,
1237,
271,
300,
360,
6327,
65,
3621,
63,
3236,
736,
461,
297,
6247,
9,
690,
378,
398,
347,
465,
338,
386,
266,
63,
388,
10153,
8,
264,
1856,
527,
63,
388,
10153,
304,
288,
372,
378,
14,
25,
627,
334,
17,
446,
378,
14,
18,
9,
627,
295,
1856,
527,
63,
388,
10153,
398,
347,
465,
338,
386,
266,
63,
264,
1856,
85,
63,
645,
3804,
266,
63,
271,
1237,
271,
300,
8,
264,
1856,
527,
63,
271,
1237,
271,
300,
304,
288,
4383,
530,
63,
3289,
337,
63,
1189,
13086,
275,
3144,
627,
4179,
14,
331,
1086,
679,
14,
2268,
14,
3300,
530,
63,
72,
63,
66,
627,
4179,
14,
331,
1086,
679,
14,
2268,
14,
4994,
63,
426,
608,
63,
1239,
86,
1054,
63,
278,
561,
13086,
288,
7115,
595,
17,
275,
1748,
2531,
16,
14,
19,
627,
4383,
530,
63,
3289,
337,
63,
1189,
13086,
12,
295,
1856,
527,
63,
271,
1237,
271,
300,
9,
288,
7115,
595,
18,
275,
295,
1856,
527,
63,
271,
1237,
271,
300,
446,
7115,
595,
17,
288,
372,
334,
17,
446,
378,
14,
24,
9,
627,
7115,
595,
17,
435,
334,
17,
446,
378,
14,
20,
9,
627,
7115,
595,
18,
398,
347,
1300,
63,
753,
616,
63,
2579,
63,
12263,
837,
288,
7795,
63,
6352,
63,
16745,
275,
6247,
14,
2246,
63,
4482,
14,
928,
14,
5191,
360,
4482,
297,
650,
680,
2743,
2801,
19,
9,
288,
1300,
63,
753,
616,
63,
645,
3804,
266,
63,
271,
1237,
271,
300,
275,
21450,
17142,
14,
271,
1237,
271,
300,
360,
2158,
72,
63,
1095,
63,
753,
616,
83,
63,
645,
3804,
266,
63,
2579,
63,
599,
278,
816,
352,
274,
297,
6247,
9,
446,
21450,
17142,
14,
271,
1237,
271,
300,
360,
2158,
72,
63,
1095,
63,
753,
616,
83,
63,
645,
3804,
266,
63,
77,
1638,
16913,
63,
496,
266,
303,
297,
7795,
63,
6352,
63,
16745,
12,
1511,
275,
359,
9732,
566,
288,
1300,
63,
753,
616,
63,
72,
1384,
63,
645,
3804,
266,
63,
271,
1237,
271,
300,
275,
21450,
17142,
14,
271,
1237,
271,
300,
360,
2158,
72,
63,
1095,
63,
753,
616,
83,
63,
72,
1384,
63,
645,
3804,
266,
63,
2579,
63,
599,
278,
816,
352,
274,
297,
6247,
9,
435,
21450,
17142,
14,
271,
1237,
271,
300,
360,
2158,
72,
63,
1095,
63,
753,
616,
83,
63,
645,
3804,
266,
63,
77,
1638,
16913,
63,
496,
266,
303,
297,
7795,
63,
6352,
63,
16745,
12,
1511,
275,
359,
9732,
566,
288,
1300,
63,
753,
616,
63,
271,
1237,
271,
300,
275,
465,
338,
386,
266,
63,
264,
1856,
85,
63,
645,
3804,
266,
63,
271,
1237,
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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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
] |
Meriipu/quodlibet
|
quodlibet/session/_xsmp.py
|
2
|
9125
|
# Copyright 2018 Christoph Reiter
#
# 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.
import enum
import ctypes
from gi.repository import GLib, GObject
try:
h = ctypes.cdll.LoadLibrary("libSM.so.6")
except OSError as e:
raise ImportError(e)
@ctypes.POINTER
class SmcConn(ctypes.Structure):
pass
SmPointer = ctypes.c_void_p
Bool = ctypes.c_int
SmcSaveYourselfProc = ctypes.CFUNCTYPE(
None, SmcConn, SmPointer, ctypes.c_int, Bool, ctypes.c_int, Bool)
SmcDieProc = ctypes.CFUNCTYPE(None, SmcConn, SmPointer)
SmcSaveCompleteProc = ctypes.CFUNCTYPE(None, SmcConn, SmPointer)
SmcShutdownCancelledProc = ctypes.CFUNCTYPE(None, SmcConn, SmPointer)
class save_yourself(ctypes.Structure):
_fields_ = [
("callback", SmcSaveYourselfProc),
("client_data", SmPointer),
]
class die(ctypes.Structure):
_fields_ = [
("callback", SmcDieProc),
("client_data", SmPointer),
]
class save_complete(ctypes.Structure):
_fields_ = [
("callback", SmcSaveCompleteProc),
("client_data", SmPointer),
]
class shutdown_cancelled(ctypes.Structure):
_fields_ = [
("callback", SmcShutdownCancelledProc),
("client_data", SmPointer),
]
class SmcCallbacks(ctypes.Structure):
_fields_ = [
("save_yourself", save_yourself),
("die", die),
("save_complete", save_complete),
("shutdown_cancelled", shutdown_cancelled),
]
SmProtoMajor = 1
SmProtoMinor = 0
SmcSaveYourselfProcMask = 1 << 0
SmcDieProcMask = 1 << 1
SmcSaveCompleteProcMask = 1 << 2
SmcShutdownCancelledProcMask = 1 << 3
SmcCloseStatus = ctypes.c_int
SmcClosedNow = 0
SmcClosedASAP = 1
SmcConnectionInUse = 2
SmcOpenConnection = h.SmcOpenConnection
SmcOpenConnection.argtypes = [
ctypes.c_char_p, SmPointer, ctypes.c_int, ctypes.c_int, ctypes.c_ulong,
ctypes.POINTER(SmcCallbacks), ctypes.c_char_p,
ctypes.POINTER(ctypes.c_char_p), ctypes.c_int, ctypes.c_char_p]
SmcOpenConnection.restype = SmcConn
SmcCloseConnection = h.SmcCloseConnection
SmcCloseConnection.argtypes = [
SmcConn, ctypes.c_int, ctypes.POINTER(ctypes.c_char_p)]
SmcCloseConnection.restype = SmcCloseStatus
SmcSaveYourselfDone = h.SmcSaveYourselfDone
SmcSaveYourselfDone.argtypes = [SmcConn, Bool]
SmcSaveYourselfDone.restype = None
@ctypes.POINTER
class IceConn(ctypes.Structure):
pass
IcePointer = ctypes.c_void_p
IceWatchProc = ctypes.CFUNCTYPE(
None, IceConn, IcePointer, Bool, ctypes.POINTER(IcePointer))
Status = ctypes.c_int
IceAddConnectionWatch = h.IceAddConnectionWatch
IceAddConnectionWatch.argtypes = [IceWatchProc, IcePointer]
IceAddConnectionWatch.restype = Status
IceRemoveConnectionWatch = h.IceRemoveConnectionWatch
IceRemoveConnectionWatch.argtypes = [IceWatchProc, IcePointer]
IceRemoveConnectionWatch.restype = None
IceConnectionNumber = h.IceConnectionNumber
IceConnectionNumber.argtypes = [IceConn]
IceConnectionNumber.restype = ctypes.c_int
IceProcessMessagesStatus = ctypes.c_int
IceProcessMessagesSuccess = 0
IceProcessMessagesIOError = 1
IceProcessMessagesConnectionClosed = 2
@ctypes.POINTER
class FIXMEPtr(ctypes.Structure):
pass
IceProcessMessages = h.IceProcessMessages
IceProcessMessages.argtypes = [IceConn, FIXMEPtr, FIXMEPtr]
IceProcessMessages.restype = IceProcessMessagesStatus
IceSetShutdownNegotiation = h.IceSetShutdownNegotiation
IceSetShutdownNegotiation.argtypes = [IceConn, Bool]
IceSetShutdownNegotiation.restype = None
IceCloseStatus = ctypes.c_int
IceCloseConnection = h.IceCloseConnection
IceCloseConnection.argtypes = [IceConn]
IceCloseConnection.restype = IceCloseStatus
class SaveType(enum.IntEnum):
GLOBAL = 0
LOCAL = 1
BOTH = 2
class InteractStyle(enum.IntEnum):
NONE = 0
ERRORS = 1
ANY = 2
class XSMPError(Exception):
pass
class XSMPSource:
"""Dispatches SM messages in the glib mainloop"""
def __init__(self):
self._watch_id = None
self._watch_proc = None
def open(self):
if self._watch_proc is not None:
raise XSMPError("already open")
@IceWatchProc
def watch_proc(conn, client_data, opening, watch_data):
if opening:
fd = IceConnectionNumber(conn)
channel = GLib.IOChannel.unix_new(fd)
self._watch_id = GLib.io_add_watch(
channel,
GLib.PRIORITY_DEFAULT,
(GLib.IOCondition.ERR | GLib.IOCondition.HUP |
GLib.IOCondition.IN),
self._process_func, conn)
else:
if self._watch_id is not None:
GObject.source_remove(self._watch_id)
self._watch_id = None
self._watch_proc = watch_proc
status = IceAddConnectionWatch(watch_proc, None)
if status == 0:
raise XSMPError(
"IceAddConnectionWatch failed with %d" % status)
def close(self):
if self._watch_proc is not None:
IceRemoveConnectionWatch(self._watch_proc, None)
self._watch_proc = None
if self._watch_id is not None:
GObject.source_remove(self._watch_id)
self._watch_id = None
def _process_func(self, channel, condition, conn):
status = IceProcessMessages(conn, None, None)
if status != IceProcessMessagesSuccess:
if status != IceProcessMessagesConnectionClosed:
IceCloseConnection(conn)
self._watch_id = None
return False
return True
class XSMPClient(GObject.Object):
__gsignals__ = {
"save-yourself":
(GObject.SignalFlags.RUN_LAST, None,
(object, object, object, object)),
"die": (GObject.SignalFlags.RUN_LAST, None, tuple()),
"save-complete": (GObject.SignalFlags.RUN_LAST, None, tuple()),
"shutdown-cancelled": (GObject.SignalFlags.RUN_LAST, None, tuple()),
}
def __init__(self):
super().__init__()
self._source = None
self._callbacks = SmcCallbacks()
self._conn = None
self._id = None
def wrap_cb(func_type, cb):
def c_callback(*args):
return cb(self, func_type, *args[2:])
return func_type(c_callback)
self._callbacks.save_yourself.callback = wrap_cb(
SmcSaveYourselfProc, self._on_save_yourself)
self._callbacks.die.callback = wrap_cb(SmcDieProc, self._on_die)
self._callbacks.save_complete.callback = wrap_cb(
SmcSaveCompleteProc, self._on_save_complete)
self._callbacks.shutdown_cancelled.callback = wrap_cb(
SmcShutdownCancelledProc, self._on_shutdown_cancelled)
def _on_save_yourself(self, conn, client_data, save_type, shutdown,
interact_style, fast):
self.emit(
"save-yourself", SaveType(save_type), bool(shutdown),
InteractStyle(interact_style), bool(fast))
def _on_die(self, conn, client_data):
self.emit("die")
def _on_save_complete(self, conn, client_data):
self.emit("save-complete")
def _on_shutdown_cancelled(self, conn, client_data):
self.emit("shutdown-cancelled")
@property
def client_id(self):
if self._conn is None:
raise XSMPError("connection closed")
return self._id
def open(self):
if self._conn is not None:
raise XSMPError("connection already open")
self._source = XSMPSource()
self._source.open()
error_string = ctypes.create_string_buffer(250)
id_ = ctypes.c_char_p()
self._conn = SmcOpenConnection(
None, None, SmProtoMajor, SmProtoMinor,
(SmcDieProcMask | SmcSaveCompleteProcMask |
SmcSaveYourselfProcMask | SmcShutdownCancelledProcMask),
ctypes.byref(self._callbacks), None, ctypes.byref(id_),
len(error_string), error_string)
# null ptr still returns an object, but its falsy
if not self._conn:
self._conn = None
if self._conn is None:
self._conn = None
self._source.close()
self._source = None
raise XSMPError("open failed: %r" %
error_string.value.decode("utf-8"))
# FIXME: id_ should be freed with free()
self._id = id_.value.decode("utf-8")
def save_yourself_done(self, success):
if self._conn is None:
raise XSMPError("connection closed")
SmcSaveYourselfDone(self._conn, success)
def close(self):
if self._conn is not None:
SmcCloseConnection(self._conn, 0, None)
self._conn = None
if self._source is not None:
self._source.close()
self._source = None
def __del__(self):
self.close()
self._callbacks = None
|
gpl-2.0
|
[
3,
1898,
14894,
2799,
322,
2379,
72,
799,
1661,
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,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
199,
646,
4952,
199,
646,
5577,
199,
199,
504,
18895,
14,
8421,
492,
3563,
1892,
12,
31264,
421,
199,
893,
26,
272,
394,
275,
5577,
14,
2866,
914,
14,
6200,
7424,
480,
773,
4029,
14,
1152,
14,
22,
531,
199,
2590,
6440,
465,
325,
26,
272,
746,
3545,
8,
69,
9,
421,
199,
32,
9798,
14,
11260,
199,
533,
428,
5466,
6805,
8,
9798,
14,
10766,
304,
272,
986,
199,
199,
16782,
12190,
275,
5577,
14,
67,
63,
1647,
63,
80,
199,
10349,
275,
5577,
14,
67,
63,
442,
199,
199,
51,
5466,
8229,
14398,
277,
15019,
275,
5577,
14,
5487,
10637,
8,
272,
488,
12,
428,
5466,
6805,
12,
16392,
12190,
12,
5577,
14,
67,
63,
442,
12,
19287,
12,
5577,
14,
67,
63,
442,
12,
19287,
9,
199,
51,
5466,
1341,
69,
15019,
275,
5577,
14,
5487,
10637,
8,
403,
12,
428,
5466,
6805,
12,
16392,
12190,
9,
199,
51,
5466,
8229,
14175,
15019,
275,
5577,
14,
5487,
10637,
8,
403,
12,
428,
5466,
6805,
12,
16392,
12190,
9,
199,
51,
5466,
20043,
22127,
15019,
275,
5577,
14,
5487,
10637,
8,
403,
12,
428,
5466,
6805,
12,
16392,
12190,
9,
421,
199,
533,
3354,
63,
12695,
277,
8,
9798,
14,
10766,
304,
272,
485,
955,
63,
275,
359,
267,
1689,
3058,
401,
428,
5466,
8229,
14398,
277,
15019,
395,
267,
1689,
1258,
63,
576,
401,
16392,
12190,
395,
272,
1622,
421,
199,
533,
18833,
8,
9798,
14,
10766,
304,
272,
485,
955,
63,
275,
359,
267,
1689,
3058,
401,
428,
5466,
1341,
69,
15019,
395,
267,
1689,
1258,
63,
576,
401,
16392,
12190,
395,
272,
1622,
421,
199,
533,
3354,
63,
4883,
8,
9798,
14,
10766,
304,
272,
485,
955,
63,
275,
359,
267,
1689,
3058,
401,
428,
5466,
8229,
14175,
15019,
395,
267,
1689,
1258,
63,
576,
401,
16392,
12190,
395,
272,
1622,
421,
199,
533,
12842,
63,
21924,
8,
9798,
14,
10766,
304,
272,
485,
955,
63,
275,
359,
267,
1689,
3058,
401,
428,
5466,
20043,
22127,
15019,
395,
267,
1689,
1258,
63,
576,
401,
16392,
12190,
395,
272,
1622,
421,
199,
533,
428,
5466,
17958,
8,
9798,
14,
10766,
304,
272,
485,
955,
63,
275,
359,
267,
1689,
2117,
63,
12695,
277,
401,
3354,
63,
12695,
277,
395,
267,
1689,
15130,
401,
18833,
395,
267,
1689,
2117,
63,
4883,
401,
3354,
63,
4883,
395,
267,
1689,
8831,
63,
21924,
401,
12842,
63,
21924,
395,
272,
1622,
199,
199,
16782,
8548,
21657,
275,
413,
199,
16782,
8548,
23094,
275,
378,
199,
199,
51,
5466,
8229,
14398,
277,
15019,
5144,
275,
413,
5213,
378,
199,
51,
5466,
1341,
69,
15019,
5144,
275,
413,
5213,
413,
199,
51,
5466,
8229,
14175,
15019,
5144,
275,
413,
5213,
499,
199,
51,
5466,
20043,
22127,
15019,
5144,
275,
413,
5213,
650,
199,
199,
51,
5466,
4724,
3694,
275,
5577,
14,
67,
63,
442,
199,
51,
5466,
15190,
14351,
275,
378,
199,
51,
5466,
15190,
1179,
1282,
275,
413,
199,
51,
5466,
3225,
31425,
275,
499,
199,
199,
51,
5466,
4299,
3225,
275,
394,
14,
51,
5466,
4299,
3225,
199,
51,
5466,
4299,
3225,
14,
10025,
275,
359,
272,
5577,
14,
67,
63,
1560,
63,
80,
12,
16392,
12190,
12,
5577,
14,
67,
63,
442,
12,
5577,
14,
67,
63,
442,
12,
5577,
14,
67,
63,
15688,
12,
272,
5577,
14,
11260,
8,
51,
5466,
17958,
395,
5577,
14,
67,
63,
1560,
63,
80,
12,
272,
5577,
14,
11260,
8,
9798,
14,
67,
63,
1560,
63,
80,
395,
5577,
14,
67,
63,
442,
12,
5577,
14,
67,
63,
1560,
63,
80,
61,
199,
51,
5466,
4299,
3225,
14,
9990,
275,
428,
5466,
6805,
199,
199,
51,
5466,
4724,
3225,
275,
394,
14,
51,
5466,
4724,
3225,
199,
51,
5466,
4724,
3225,
14,
10025,
275,
359,
272,
428,
5466,
6805,
12,
5577,
14,
67,
63,
442,
12,
5577,
14,
11260,
8,
9798,
14,
67,
63,
1560,
63,
80,
1874,
199,
51,
5466,
4724,
3225,
14,
9990,
275,
428,
5466,
4724,
3694,
199,
199,
51,
5466,
8229,
14398,
277,
10759,
275,
394,
14,
51,
5466,
8229,
14398,
277,
10759,
199,
51,
5466,
8229,
14398,
277,
10759,
14,
10025,
275,
359,
51,
5466,
6805,
12,
19287,
61,
199,
51,
5466,
8229,
14398,
277,
10759,
14,
9990,
275,
488,
421,
199,
32,
9798,
14,
11260,
199,
533,
473,
301,
6805,
8,
9798,
14,
10766,
304,
272,
986,
199,
199,
41,
301,
12190,
275,
5577,
14,
67,
63,
1647,
63,
80,
199,
41,
301,
13978,
15019,
275,
5577,
14,
5487,
10637,
8,
272,
488,
12,
473,
301,
6805,
12,
473,
301,
12190,
12,
19287,
12,
5577,
14,
11260,
8,
41,
301,
12190,
430,
199,
199,
3694,
275,
5577,
14,
67,
63,
442,
199,
199,
41,
301,
1123,
3225,
13978,
275,
394,
14,
41,
301,
1123,
3225,
13978,
199,
41,
301,
1123,
3225,
13978,
14,
10025,
275,
359,
41,
301,
13978,
15019,
12,
473,
301,
12190,
61,
199,
41,
301,
1123,
3225,
13978,
14,
9990,
275,
9795,
199,
199,
41,
301,
5587,
3225,
13978,
275,
394,
14,
41,
301,
5587,
3225,
13978,
199,
41,
301,
5587,
3225,
13978,
14,
10025,
275,
359,
41,
301,
13978,
15019,
12,
473,
301,
12190,
61,
199,
41,
301,
5587,
3225,
13978,
14,
9990,
275,
488,
199,
199,
41,
301,
3225,
3259,
275,
394,
14,
41,
301,
3225,
3259,
199,
41,
301,
3225,
3259,
14,
10025,
275,
359,
41,
301,
6805,
61,
199,
41,
301,
3225,
3259,
14,
9990,
275,
5577,
14,
67,
63,
442,
199,
199,
41,
301,
3498,
14508,
3694,
275,
5577,
14,
67,
63,
442,
199,
41,
301,
3498,
14508,
8300,
275,
378,
199,
41,
301,
3498,
14508,
13760,
275,
413,
199,
41,
301,
3498,
14508,
3225,
15190,
275,
499,
421,
199,
32,
9798,
14,
11260,
199,
533,
7600,
2115,
8,
9798,
14,
10766,
304
] |
[
1898,
14894,
2799,
322,
2379,
72,
799,
1661,
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,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
199,
646,
4952,
199,
646,
5577,
199,
199,
504,
18895,
14,
8421,
492,
3563,
1892,
12,
31264,
421,
199,
893,
26,
272,
394,
275,
5577,
14,
2866,
914,
14,
6200,
7424,
480,
773,
4029,
14,
1152,
14,
22,
531,
199,
2590,
6440,
465,
325,
26,
272,
746,
3545,
8,
69,
9,
421,
199,
32,
9798,
14,
11260,
199,
533,
428,
5466,
6805,
8,
9798,
14,
10766,
304,
272,
986,
199,
199,
16782,
12190,
275,
5577,
14,
67,
63,
1647,
63,
80,
199,
10349,
275,
5577,
14,
67,
63,
442,
199,
199,
51,
5466,
8229,
14398,
277,
15019,
275,
5577,
14,
5487,
10637,
8,
272,
488,
12,
428,
5466,
6805,
12,
16392,
12190,
12,
5577,
14,
67,
63,
442,
12,
19287,
12,
5577,
14,
67,
63,
442,
12,
19287,
9,
199,
51,
5466,
1341,
69,
15019,
275,
5577,
14,
5487,
10637,
8,
403,
12,
428,
5466,
6805,
12,
16392,
12190,
9,
199,
51,
5466,
8229,
14175,
15019,
275,
5577,
14,
5487,
10637,
8,
403,
12,
428,
5466,
6805,
12,
16392,
12190,
9,
199,
51,
5466,
20043,
22127,
15019,
275,
5577,
14,
5487,
10637,
8,
403,
12,
428,
5466,
6805,
12,
16392,
12190,
9,
421,
199,
533,
3354,
63,
12695,
277,
8,
9798,
14,
10766,
304,
272,
485,
955,
63,
275,
359,
267,
1689,
3058,
401,
428,
5466,
8229,
14398,
277,
15019,
395,
267,
1689,
1258,
63,
576,
401,
16392,
12190,
395,
272,
1622,
421,
199,
533,
18833,
8,
9798,
14,
10766,
304,
272,
485,
955,
63,
275,
359,
267,
1689,
3058,
401,
428,
5466,
1341,
69,
15019,
395,
267,
1689,
1258,
63,
576,
401,
16392,
12190,
395,
272,
1622,
421,
199,
533,
3354,
63,
4883,
8,
9798,
14,
10766,
304,
272,
485,
955,
63,
275,
359,
267,
1689,
3058,
401,
428,
5466,
8229,
14175,
15019,
395,
267,
1689,
1258,
63,
576,
401,
16392,
12190,
395,
272,
1622,
421,
199,
533,
12842,
63,
21924,
8,
9798,
14,
10766,
304,
272,
485,
955,
63,
275,
359,
267,
1689,
3058,
401,
428,
5466,
20043,
22127,
15019,
395,
267,
1689,
1258,
63,
576,
401,
16392,
12190,
395,
272,
1622,
421,
199,
533,
428,
5466,
17958,
8,
9798,
14,
10766,
304,
272,
485,
955,
63,
275,
359,
267,
1689,
2117,
63,
12695,
277,
401,
3354,
63,
12695,
277,
395,
267,
1689,
15130,
401,
18833,
395,
267,
1689,
2117,
63,
4883,
401,
3354,
63,
4883,
395,
267,
1689,
8831,
63,
21924,
401,
12842,
63,
21924,
395,
272,
1622,
199,
199,
16782,
8548,
21657,
275,
413,
199,
16782,
8548,
23094,
275,
378,
199,
199,
51,
5466,
8229,
14398,
277,
15019,
5144,
275,
413,
5213,
378,
199,
51,
5466,
1341,
69,
15019,
5144,
275,
413,
5213,
413,
199,
51,
5466,
8229,
14175,
15019,
5144,
275,
413,
5213,
499,
199,
51,
5466,
20043,
22127,
15019,
5144,
275,
413,
5213,
650,
199,
199,
51,
5466,
4724,
3694,
275,
5577,
14,
67,
63,
442,
199,
51,
5466,
15190,
14351,
275,
378,
199,
51,
5466,
15190,
1179,
1282,
275,
413,
199,
51,
5466,
3225,
31425,
275,
499,
199,
199,
51,
5466,
4299,
3225,
275,
394,
14,
51,
5466,
4299,
3225,
199,
51,
5466,
4299,
3225,
14,
10025,
275,
359,
272,
5577,
14,
67,
63,
1560,
63,
80,
12,
16392,
12190,
12,
5577,
14,
67,
63,
442,
12,
5577,
14,
67,
63,
442,
12,
5577,
14,
67,
63,
15688,
12,
272,
5577,
14,
11260,
8,
51,
5466,
17958,
395,
5577,
14,
67,
63,
1560,
63,
80,
12,
272,
5577,
14,
11260,
8,
9798,
14,
67,
63,
1560,
63,
80,
395,
5577,
14,
67,
63,
442,
12,
5577,
14,
67,
63,
1560,
63,
80,
61,
199,
51,
5466,
4299,
3225,
14,
9990,
275,
428,
5466,
6805,
199,
199,
51,
5466,
4724,
3225,
275,
394,
14,
51,
5466,
4724,
3225,
199,
51,
5466,
4724,
3225,
14,
10025,
275,
359,
272,
428,
5466,
6805,
12,
5577,
14,
67,
63,
442,
12,
5577,
14,
11260,
8,
9798,
14,
67,
63,
1560,
63,
80,
1874,
199,
51,
5466,
4724,
3225,
14,
9990,
275,
428,
5466,
4724,
3694,
199,
199,
51,
5466,
8229,
14398,
277,
10759,
275,
394,
14,
51,
5466,
8229,
14398,
277,
10759,
199,
51,
5466,
8229,
14398,
277,
10759,
14,
10025,
275,
359,
51,
5466,
6805,
12,
19287,
61,
199,
51,
5466,
8229,
14398,
277,
10759,
14,
9990,
275,
488,
421,
199,
32,
9798,
14,
11260,
199,
533,
473,
301,
6805,
8,
9798,
14,
10766,
304,
272,
986,
199,
199,
41,
301,
12190,
275,
5577,
14,
67,
63,
1647,
63,
80,
199,
41,
301,
13978,
15019,
275,
5577,
14,
5487,
10637,
8,
272,
488,
12,
473,
301,
6805,
12,
473,
301,
12190,
12,
19287,
12,
5577,
14,
11260,
8,
41,
301,
12190,
430,
199,
199,
3694,
275,
5577,
14,
67,
63,
442,
199,
199,
41,
301,
1123,
3225,
13978,
275,
394,
14,
41,
301,
1123,
3225,
13978,
199,
41,
301,
1123,
3225,
13978,
14,
10025,
275,
359,
41,
301,
13978,
15019,
12,
473,
301,
12190,
61,
199,
41,
301,
1123,
3225,
13978,
14,
9990,
275,
9795,
199,
199,
41,
301,
5587,
3225,
13978,
275,
394,
14,
41,
301,
5587,
3225,
13978,
199,
41,
301,
5587,
3225,
13978,
14,
10025,
275,
359,
41,
301,
13978,
15019,
12,
473,
301,
12190,
61,
199,
41,
301,
5587,
3225,
13978,
14,
9990,
275,
488,
199,
199,
41,
301,
3225,
3259,
275,
394,
14,
41,
301,
3225,
3259,
199,
41,
301,
3225,
3259,
14,
10025,
275,
359,
41,
301,
6805,
61,
199,
41,
301,
3225,
3259,
14,
9990,
275,
5577,
14,
67,
63,
442,
199,
199,
41,
301,
3498,
14508,
3694,
275,
5577,
14,
67,
63,
442,
199,
41,
301,
3498,
14508,
8300,
275,
378,
199,
41,
301,
3498,
14508,
13760,
275,
413,
199,
41,
301,
3498,
14508,
3225,
15190,
275,
499,
421,
199,
32,
9798,
14,
11260,
199,
533,
7600,
2115,
8,
9798,
14,
10766,
304,
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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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
] |
b-kolodziej/cookiecutter-django
|
{{cookiecutter.repo_name}}/{{cookiecutter.repo_name}}/users/tests/test_admin.py
|
264
|
1308
|
from test_plus.test import TestCase
from ..admin import MyUserCreationForm
class TestMyUserCreationForm(TestCase):
def setUp(self):
self.user = self.make_user()
def test_clean_username_success(self):
# Instantiate the form with a new username
form = MyUserCreationForm({
'username': 'alamode',
'password1': '123456',
'password2': '123456',
})
# Run is_valid() to trigger the validation
valid = form.is_valid()
self.assertTrue(valid)
# Run the actual clean_username method
username = form.clean_username()
self.assertEqual('alamode', username)
def test_clean_username_false(self):
# Instantiate the form with the same username as self.user
form = MyUserCreationForm({
'username': self.user.username,
'password1': '123456',
'password2': '123456',
})
# Run is_valid() to trigger the validation, which is going to fail
# because the username is already taken
valid = form.is_valid()
self.assertFalse(valid)
# The form.errors dict should contain a single error called 'username'
self.assertTrue(len(form.errors) == 1)
self.assertTrue('username' in form.errors)
|
bsd-3-clause
|
[
504,
511,
63,
6666,
14,
396,
492,
7640,
199,
199,
504,
2508,
2113,
492,
4932,
1899,
13921,
2821,
421,
199,
533,
1379,
5713,
1899,
13921,
2821,
8,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
751,
275,
291,
14,
1875,
63,
751,
342,
339,
347,
511,
63,
3118,
63,
2473,
63,
3742,
8,
277,
304,
267,
327,
32092,
314,
1824,
543,
282,
892,
3434,
267,
1824,
275,
4932,
1899,
13921,
2821,
2561,
288,
283,
2473,
356,
283,
279,
455,
380,
297,
288,
283,
2060,
17,
356,
283,
19060,
297,
288,
283,
2060,
18,
356,
283,
19060,
297,
267,
3828,
267,
327,
3378,
365,
63,
1078,
342,
370,
6804,
314,
6411,
267,
1686,
275,
1824,
14,
374,
63,
1078,
342,
267,
291,
14,
1815,
8,
1078,
9,
398,
327,
3378,
314,
3503,
3633,
63,
2473,
1083,
267,
3434,
275,
1824,
14,
3118,
63,
2473,
342,
267,
291,
14,
629,
360,
279,
455,
380,
297,
3434,
9,
339,
347,
511,
63,
3118,
63,
2473,
63,
3910,
8,
277,
304,
267,
327,
32092,
314,
1824,
543,
314,
2011,
3434,
465,
291,
14,
751,
267,
1824,
275,
4932,
1899,
13921,
2821,
2561,
288,
283,
2473,
356,
291,
14,
751,
14,
2473,
12,
288,
283,
2060,
17,
356,
283,
19060,
297,
288,
283,
2060,
18,
356,
283,
19060,
297,
267,
3828,
267,
327,
3378,
365,
63,
1078,
342,
370,
6804,
314,
6411,
12,
1314,
365,
9995,
370,
2449,
267,
327,
2952,
314,
3434,
365,
2575,
9394,
267,
1686,
275,
1824,
14,
374,
63,
1078,
342,
267,
291,
14,
3334,
8,
1078,
9,
398,
327,
710,
1824,
14,
2550,
1211,
1077,
1395,
282,
2849,
1125,
2797,
283,
2473,
7,
267,
291,
14,
1815,
8,
552,
8,
964,
14,
2550,
9,
508,
413,
9,
267,
291,
14,
1815,
360,
2473,
7,
315,
1824,
14,
2550,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
511,
63,
6666,
14,
396,
492,
7640,
199,
199,
504,
2508,
2113,
492,
4932,
1899,
13921,
2821,
421,
199,
533,
1379,
5713,
1899,
13921,
2821,
8,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
751,
275,
291,
14,
1875,
63,
751,
342,
339,
347,
511,
63,
3118,
63,
2473,
63,
3742,
8,
277,
304,
267,
327,
32092,
314,
1824,
543,
282,
892,
3434,
267,
1824,
275,
4932,
1899,
13921,
2821,
2561,
288,
283,
2473,
356,
283,
279,
455,
380,
297,
288,
283,
2060,
17,
356,
283,
19060,
297,
288,
283,
2060,
18,
356,
283,
19060,
297,
267,
3828,
267,
327,
3378,
365,
63,
1078,
342,
370,
6804,
314,
6411,
267,
1686,
275,
1824,
14,
374,
63,
1078,
342,
267,
291,
14,
1815,
8,
1078,
9,
398,
327,
3378,
314,
3503,
3633,
63,
2473,
1083,
267,
3434,
275,
1824,
14,
3118,
63,
2473,
342,
267,
291,
14,
629,
360,
279,
455,
380,
297,
3434,
9,
339,
347,
511,
63,
3118,
63,
2473,
63,
3910,
8,
277,
304,
267,
327,
32092,
314,
1824,
543,
314,
2011,
3434,
465,
291,
14,
751,
267,
1824,
275,
4932,
1899,
13921,
2821,
2561,
288,
283,
2473,
356,
291,
14,
751,
14,
2473,
12,
288,
283,
2060,
17,
356,
283,
19060,
297,
288,
283,
2060,
18,
356,
283,
19060,
297,
267,
3828,
267,
327,
3378,
365,
63,
1078,
342,
370,
6804,
314,
6411,
12,
1314,
365,
9995,
370,
2449,
267,
327,
2952,
314,
3434,
365,
2575,
9394,
267,
1686,
275,
1824,
14,
374,
63,
1078,
342,
267,
291,
14,
3334,
8,
1078,
9,
398,
327,
710,
1824,
14,
2550,
1211,
1077,
1395,
282,
2849,
1125,
2797,
283,
2473,
7,
267,
291,
14,
1815,
8,
552,
8,
964,
14,
2550,
9,
508,
413,
9,
267,
291,
14,
1815,
360,
2473,
7,
315,
1824,
14,
2550,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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gmail.com>
# Author: Nick Travers <nickt@squareup.com>
# License: BSD 3 clause (C) 2014
# This is the exact and Barnes-Hut t-SNE implementation. There are other
# modifications of the algorithm:
# * Fast Optimization for t-SNE:
# http://cseweb.ucsd.edu/~lvdmaaten/workshops/nips2010/papers/vandermaaten.pdf
import numpy as np
from scipy import linalg
import scipy.sparse as sp
from scipy.spatial.distance import pdist
from scipy.spatial.distance import squareform
from ..neighbors import BallTree
from ..base import BaseEstimator
from ..utils import check_array
from ..utils import check_random_state
from ..utils.extmath import _ravel
from ..decomposition import RandomizedPCA
from ..metrics.pairwise import pairwise_distances
from . import _utils
from . import _barnes_hut_tsne
from ..utils.fixes import astype
MACHINE_EPSILON = np.finfo(np.double).eps
def _joint_probabilities(distances, desired_perplexity, verbose):
"""Compute joint probabilities p_ij from distances.
Parameters
----------
distances : array, shape (n_samples * (n_samples-1) / 2,)
Distances of samples are stored as condensed matrices, i.e.
we omit the diagonal and duplicate entries and store everything
in a one-dimensional array.
desired_perplexity : float
Desired perplexity of the joint probability distributions.
verbose : int
Verbosity level.
Returns
-------
P : array, shape (n_samples * (n_samples-1) / 2,)
Condensed joint probability matrix.
"""
# Compute conditional probabilities such that they approximately match
# the desired perplexity
distances = astype(distances, np.float32, copy=False)
conditional_P = _utils._binary_search_perplexity(
distances, None, desired_perplexity, verbose)
P = conditional_P + conditional_P.T
sum_P = np.maximum(np.sum(P), MACHINE_EPSILON)
P = np.maximum(squareform(P) / sum_P, MACHINE_EPSILON)
return P
def _joint_probabilities_nn(distances, neighbors, desired_perplexity, verbose):
"""Compute joint probabilities p_ij from distances using just nearest
neighbors.
This method is approximately equal to _joint_probabilities. The latter
is O(N), but limiting the joint probability to nearest neighbors improves
this substantially to O(uN).
Parameters
----------
distances : array, shape (n_samples * (n_samples-1) / 2,)
Distances of samples are stored as condensed matrices, i.e.
we omit the diagonal and duplicate entries and store everything
in a one-dimensional array.
desired_perplexity : float
Desired perplexity of the joint probability distributions.
verbose : int
Verbosity level.
Returns
-------
P : array, shape (n_samples * (n_samples-1) / 2,)
Condensed joint probability matrix.
"""
# Compute conditional probabilities such that they approximately match
# the desired perplexity
distances = astype(distances, np.float32, copy=False)
neighbors = astype(neighbors, np.int64, copy=False)
conditional_P = _utils._binary_search_perplexity(
distances, neighbors, desired_perplexity, verbose)
m = "All probabilities should be finite"
assert np.all(np.isfinite(conditional_P)), m
P = conditional_P + conditional_P.T
sum_P = np.maximum(np.sum(P), MACHINE_EPSILON)
P = np.maximum(squareform(P) / sum_P, MACHINE_EPSILON)
assert np.all(np.abs(P) <= 1.0)
return P
def _kl_divergence(params, P, degrees_of_freedom, n_samples, n_components,
skip_num_points=0):
"""t-SNE objective function: gradient of the KL divergence
of p_ijs and q_ijs and the absolute error.
Parameters
----------
params : array, shape (n_params,)
Unraveled embedding.
P : array, shape (n_samples * (n_samples-1) / 2,)
Condensed joint probability matrix.
degrees_of_freedom : float
Degrees of freedom of the Student's-t distribution.
n_samples : int
Number of samples.
n_components : int
Dimension of the embedded space.
skip_num_points : int (optional, default:0)
This does not compute the gradient for points with indices below
`skip_num_points`. This is useful when computing transforms of new
data where you'd like to keep the old data fixed.
Returns
-------
kl_divergence : float
Kullback-Leibler divergence of p_ij and q_ij.
grad : array, shape (n_params,)
Unraveled gradient of the Kullback-Leibler divergence with respect to
the embedding.
"""
X_embedded = params.reshape(n_samples, n_components)
# Q is a heavy-tailed distribution: Student's t-distribution
n = pdist(X_embedded, "sqeuclidean")
n += 1.
n /= degrees_of_freedom
n **= (degrees_of_freedom + 1.0) / -2.0
Q = np.maximum(n / (2.0 * np.sum(n)), MACHINE_EPSILON)
# Optimization trick below: np.dot(x, y) is faster than
# np.sum(x * y) because it calls BLAS
# Objective: C (Kullback-Leibler divergence of P and Q)
kl_divergence = 2.0 * np.dot(P, np.log(P / Q))
# Gradient: dC/dY
grad = np.ndarray((n_samples, n_components))
PQd = squareform((P - Q) * n)
for i in range(skip_num_points, n_samples):
np.dot(_ravel(PQd[i]), X_embedded[i] - X_embedded, out=grad[i])
grad = grad.ravel()
c = 2.0 * (degrees_of_freedom + 1.0) / degrees_of_freedom
grad *= c
return kl_divergence, grad
def _kl_divergence_error(params, P, neighbors, degrees_of_freedom, n_samples,
n_components):
"""t-SNE objective function: the absolute error of the
KL divergence of p_ijs and q_ijs.
Parameters
----------
params : array, shape (n_params,)
Unraveled embedding.
P : array, shape (n_samples * (n_samples-1) / 2,)
Condensed joint probability matrix.
neighbors : array (n_samples, K)
The neighbors is not actually required to calculate the
divergence, but is here to match the signature of the
gradient function
degrees_of_freedom : float
Degrees of freedom of the Student's-t distribution.
n_samples : int
Number of samples.
n_components : int
Dimension of the embedded space.
Returns
-------
kl_divergence : float
Kullback-Leibler divergence of p_ij and q_ij.
grad : array, shape (n_params,)
Unraveled gradient of the Kullback-Leibler divergence with respect to
the embedding.
"""
X_embedded = params.reshape(n_samples, n_components)
# Q is a heavy-tailed distribution: Student's t-distribution
n = pdist(X_embedded, "sqeuclidean")
n += 1.
n /= degrees_of_freedom
n **= (degrees_of_freedom + 1.0) / -2.0
Q = np.maximum(n / (2.0 * np.sum(n)), MACHINE_EPSILON)
# Optimization trick below: np.dot(x, y) is faster than
# np.sum(x * y) because it calls BLAS
# Objective: C (Kullback-Leibler divergence of P and Q)
if len(P.shape) == 2:
P = squareform(P)
kl_divergence = 2.0 * np.dot(P, np.log(P / Q))
return kl_divergence
def _kl_divergence_bh(params, P, neighbors, degrees_of_freedom, n_samples,
n_components, angle=0.5, skip_num_points=0,
verbose=False):
"""t-SNE objective function: KL divergence of p_ijs and q_ijs.
Uses Barnes-Hut tree methods to calculate the gradient that
runs in O(NlogN) instead of O(N^2)
Parameters
----------
params : array, shape (n_params,)
Unraveled embedding.
P : array, shape (n_samples * (n_samples-1) / 2,)
Condensed joint probability matrix.
neighbors: int64 array, shape (n_samples, K)
Array with element [i, j] giving the index for the jth
closest neighbor to point i.
degrees_of_freedom : float
Degrees of freedom of the Student's-t distribution.
n_samples : int
Number of samples.
n_components : int
Dimension of the embedded space.
angle : float (default: 0.5)
This is the trade-off between speed and accuracy for Barnes-Hut T-SNE.
'angle' is the angular size (referred to as theta in [3]) of a distant
node as measured from a point. If this size is below 'angle' then it is
used as a summary node of all points contained within it.
This method is not very sensitive to changes in this parameter
in the range of 0.2 - 0.8. Angle less than 0.2 has quickly increasing
computation time and angle greater 0.8 has quickly increasing error.
skip_num_points : int (optional, default:0)
This does not compute the gradient for points with indices below
`skip_num_points`. This is useful when computing transforms of new
data where you'd like to keep the old data fixed.
verbose : int
Verbosity level.
Returns
-------
kl_divergence : float
Kullback-Leibler divergence of p_ij and q_ij.
grad : array, shape (n_params,)
Unraveled gradient of the Kullback-Leibler divergence with respect to
the embedding.
"""
params = astype(params, np.float32, copy=False)
X_embedded = params.reshape(n_samples, n_components)
neighbors = astype(neighbors, np.int64, copy=False)
if len(P.shape) == 1:
sP = squareform(P).astype(np.float32)
else:
sP = P.astype(np.float32)
grad = np.zeros(X_embedded.shape, dtype=np.float32)
error = _barnes_hut_tsne.gradient(sP, X_embedded, neighbors,
grad, angle, n_components, verbose,
dof=degrees_of_freedom)
c = 2.0 * (degrees_of_freedom + 1.0) / degrees_of_freedom
grad = grad.ravel()
grad *= c
return error, grad
def _gradient_descent(objective, p0, it, n_iter, objective_error=None,
n_iter_check=1, n_iter_without_progress=50,
momentum=0.5, learning_rate=1000.0, min_gain=0.01,
min_grad_norm=1e-7, min_error_diff=1e-7, verbose=0,
args=None, kwargs=None):
"""Batch gradient descent with momentum and individual gains.
Parameters
----------
objective : function or callable
Should return a tuple of cost and gradient for a given parameter
vector. When expensive to compute, the cost can optionally
be None and can be computed every n_iter_check steps using
the objective_error function.
p0 : array-like, shape (n_params,)
Initial parameter vector.
it : int
Current number of iterations (this function will be called more than
once during the optimization).
n_iter : int
Maximum number of gradient descent iterations.
n_iter_check : int
Number of iterations before evaluating the global error. If the error
is sufficiently low, we abort the optimization.
objective_error : function or callable
Should return a tuple of cost and gradient for a given parameter
vector.
n_iter_without_progress : int, optional (default: 30)
Maximum number of iterations without progress before we abort the
optimization.
momentum : float, within (0.0, 1.0), optional (default: 0.5)
The momentum generates a weight for previous gradients that decays
exponentially.
learning_rate : float, optional (default: 1000.0)
The learning rate should be extremely high for t-SNE! Values in the
range [100.0, 1000.0] are common.
min_gain : float, optional (default: 0.01)
Minimum individual gain for each parameter.
min_grad_norm : float, optional (default: 1e-7)
If the gradient norm is below this threshold, the optimization will
be aborted.
min_error_diff : float, optional (default: 1e-7)
If the absolute difference of two successive cost function values
is below this threshold, the optimization will be aborted.
verbose : int, optional (default: 0)
Verbosity level.
args : sequence
Arguments to pass to objective function.
kwargs : dict
Keyword arguments to pass to objective function.
Returns
-------
p : array, shape (n_params,)
Optimum parameters.
error : float
Optimum.
i : int
Last iteration.
"""
if args is None:
args = []
if kwargs is None:
kwargs = {}
p = p0.copy().ravel()
update = np.zeros_like(p)
gains = np.ones_like(p)
error = np.finfo(np.float).max
best_error = np.finfo(np.float).max
best_iter = 0
for i in range(it, n_iter):
new_error, grad = objective(p, *args, **kwargs)
grad_norm = linalg.norm(grad)
inc = update * grad >= 0.0
dec = np.invert(inc)
gains[inc] += 0.05
gains[dec] *= 0.95
np.clip(gains, min_gain, np.inf)
grad *= gains
update = momentum * update - learning_rate * grad
p += update
if (i + 1) % n_iter_check == 0:
if new_error is None:
new_error = objective_error(p, *args)
error_diff = np.abs(new_error - error)
error = new_error
if verbose >= 2:
m = "[t-SNE] Iteration %d: error = %.7f, gradient norm = %.7f"
print(m % (i + 1, error, grad_norm))
if error < best_error:
best_error = error
best_iter = i
elif i - best_iter > n_iter_without_progress:
if verbose >= 2:
print("[t-SNE] Iteration %d: did not make any progress "
"during the last %d episodes. Finished."
% (i + 1, n_iter_without_progress))
break
if grad_norm <= min_grad_norm:
if verbose >= 2:
print("[t-SNE] Iteration %d: gradient norm %f. Finished."
% (i + 1, grad_norm))
break
if error_diff <= min_error_diff:
if verbose >= 2:
m = "[t-SNE] Iteration %d: error difference %f. Finished."
print(m % (i + 1, error_diff))
break
if new_error is not None:
error = new_error
return p, error, i
def trustworthiness(X, X_embedded, n_neighbors=5, precomputed=False):
"""Expresses to what extent the local structure is retained.
The trustworthiness is within [0, 1]. It is defined as
.. math::
T(k) = 1 - \frac{2}{nk (2n - 3k - 1)} \sum^n_{i=1}
\sum_{j \in U^{(k)}_i (r(i, j) - k)}
where :math:`r(i, j)` is the rank of the embedded datapoint j
according to the pairwise distances between the embedded datapoints,
:math:`U^{(k)}_i` is the set of points that are in the k nearest
neighbors in the embedded space but not in the original space.
* "Neighborhood Preservation in Nonlinear Projection Methods: An
Experimental Study"
J. Venna, S. Kaski
* "Learning a Parametric Embedding by Preserving Local Structure"
L.J.P. van der Maaten
Parameters
----------
X : array, shape (n_samples, n_features) or (n_samples, n_samples)
If the metric is 'precomputed' X must be a square distance
matrix. Otherwise it contains a sample per row.
X_embedded : array, shape (n_samples, n_components)
Embedding of the training data in low-dimensional space.
n_neighbors : int, optional (default: 5)
Number of neighbors k that will be considered.
precomputed : bool, optional (default: False)
Set this flag if X is a precomputed square distance matrix.
Returns
-------
trustworthiness : float
Trustworthiness of the low-dimensional embedding.
"""
if precomputed:
dist_X = X
else:
dist_X = pairwise_distances(X, squared=True)
dist_X_embedded = pairwise_distances(X_embedded, squared=True)
ind_X = np.argsort(dist_X, axis=1)
ind_X_embedded = np.argsort(dist_X_embedded, axis=1)[:, 1:n_neighbors + 1]
n_samples = X.shape[0]
t = 0.0
ranks = np.zeros(n_neighbors)
for i in range(n_samples):
for j in range(n_neighbors):
ranks[j] = np.where(ind_X[i] == ind_X_embedded[i, j])[0][0]
ranks -= n_neighbors
t += np.sum(ranks[ranks > 0])
t = 1.0 - t * (2.0 / (n_samples * n_neighbors *
(2.0 * n_samples - 3.0 * n_neighbors - 1.0)))
return t
class TSNE(BaseEstimator):
"""t-distributed Stochastic Neighbor Embedding.
t-SNE [1] is a tool to visualize high-dimensional data. It converts
similarities between data points to joint probabilities and tries
to minimize the Kullback-Leibler divergence between the joint
probabilities of the low-dimensional embedding and the
high-dimensional data. t-SNE has a cost function that is not convex,
i.e. with different initializations we can get different results.
It is highly recommended to use another dimensionality reduction
method (e.g. PCA for dense data or TruncatedSVD for sparse data)
to reduce the number of dimensions to a reasonable amount (e.g. 50)
if the number of features is very high. This will suppress some
noise and speed up the computation of pairwise distances between
samples. For more tips see Laurens van der Maaten's FAQ [2].
Read more in the :ref:`User Guide <t_sne>`.
Parameters
----------
n_components : int, optional (default: 2)
Dimension of the embedded space.
perplexity : float, optional (default: 30)
The perplexity is related to the number of nearest neighbors that
is used in other manifold learning algorithms. Larger datasets
usually require a larger perplexity. Consider selecting a value
between 5 and 50. The choice is not extremely critical since t-SNE
is quite insensitive to this parameter.
early_exaggeration : float, optional (default: 4.0)
Controls how tight natural clusters in the original space are in
the embedded space and how much space will be between them. For
larger values, the space between natural clusters will be larger
in the embedded space. Again, the choice of this parameter is not
very critical. If the cost function increases during initial
optimization, the early exaggeration factor or the learning rate
might be too high.
learning_rate : float, optional (default: 1000)
The learning rate can be a critical parameter. It should be
between 100 and 1000. If the cost function increases during initial
optimization, the early exaggeration factor or the learning rate
might be too high. If the cost function gets stuck in a bad local
minimum increasing the learning rate helps sometimes.
n_iter : int, optional (default: 1000)
Maximum number of iterations for the optimization. Should be at
least 200.
n_iter_without_progress : int, optional (default: 30)
Maximum number of iterations without progress before we abort the
optimization.
.. versionadded:: 0.17
parameter *n_iter_without_progress* to control stopping criteria.
min_grad_norm : float, optional (default: 1E-7)
If the gradient norm is below this threshold, the optimization will
be aborted.
metric : string or callable, optional
The metric to use when calculating distance between instances in a
feature array. If metric is a string, it must be one of the options
allowed by scipy.spatial.distance.pdist for its metric parameter, or
a metric listed in pairwise.PAIRWISE_DISTANCE_FUNCTIONS.
If metric is "precomputed", X is assumed to be a distance matrix.
Alternatively, if metric is a callable function, it is called on each
pair of instances (rows) and the resulting value recorded. The callable
should take two arrays from X as input and return a value indicating
the distance between them. The default is "euclidean" which is
interpreted as squared euclidean distance.
init : string, optional (default: "random")
Initialization of embedding. Possible options are 'random' and 'pca'.
PCA initialization cannot be used with precomputed distances and is
usually more globally stable than random initialization.
verbose : int, optional (default: 0)
Verbosity level.
random_state : int or RandomState instance or None (default)
Pseudo Random Number generator seed control. If None, use the
numpy.random singleton. Note that different initializations
might result in different local minima of the cost function.
method : string (default: 'barnes_hut')
By default the gradient calculation algorithm uses Barnes-Hut
approximation running in O(NlogN) time. method='exact'
will run on the slower, but exact, algorithm in O(N^2) time. The
exact algorithm should be used when nearest-neighbor errors need
to be better than 3%. However, the exact method cannot scale to
millions of examples.
.. versionadded:: 0.17
Approximate optimization *method* via the Barnes-Hut.
angle : float (default: 0.5)
Only used if method='barnes_hut'
This is the trade-off between speed and accuracy for Barnes-Hut T-SNE.
'angle' is the angular size (referred to as theta in [3]) of a distant
node as measured from a point. If this size is below 'angle' then it is
used as a summary node of all points contained within it.
This method is not very sensitive to changes in this parameter
in the range of 0.2 - 0.8. Angle less than 0.2 has quickly increasing
computation time and angle greater 0.8 has quickly increasing error.
Attributes
----------
embedding_ : array-like, shape (n_samples, n_components)
Stores the embedding vectors.
kl_divergence_ : float
Kullback-Leibler divergence after optimization.
Examples
--------
>>> import numpy as np
>>> from sklearn.manifold import TSNE
>>> X = np.array([[0, 0, 0], [0, 1, 1], [1, 0, 1], [1, 1, 1]])
>>> model = TSNE(n_components=2, random_state=0)
>>> np.set_printoptions(suppress=True)
>>> model.fit_transform(X) # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
array([[ 0.00017599, 0.00003993],
[ 0.00009891, 0.00021913],
[ 0.00018554, -0.00009357],
[ 0.00009528, -0.00001407]])
References
----------
[1] van der Maaten, L.J.P.; Hinton, G.E. Visualizing High-Dimensional Data
Using t-SNE. Journal of Machine Learning Research 9:2579-2605, 2008.
[2] van der Maaten, L.J.P. t-Distributed Stochastic Neighbor Embedding
http://homepage.tudelft.nl/19j49/t-SNE.html
[3] L.J.P. van der Maaten. Accelerating t-SNE using Tree-Based Algorithms.
Journal of Machine Learning Research 15(Oct):3221-3245, 2014.
http://lvdmaaten.github.io/publications/papers/JMLR_2014.pdf
"""
def __init__(self, n_components=2, perplexity=30.0,
early_exaggeration=4.0, learning_rate=1000.0, n_iter=1000,
n_iter_without_progress=30, min_grad_norm=1e-7,
metric="euclidean", init="random", verbose=0,
random_state=None, method='barnes_hut', angle=0.5):
if init not in ["pca", "random"] or isinstance(init, np.ndarray):
msg = "'init' must be 'pca', 'random' or a NumPy array"
raise ValueError(msg)
self.n_components = n_components
self.perplexity = perplexity
self.early_exaggeration = early_exaggeration
self.learning_rate = learning_rate
self.n_iter = n_iter
self.n_iter_without_progress = n_iter_without_progress
self.min_grad_norm = min_grad_norm
self.metric = metric
self.init = init
self.verbose = verbose
self.random_state = random_state
self.method = method
self.angle = angle
self.embedding_ = None
def _fit(self, X, skip_num_points=0):
"""Fit the model using X as training data.
Note that sparse arrays can only be handled by method='exact'.
It is recommended that you convert your sparse array to dense
(e.g. `X.toarray()`) if it fits in memory, or otherwise using a
dimensionality reduction technique (e.g. TruncatedSVD).
Parameters
----------
X : array, shape (n_samples, n_features) or (n_samples, n_samples)
If the metric is 'precomputed' X must be a square distance
matrix. Otherwise it contains a sample per row. Note that this
when method='barnes_hut', X cannot be a sparse array and if need be
will be converted to a 32 bit float array. Method='exact' allows
sparse arrays and 64bit floating point inputs.
skip_num_points : int (optional, default:0)
This does not compute the gradient for points with indices below
`skip_num_points`. This is useful when computing transforms of new
data where you'd like to keep the old data fixed.
"""
if self.method not in ['barnes_hut', 'exact']:
raise ValueError("'method' must be 'barnes_hut' or 'exact'")
if self.angle < 0.0 or self.angle > 1.0:
raise ValueError("'angle' must be between 0.0 - 1.0")
if self.method == 'barnes_hut' and sp.issparse(X):
raise TypeError('A sparse matrix was passed, but dense '
'data is required for method="barnes_hut". Use '
'X.toarray() to convert to a dense numpy array if '
'the array is small enough for it to fit in '
'memory. Otherwise consider dimensionality '
'reduction techniques (e.g. TruncatedSVD)')
else:
X = check_array(X, accept_sparse=['csr', 'csc', 'coo'], dtype=np.float64)
random_state = check_random_state(self.random_state)
if self.early_exaggeration < 1.0:
raise ValueError("early_exaggeration must be at least 1, but is "
"%f" % self.early_exaggeration)
if self.n_iter < 200:
raise ValueError("n_iter should be at least 200")
if self.metric == "precomputed":
if self.init == 'pca':
raise ValueError("The parameter init=\"pca\" cannot be used "
"with metric=\"precomputed\".")
if X.shape[0] != X.shape[1]:
raise ValueError("X should be a square distance matrix")
distances = X
else:
if self.verbose:
print("[t-SNE] Computing pairwise distances...")
if self.metric == "euclidean":
distances = pairwise_distances(X, metric=self.metric,
squared=True)
else:
distances = pairwise_distances(X, metric=self.metric)
if not np.all(distances >= 0):
raise ValueError("All distances should be positive, either "
"the metric or precomputed distances given "
"as X are not correct")
# Degrees of freedom of the Student's t-distribution. The suggestion
# degrees_of_freedom = n_components - 1 comes from
# "Learning a Parametric Embedding by Preserving Local Structure"
# Laurens van der Maaten, 2009.
degrees_of_freedom = max(self.n_components - 1.0, 1)
n_samples = X.shape[0]
# the number of nearest neighbors to find
k = min(n_samples - 1, int(3. * self.perplexity + 1))
neighbors_nn = None
if self.method == 'barnes_hut':
if self.verbose:
print("[t-SNE] Computing %i nearest neighbors..." % k)
if self.metric == 'precomputed':
# Use the precomputed distances to find
# the k nearest neighbors and their distances
neighbors_nn = np.argsort(distances, axis=1)[:, :k]
else:
# Find the nearest neighbors for every point
bt = BallTree(X)
# LvdM uses 3 * perplexity as the number of neighbors
# And we add one to not count the data point itself
# In the event that we have very small # of points
# set the neighbors to n - 1
distances_nn, neighbors_nn = bt.query(X, k=k + 1)
neighbors_nn = neighbors_nn[:, 1:]
P = _joint_probabilities_nn(distances, neighbors_nn,
self.perplexity, self.verbose)
else:
P = _joint_probabilities(distances, self.perplexity, self.verbose)
assert np.all(np.isfinite(P)), "All probabilities should be finite"
assert np.all(P >= 0), "All probabilities should be zero or positive"
assert np.all(P <= 1), ("All probabilities should be less "
"or then equal to one")
if self.init == 'pca':
pca = RandomizedPCA(n_components=self.n_components,
random_state=random_state)
X_embedded = pca.fit_transform(X)
elif isinstance(self.init, np.ndarray):
X_embedded = self.init
elif self.init == 'random':
X_embedded = None
else:
raise ValueError("Unsupported initialization scheme: %s"
% self.init)
return self._tsne(P, degrees_of_freedom, n_samples, random_state,
X_embedded=X_embedded,
neighbors=neighbors_nn,
skip_num_points=skip_num_points)
def _tsne(self, P, degrees_of_freedom, n_samples, random_state,
X_embedded=None, neighbors=None, skip_num_points=0):
"""Runs t-SNE."""
# t-SNE minimizes the Kullback-Leiber divergence of the Gaussians P
# and the Student's t-distributions Q. The optimization algorithm that
# we use is batch gradient descent with three stages:
# * early exaggeration with momentum 0.5
# * early exaggeration with momentum 0.8
# * final optimization with momentum 0.8
# The embedding is initialized with iid samples from Gaussians with
# standard deviation 1e-4.
if X_embedded is None:
# Initialize embedding randomly
X_embedded = 1e-4 * random_state.randn(n_samples,
self.n_components)
params = X_embedded.ravel()
opt_args = {}
opt_args = {"n_iter": 50, "momentum": 0.5, "it": 0,
"learning_rate": self.learning_rate,
"verbose": self.verbose, "n_iter_check": 25,
"kwargs": dict(skip_num_points=skip_num_points)}
if self.method == 'barnes_hut':
m = "Must provide an array of neighbors to use Barnes-Hut"
assert neighbors is not None, m
obj_func = _kl_divergence_bh
objective_error = _kl_divergence_error
sP = squareform(P).astype(np.float32)
neighbors = neighbors.astype(np.int64)
args = [sP, neighbors, degrees_of_freedom, n_samples,
self.n_components]
opt_args['args'] = args
opt_args['min_grad_norm'] = 1e-3
opt_args['n_iter_without_progress'] = 30
# Don't always calculate the cost since that calculation
# can be nearly as expensive as the gradient
opt_args['objective_error'] = objective_error
opt_args['kwargs']['angle'] = self.angle
opt_args['kwargs']['verbose'] = self.verbose
else:
obj_func = _kl_divergence
opt_args['args'] = [P, degrees_of_freedom, n_samples,
self.n_components]
opt_args['min_error_diff'] = 0.0
opt_args['min_grad_norm'] = 0.0
# Early exaggeration
P *= self.early_exaggeration
params, kl_divergence, it = _gradient_descent(obj_func, params,
**opt_args)
opt_args['n_iter'] = 100
opt_args['momentum'] = 0.8
opt_args['it'] = it + 1
params, kl_divergence, it = _gradient_descent(obj_func, params,
**opt_args)
if self.verbose:
print("[t-SNE] KL divergence after %d iterations with early "
"exaggeration: %f" % (it + 1, kl_divergence))
# Save the final number of iterations
self.n_iter_final = it
# Final optimization
P /= self.early_exaggeration
opt_args['n_iter'] = self.n_iter
opt_args['it'] = it + 1
params, error, it = _gradient_descent(obj_func, params, **opt_args)
if self.verbose:
print("[t-SNE] Error after %d iterations: %f"
% (it + 1, kl_divergence))
X_embedded = params.reshape(n_samples, self.n_components)
self.kl_divergence_ = kl_divergence
return X_embedded
def fit_transform(self, X, y=None):
"""Fit X into an embedded space and return that transformed
output.
Parameters
----------
X : array, shape (n_samples, n_features) or (n_samples, n_samples)
If the metric is 'precomputed' X must be a square distance
matrix. Otherwise it contains a sample per row.
Returns
-------
X_new : array, shape (n_samples, n_components)
Embedding of the training data in low-dimensional space.
"""
embedding = self._fit(X)
self.embedding_ = embedding
return self.embedding_
def fit(self, X, y=None):
"""Fit X into an embedded space.
Parameters
----------
X : array, shape (n_samples, n_features) or (n_samples, n_samples)
If the metric is 'precomputed' X must be a square distance
matrix. Otherwise it contains a sample per row. If the method
is 'exact', X may be a sparse matrix of type 'csr', 'csc'
or 'coo'.
"""
self.fit_transform(X)
return self
|
bsd-3-clause
|
[
3,
6529,
26,
22986,
11438,
481,
371,
374,
335,
221,
1553,
665,
2756,
371,
374,
335,
32,
262,
10928,
30298,
14,
5411,
13,
10205,
1410,
14,
271,
30,
199,
3,
6529,
26,
2799,
322,
2379,
2523,
3930,
1351,
665,
335,
28479,
573,
1351,
32,
6799,
14,
957,
30,
199,
3,
6529,
26,
653,
2000,
12643,
14895,
665,
11082,
84,
32,
9646,
384,
14,
957,
30,
199,
3,
844,
26,
6289,
650,
8502,
334,
35,
9,
6927,
199,
199,
3,
961,
365,
314,
5835,
436,
699,
1060,
397,
13,
40,
337,
307,
13,
51,
6388,
4514,
14,
6006,
787,
1163,
199,
3,
23070,
402,
314,
5563,
26,
199,
3,
627,
22613,
19246,
2072,
367,
307,
13,
51,
6388,
26,
199,
3,
257,
1455,
921,
67,
261,
2520,
14,
947,
3893,
14,
8654,
22500,
6371,
68,
391,
323,
78,
15,
800,
609,
1483,
15,
78,
6142,
6542,
15,
10443,
83,
15,
86,
11438,
391,
323,
78,
14,
5607,
199,
199,
646,
2680,
465,
980,
199,
504,
7026,
492,
16727,
199,
646,
7026,
14,
4421,
465,
2249,
199,
504,
7026,
14,
11679,
14,
5590,
492,
299,
2686,
199,
504,
7026,
14,
11679,
14,
5590,
492,
12386,
964,
199,
504,
2508,
11113,
492,
699,
452,
3987,
199,
504,
2508,
1095,
492,
3523,
13183,
199,
504,
2508,
1208,
492,
1104,
63,
1144,
199,
504,
2508,
1208,
492,
1104,
63,
2355,
63,
929,
199,
504,
2508,
1208,
14,
832,
3442,
492,
485,
11186,
199,
504,
2508,
31384,
492,
9571,
1759,
23852,
199,
504,
2508,
6759,
14,
25069,
492,
24859,
63,
15482,
199,
504,
1275,
492,
485,
1208,
199,
504,
1275,
492,
485,
66,
1060,
397,
63,
72,
337,
63,
1086,
685,
199,
504,
2508,
1208,
14,
26205,
492,
6073,
514,
421,
199,
20890,
63,
37,
20725,
275,
980,
14,
23087,
8,
1590,
14,
3157,
680,
8277,
421,
199,
318,
485,
10153,
63,
27583,
8,
15482,
12,
6387,
63,
529,
22198,
1209,
12,
3376,
304,
272,
408,
8564,
22211,
19555,
299,
63,
7879,
687,
15108,
14,
339,
3897,
272,
4143,
272,
15108,
520,
1625,
12,
2215,
334,
78,
63,
3356,
627,
334,
78,
63,
3356,
13,
17,
9,
1182,
499,
4258,
267,
21892,
83,
402,
5845,
787,
5489,
465,
406,
848,
939,
12627,
12,
284,
14,
69,
14,
267,
781,
19413,
314,
16788,
436,
9250,
4811,
436,
3877,
8137,
267,
315,
282,
1373,
13,
13014,
1625,
14,
339,
6387,
63,
529,
22198,
1209,
520,
2069,
267,
1487,
5381,
1126,
22198,
1209,
402,
314,
22211,
12224,
10208,
14,
339,
3376,
520,
1109,
267,
5444,
5947,
2166,
14,
339,
1803,
272,
5514,
272,
510,
520,
1625,
12,
2215,
334,
78,
63,
3356,
627,
334,
78,
63,
3356,
13,
17,
9,
1182,
499,
4258,
267,
1448,
848,
939,
22211,
12224,
3634,
14,
272,
408,
272,
327,
8354,
12303,
19555,
4066,
626,
2985,
19917,
590,
1336,
272,
327,
314,
6387,
1126,
22198,
1209,
272,
15108,
275,
6073,
514,
8,
15482,
12,
980,
14,
1609,
708,
12,
1331,
29,
797,
9,
272,
12303,
63,
48,
275,
485,
1208,
423,
3008,
63,
1733,
63,
529,
22198,
1209,
8,
267,
15108,
12,
488,
12,
6387,
63,
529,
22198,
1209,
12,
3376,
9,
272,
510,
275,
12303,
63,
48,
435,
12303,
63,
48,
14,
52,
272,
3089,
63,
48,
275,
980,
14,
11555,
8,
1590,
14,
1838,
8,
48,
395,
4828,
1244,
3565,
63,
37,
20725,
9,
272,
510,
275,
980,
14,
11555,
8,
9646,
964,
8,
48,
9,
1182,
3089,
63,
48,
12,
4828,
1244,
3565,
63,
37,
20725,
9,
272,
372,
510,
421,
199,
318,
485,
10153,
63,
27583,
63,
4411,
8,
15482,
12,
15845,
12,
6387,
63,
529,
22198,
1209,
12,
3376,
304,
272,
408,
8564,
22211,
19555,
299,
63,
7879,
687,
15108,
1808,
2951,
17173,
272,
15845,
14,
339,
961,
1083,
365,
19917,
590,
4472,
370,
485,
10153,
63,
27583,
14,
710,
19045,
272,
365,
593,
8,
46,
395,
1325,
2304,
316,
314,
22211,
12224,
370,
17173,
15845,
1742,
293,
2310,
272,
642,
27321,
4466,
1183,
370,
593,
8,
85,
46,
680,
339,
3897,
272,
4143,
272,
15108,
520,
1625,
12,
2215,
334,
78,
63,
3356,
627,
334,
78,
63,
3356,
13,
17,
9,
1182,
499,
4258,
267,
21892,
83,
402,
5845,
787,
5489,
465,
406,
848,
939,
12627,
12,
284,
14,
69,
14,
267,
781,
19413,
314,
16788,
436,
9250,
4811,
436,
3877,
8137,
267,
315,
282,
1373,
13,
13014,
1625,
14,
339,
6387,
63,
529,
22198,
1209,
520,
2069,
267,
1487,
5381,
1126,
22198,
1209,
402,
314,
22211,
12224,
10208,
14,
339,
3376,
520,
1109,
267,
5444,
5947,
2166,
14,
339,
1803,
272,
5514,
272,
510,
520,
1625,
12,
2215,
334,
78,
63,
3356,
627,
334,
78,
63,
3356,
13,
17,
9,
1182,
499,
4258,
267,
1448,
848,
939,
22211,
12224,
3634,
14,
272,
408,
272,
327,
8354,
12303,
19555,
4066,
626,
2985,
19917,
590,
1336,
272,
327,
314,
6387,
1126,
22198,
1209,
272,
15108,
275,
6073,
514,
8,
15482,
12,
980,
14,
1609,
708,
12,
1331,
29,
797,
9,
272,
15845,
275,
6073,
514,
8,
11113,
12,
980,
14,
442,
772,
12,
1331,
29,
797,
9,
272,
12303,
63,
48,
275,
485,
1208,
423,
3008,
63,
1733,
63,
529,
22198,
1209,
8,
267,
15108,
12,
15845,
12,
6387,
63,
529,
22198,
1209,
12,
3376,
9,
272,
333,
275,
298,
2422,
19555,
1077,
506,
21837,
2,
272,
702,
980,
14,
452,
8,
1590,
14,
30276,
8,
14353,
63,
48,
1826,
333,
272,
510,
275,
12303,
63,
48,
435,
12303,
63,
48,
14,
52,
272,
3089,
63,
48,
275,
980,
14,
11555,
8,
1590,
14,
1838,
8,
48,
395,
4828,
1244,
3565,
63,
37,
20725,
9,
272,
510,
275,
980,
14,
11555,
8,
9646,
964,
8,
48,
9,
1182,
3089,
63,
48,
12,
4828,
1244,
3565,
63,
37,
20725,
9,
272,
702,
980,
14,
452,
8,
1590,
14,
2101,
8,
48,
9,
2695,
413,
14,
16,
9,
272,
372,
510,
421,
199,
318,
485,
9503,
63,
32049,
8,
1162,
12,
510,
12,
14358,
63,
1618,
63,
70,
3798,
676,
12,
302,
63,
3356,
12,
302,
63,
4608,
12,
673,
3372,
63,
1507,
63,
3438,
29,
16,
304,
272,
408,
84,
13,
51,
6388,
20632,
805,
26,
6709,
402,
314,
1804,
44,
487,
23803,
272
] |
[
6529,
26,
22986,
11438,
481,
371,
374,
335,
221,
1553,
665,
2756,
371,
374,
335,
32,
262,
10928,
30298,
14,
5411,
13,
10205,
1410,
14,
271,
30,
199,
3,
6529,
26,
2799,
322,
2379,
2523,
3930,
1351,
665,
335,
28479,
573,
1351,
32,
6799,
14,
957,
30,
199,
3,
6529,
26,
653,
2000,
12643,
14895,
665,
11082,
84,
32,
9646,
384,
14,
957,
30,
199,
3,
844,
26,
6289,
650,
8502,
334,
35,
9,
6927,
199,
199,
3,
961,
365,
314,
5835,
436,
699,
1060,
397,
13,
40,
337,
307,
13,
51,
6388,
4514,
14,
6006,
787,
1163,
199,
3,
23070,
402,
314,
5563,
26,
199,
3,
627,
22613,
19246,
2072,
367,
307,
13,
51,
6388,
26,
199,
3,
257,
1455,
921,
67,
261,
2520,
14,
947,
3893,
14,
8654,
22500,
6371,
68,
391,
323,
78,
15,
800,
609,
1483,
15,
78,
6142,
6542,
15,
10443,
83,
15,
86,
11438,
391,
323,
78,
14,
5607,
199,
199,
646,
2680,
465,
980,
199,
504,
7026,
492,
16727,
199,
646,
7026,
14,
4421,
465,
2249,
199,
504,
7026,
14,
11679,
14,
5590,
492,
299,
2686,
199,
504,
7026,
14,
11679,
14,
5590,
492,
12386,
964,
199,
504,
2508,
11113,
492,
699,
452,
3987,
199,
504,
2508,
1095,
492,
3523,
13183,
199,
504,
2508,
1208,
492,
1104,
63,
1144,
199,
504,
2508,
1208,
492,
1104,
63,
2355,
63,
929,
199,
504,
2508,
1208,
14,
832,
3442,
492,
485,
11186,
199,
504,
2508,
31384,
492,
9571,
1759,
23852,
199,
504,
2508,
6759,
14,
25069,
492,
24859,
63,
15482,
199,
504,
1275,
492,
485,
1208,
199,
504,
1275,
492,
485,
66,
1060,
397,
63,
72,
337,
63,
1086,
685,
199,
504,
2508,
1208,
14,
26205,
492,
6073,
514,
421,
199,
20890,
63,
37,
20725,
275,
980,
14,
23087,
8,
1590,
14,
3157,
680,
8277,
421,
199,
318,
485,
10153,
63,
27583,
8,
15482,
12,
6387,
63,
529,
22198,
1209,
12,
3376,
304,
272,
408,
8564,
22211,
19555,
299,
63,
7879,
687,
15108,
14,
339,
3897,
272,
4143,
272,
15108,
520,
1625,
12,
2215,
334,
78,
63,
3356,
627,
334,
78,
63,
3356,
13,
17,
9,
1182,
499,
4258,
267,
21892,
83,
402,
5845,
787,
5489,
465,
406,
848,
939,
12627,
12,
284,
14,
69,
14,
267,
781,
19413,
314,
16788,
436,
9250,
4811,
436,
3877,
8137,
267,
315,
282,
1373,
13,
13014,
1625,
14,
339,
6387,
63,
529,
22198,
1209,
520,
2069,
267,
1487,
5381,
1126,
22198,
1209,
402,
314,
22211,
12224,
10208,
14,
339,
3376,
520,
1109,
267,
5444,
5947,
2166,
14,
339,
1803,
272,
5514,
272,
510,
520,
1625,
12,
2215,
334,
78,
63,
3356,
627,
334,
78,
63,
3356,
13,
17,
9,
1182,
499,
4258,
267,
1448,
848,
939,
22211,
12224,
3634,
14,
272,
408,
272,
327,
8354,
12303,
19555,
4066,
626,
2985,
19917,
590,
1336,
272,
327,
314,
6387,
1126,
22198,
1209,
272,
15108,
275,
6073,
514,
8,
15482,
12,
980,
14,
1609,
708,
12,
1331,
29,
797,
9,
272,
12303,
63,
48,
275,
485,
1208,
423,
3008,
63,
1733,
63,
529,
22198,
1209,
8,
267,
15108,
12,
488,
12,
6387,
63,
529,
22198,
1209,
12,
3376,
9,
272,
510,
275,
12303,
63,
48,
435,
12303,
63,
48,
14,
52,
272,
3089,
63,
48,
275,
980,
14,
11555,
8,
1590,
14,
1838,
8,
48,
395,
4828,
1244,
3565,
63,
37,
20725,
9,
272,
510,
275,
980,
14,
11555,
8,
9646,
964,
8,
48,
9,
1182,
3089,
63,
48,
12,
4828,
1244,
3565,
63,
37,
20725,
9,
272,
372,
510,
421,
199,
318,
485,
10153,
63,
27583,
63,
4411,
8,
15482,
12,
15845,
12,
6387,
63,
529,
22198,
1209,
12,
3376,
304,
272,
408,
8564,
22211,
19555,
299,
63,
7879,
687,
15108,
1808,
2951,
17173,
272,
15845,
14,
339,
961,
1083,
365,
19917,
590,
4472,
370,
485,
10153,
63,
27583,
14,
710,
19045,
272,
365,
593,
8,
46,
395,
1325,
2304,
316,
314,
22211,
12224,
370,
17173,
15845,
1742,
293,
2310,
272,
642,
27321,
4466,
1183,
370,
593,
8,
85,
46,
680,
339,
3897,
272,
4143,
272,
15108,
520,
1625,
12,
2215,
334,
78,
63,
3356,
627,
334,
78,
63,
3356,
13,
17,
9,
1182,
499,
4258,
267,
21892,
83,
402,
5845,
787,
5489,
465,
406,
848,
939,
12627,
12,
284,
14,
69,
14,
267,
781,
19413,
314,
16788,
436,
9250,
4811,
436,
3877,
8137,
267,
315,
282,
1373,
13,
13014,
1625,
14,
339,
6387,
63,
529,
22198,
1209,
520,
2069,
267,
1487,
5381,
1126,
22198,
1209,
402,
314,
22211,
12224,
10208,
14,
339,
3376,
520,
1109,
267,
5444,
5947,
2166,
14,
339,
1803,
272,
5514,
272,
510,
520,
1625,
12,
2215,
334,
78,
63,
3356,
627,
334,
78,
63,
3356,
13,
17,
9,
1182,
499,
4258,
267,
1448,
848,
939,
22211,
12224,
3634,
14,
272,
408,
272,
327,
8354,
12303,
19555,
4066,
626,
2985,
19917,
590,
1336,
272,
327,
314,
6387,
1126,
22198,
1209,
272,
15108,
275,
6073,
514,
8,
15482,
12,
980,
14,
1609,
708,
12,
1331,
29,
797,
9,
272,
15845,
275,
6073,
514,
8,
11113,
12,
980,
14,
442,
772,
12,
1331,
29,
797,
9,
272,
12303,
63,
48,
275,
485,
1208,
423,
3008,
63,
1733,
63,
529,
22198,
1209,
8,
267,
15108,
12,
15845,
12,
6387,
63,
529,
22198,
1209,
12,
3376,
9,
272,
333,
275,
298,
2422,
19555,
1077,
506,
21837,
2,
272,
702,
980,
14,
452,
8,
1590,
14,
30276,
8,
14353,
63,
48,
1826,
333,
272,
510,
275,
12303,
63,
48,
435,
12303,
63,
48,
14,
52,
272,
3089,
63,
48,
275,
980,
14,
11555,
8,
1590,
14,
1838,
8,
48,
395,
4828,
1244,
3565,
63,
37,
20725,
9,
272,
510,
275,
980,
14,
11555,
8,
9646,
964,
8,
48,
9,
1182,
3089,
63,
48,
12,
4828,
1244,
3565,
63,
37,
20725,
9,
272,
702,
980,
14,
452,
8,
1590,
14,
2101,
8,
48,
9,
2695,
413,
14,
16,
9,
272,
372,
510,
421,
199,
318,
485,
9503,
63,
32049,
8,
1162,
12,
510,
12,
14358,
63,
1618,
63,
70,
3798,
676,
12,
302,
63,
3356,
12,
302,
63,
4608,
12,
673,
3372,
63,
1507,
63,
3438,
29,
16,
304,
272,
408,
84,
13,
51,
6388,
20632,
805,
26,
6709,
402,
314,
1804,
44,
487,
23803,
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,
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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
] |
VitalPet/sale-workflow
|
sale_quotation_sourcing/model/sale_order.py
|
34
|
6276
|
# -*- coding: utf-8 -*-
#
# Author: Alexandre Fayolle, Leonardo Pistone, Yannick Vaucher
# Copyright 2014-2015 Camptocamp SA
#
# 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 logging
from openerp import models, fields, api
_logger = logging.getLogger(__name__)
class SaleOrder(models.Model):
_inherit = 'sale.order'
@api.multi
def action_button_confirm(self):
"""before triggering the workflow, if some lines need sourcing, run the
sourcing wizard, otherwise, propagate the call and do the confirmation
of the SO.
"""
self.ensure_one()
order = self[0]
lines_to_source = []
for line in order.order_line:
if line.needs_sourcing():
lines_to_source.append(line)
if lines_to_source:
wizard = self._create_sourcing_wizard(lines_to_source)
return {'type': 'ir.actions.act_window',
'view_mode': 'form',
'view_type': 'form',
'res_model': 'sale.order.sourcing',
'res_id': wizard.id,
'target': 'new',
}
else:
return super(SaleOrder, self).action_button_confirm()
@api.model
def _prepare_procurement_group_by_line(self, line):
vals = super(SaleOrder, self)._prepare_procurement_group_by_line(line)
# for compatibility with sale_quotation_sourcing
if line._get_procurement_group_key()[0] == 16:
if line.sourced_by:
vals['name'] += '/' + line.sourced_by.order_id.name
return vals
@api.model
def _create_sourcing_wizard(self, lines_to_source):
line_values = []
for line in lines_to_source:
line_values.append((0, 0, {'so_line_id': line.id}))
values = {'sale_id': self[0].id,
'line_ids': line_values,
}
return self.env['sale.order.sourcing'].create(values)
@api.multi
def has_consistent_routes(self):
self.ensure_one()
return all((line.has_consistent_route() for line in self.order_line))
class SaleOrderLine(models.Model):
_inherit = 'sale.order.line'
manually_sourced = fields.Boolean('Manually Sourced')
sourced_by = fields.Many2one(
'purchase.order.line', copy=False,
domain="[('product_id', '=', product_id),"
" ('order_id.state', 'in', ['draft', 'confirmed'])]")
@api.multi
def has_consistent_route(self):
self.ensure_one()
if self.route_id and self.sourced_by:
selected_route = self.route_id
self.set_route_form_so()
return selected_route == self.route_id
else:
return True
@api.multi
def needs_sourcing(self):
return any(line.manually_sourced and not line.sourced_by
for line in self)
@api.model
def _get_po_location_usage(self, purchase_order_line):
"""Retrieve the destination location usage of a PO
from a PO line
:param purchase_order_line: record of `purchase.order.line` Model
:type purchase_order_line: :py:class:`openerp.models.Model`
:return: PO location usage
:rtype: str
"""
return purchase_order_line.order_id.location_id.usage
@api.model
def _find_route_from_usage(self, usage):
"""Return the routes to assing on SO lines
based on a location usage.
If no match return None.
At the moment this method returns the standard dropshipping and MTO
routes. This method will work in many cases, but we could improve it to
find dropshipping-like and MTO-like routes that have been configured
afterwards.
See onchange_dest_address_in in the module purchase_delivery_address
for a similar situation.
:param usage: stock.location Model usage
:type usage: str
:return: a record of `stock.location.route`
:rtype: :py:class:`openerp.models.Model` or None
"""
if usage == 'customer':
return self.env.ref('stock_dropshipping.route_drop_shipping')
elif usage == 'internal':
return self.env.ref('stock.route_warehouse0_mto')
else:
return None
@api.one
@api.onchange('sourced_by')
@api.constrains('sourced_by')
def set_route_form_so(self):
"""Set route on SO line based on fields sourced_by.
Wee look for the PO related
to current SO line by the sourced_by fields.
If the PO has a destination location with usage
"customer" we apply the dropshipping route to current SO line.
If the PO has a destination location with usage
"internal" we apply the make to order route to current SO line.
As there is no trigger decorator that works on
non computed fields we use constrains decorator instead.
"""
if not self.sourced_by:
return
usage = self._get_po_location_usage(self.sourced_by)
route = self._find_route_from_usage(usage)
if route:
self.route_id = route
@api.multi
def _get_procurement_group_key(self):
""" Return a key with priority to be used to regroup lines in multiple
procurement groups
"""
priority = 16
key = super(SaleOrderLine, self)._get_procurement_group_key()
# Check priority
if key[0] < priority:
if self.sourced_by:
return (priority, self.sourced_by.order_id.id)
return key
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
259,
6529,
26,
22986,
28547,
481,
1187,
393,
274,
12,
7005,
265,
1005,
79,
510,
631,
368,
12,
1488,
1189,
2000,
812,
65,
2133,
281,
199,
3,
259,
1898,
6927,
13,
7806,
24569,
475,
20290,
13950,
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,
3,
199,
646,
2050,
199,
199,
504,
5166,
492,
1709,
12,
1504,
12,
2986,
199,
199,
63,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
428,
1895,
4738,
8,
992,
14,
1685,
304,
272,
485,
6486,
275,
283,
8515,
14,
1648,
7,
339,
768,
1246,
14,
3029,
272,
347,
1595,
63,
3887,
63,
9548,
8,
277,
304,
267,
408,
5182,
6804,
316,
314,
10431,
12,
340,
2005,
2385,
1929,
308,
567,
4477,
12,
1255,
314,
267,
308,
567,
4477,
12262,
12,
4257,
12,
19843,
314,
1240,
436,
886,
314,
18791,
267,
402,
314,
3562,
14,
267,
408,
267,
291,
14,
7505,
63,
368,
342,
267,
1865,
275,
291,
59,
16,
61,
267,
2385,
63,
475,
63,
1365,
275,
942,
267,
367,
1004,
315,
1865,
14,
1648,
63,
604,
26,
288,
340,
1004,
14,
10065,
63,
83,
567,
4477,
837,
355,
2385,
63,
475,
63,
1365,
14,
740,
8,
604,
9,
267,
340,
2385,
63,
475,
63,
1365,
26,
288,
12262,
275,
291,
423,
981,
63,
83,
567,
4477,
63,
9819,
8,
1278,
63,
475,
63,
1365,
9,
288,
372,
791,
466,
356,
283,
723,
14,
3723,
14,
2442,
63,
3806,
297,
490,
283,
1345,
63,
632,
356,
283,
964,
297,
490,
283,
1345,
63,
466,
356,
283,
964,
297,
490,
283,
470,
63,
1238,
356,
283,
8515,
14,
1648,
14,
83,
567,
4477,
297,
490,
283,
470,
63,
344,
356,
12262,
14,
344,
12,
490,
283,
1375,
356,
283,
1222,
297,
490,
789,
267,
587,
26,
288,
372,
1613,
8,
30005,
4738,
12,
291,
680,
1287,
63,
3887,
63,
9548,
342,
339,
768,
1246,
14,
1238,
272,
347,
485,
6726,
63,
18546,
63,
923,
63,
991,
63,
604,
8,
277,
12,
1004,
304,
267,
5322,
275,
1613,
8,
30005,
4738,
12,
291,
10445,
6726,
63,
18546,
63,
923,
63,
991,
63,
604,
8,
604,
9,
267,
327,
367,
7163,
543,
13590,
63,
29318,
63,
83,
567,
4477,
267,
340,
1004,
423,
362,
63,
18546,
63,
923,
63,
498,
3430,
16,
61,
508,
3193,
26,
288,
340,
1004,
14,
1365,
68,
63,
991,
26,
355,
5322,
459,
354,
418,
847,
7324,
435,
1004,
14,
1365,
68,
63,
991,
14,
1648,
63,
344,
14,
354,
267,
372,
5322,
339,
768,
1246,
14,
1238,
272,
347,
485,
981,
63,
83,
567,
4477,
63,
9819,
8,
277,
12,
2385,
63,
475,
63,
1365,
304,
267,
1004,
63,
1459,
275,
942,
267,
367,
1004,
315,
2385,
63,
475,
63,
1365,
26,
288,
1004,
63,
1459,
14,
740,
1332,
16,
12,
378,
12,
791,
1152,
63,
604,
63,
344,
356,
1004,
14,
344,
12466,
267,
1338,
275,
791,
8515,
63,
344,
356,
291,
59,
16,
1055,
344,
12,
2116,
283,
604,
63,
1580,
356,
1004,
63,
1459,
12,
2116,
789,
267,
372,
291,
14,
1813,
459,
8515,
14,
1648,
14,
83,
567,
4477,
2278,
981,
8,
1459,
9,
339,
768,
1246,
14,
3029,
272,
347,
965,
63,
15478,
63,
13243,
8,
277,
304,
267,
291,
14,
7505,
63,
368,
342,
267,
372,
1006,
1332,
604,
14,
1989,
63,
15478,
63,
4449,
342,
367,
1004,
315,
291,
14,
1648,
63,
604,
430,
421,
199,
533,
428,
1895,
4738,
3049,
8,
992,
14,
1685,
304,
272,
485,
6486,
275,
283,
8515,
14,
1648,
14,
604,
7,
272,
10250,
63,
1365,
68,
275,
1504,
14,
4082,
360,
2395,
3163,
5800,
68,
358,
272,
1350,
68,
63,
991,
275,
1504,
14,
4089,
18,
368,
8,
267,
283,
9533,
14,
1648,
14,
604,
297,
1331,
29,
797,
12,
267,
2881,
628,
19412,
2558,
63,
344,
297,
6291,
3336,
63,
344,
395,
2,
2049,
298,
661,
1648,
63,
344,
14,
929,
297,
283,
262,
297,
788,
7185,
297,
283,
16391,
1105,
12523,
339,
768,
1246,
14,
3029,
272,
347,
965,
63,
15478,
63,
4449,
8,
277,
304,
267,
291,
14,
7505,
63,
368,
342,
267,
340,
291,
14,
4449,
63,
344,
436,
291,
14,
1365,
68,
63,
991,
26,
288,
4895,
63,
4449,
275,
291,
14,
4449,
63,
344,
288,
291,
14,
409,
63,
4449,
63,
964,
63,
1152,
342,
288,
372,
4895,
63,
4449,
508,
291,
14,
4449,
63,
344,
267,
587,
26,
288,
372,
715,
339,
768,
1246,
14,
3029,
272,
347,
4839,
63,
83,
567,
4477,
8,
277,
304,
267,
372,
1263,
8,
604,
14,
1237,
3163,
63,
1365,
68,
436,
440,
1004,
14,
1365,
68,
63,
991,
673,
367,
1004,
315,
291,
9,
339,
768,
1246,
14,
1238,
272,
347,
485,
362,
63,
555,
63,
1985,
63,
3807,
8,
277,
12,
15932,
63,
1648,
63,
604,
304,
267,
408,
15310,
314,
5724,
2909,
4503,
402,
282,
3625,
267,
687,
282,
3625,
1004,
398,
520,
635,
15932,
63,
1648,
63,
604,
26,
2777,
402,
658,
9533,
14,
1648,
14,
604,
64,
5822,
267,
520,
466,
15932,
63,
1648,
63,
604,
26,
520,
647,
26,
533,
1705,
11267,
14,
992,
14,
1685,
64,
267,
520,
1107
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
259,
6529,
26,
22986,
28547,
481,
1187,
393,
274,
12,
7005,
265,
1005,
79,
510,
631,
368,
12,
1488,
1189,
2000,
812,
65,
2133,
281,
199,
3,
259,
1898,
6927,
13,
7806,
24569,
475,
20290,
13950,
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,
3,
199,
646,
2050,
199,
199,
504,
5166,
492,
1709,
12,
1504,
12,
2986,
199,
199,
63,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
428,
1895,
4738,
8,
992,
14,
1685,
304,
272,
485,
6486,
275,
283,
8515,
14,
1648,
7,
339,
768,
1246,
14,
3029,
272,
347,
1595,
63,
3887,
63,
9548,
8,
277,
304,
267,
408,
5182,
6804,
316,
314,
10431,
12,
340,
2005,
2385,
1929,
308,
567,
4477,
12,
1255,
314,
267,
308,
567,
4477,
12262,
12,
4257,
12,
19843,
314,
1240,
436,
886,
314,
18791,
267,
402,
314,
3562,
14,
267,
408,
267,
291,
14,
7505,
63,
368,
342,
267,
1865,
275,
291,
59,
16,
61,
267,
2385,
63,
475,
63,
1365,
275,
942,
267,
367,
1004,
315,
1865,
14,
1648,
63,
604,
26,
288,
340,
1004,
14,
10065,
63,
83,
567,
4477,
837,
355,
2385,
63,
475,
63,
1365,
14,
740,
8,
604,
9,
267,
340,
2385,
63,
475,
63,
1365,
26,
288,
12262,
275,
291,
423,
981,
63,
83,
567,
4477,
63,
9819,
8,
1278,
63,
475,
63,
1365,
9,
288,
372,
791,
466,
356,
283,
723,
14,
3723,
14,
2442,
63,
3806,
297,
490,
283,
1345,
63,
632,
356,
283,
964,
297,
490,
283,
1345,
63,
466,
356,
283,
964,
297,
490,
283,
470,
63,
1238,
356,
283,
8515,
14,
1648,
14,
83,
567,
4477,
297,
490,
283,
470,
63,
344,
356,
12262,
14,
344,
12,
490,
283,
1375,
356,
283,
1222,
297,
490,
789,
267,
587,
26,
288,
372,
1613,
8,
30005,
4738,
12,
291,
680,
1287,
63,
3887,
63,
9548,
342,
339,
768,
1246,
14,
1238,
272,
347,
485,
6726,
63,
18546,
63,
923,
63,
991,
63,
604,
8,
277,
12,
1004,
304,
267,
5322,
275,
1613,
8,
30005,
4738,
12,
291,
10445,
6726,
63,
18546,
63,
923,
63,
991,
63,
604,
8,
604,
9,
267,
327,
367,
7163,
543,
13590,
63,
29318,
63,
83,
567,
4477,
267,
340,
1004,
423,
362,
63,
18546,
63,
923,
63,
498,
3430,
16,
61,
508,
3193,
26,
288,
340,
1004,
14,
1365,
68,
63,
991,
26,
355,
5322,
459,
354,
418,
847,
7324,
435,
1004,
14,
1365,
68,
63,
991,
14,
1648,
63,
344,
14,
354,
267,
372,
5322,
339,
768,
1246,
14,
1238,
272,
347,
485,
981,
63,
83,
567,
4477,
63,
9819,
8,
277,
12,
2385,
63,
475,
63,
1365,
304,
267,
1004,
63,
1459,
275,
942,
267,
367,
1004,
315,
2385,
63,
475,
63,
1365,
26,
288,
1004,
63,
1459,
14,
740,
1332,
16,
12,
378,
12,
791,
1152,
63,
604,
63,
344,
356,
1004,
14,
344,
12466,
267,
1338,
275,
791,
8515,
63,
344,
356,
291,
59,
16,
1055,
344,
12,
2116,
283,
604,
63,
1580,
356,
1004,
63,
1459,
12,
2116,
789,
267,
372,
291,
14,
1813,
459,
8515,
14,
1648,
14,
83,
567,
4477,
2278,
981,
8,
1459,
9,
339,
768,
1246,
14,
3029,
272,
347,
965,
63,
15478,
63,
13243,
8,
277,
304,
267,
291,
14,
7505,
63,
368,
342,
267,
372,
1006,
1332,
604,
14,
1989,
63,
15478,
63,
4449,
342,
367,
1004,
315,
291,
14,
1648,
63,
604,
430,
421,
199,
533,
428,
1895,
4738,
3049,
8,
992,
14,
1685,
304,
272,
485,
6486,
275,
283,
8515,
14,
1648,
14,
604,
7,
272,
10250,
63,
1365,
68,
275,
1504,
14,
4082,
360,
2395,
3163,
5800,
68,
358,
272,
1350,
68,
63,
991,
275,
1504,
14,
4089,
18,
368,
8,
267,
283,
9533,
14,
1648,
14,
604,
297,
1331,
29,
797,
12,
267,
2881,
628,
19412,
2558,
63,
344,
297,
6291,
3336,
63,
344,
395,
2,
2049,
298,
661,
1648,
63,
344,
14,
929,
297,
283,
262,
297,
788,
7185,
297,
283,
16391,
1105,
12523,
339,
768,
1246,
14,
3029,
272,
347,
965,
63,
15478,
63,
4449,
8,
277,
304,
267,
291,
14,
7505,
63,
368,
342,
267,
340,
291,
14,
4449,
63,
344,
436,
291,
14,
1365,
68,
63,
991,
26,
288,
4895,
63,
4449,
275,
291,
14,
4449,
63,
344,
288,
291,
14,
409,
63,
4449,
63,
964,
63,
1152,
342,
288,
372,
4895,
63,
4449,
508,
291,
14,
4449,
63,
344,
267,
587,
26,
288,
372,
715,
339,
768,
1246,
14,
3029,
272,
347,
4839,
63,
83,
567,
4477,
8,
277,
304,
267,
372,
1263,
8,
604,
14,
1237,
3163,
63,
1365,
68,
436,
440,
1004,
14,
1365,
68,
63,
991,
673,
367,
1004,
315,
291,
9,
339,
768,
1246,
14,
1238,
272,
347,
485,
362,
63,
555,
63,
1985,
63,
3807,
8,
277,
12,
15932,
63,
1648,
63,
604,
304,
267,
408,
15310,
314,
5724,
2909,
4503,
402,
282,
3625,
267,
687,
282,
3625,
1004,
398,
520,
635,
15932,
63,
1648,
63,
604,
26,
2777,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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
] |
brianlsharp/MissionPlanner
|
Lib/site-packages/numpy/f2py/capi_maps.py
|
51
|
29016
|
#!"C:\Users\hog\Documents\Visual Studio 2010\Projects\ArdupilotMega\ArdupilotMega\bin\Debug\ipy.exe"
"""
Copyright 1999,2000 Pearu Peterson all rights reserved,
Pearu Peterson <pearu@ioc.ee>
Permission to use, modify, and distribute this software is given under the
terms of the NumPy License.
NO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
$Date: 2005/05/06 10:57:33 $
Pearu Peterson
"""
__version__ = "$Revision: 1.60 $"[10:-1]
import __version__
f2py_version = __version__.version
import copy
import re
import os
import sys
from auxfuncs import *
from crackfortran import markoutercomma
import cb_rules
# Numarray and Numeric users should set this False
using_newcore = True
depargs=[]
lcb_map={}
lcb2_map={}
# forced casting: mainly caused by the fact that Python or Numeric
# C/APIs do not support the corresponding C types.
c2py_map={'double':'float',
'float':'float', # forced casting
'long_double':'float', # forced casting
'char':'int', # forced casting
'signed_char':'int', # forced casting
'unsigned_char':'int', # forced casting
'short':'int', # forced casting
'unsigned_short':'int', # forced casting
'int':'int', # (forced casting)
'long':'int',
'long_long':'long',
'unsigned':'int', # forced casting
'complex_float':'complex', # forced casting
'complex_double':'complex',
'complex_long_double':'complex', # forced casting
'string':'string',
}
c2capi_map={'double':'PyArray_DOUBLE',
'float':'PyArray_FLOAT',
'long_double':'PyArray_DOUBLE', # forced casting
'char':'PyArray_CHAR',
'unsigned_char':'PyArray_UBYTE',
'signed_char':'PyArray_SBYTE',
'short':'PyArray_SHORT',
'unsigned_short':'PyArray_USHORT',
'int':'PyArray_INT',
'unsigned':'PyArray_UINT',
'long':'PyArray_LONG',
'long_long':'PyArray_LONG', # forced casting
'complex_float':'PyArray_CFLOAT',
'complex_double':'PyArray_CDOUBLE',
'complex_long_double':'PyArray_CDOUBLE', # forced casting
'string':'PyArray_CHAR'}
#These new maps aren't used anyhere yet, but should be by default
# unless building numeric or numarray extensions.
if using_newcore:
c2capi_map={'double':'PyArray_DOUBLE',
'float':'PyArray_FLOAT',
'long_double':'PyArray_LONGDOUBLE',
'char':'PyArray_BYTE',
'unsigned_char':'PyArray_UBYTE',
'signed_char':'PyArray_BYTE',
'short':'PyArray_SHORT',
'unsigned_short':'PyArray_USHORT',
'int':'PyArray_INT',
'unsigned':'PyArray_UINT',
'long':'PyArray_LONG',
'unsigned_long':'PyArray_ULONG',
'long_long':'PyArray_LONGLONG',
'unsigned_long_long':'Pyarray_ULONGLONG',
'complex_float':'PyArray_CFLOAT',
'complex_double':'PyArray_CDOUBLE',
'complex_long_double':'PyArray_CDOUBLE',
'string':'PyArray_CHAR', # f2py 2e is not ready for PyArray_STRING (must set itemisize etc)
#'string':'PyArray_STRING'
}
c2pycode_map={'double':'d',
'float':'f',
'long_double':'d', # forced casting
'char':'1',
'signed_char':'1',
'unsigned_char':'b',
'short':'s',
'unsigned_short':'w',
'int':'i',
'unsigned':'u',
'long':'l',
'long_long':'L',
'complex_float':'F',
'complex_double':'D',
'complex_long_double':'D', # forced casting
'string':'c'
}
if using_newcore:
c2pycode_map={'double':'d',
'float':'f',
'long_double':'g',
'char':'b',
'unsigned_char':'B',
'signed_char':'b',
'short':'h',
'unsigned_short':'H',
'int':'i',
'unsigned':'I',
'long':'l',
'unsigned_long':'L',
'long_long':'q',
'unsigned_long_long':'Q',
'complex_float':'F',
'complex_double':'D',
'complex_long_double':'G',
'string':'S'}
c2buildvalue_map={'double':'d',
'float':'f',
'char':'b',
'signed_char':'b',
'short':'h',
'int':'i',
'long':'l',
'long_long':'L',
'complex_float':'N',
'complex_double':'N',
'complex_long_double':'N',
'string':'z'}
if sys.version_info[0] >= 3:
# Bytes, not Unicode strings
c2buildvalue_map['string'] = 'y'
if using_newcore:
#c2buildvalue_map=???
pass
f2cmap_all={'real':{'':'float','4':'float','8':'double','12':'long_double','16':'long_double'},
'integer':{'':'int','1':'signed_char','2':'short','4':'int','8':'long_long',
'-1':'unsigned_char','-2':'unsigned_short','-4':'unsigned',
'-8':'unsigned_long_long'},
'complex':{'':'complex_float','8':'complex_float',
'16':'complex_double','24':'complex_long_double',
'32':'complex_long_double'},
'complexkind':{'':'complex_float','4':'complex_float',
'8':'complex_double','12':'complex_long_double',
'16':'complex_long_double'},
'logical':{'':'int','1':'char','2':'short','4':'int','8':'long_long'},
'double complex':{'':'complex_double'},
'double precision':{'':'double'},
'byte':{'':'char'},
'character':{'':'string'}
}
if os.path.isfile('.f2py_f2cmap'):
# User defined additions to f2cmap_all.
# .f2py_f2cmap must contain a dictionary of dictionaries, only.
# For example, {'real':{'low':'float'}} means that Fortran 'real(low)' is
# interpreted as C 'float'.
# This feature is useful for F90/95 users if they use PARAMETERSs
# in type specifications.
try:
outmess('Reading .f2py_f2cmap ...\n')
f = open('.f2py_f2cmap','r')
d = eval(f.read(),{},{})
f.close()
for k,d1 in d.items():
for k1 in d1.keys():
d1[k1.lower()] = d1[k1]
d[k.lower()] = d[k]
for k in d.keys():
if k not in f2cmap_all:
f2cmap_all[k]={}
for k1 in d[k].keys():
if d[k][k1] in c2py_map:
if k1 in f2cmap_all[k]:
outmess("\tWarning: redefinition of {'%s':{'%s':'%s'->'%s'}}\n"%(k,k1,f2cmap_all[k][k1],d[k][k1]))
f2cmap_all[k][k1] = d[k][k1]
outmess('\tMapping "%s(kind=%s)" to "%s"\n' % (k,k1,d[k][k1]))
else:
errmess("\tIgnoring map {'%s':{'%s':'%s'}}: '%s' must be in %s\n"%(k,k1,d[k][k1],d[k][k1],c2py_map.keys()))
outmess('Succesfully applied user defined changes from .f2py_f2cmap\n')
except:
errmess('Failed to apply user defined changes from .f2py_f2cmap. Skipping.\n')
cformat_map={'double':'%g',
'float':'%g',
'long_double':'%Lg',
'char':'%d',
'signed_char':'%d',
'unsigned_char':'%hhu',
'short':'%hd',
'unsigned_short':'%hu',
'int':'%d',
'unsigned':'%u',
'long':'%ld',
'unsigned_long':'%lu',
'long_long':'%ld',
'complex_float':'(%g,%g)',
'complex_double':'(%g,%g)',
'complex_long_double':'(%Lg,%Lg)',
'string':'%s',
}
############### Auxiliary functions
def getctype(var):
"""
Determines C type
"""
ctype='void'
if isfunction(var):
if 'result' in var:
a=var['result']
else:
a=var['name']
if a in var['vars']:
return getctype(var['vars'][a])
else:
errmess('getctype: function %s has no return value?!\n'%a)
elif issubroutine(var):
return ctype
elif 'typespec' in var and var['typespec'].lower() in f2cmap_all:
typespec = var['typespec'].lower()
f2cmap=f2cmap_all[typespec]
ctype=f2cmap[''] # default type
if 'kindselector' in var:
if '*' in var['kindselector']:
try:
ctype=f2cmap[var['kindselector']['*']]
except KeyError:
errmess('getctype: "%s %s %s" not supported.\n'%(var['typespec'],'*',var['kindselector']['*']))
elif 'kind' in var['kindselector']:
if typespec+'kind' in f2cmap_all:
f2cmap=f2cmap_all[typespec+'kind']
try:
ctype=f2cmap[var['kindselector']['kind']]
except KeyError:
if typespec in f2cmap_all:
f2cmap=f2cmap_all[typespec]
try:
ctype=f2cmap[str(var['kindselector']['kind'])]
except KeyError:
errmess('getctype: "%s(kind=%s)" not supported (use .f2py_f2cmap).\n'\
%(typespec,var['kindselector']['kind']))
else:
if not isexternal(var):
errmess('getctype: No C-type found in "%s", assuming void.\n'%var)
return ctype
def getstrlength(var):
if isstringfunction(var):
if 'result' in var:
a=var['result']
else:
a=var['name']
if a in var['vars']:
return getstrlength(var['vars'][a])
else:
errmess('getstrlength: function %s has no return value?!\n'%a)
if not isstring(var):
errmess('getstrlength: expected a signature of a string but got: %s\n'%(`var`))
len='1'
if 'charselector' in var:
a=var['charselector']
if '*' in a:
len=a['*']
elif 'len' in a:
len=a['len']
if re.match(r'\(\s*([*]|[:])\s*\)',len) or re.match(r'([*]|[:])',len):
#if len in ['(*)','*','(:)',':']:
if isintent_hide(var):
errmess('getstrlength:intent(hide): expected a string with defined length but got: %s\n'%(`var`))
len='-1'
return len
def getarrdims(a,var,verbose=0):
global depargs
ret={}
if isstring(var) and not isarray(var):
ret['dims']=getstrlength(var)
ret['size']=ret['dims']
ret['rank']='1'
elif isscalar(var):
ret['size']='1'
ret['rank']='0'
ret['dims']=''
elif isarray(var):
# if not isintent_c(var):
# var['dimension'].reverse()
dim=copy.copy(var['dimension'])
ret['size']='*'.join(dim)
try: ret['size']=`eval(ret['size'])`
except: pass
ret['dims']=','.join(dim)
ret['rank']=`len(dim)`
ret['rank*[-1]']=`len(dim)*[-1]`[1:-1]
for i in range(len(dim)): # solve dim for dependecies
v=[]
if dim[i] in depargs: v=[dim[i]]
else:
for va in depargs:
if re.match(r'.*?\b%s\b.*'%va,dim[i]):
v.append(va)
for va in v:
if depargs.index(va)>depargs.index(a):
dim[i]='*'
break
ret['setdims'],i='',-1
for d in dim:
i=i+1
if d not in ['*',':','(*)','(:)']:
ret['setdims']='%s#varname#_Dims[%d]=%s,'%(ret['setdims'],i,d)
if ret['setdims']: ret['setdims']=ret['setdims'][:-1]
ret['cbsetdims'],i='',-1
for d in var['dimension']:
i=i+1
if d not in ['*',':','(*)','(:)']:
ret['cbsetdims']='%s#varname#_Dims[%d]=%s,'%(ret['cbsetdims'],i,d)
elif isintent_in(var):
outmess('getarrdims:warning: assumed shape array, using 0 instead of %r\n' \
% (d))
ret['cbsetdims']='%s#varname#_Dims[%d]=%s,'%(ret['cbsetdims'],i,0)
elif verbose :
errmess('getarrdims: If in call-back function: array argument %s must have bounded dimensions: got %s\n'%(`a`,`d`))
if ret['cbsetdims']: ret['cbsetdims']=ret['cbsetdims'][:-1]
# if not isintent_c(var):
# var['dimension'].reverse()
return ret
def getpydocsign(a,var):
global lcb_map
if isfunction(var):
if 'result' in var:
af=var['result']
else:
af=var['name']
if af in var['vars']:
return getpydocsign(af,var['vars'][af])
else:
errmess('getctype: function %s has no return value?!\n'%af)
return '',''
sig,sigout=a,a
opt=''
if isintent_in(var): opt='input'
elif isintent_inout(var): opt='in/output'
out_a = a
if isintent_out(var):
for k in var['intent']:
if k[:4]=='out=':
out_a = k[4:]
break
init=''
ctype=getctype(var)
if hasinitvalue(var):
init,showinit=getinit(a,var)
init='= %s'%(showinit)
if isscalar(var):
if isintent_inout(var):
sig='%s :%s %s rank-0 array(%s,\'%s\')'%(a,init,opt,c2py_map[ctype],
c2pycode_map[ctype],)
else:
sig='%s :%s %s %s'%(a,init,opt,c2py_map[ctype])
sigout='%s : %s'%(out_a,c2py_map[ctype])
elif isstring(var):
if isintent_inout(var):
sig='%s :%s %s rank-0 array(string(len=%s),\'c\')'%(a,init,opt,getstrlength(var))
else:
sig='%s :%s %s string(len=%s)'%(a,init,opt,getstrlength(var))
sigout='%s : string(len=%s)'%(out_a,getstrlength(var))
elif isarray(var):
dim=var['dimension']
rank=`len(dim)`
sig='%s :%s %s rank-%s array(\'%s\') with bounds (%s)'%(a,init,opt,rank,
c2pycode_map[ctype],
','.join(dim))
if a==out_a:
sigout='%s : rank-%s array(\'%s\') with bounds (%s)'\
%(a,rank,c2pycode_map[ctype],','.join(dim))
else:
sigout='%s : rank-%s array(\'%s\') with bounds (%s) and %s storage'\
%(out_a,rank,c2pycode_map[ctype],','.join(dim),a)
elif isexternal(var):
ua=''
if a in lcb_map and lcb_map[a] in lcb2_map and 'argname' in lcb2_map[lcb_map[a]]:
ua=lcb2_map[lcb_map[a]]['argname']
if not ua==a: ua=' => %s'%ua
else: ua=''
sig='%s : call-back function%s'%(a,ua)
sigout=sig
else:
errmess('getpydocsign: Could not resolve docsignature for "%s".\\n'%a)
return sig,sigout
def getarrdocsign(a,var):
ctype=getctype(var)
if isstring(var) and (not isarray(var)):
sig='%s : rank-0 array(string(len=%s),\'c\')'%(a,getstrlength(var))
elif isscalar(var):
sig='%s : rank-0 array(%s,\'%s\')'%(a,c2py_map[ctype],
c2pycode_map[ctype],)
elif isarray(var):
dim=var['dimension']
rank=`len(dim)`
sig='%s : rank-%s array(\'%s\') with bounds (%s)'%(a,rank,
c2pycode_map[ctype],
','.join(dim))
return sig
def getinit(a,var):
if isstring(var): init,showinit='""',"''"
else: init,showinit='',''
if hasinitvalue(var):
init=var['=']
showinit=init
if iscomplex(var) or iscomplexarray(var):
ret={}
try:
v = var["="]
if ',' in v:
ret['init.r'],ret['init.i']=markoutercomma(v[1:-1]).split('@,@')
else:
v = eval(v,{},{})
ret['init.r'],ret['init.i']=str(v.real),str(v.imag)
except:
raise ValueError('sign2map: expected complex number `(r,i)\' but got `%s\' as initial value of %r.' % (init, a))
if isarray(var):
init='(capi_c.r=%s,capi_c.i=%s,capi_c)'%(ret['init.r'],ret['init.i'])
elif isstring(var):
if not init: init,showinit='""',"''"
if init[0]=="'":
init='"%s"'%(init[1:-1].replace('"','\\"'))
if init[0]=='"': showinit="'%s'"%(init[1:-1])
return init,showinit
def sign2map(a,var):
"""
varname,ctype,atype
init,init.r,init.i,pytype
vardebuginfo,vardebugshowvalue,varshowvalue
varrfromat
intent
"""
global lcb_map,cb_map
out_a = a
if isintent_out(var):
for k in var['intent']:
if k[:4]=='out=':
out_a = k[4:]
break
ret={'varname':a,'outvarname':out_a}
ret['ctype']=getctype(var)
intent_flags = []
for f,s in isintent_dict.items():
if f(var): intent_flags.append('F2PY_%s'%s)
if intent_flags:
#XXX: Evaluate intent_flags here.
ret['intent'] = '|'.join(intent_flags)
else:
ret['intent'] = 'F2PY_INTENT_IN'
if isarray(var): ret['varrformat']='N'
elif ret['ctype'] in c2buildvalue_map:
ret['varrformat']=c2buildvalue_map[ret['ctype']]
else: ret['varrformat']='O'
ret['init'],ret['showinit']=getinit(a,var)
if hasinitvalue(var) and iscomplex(var) and not isarray(var):
ret['init.r'],ret['init.i'] = markoutercomma(ret['init'][1:-1]).split('@,@')
if isexternal(var):
ret['cbnamekey']=a
if a in lcb_map:
ret['cbname']=lcb_map[a]
ret['maxnofargs']=lcb2_map[lcb_map[a]]['maxnofargs']
ret['nofoptargs']=lcb2_map[lcb_map[a]]['nofoptargs']
ret['cbdocstr']=lcb2_map[lcb_map[a]]['docstr']
ret['cblatexdocstr']=lcb2_map[lcb_map[a]]['latexdocstr']
else:
ret['cbname']=a
errmess('sign2map: Confused: external %s is not in lcb_map%s.\n'%(a,lcb_map.keys()))
if isstring(var):
ret['length']=getstrlength(var)
if isarray(var):
ret=dictappend(ret,getarrdims(a,var))
dim=copy.copy(var['dimension'])
if ret['ctype'] in c2capi_map:
ret['atype']=c2capi_map[ret['ctype']]
# Debug info
if debugcapi(var):
il=[isintent_in,'input',isintent_out,'output',
isintent_inout,'inoutput',isrequired,'required',
isoptional,'optional',isintent_hide,'hidden',
iscomplex,'complex scalar',
l_and(isscalar,l_not(iscomplex)),'scalar',
isstring,'string',isarray,'array',
iscomplexarray,'complex array',isstringarray,'string array',
iscomplexfunction,'complex function',
l_and(isfunction,l_not(iscomplexfunction)),'function',
isexternal,'callback',
isintent_callback,'callback',
isintent_aux,'auxiliary',
#ismutable,'mutable',l_not(ismutable),'immutable',
]
rl=[]
for i in range(0,len(il),2):
if il[i](var): rl.append(il[i+1])
if isstring(var):
rl.append('slen(%s)=%s'%(a,ret['length']))
if isarray(var):
# if not isintent_c(var):
# var['dimension'].reverse()
ddim=','.join(map(lambda x,y:'%s|%s'%(x,y),var['dimension'],dim))
rl.append('dims(%s)'%ddim)
# if not isintent_c(var):
# var['dimension'].reverse()
if isexternal(var):
ret['vardebuginfo']='debug-capi:%s=>%s:%s'%(a,ret['cbname'],','.join(rl))
else:
ret['vardebuginfo']='debug-capi:%s %s=%s:%s'%(ret['ctype'],a,ret['showinit'],','.join(rl))
if isscalar(var):
if ret['ctype'] in cformat_map:
ret['vardebugshowvalue']='debug-capi:%s=%s'%(a,cformat_map[ret['ctype']])
if isstring(var):
ret['vardebugshowvalue']='debug-capi:slen(%s)=%%d %s=\\"%%s\\"'%(a,a)
if isexternal(var):
ret['vardebugshowvalue']='debug-capi:%s=%%p'%(a)
if ret['ctype'] in cformat_map:
ret['varshowvalue']='#name#:%s=%s'%(a,cformat_map[ret['ctype']])
ret['showvalueformat']='%s'%(cformat_map[ret['ctype']])
if isstring(var):
ret['varshowvalue']='#name#:slen(%s)=%%d %s=\\"%%s\\"'%(a,a)
ret['pydocsign'],ret['pydocsignout']=getpydocsign(a,var)
if hasnote(var):
ret['note']=var['note']
return ret
def routsign2map(rout):
"""
name,NAME,begintitle,endtitle
rname,ctype,rformat
routdebugshowvalue
"""
global lcb_map
name = rout['name']
fname = getfortranname(rout)
ret={'name':name,
'texname':name.replace('_','\\_'),
'name_lower':name.lower(),
'NAME':name.upper(),
'begintitle':gentitle(name),
'endtitle':gentitle('end of %s'%name),
'fortranname':fname,
'FORTRANNAME':fname.upper(),
'callstatement':getcallstatement(rout) or '',
'usercode':getusercode(rout) or '',
'usercode1':getusercode1(rout) or '',
}
if '_' in fname:
ret['F_FUNC'] = 'F_FUNC_US'
else:
ret['F_FUNC'] = 'F_FUNC'
if '_' in name:
ret['F_WRAPPEDFUNC'] = 'F_WRAPPEDFUNC_US'
else:
ret['F_WRAPPEDFUNC'] = 'F_WRAPPEDFUNC'
lcb_map={}
if 'use' in rout:
for u in rout['use'].keys():
if u in cb_rules.cb_map:
for un in cb_rules.cb_map[u]:
ln=un[0]
if 'map' in rout['use'][u]:
for k in rout['use'][u]['map'].keys():
if rout['use'][u]['map'][k]==un[0]: ln=k;break
lcb_map[ln]=un[1]
#else:
# errmess('routsign2map: cb_map does not contain module "%s" used in "use" statement.\n'%(u))
elif 'externals' in rout and rout['externals']:
errmess('routsign2map: Confused: function %s has externals %s but no "use" statement.\n'%(ret['name'],`rout['externals']`))
ret['callprotoargument'] = getcallprotoargument(rout,lcb_map) or ''
if isfunction(rout):
if 'result' in rout:
a=rout['result']
else:
a=rout['name']
ret['rname']=a
ret['pydocsign'],ret['pydocsignout']=getpydocsign(a,rout)
ret['ctype']=getctype(rout['vars'][a])
if hasresultnote(rout):
ret['resultnote']=rout['vars'][a]['note']
rout['vars'][a]['note']=['See elsewhere.']
if ret['ctype'] in c2buildvalue_map:
ret['rformat']=c2buildvalue_map[ret['ctype']]
else:
ret['rformat']='O'
errmess('routsign2map: no c2buildvalue key for type %s\n'%(`ret['ctype']`))
if debugcapi(rout):
if ret['ctype'] in cformat_map:
ret['routdebugshowvalue']='debug-capi:%s=%s'%(a,cformat_map[ret['ctype']])
if isstringfunction(rout):
ret['routdebugshowvalue']='debug-capi:slen(%s)=%%d %s=\\"%%s\\"'%(a,a)
if isstringfunction(rout):
ret['rlength']=getstrlength(rout['vars'][a])
if ret['rlength']=='-1':
errmess('routsign2map: expected explicit specification of the length of the string returned by the fortran function %s; taking 10.\n'%(`rout['name']`))
ret['rlength']='10'
if hasnote(rout):
ret['note']=rout['note']
rout['note']=['See elsewhere.']
return ret
def modsign2map(m):
"""
modulename
"""
if ismodule(m):
ret={'f90modulename':m['name'],
'F90MODULENAME':m['name'].upper(),
'texf90modulename':m['name'].replace('_','\\_')}
else:
ret={'modulename':m['name'],
'MODULENAME':m['name'].upper(),
'texmodulename':m['name'].replace('_','\\_')}
ret['restdoc'] = getrestdoc(m) or []
if hasnote(m):
ret['note']=m['note']
#m['note']=['See elsewhere.']
ret['usercode'] = getusercode(m) or ''
ret['usercode1'] = getusercode1(m) or ''
if m['body']:
ret['interface_usercode'] = getusercode(m['body'][0]) or ''
else:
ret['interface_usercode'] = ''
ret['pymethoddef'] = getpymethoddef(m) or ''
if 'coutput' in m:
ret['coutput'] = m['coutput']
if 'f2py_wrapper_output' in m:
ret['f2py_wrapper_output'] = m['f2py_wrapper_output']
return ret
def cb_sign2map(a,var,index=None):
ret={'varname':a}
if index is None or 1: # disable 7712 patch
ret['varname_i'] = ret['varname']
else:
ret['varname_i'] = ret['varname'] + '_' + str(index)
ret['ctype']=getctype(var)
if ret['ctype'] in c2capi_map:
ret['atype']=c2capi_map[ret['ctype']]
if ret['ctype'] in cformat_map:
ret['showvalueformat']='%s'%(cformat_map[ret['ctype']])
if isarray(var):
ret=dictappend(ret,getarrdims(a,var))
ret['pydocsign'],ret['pydocsignout']=getpydocsign(a,var)
if hasnote(var):
ret['note']=var['note']
var['note']=['See elsewhere.']
return ret
def cb_routsign2map(rout,um):
"""
name,begintitle,endtitle,argname
ctype,rctype,maxnofargs,nofoptargs,returncptr
"""
ret={'name':'cb_%s_in_%s'%(rout['name'],um),
'returncptr':''}
if isintent_callback(rout):
if '_' in rout['name']:
F_FUNC='F_FUNC_US'
else:
F_FUNC='F_FUNC'
ret['callbackname'] = '%s(%s,%s)' \
% (F_FUNC,
rout['name'].lower(),
rout['name'].upper(),
)
ret['static'] = 'extern'
else:
ret['callbackname'] = ret['name']
ret['static'] = 'static'
ret['argname']=rout['name']
ret['begintitle']=gentitle(ret['name'])
ret['endtitle']=gentitle('end of %s'%ret['name'])
ret['ctype']=getctype(rout)
ret['rctype']='void'
if ret['ctype']=='string': ret['rctype']='void'
else:
ret['rctype']=ret['ctype']
if ret['rctype']!='void':
if iscomplexfunction(rout):
ret['returncptr'] = """
#ifdef F2PY_CB_RETURNCOMPLEX
return_value=
#endif
"""
else:
ret['returncptr'] = 'return_value='
if ret['ctype'] in cformat_map:
ret['showvalueformat']='%s'%(cformat_map[ret['ctype']])
if isstringfunction(rout):
ret['strlength']=getstrlength(rout)
if isfunction(rout):
if 'result' in rout:
a=rout['result']
else:
a=rout['name']
if hasnote(rout['vars'][a]):
ret['note']=rout['vars'][a]['note']
rout['vars'][a]['note']=['See elsewhere.']
ret['rname']=a
ret['pydocsign'],ret['pydocsignout']=getpydocsign(a,rout)
if iscomplexfunction(rout):
ret['rctype']="""
#ifdef F2PY_CB_RETURNCOMPLEX
#ctype#
#else
void
#endif
"""
else:
if hasnote(rout):
ret['note']=rout['note']
rout['note']=['See elsewhere.']
nofargs=0
nofoptargs=0
if 'args' in rout and 'vars' in rout:
for a in rout['args']:
var=rout['vars'][a]
if l_or(isintent_in,isintent_inout)(var):
nofargs=nofargs+1
if isoptional(var):
nofoptargs=nofoptargs+1
ret['maxnofargs']=`nofargs`
ret['nofoptargs']=`nofoptargs`
if hasnote(rout) and isfunction(rout) and 'result' in rout:
ret['routnote']=rout['note']
rout['note']=['See elsewhere.']
return ret
def common_sign2map(a,var): # obsolute
ret={'varname':a}
ret['ctype']=getctype(var)
if isstringarray(var):
ret['ctype']='char'
if ret['ctype'] in c2capi_map:
ret['atype']=c2capi_map[ret['ctype']]
if ret['ctype'] in cformat_map:
ret['showvalueformat']='%s'%(cformat_map[ret['ctype']])
if isarray(var):
ret=dictappend(ret,getarrdims(a,var))
elif isstring(var):
ret['size']=getstrlength(var)
ret['rank']='1'
ret['pydocsign'],ret['pydocsignout']=getpydocsign(a,var)
if hasnote(var):
ret['note']=var['note']
var['note']=['See elsewhere.']
ret['arrdocstr']=getarrdocsign(a,var) # for strings this returns 0-rank but actually is 1-rank
return ret
|
gpl-3.0
|
[
3168,
2,
35,
3427,
12117,
60,
526,
71,
60,
26872,
60,
15039,
13225,
7129,
60,
24286,
60,
1596,
11048,
73,
1653,
1352,
5294,
60,
1596,
11048,
73,
1653,
1352,
5294,
60,
1393,
60,
7084,
60,
73,
647,
14,
5803,
2,
199,
624,
199,
199,
7384,
21300,
12,
8269,
510,
2210,
85,
22912,
834,
1006,
4481,
4644,
12,
199,
48,
2210,
85,
22912,
834,
665,
16343,
85,
32,
73,
679,
14,
1024,
30,
199,
7980,
370,
675,
12,
2811,
12,
436,
11207,
642,
2032,
365,
1627,
1334,
314,
199,
9187,
402,
314,
20602,
844,
14,
199,
199,
2826,
3408,
2281,
3651,
14956,
10934,
1549,
5292,
14,
221,
4815,
15059,
1488,
11237,
593,
3705,
820,
22481,
14,
199,
4,
2506,
26,
11811,
15,
1717,
15,
1690,
1616,
26,
1641,
26,
1153,
2672,
199,
48,
2210,
85,
22912,
834,
199,
624,
199,
199,
363,
1023,
363,
275,
7880,
12714,
26,
413,
14,
2259,
2672,
22774,
709,
6809,
17,
61,
199,
199,
646,
636,
1023,
363,
199,
70,
18,
647,
63,
1023,
275,
636,
1023,
4343,
1023,
199,
199,
646,
1331,
199,
646,
295,
199,
646,
747,
199,
646,
984,
199,
504,
11593,
9204,
492,
627,
199,
504,
286,
8085,
18496,
492,
2216,
7837,
13184,
199,
646,
7434,
63,
4423,
199,
199,
3,
16817,
1144,
436,
19378,
4390,
1077,
663,
642,
756,
199,
4941,
63,
1222,
1018,
275,
715,
199,
199,
271,
462,
458,
9811,
199,
76,
2894,
63,
1130,
7622,
199,
76,
2894,
18,
63,
1130,
7622,
199,
3,
19565,
22883,
26,
27580,
18104,
701,
314,
10572,
626,
2018,
503,
19378,
199,
3,
463,
445,
15,
1282,
1831,
886,
440,
2291,
314,
5226,
445,
2943,
14,
199,
67,
18,
647,
63,
1130,
3713,
3157,
5242,
1609,
297,
881,
283,
1609,
5242,
1609,
297,
14516,
327,
19565,
22883,
881,
283,
2809,
63,
3157,
5242,
1609,
297,
8540,
327,
19565,
22883,
881,
283,
1560,
5242,
442,
297,
17907,
327,
19565,
22883,
881,
283,
1737,
63,
1560,
5242,
442,
297,
10473,
327,
19565,
22883,
881,
283,
2244,
63,
1560,
5242,
442,
297,
8540,
327,
19565,
22883,
881,
283,
3612,
5242,
442,
297,
14960,
327,
19565,
22883,
881,
283,
2244,
63,
3612,
5242,
442,
297,
7861,
327,
19565,
22883,
881,
283,
442,
5242,
442,
297,
19242,
327,
334,
28074,
22883,
9,
881,
283,
2809,
5242,
442,
297,
881,
283,
2809,
63,
2809,
5242,
2809,
297,
881,
283,
2244,
5242,
442,
297,
12793,
327,
19565,
22883,
881,
283,
5254,
63,
1609,
5242,
5254,
297,
4483,
327,
19565,
22883,
881,
283,
5254,
63,
3157,
5242,
5254,
297,
881,
283,
5254,
63,
2809,
63,
3157,
5242,
5254,
297,
3515,
327,
19565,
22883,
881,
283,
875,
5242,
875,
297,
881,
789,
199,
67,
18,
14145,
63,
1130,
3713,
3157,
5242,
28726,
63,
14989,
297,
288,
283,
1609,
5242,
28726,
63,
11783,
297,
288,
283,
2809,
63,
3157,
5242,
28726,
63,
14989,
297,
3698,
327,
19565,
22883,
288,
283,
1560,
5242,
28726,
63,
5901,
297,
288,
283,
2244,
63,
1560,
5242,
28726,
63,
2533,
57,
3727,
297,
288,
283,
1737,
63,
1560,
5242,
28726,
63,
51,
19714,
297,
288,
283,
3612,
5242,
28726,
63,
13003,
297,
288,
283,
2244,
63,
3612,
5242,
28726,
63,
14527,
2596,
297,
288,
283,
442,
5242,
28726,
63,
2919,
297,
288,
283,
2244,
5242,
28726,
63,
17459,
297,
288,
283,
2809,
5242,
28726,
63,
12375,
297,
288,
283,
2809,
63,
2809,
5242,
28726,
63,
12375,
297,
4483,
327,
19565,
22883,
288,
283,
5254,
63,
1609,
5242,
28726,
63,
5487,
10440,
297,
288,
283,
5254,
63,
3157,
5242,
28726,
63,
35,
14989,
297,
288,
283,
5254,
63,
2809,
63,
3157,
5242,
28726,
63,
35,
14989,
297,
257,
327,
19565,
22883,
288,
283,
875,
5242,
28726,
63,
5901,
936,
199,
199,
3,
20676,
892,
9033,
10621,
1133,
1202,
1263,
1681,
5966,
12,
1325,
1077,
506,
701,
849,
199,
3,
221,
7444,
10015,
8950,
503,
1967,
1144,
5478,
14,
199,
692,
1808,
63,
1222,
1018,
26,
272,
286,
18,
14145,
63,
1130,
3713,
3157,
5242,
28726,
63,
14989,
297,
288,
283,
1609,
5242,
28726,
63,
11783,
297,
288,
283,
2809,
63,
3157,
5242,
28726,
63,
12375,
14989,
297,
288,
283,
1560,
5242,
28726,
63,
19714,
297,
288,
283,
2244,
63,
1560,
5242,
28726,
63,
2533,
57,
3727,
297,
288,
283,
1737,
63,
1560,
5242,
28726,
63,
19714,
297,
288,
283,
3612,
5242,
28726,
63,
13003,
297,
288,
283,
2244,
63,
3612,
5242,
28726,
63,
14527,
2596,
297,
288,
283,
442,
5242,
28726,
63,
2919,
297,
288,
283,
2244,
5242,
28726,
63,
17459,
297,
288,
283,
2809,
5242,
28726,
63,
12375,
297,
288,
283,
2244,
63,
2809,
5242,
28726,
63,
1293,
7770,
297,
288,
283,
2809,
63,
2809,
5242,
28726,
63,
44,
615,
2226,
7770,
297,
288,
283,
2244,
63,
2809,
63,
2809,
5242,
2713,
1144,
63,
1293,
615,
2226,
7770,
297,
288,
283,
5254,
63,
1609,
5242,
28726,
63,
5487,
10440,
297,
288,
283,
5254,
63,
3157,
5242,
28726,
63,
35,
14989,
297,
288,
283,
5254,
63,
2809,
63,
3157,
5242,
28726,
63,
35,
14989,
297,
288,
283,
875,
5242,
28726,
63,
5901,
297,
327,
289,
18,
647,
499,
69,
365,
440,
10144,
367,
1611,
3836,
63,
5353,
334,
7790,
663,
1242,
73,
890,
5423,
9,
288,
17384,
875,
5242,
28726,
63,
5353,
7,
2234,
789,
199,
67,
18,
647,
600,
63,
1130,
3713,
3157,
5242,
68,
297,
1598,
283,
1609,
5242,
70,
297,
1598,
283,
2809,
63,
3157,
5242,
68,
297,
9668,
327,
19565,
22883,
1598,
283,
1560,
5242,
17,
297,
1598,
283,
1737,
63,
1560,
5242,
17,
297,
1598,
283,
2244,
63,
1560,
5242,
66,
297,
1598,
283,
3612,
5242,
83,
297,
1598,
283,
2244,
63,
3612,
5242,
87,
297,
1598,
283,
442,
5242,
73,
297,
1598,
283,
2244,
5242,
85,
297,
1598,
283,
2809,
5242,
76,
297,
1598,
283,
2809,
63,
2809,
5242,
44,
297,
1598,
283,
5254,
63,
1609,
5242,
38,
297,
1598,
283,
5254,
63,
3157,
5242,
36,
297,
1598,
283,
5254,
63,
2809,
63,
3157,
5242,
36,
297,
5185,
327,
19565,
22883,
1598,
283,
875,
5242,
67,
7,
1598,
789,
199,
692,
1808,
63,
1222,
1018,
26,
272,
286,
18,
647,
600,
63,
1130,
3713,
3157,
5242,
68,
297,
326,
283,
1609,
5242,
70,
297,
326,
283,
2809
] |
[
2,
35,
3427,
12117,
60,
526,
71,
60,
26872,
60,
15039,
13225,
7129,
60,
24286,
60,
1596,
11048,
73,
1653,
1352,
5294,
60,
1596,
11048,
73,
1653,
1352,
5294,
60,
1393,
60,
7084,
60,
73,
647,
14,
5803,
2,
199,
624,
199,
199,
7384,
21300,
12,
8269,
510,
2210,
85,
22912,
834,
1006,
4481,
4644,
12,
199,
48,
2210,
85,
22912,
834,
665,
16343,
85,
32,
73,
679,
14,
1024,
30,
199,
7980,
370,
675,
12,
2811,
12,
436,
11207,
642,
2032,
365,
1627,
1334,
314,
199,
9187,
402,
314,
20602,
844,
14,
199,
199,
2826,
3408,
2281,
3651,
14956,
10934,
1549,
5292,
14,
221,
4815,
15059,
1488,
11237,
593,
3705,
820,
22481,
14,
199,
4,
2506,
26,
11811,
15,
1717,
15,
1690,
1616,
26,
1641,
26,
1153,
2672,
199,
48,
2210,
85,
22912,
834,
199,
624,
199,
199,
363,
1023,
363,
275,
7880,
12714,
26,
413,
14,
2259,
2672,
22774,
709,
6809,
17,
61,
199,
199,
646,
636,
1023,
363,
199,
70,
18,
647,
63,
1023,
275,
636,
1023,
4343,
1023,
199,
199,
646,
1331,
199,
646,
295,
199,
646,
747,
199,
646,
984,
199,
504,
11593,
9204,
492,
627,
199,
504,
286,
8085,
18496,
492,
2216,
7837,
13184,
199,
646,
7434,
63,
4423,
199,
199,
3,
16817,
1144,
436,
19378,
4390,
1077,
663,
642,
756,
199,
4941,
63,
1222,
1018,
275,
715,
199,
199,
271,
462,
458,
9811,
199,
76,
2894,
63,
1130,
7622,
199,
76,
2894,
18,
63,
1130,
7622,
199,
3,
19565,
22883,
26,
27580,
18104,
701,
314,
10572,
626,
2018,
503,
19378,
199,
3,
463,
445,
15,
1282,
1831,
886,
440,
2291,
314,
5226,
445,
2943,
14,
199,
67,
18,
647,
63,
1130,
3713,
3157,
5242,
1609,
297,
881,
283,
1609,
5242,
1609,
297,
14516,
327,
19565,
22883,
881,
283,
2809,
63,
3157,
5242,
1609,
297,
8540,
327,
19565,
22883,
881,
283,
1560,
5242,
442,
297,
17907,
327,
19565,
22883,
881,
283,
1737,
63,
1560,
5242,
442,
297,
10473,
327,
19565,
22883,
881,
283,
2244,
63,
1560,
5242,
442,
297,
8540,
327,
19565,
22883,
881,
283,
3612,
5242,
442,
297,
14960,
327,
19565,
22883,
881,
283,
2244,
63,
3612,
5242,
442,
297,
7861,
327,
19565,
22883,
881,
283,
442,
5242,
442,
297,
19242,
327,
334,
28074,
22883,
9,
881,
283,
2809,
5242,
442,
297,
881,
283,
2809,
63,
2809,
5242,
2809,
297,
881,
283,
2244,
5242,
442,
297,
12793,
327,
19565,
22883,
881,
283,
5254,
63,
1609,
5242,
5254,
297,
4483,
327,
19565,
22883,
881,
283,
5254,
63,
3157,
5242,
5254,
297,
881,
283,
5254,
63,
2809,
63,
3157,
5242,
5254,
297,
3515,
327,
19565,
22883,
881,
283,
875,
5242,
875,
297,
881,
789,
199,
67,
18,
14145,
63,
1130,
3713,
3157,
5242,
28726,
63,
14989,
297,
288,
283,
1609,
5242,
28726,
63,
11783,
297,
288,
283,
2809,
63,
3157,
5242,
28726,
63,
14989,
297,
3698,
327,
19565,
22883,
288,
283,
1560,
5242,
28726,
63,
5901,
297,
288,
283,
2244,
63,
1560,
5242,
28726,
63,
2533,
57,
3727,
297,
288,
283,
1737,
63,
1560,
5242,
28726,
63,
51,
19714,
297,
288,
283,
3612,
5242,
28726,
63,
13003,
297,
288,
283,
2244,
63,
3612,
5242,
28726,
63,
14527,
2596,
297,
288,
283,
442,
5242,
28726,
63,
2919,
297,
288,
283,
2244,
5242,
28726,
63,
17459,
297,
288,
283,
2809,
5242,
28726,
63,
12375,
297,
288,
283,
2809,
63,
2809,
5242,
28726,
63,
12375,
297,
4483,
327,
19565,
22883,
288,
283,
5254,
63,
1609,
5242,
28726,
63,
5487,
10440,
297,
288,
283,
5254,
63,
3157,
5242,
28726,
63,
35,
14989,
297,
288,
283,
5254,
63,
2809,
63,
3157,
5242,
28726,
63,
35,
14989,
297,
257,
327,
19565,
22883,
288,
283,
875,
5242,
28726,
63,
5901,
936,
199,
199,
3,
20676,
892,
9033,
10621,
1133,
1202,
1263,
1681,
5966,
12,
1325,
1077,
506,
701,
849,
199,
3,
221,
7444,
10015,
8950,
503,
1967,
1144,
5478,
14,
199,
692,
1808,
63,
1222,
1018,
26,
272,
286,
18,
14145,
63,
1130,
3713,
3157,
5242,
28726,
63,
14989,
297,
288,
283,
1609,
5242,
28726,
63,
11783,
297,
288,
283,
2809,
63,
3157,
5242,
28726,
63,
12375,
14989,
297,
288,
283,
1560,
5242,
28726,
63,
19714,
297,
288,
283,
2244,
63,
1560,
5242,
28726,
63,
2533,
57,
3727,
297,
288,
283,
1737,
63,
1560,
5242,
28726,
63,
19714,
297,
288,
283,
3612,
5242,
28726,
63,
13003,
297,
288,
283,
2244,
63,
3612,
5242,
28726,
63,
14527,
2596,
297,
288,
283,
442,
5242,
28726,
63,
2919,
297,
288,
283,
2244,
5242,
28726,
63,
17459,
297,
288,
283,
2809,
5242,
28726,
63,
12375,
297,
288,
283,
2244,
63,
2809,
5242,
28726,
63,
1293,
7770,
297,
288,
283,
2809,
63,
2809,
5242,
28726,
63,
44,
615,
2226,
7770,
297,
288,
283,
2244,
63,
2809,
63,
2809,
5242,
2713,
1144,
63,
1293,
615,
2226,
7770,
297,
288,
283,
5254,
63,
1609,
5242,
28726,
63,
5487,
10440,
297,
288,
283,
5254,
63,
3157,
5242,
28726,
63,
35,
14989,
297,
288,
283,
5254,
63,
2809,
63,
3157,
5242,
28726,
63,
35,
14989,
297,
288,
283,
875,
5242,
28726,
63,
5901,
297,
327,
289,
18,
647,
499,
69,
365,
440,
10144,
367,
1611,
3836,
63,
5353,
334,
7790,
663,
1242,
73,
890,
5423,
9,
288,
17384,
875,
5242,
28726,
63,
5353,
7,
2234,
789,
199,
67,
18,
647,
600,
63,
1130,
3713,
3157,
5242,
68,
297,
1598,
283,
1609,
5242,
70,
297,
1598,
283,
2809,
63,
3157,
5242,
68,
297,
9668,
327,
19565,
22883,
1598,
283,
1560,
5242,
17,
297,
1598,
283,
1737,
63,
1560,
5242,
17,
297,
1598,
283,
2244,
63,
1560,
5242,
66,
297,
1598,
283,
3612,
5242,
83,
297,
1598,
283,
2244,
63,
3612,
5242,
87,
297,
1598,
283,
442,
5242,
73,
297,
1598,
283,
2244,
5242,
85,
297,
1598,
283,
2809,
5242,
76,
297,
1598,
283,
2809,
63,
2809,
5242,
44,
297,
1598,
283,
5254,
63,
1609,
5242,
38,
297,
1598,
283,
5254,
63,
3157,
5242,
36,
297,
1598,
283,
5254,
63,
2809,
63,
3157,
5242,
36,
297,
5185,
327,
19565,
22883,
1598,
283,
875,
5242,
67,
7,
1598,
789,
199,
692,
1808,
63,
1222,
1018,
26,
272,
286,
18,
647,
600,
63,
1130,
3713,
3157,
5242,
68,
297,
326,
283,
1609,
5242,
70,
297,
326,
283,
2809,
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,
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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
] |
Archcady/mbed-os
|
tools/host_tests/midi.py
|
111
|
1933
|
from __future__ import print_function
import sys
import re
import time
import mido
from mido import Message
def test_midi_in(port):
expected_messages_count=0
while expected_messages_count < 7:
for message in port.iter_pending():
if message.type in ('note_on', 'note_off', 'program_change', 'sysex'):
yield message
expected_messages_count+=1
time.sleep(0.1)
def test_midi_loopback(input_port):
expected_messages_count=0
while expected_messages_count < 1:
for message in input_port.iter_pending():
print('Test MIDI OUT loopback received {}'.format(message.hex()))
expected_messages_count+=1
def test_midi_out_loopback(output_port,input_port):
print("Test MIDI OUT loopback")
output_port.send(Message('program_change', program=1))
test_midi_loopback(input_port)
output_port.send(Message('note_on', note=21))
test_midi_loopback(input_port)
output_port.send(Message('note_off', note=21))
test_midi_loopback(input_port)
output_port.send(Message('sysex', data=[0x7E,0x7F,0x09,0x01]))
test_midi_loopback(input_port)
output_port.send(Message('sysex', data=[0x7F,0x7F,0x04,0x01,0x7F,0x7F]))
test_midi_loopback(input_port)
output_port.send(Message('sysex', data=[0x41,0x10,0x42,0x12,0x40,0x00,0x7F,0x00,0x41]))
test_midi_loopback(input_port)
output_port.send(Message('sysex', data=[0x41,0x10,0x42,0x12,0x40,0x00,0x04,0x7F,0x3D]))
test_midi_loopback(input_port)
portname=""
while portname=="":
print("Wait for MIDI IN plug ...")
for name in mido.get_input_names():
matchObj = re.match( r'Mbed', name)
if matchObj:
portname=name
time.sleep( 1 )
try:
input_port = mido.open_input(portname)
output_port = mido.open_output(portname)
print('Using {}'.format(input_port))
print("Test MIDI IN")
for message in test_midi_in(input_port):
print('Test MIDI IN received {}'.format(message.hex()))
test_midi_out_loopback(output_port,input_port)
except KeyboardInterrupt:
pass
|
apache-2.0
|
[
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
646,
984,
199,
646,
295,
199,
646,
900,
199,
646,
10887,
79,
199,
504,
10887,
79,
492,
6430,
421,
199,
318,
511,
63,
26859,
63,
262,
8,
719,
304,
199,
198,
2062,
63,
3431,
63,
835,
29,
16,
199,
198,
6710,
1420,
63,
3431,
63,
835,
665,
1520,
26,
507,
198,
509,
1245,
315,
1844,
14,
1661,
63,
6455,
837,
686,
198,
692,
1245,
14,
466,
315,
661,
4610,
63,
265,
297,
283,
4610,
63,
1997,
297,
283,
6815,
63,
1461,
297,
283,
1786,
20160,
735,
1585,
198,
11481,
1245,
1585,
198,
2062,
63,
3431,
63,
835,
10365,
17,
507,
198,
521,
14,
4532,
8,
16,
14,
17,
9,
199,
199,
318,
511,
63,
26859,
63,
23983,
8,
1210,
63,
719,
304,
199,
198,
2062,
63,
3431,
63,
835,
29,
16,
199,
198,
6710,
1420,
63,
3431,
63,
835,
665,
413,
26,
507,
198,
509,
1245,
315,
1324,
63,
719,
14,
1661,
63,
6455,
837,
686,
198,
1361,
360,
774,
603,
28904,
5738,
4438,
894,
3086,
9499,
908,
8,
1188,
14,
4097,
4059,
686,
198,
2062,
63,
3431,
63,
835,
10365,
17,
199,
199,
318,
511,
63,
26859,
63,
548,
63,
23983,
8,
1199,
63,
719,
12,
1210,
63,
719,
304,
199,
198,
1361,
480,
774,
603,
28904,
5738,
4438,
894,
531,
199,
198,
1199,
63,
719,
14,
2254,
8,
2209,
360,
6815,
63,
1461,
297,
2240,
29,
17,
430,
199,
198,
396,
63,
26859,
63,
23983,
8,
1210,
63,
719,
9,
421,
198,
1199,
63,
719,
14,
2254,
8,
2209,
360,
4610,
63,
265,
297,
5317,
29,
2025,
430,
199,
198,
396,
63,
26859,
63,
23983,
8,
1210,
63,
719,
9,
421,
198,
1199,
63,
719,
14,
2254,
8,
2209,
360,
4610,
63,
1997,
297,
5317,
29,
2025,
430,
199,
198,
396,
63,
26859,
63,
23983,
8,
1210,
63,
719,
9,
421,
198,
1199,
63,
719,
14,
2254,
8,
2209,
360,
1786,
20160,
297,
666,
1524,
16,
88,
23,
37,
12,
16,
88,
23,
38,
12,
16,
88,
1643,
12,
16,
88,
614,
2459,
199,
198,
396,
63,
26859,
63,
23983,
8,
1210,
63,
719,
9,
421,
198,
1199,
63,
719,
14,
2254,
8,
2209,
360,
1786,
20160,
297,
666,
1524,
16,
88,
23,
38,
12,
16,
88,
23,
38,
12,
16,
88,
966,
12,
16,
88,
614,
12,
16,
88,
23,
38,
12,
16,
88,
23,
38,
2459,
199,
198,
396,
63,
26859,
63,
23983,
8,
1210,
63,
719,
9,
421,
198,
1199,
63,
719,
14,
2254,
8,
2209,
360,
1786,
20160,
297,
666,
1524,
16,
88,
2953,
12,
16,
88,
709,
12,
16,
88,
2260,
12,
16,
88,
713,
12,
16,
88,
2167,
12,
16,
88,
383,
12,
16,
88,
23,
38,
12,
16,
88,
383,
12,
16,
88,
2953,
2459,
199,
198,
396,
63,
26859,
63,
23983,
8,
1210,
63,
719,
9,
421,
198,
1199,
63,
719,
14,
2254,
8,
2209,
360,
1786,
20160,
297,
666,
1524,
16,
88,
2953,
12,
16,
88,
709,
12,
16,
88,
2260,
12,
16,
88,
713,
12,
16,
88,
2167,
12,
16,
88,
383,
12,
16,
88,
966,
12,
16,
88,
23,
38,
12,
16,
88,
19,
36,
2459,
199,
198,
396,
63,
26859,
63,
23983,
8,
1210,
63,
719,
9,
199,
199,
719,
354,
9287,
199,
199,
6710,
1844,
354,
389,
29679,
199,
198,
1361,
480,
7536,
367,
603,
28904,
1621,
14202,
2263,
531,
199,
198,
509,
536,
315,
10887,
79,
14,
362,
63,
1210,
63,
1247,
837,
507,
198,
1431,
5665,
275,
295,
14,
1431,
8,
519,
7,
45,
6123,
297,
536,
9,
2742,
198,
692,
1336,
5665,
26,
686,
198,
719,
354,
29,
354,
199,
198,
521,
14,
4532,
8,
413,
776,
199,
199,
893,
26,
199,
198,
1210,
63,
719,
275,
10887,
79,
14,
1490,
63,
1210,
8,
719,
354,
9,
199,
198,
1199,
63,
719,
275,
10887,
79,
14,
1490,
63,
1199,
8,
719,
354,
9,
8299,
198,
1361,
360,
10369,
9499,
908,
8,
1210,
63,
719,
430,
421,
198,
1361,
480,
774,
603,
28904,
1621,
531,
421,
198,
509,
1245,
315,
511,
63,
26859,
63,
262,
8,
1210,
63,
719,
304,
507,
198,
1361,
360,
774,
603,
28904,
1621,
3086,
9499,
908,
8,
1188,
14,
4097,
4059,
421,
198,
396,
63,
26859,
63,
548,
63,
23983,
8,
1199,
63,
719,
12,
1210,
63,
719,
9,
199,
2590,
13483,
26,
272,
986,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
646,
984,
199,
646,
295,
199,
646,
900,
199,
646,
10887,
79,
199,
504,
10887,
79,
492,
6430,
421,
199,
318,
511,
63,
26859,
63,
262,
8,
719,
304,
199,
198,
2062,
63,
3431,
63,
835,
29,
16,
199,
198,
6710,
1420,
63,
3431,
63,
835,
665,
1520,
26,
507,
198,
509,
1245,
315,
1844,
14,
1661,
63,
6455,
837,
686,
198,
692,
1245,
14,
466,
315,
661,
4610,
63,
265,
297,
283,
4610,
63,
1997,
297,
283,
6815,
63,
1461,
297,
283,
1786,
20160,
735,
1585,
198,
11481,
1245,
1585,
198,
2062,
63,
3431,
63,
835,
10365,
17,
507,
198,
521,
14,
4532,
8,
16,
14,
17,
9,
199,
199,
318,
511,
63,
26859,
63,
23983,
8,
1210,
63,
719,
304,
199,
198,
2062,
63,
3431,
63,
835,
29,
16,
199,
198,
6710,
1420,
63,
3431,
63,
835,
665,
413,
26,
507,
198,
509,
1245,
315,
1324,
63,
719,
14,
1661,
63,
6455,
837,
686,
198,
1361,
360,
774,
603,
28904,
5738,
4438,
894,
3086,
9499,
908,
8,
1188,
14,
4097,
4059,
686,
198,
2062,
63,
3431,
63,
835,
10365,
17,
199,
199,
318,
511,
63,
26859,
63,
548,
63,
23983,
8,
1199,
63,
719,
12,
1210,
63,
719,
304,
199,
198,
1361,
480,
774,
603,
28904,
5738,
4438,
894,
531,
199,
198,
1199,
63,
719,
14,
2254,
8,
2209,
360,
6815,
63,
1461,
297,
2240,
29,
17,
430,
199,
198,
396,
63,
26859,
63,
23983,
8,
1210,
63,
719,
9,
421,
198,
1199,
63,
719,
14,
2254,
8,
2209,
360,
4610,
63,
265,
297,
5317,
29,
2025,
430,
199,
198,
396,
63,
26859,
63,
23983,
8,
1210,
63,
719,
9,
421,
198,
1199,
63,
719,
14,
2254,
8,
2209,
360,
4610,
63,
1997,
297,
5317,
29,
2025,
430,
199,
198,
396,
63,
26859,
63,
23983,
8,
1210,
63,
719,
9,
421,
198,
1199,
63,
719,
14,
2254,
8,
2209,
360,
1786,
20160,
297,
666,
1524,
16,
88,
23,
37,
12,
16,
88,
23,
38,
12,
16,
88,
1643,
12,
16,
88,
614,
2459,
199,
198,
396,
63,
26859,
63,
23983,
8,
1210,
63,
719,
9,
421,
198,
1199,
63,
719,
14,
2254,
8,
2209,
360,
1786,
20160,
297,
666,
1524,
16,
88,
23,
38,
12,
16,
88,
23,
38,
12,
16,
88,
966,
12,
16,
88,
614,
12,
16,
88,
23,
38,
12,
16,
88,
23,
38,
2459,
199,
198,
396,
63,
26859,
63,
23983,
8,
1210,
63,
719,
9,
421,
198,
1199,
63,
719,
14,
2254,
8,
2209,
360,
1786,
20160,
297,
666,
1524,
16,
88,
2953,
12,
16,
88,
709,
12,
16,
88,
2260,
12,
16,
88,
713,
12,
16,
88,
2167,
12,
16,
88,
383,
12,
16,
88,
23,
38,
12,
16,
88,
383,
12,
16,
88,
2953,
2459,
199,
198,
396,
63,
26859,
63,
23983,
8,
1210,
63,
719,
9,
421,
198,
1199,
63,
719,
14,
2254,
8,
2209,
360,
1786,
20160,
297,
666,
1524,
16,
88,
2953,
12,
16,
88,
709,
12,
16,
88,
2260,
12,
16,
88,
713,
12,
16,
88,
2167,
12,
16,
88,
383,
12,
16,
88,
966,
12,
16,
88,
23,
38,
12,
16,
88,
19,
36,
2459,
199,
198,
396,
63,
26859,
63,
23983,
8,
1210,
63,
719,
9,
199,
199,
719,
354,
9287,
199,
199,
6710,
1844,
354,
389,
29679,
199,
198,
1361,
480,
7536,
367,
603,
28904,
1621,
14202,
2263,
531,
199,
198,
509,
536,
315,
10887,
79,
14,
362,
63,
1210,
63,
1247,
837,
507,
198,
1431,
5665,
275,
295,
14,
1431,
8,
519,
7,
45,
6123,
297,
536,
9,
2742,
198,
692,
1336,
5665,
26,
686,
198,
719,
354,
29,
354,
199,
198,
521,
14,
4532,
8,
413,
776,
199,
199,
893,
26,
199,
198,
1210,
63,
719,
275,
10887,
79,
14,
1490,
63,
1210,
8,
719,
354,
9,
199,
198,
1199,
63,
719,
275,
10887,
79,
14,
1490,
63,
1199,
8,
719,
354,
9,
8299,
198,
1361,
360,
10369,
9499,
908,
8,
1210,
63,
719,
430,
421,
198,
1361,
480,
774,
603,
28904,
1621,
531,
421,
198,
509,
1245,
315,
511,
63,
26859,
63,
262,
8,
1210,
63,
719,
304,
507,
198,
1361,
360,
774,
603,
28904,
1621,
3086,
9499,
908,
8,
1188,
14,
4097,
4059,
421,
198,
396,
63,
26859,
63,
548,
63,
23983,
8,
1199,
63,
719,
12,
1210,
63,
719,
9,
199,
2590,
13483,
26,
272,
986,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
moylop260/odoo-dev
|
addons/base_iban/__init__.py
|
447
|
1073
|
# -*- 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 base_iban
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
258,
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,
420,
199,
3,
199,
4605,
199,
199,
646,
1300,
63,
1892,
290,
199,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
258,
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,
420,
199,
3,
199,
4605,
199,
199,
646,
1300,
63,
1892,
290,
199,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
porduna/weblabdeusto
|
server/launch/sample_balanced2_concurrent_experiments/main_machine/lab_and_experiment1/experiment55/server_config.py
|
968
|
1526
|
#!/usr/bin/env python
#-*-*- encoding: utf-8 -*-*-
weblab_xilinx_experiment_xilinx_device = 'FPGA'
weblab_xilinx_experiment_port_number = 1
# This should be something like this:
# import os as _os
# xilinx_home = _os.getenv('XILINX_HOME')
# if xilinx_home == None:
# if _os.name == 'nt':
# xilinx_home = r'C:\Program Files\Xilinx'
# elif _os.name == 'posix':
# xilinx_home = r"/home/nctrun/Xilinx"
#
# if _os.name == 'nt':
# xilinx_impact_full_path = [xilinx_home + r'\bin\nt\impact']
# elif _os.name == 'posix':
# xilinx_impact_full_path = [xilinx_home + r'/bin/lin/impact']
# But for testing we are going to fake it:
xilinx_home = "."
xilinx_impact_full_path = ["python","./tests/unit/weblab/experiment/devices/xilinx_impact/fake_impact.py" ]
xilinx_device_to_program = 'XilinxImpact' # 'JTagBlazer', 'DigilentAdept'
xilinx_device_to_send_commands = 'SerialPort' # 'HttpDevice'
digilent_adept_full_path = ["python","./test/unit/weblab/experiment/devices/digilent_adept/fake_digilent_adept.py" ]
digilent_adept_batch_content = """something with the variable $FILE"""
xilinx_http_device_ip_FPGA = "192.168.50.138"
xilinx_http_device_port_FPGA = 80
xilinx_http_device_app_FPGA = ""
xilinx_batch_content_FPGA = """setMode -bs
setCable -port auto
addDevice -position 1 -file $FILE
Program -p 1
exit
"""
# Though it is not really a FPGA, the webcam url var name depends on the device,
# specified above.
fpga_webcam_url = '''https://www.weblab.deusto.es/webcam/fpga0/image.jpg'''
|
bsd-2-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
13,
1837,
1837,
2644,
26,
2774,
13,
24,
1882,
1837,
199,
199,
2520,
5561,
63,
88,
382,
5092,
63,
10873,
63,
88,
382,
5092,
63,
1782,
275,
283,
17095,
9741,
7,
199,
2520,
5561,
63,
88,
382,
5092,
63,
10873,
63,
719,
63,
1955,
257,
275,
413,
199,
199,
3,
961,
1077,
506,
6020,
2839,
642,
26,
199,
3,
492,
747,
465,
485,
736,
199,
3,
671,
382,
5092,
63,
4219,
275,
485,
736,
14,
12959,
360,
56,
1193,
568,
56,
63,
9524,
358,
199,
3,
340,
671,
382,
5092,
63,
4219,
508,
488,
26,
199,
3,
257,
340,
485,
736,
14,
354,
508,
283,
343,
356,
199,
3,
755,
671,
382,
5092,
63,
4219,
275,
519,
7,
35,
3427,
9184,
16920,
60,
56,
382,
5092,
7,
199,
3,
257,
916,
485,
736,
14,
354,
508,
283,
9228,
356,
199,
3,
755,
671,
382,
5092,
63,
4219,
275,
519,
15313,
4219,
15,
78,
319,
1065,
15,
56,
382,
5092,
2,
199,
3,
221,
199,
3,
340,
485,
736,
14,
354,
508,
283,
343,
356,
199,
3,
257,
671,
382,
5092,
63,
31822,
63,
2861,
63,
515,
275,
359,
88,
382,
5092,
63,
4219,
435,
519,
1154,
1393,
60,
343,
60,
31822,
418,
199,
3,
916,
485,
736,
14,
354,
508,
283,
9228,
356,
199,
3,
257,
671,
382,
5092,
63,
31822,
63,
2861,
63,
515,
275,
359,
88,
382,
5092,
63,
4219,
435,
519,
9807,
1393,
15,
472,
15,
31822,
418,
199,
199,
3,
11017,
367,
5343,
781,
787,
9995,
370,
4026,
652,
26,
199,
199,
88,
382,
5092,
63,
4219,
275,
14530,
199,
88,
382,
5092,
63,
31822,
63,
2861,
63,
515,
275,
2097,
1548,
401,
1674,
15,
2219,
15,
3248,
15,
2520,
5561,
15,
10873,
15,
6410,
15,
88,
382,
5092,
63,
31822,
15,
3183,
63,
31822,
14,
647,
2,
1622,
199,
199,
88,
382,
5092,
63,
1782,
63,
475,
63,
6815,
275,
283,
56,
382,
5092,
8499,
2442,
7,
327,
283,
42,
1931,
34,
416,
2282,
297,
283,
17107,
441,
343,
33,
271,
541,
7,
199,
88,
382,
5092,
63,
1782,
63,
475,
63,
2254,
63,
4405,
275,
283,
3571,
4313,
7,
327,
283,
5779,
2510,
7,
199,
199,
18367,
441,
343,
63,
9587,
541,
63,
2861,
63,
515,
275,
2097,
1548,
401,
1674,
15,
396,
15,
3248,
15,
2520,
5561,
15,
10873,
15,
6410,
15,
18367,
441,
343,
63,
9587,
541,
15,
3183,
63,
18367,
441,
343,
63,
9587,
541,
14,
647,
2,
1622,
199,
18367,
441,
343,
63,
9587,
541,
63,
2912,
63,
1317,
275,
408,
10297,
543,
314,
1750,
2672,
3817,
624,
199,
199,
88,
382,
5092,
63,
1014,
63,
1782,
63,
711,
63,
17095,
9741,
263,
275,
298,
5756,
14,
6568,
14,
1400,
14,
8527,
2,
199,
88,
382,
5092,
63,
1014,
63,
1782,
63,
719,
63,
17095,
9741,
420,
275,
5939,
199,
88,
382,
5092,
63,
1014,
63,
1782,
63,
571,
63,
17095,
9741,
755,
275,
3087,
199,
199,
88,
382,
5092,
63,
2912,
63,
1317,
63,
17095,
9741,
275,
408,
409,
1385,
446,
1533,
199,
409,
35,
461,
446,
719,
2599,
199,
525,
2510,
446,
3124,
413,
446,
493,
2672,
3817,
199,
9184,
446,
80,
413,
199,
2224,
199,
624,
199,
199,
3,
18049,
3080,
652,
365,
440,
7710,
282,
481,
48,
9741,
12,
314,
3330,
15176,
1166,
2729,
536,
8350,
641,
314,
2243,
12,
199,
3,
2013,
3432,
14,
199,
3997,
5294,
63,
2520,
15176,
63,
633,
275,
1449,
2859,
921,
1544,
14,
2520,
5561,
14,
271,
833,
79,
14,
397,
15,
2520,
15176,
15,
3997,
5294,
16,
15,
1569,
14,
8476,
2344,
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
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
13,
1837,
1837,
2644,
26,
2774,
13,
24,
1882,
1837,
199,
199,
2520,
5561,
63,
88,
382,
5092,
63,
10873,
63,
88,
382,
5092,
63,
1782,
275,
283,
17095,
9741,
7,
199,
2520,
5561,
63,
88,
382,
5092,
63,
10873,
63,
719,
63,
1955,
257,
275,
413,
199,
199,
3,
961,
1077,
506,
6020,
2839,
642,
26,
199,
3,
492,
747,
465,
485,
736,
199,
3,
671,
382,
5092,
63,
4219,
275,
485,
736,
14,
12959,
360,
56,
1193,
568,
56,
63,
9524,
358,
199,
3,
340,
671,
382,
5092,
63,
4219,
508,
488,
26,
199,
3,
257,
340,
485,
736,
14,
354,
508,
283,
343,
356,
199,
3,
755,
671,
382,
5092,
63,
4219,
275,
519,
7,
35,
3427,
9184,
16920,
60,
56,
382,
5092,
7,
199,
3,
257,
916,
485,
736,
14,
354,
508,
283,
9228,
356,
199,
3,
755,
671,
382,
5092,
63,
4219,
275,
519,
15313,
4219,
15,
78,
319,
1065,
15,
56,
382,
5092,
2,
199,
3,
221,
199,
3,
340,
485,
736,
14,
354,
508,
283,
343,
356,
199,
3,
257,
671,
382,
5092,
63,
31822,
63,
2861,
63,
515,
275,
359,
88,
382,
5092,
63,
4219,
435,
519,
1154,
1393,
60,
343,
60,
31822,
418,
199,
3,
916,
485,
736,
14,
354,
508,
283,
9228,
356,
199,
3,
257,
671,
382,
5092,
63,
31822,
63,
2861,
63,
515,
275,
359,
88,
382,
5092,
63,
4219,
435,
519,
9807,
1393,
15,
472,
15,
31822,
418,
199,
199,
3,
11017,
367,
5343,
781,
787,
9995,
370,
4026,
652,
26,
199,
199,
88,
382,
5092,
63,
4219,
275,
14530,
199,
88,
382,
5092,
63,
31822,
63,
2861,
63,
515,
275,
2097,
1548,
401,
1674,
15,
2219,
15,
3248,
15,
2520,
5561,
15,
10873,
15,
6410,
15,
88,
382,
5092,
63,
31822,
15,
3183,
63,
31822,
14,
647,
2,
1622,
199,
199,
88,
382,
5092,
63,
1782,
63,
475,
63,
6815,
275,
283,
56,
382,
5092,
8499,
2442,
7,
327,
283,
42,
1931,
34,
416,
2282,
297,
283,
17107,
441,
343,
33,
271,
541,
7,
199,
88,
382,
5092,
63,
1782,
63,
475,
63,
2254,
63,
4405,
275,
283,
3571,
4313,
7,
327,
283,
5779,
2510,
7,
199,
199,
18367,
441,
343,
63,
9587,
541,
63,
2861,
63,
515,
275,
2097,
1548,
401,
1674,
15,
396,
15,
3248,
15,
2520,
5561,
15,
10873,
15,
6410,
15,
18367,
441,
343,
63,
9587,
541,
15,
3183,
63,
18367,
441,
343,
63,
9587,
541,
14,
647,
2,
1622,
199,
18367,
441,
343,
63,
9587,
541,
63,
2912,
63,
1317,
275,
408,
10297,
543,
314,
1750,
2672,
3817,
624,
199,
199,
88,
382,
5092,
63,
1014,
63,
1782,
63,
711,
63,
17095,
9741,
263,
275,
298,
5756,
14,
6568,
14,
1400,
14,
8527,
2,
199,
88,
382,
5092,
63,
1014,
63,
1782,
63,
719,
63,
17095,
9741,
420,
275,
5939,
199,
88,
382,
5092,
63,
1014,
63,
1782,
63,
571,
63,
17095,
9741,
755,
275,
3087,
199,
199,
88,
382,
5092,
63,
2912,
63,
1317,
63,
17095,
9741,
275,
408,
409,
1385,
446,
1533,
199,
409,
35,
461,
446,
719,
2599,
199,
525,
2510,
446,
3124,
413,
446,
493,
2672,
3817,
199,
9184,
446,
80,
413,
199,
2224,
199,
624,
199,
199,
3,
18049,
3080,
652,
365,
440,
7710,
282,
481,
48,
9741,
12,
314,
3330,
15176,
1166,
2729,
536,
8350,
641,
314,
2243,
12,
199,
3,
2013,
3432,
14,
199,
3997,
5294,
63,
2520,
15176,
63,
633,
275,
1449,
2859,
921,
1544,
14,
2520,
5561,
14,
271,
833,
79,
14,
397,
15,
2520,
15176,
15,
3997,
5294,
16,
15,
1569,
14,
8476,
2344,
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,
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,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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
] |
jamespcole/home-assistant
|
homeassistant/components/lcn/sensor.py
|
1
|
4063
|
"""Support for LCN sensors."""
from homeassistant.const import CONF_ADDRESS, CONF_UNIT_OF_MEASUREMENT
from . import LcnDevice, get_connection
from .const import (
CONF_CONNECTIONS, CONF_SOURCE, DATA_LCN, LED_PORTS, S0_INPUTS, SETPOINTS,
THRESHOLDS, VARIABLES)
DEPENDENCIES = ['lcn']
async def async_setup_platform(hass, hass_config, async_add_entities,
discovery_info=None):
"""Set up the LCN sensor platform."""
if discovery_info is None:
return
import pypck
devices = []
for config in discovery_info:
address, connection_id = config[CONF_ADDRESS]
addr = pypck.lcn_addr.LcnAddr(*address)
connections = hass.data[DATA_LCN][CONF_CONNECTIONS]
connection = get_connection(connections, connection_id)
address_connection = connection.get_address_conn(addr)
if config[CONF_SOURCE] in VARIABLES + SETPOINTS + THRESHOLDS + \
S0_INPUTS:
device = LcnVariableSensor(config, address_connection)
else: # in LED_PORTS + LOGICOP_PORTS
device = LcnLedLogicSensor(config, address_connection)
devices.append(device)
async_add_entities(devices)
class LcnVariableSensor(LcnDevice):
"""Representation of a LCN sensor for variables."""
def __init__(self, config, address_connection):
"""Initialize the LCN sensor."""
super().__init__(config, address_connection)
self.variable = self.pypck.lcn_defs.Var[config[CONF_SOURCE]]
self.unit = self.pypck.lcn_defs.VarUnit.parse(
config[CONF_UNIT_OF_MEASUREMENT])
self._value = None
async def async_added_to_hass(self):
"""Run when entity about to be added to hass."""
await super().async_added_to_hass()
self.hass.async_create_task(
self.address_connection.activate_status_request_handler(
self.variable))
@property
def state(self):
"""Return the state of the entity."""
return self._value
@property
def unit_of_measurement(self):
"""Return the unit of measurement of this entity, if any."""
return self.unit.value
def input_received(self, input_obj):
"""Set sensor value when LCN input object (command) is received."""
if not isinstance(input_obj, self.pypck.inputs.ModStatusVar) or \
input_obj.get_var() != self.variable:
return
self._value = (input_obj.get_value().to_var_unit(self.unit))
self.async_schedule_update_ha_state()
class LcnLedLogicSensor(LcnDevice):
"""Representation of a LCN sensor for leds and logicops."""
def __init__(self, config, address_connection):
"""Initialize the LCN sensor."""
super().__init__(config, address_connection)
if config[CONF_SOURCE] in LED_PORTS:
self.source = self.pypck.lcn_defs.LedPort[config[CONF_SOURCE]]
else:
self.source = self.pypck.lcn_defs.LogicOpPort[config[CONF_SOURCE]]
self._value = None
async def async_added_to_hass(self):
"""Run when entity about to be added to hass."""
await super().async_added_to_hass()
self.hass.async_create_task(
self.address_connection.activate_status_request_handler(
self.source))
@property
def state(self):
"""Return the state of the entity."""
return self._value
def input_received(self, input_obj):
"""Set sensor value when LCN input object (command) is received."""
if not isinstance(input_obj,
self.pypck.inputs.ModStatusLedsAndLogicOps):
return
if self.source in self.pypck.lcn_defs.LedPort:
self._value = input_obj.get_led_state(
self.source.value).name.lower()
elif self.source in self.pypck.lcn_defs.LogicOpPort:
self._value = input_obj.get_logic_op_state(
self.source.value).name.lower()
self.async_schedule_update_ha_state()
|
apache-2.0
|
[
624,
11532,
367,
491,
12874,
19678,
1041,
199,
504,
8846,
14,
1297,
492,
6392,
63,
12368,
12,
6392,
63,
15505,
63,
3359,
63,
31097,
3942,
4479,
199,
199,
504,
1275,
492,
491,
6413,
2510,
12,
664,
63,
2105,
199,
504,
1275,
1297,
492,
334,
272,
6392,
63,
14657,
2823,
12,
6392,
63,
10187,
12,
7126,
63,
7027,
46,
12,
491,
1149,
63,
3657,
51,
12,
428,
16,
63,
7321,
51,
12,
11543,
7217,
51,
12,
272,
4221,
15098,
2228,
3177,
12,
30098,
17041,
9,
199,
199,
25743,
9415,
2563,
275,
788,
76,
6413,
418,
421,
199,
4146,
347,
5316,
63,
2758,
63,
3246,
8,
5387,
12,
6298,
63,
888,
12,
5316,
63,
525,
63,
8327,
12,
3044,
13172,
63,
815,
29,
403,
304,
272,
408,
1084,
1536,
314,
491,
12874,
8778,
4298,
1041,
272,
340,
13172,
63,
815,
365,
488,
26,
267,
372,
339,
492,
1134,
80,
346,
339,
7256,
275,
942,
272,
367,
1101,
315,
13172,
63,
815,
26,
267,
2287,
12,
1950,
63,
344,
275,
1101,
59,
3103,
63,
12368,
61,
267,
5552,
275,
1134,
80,
346,
14,
76,
6413,
63,
2697,
14,
44,
6413,
11404,
2031,
1562,
9,
267,
6947,
275,
6298,
14,
576,
59,
3998,
63,
7027,
46,
1527,
3103,
63,
14657,
2823,
61,
267,
1950,
275,
664,
63,
2105,
8,
7995,
12,
1950,
63,
344,
9,
267,
2287,
63,
2105,
275,
1950,
14,
362,
63,
1562,
63,
1631,
8,
2697,
9,
398,
340,
1101,
59,
3103,
63,
10187,
61,
315,
30098,
17041,
435,
11543,
7217,
51,
435,
4221,
15098,
2228,
3177,
435,
971,
355,
428,
16,
63,
7321,
51,
26,
288,
2243,
275,
491,
6413,
2773,
10160,
8,
888,
12,
2287,
63,
2105,
9,
267,
587,
26,
221,
327,
315,
491,
1149,
63,
3657,
51,
435,
5051,
948,
1938,
63,
3657,
51,
288,
2243,
275,
491,
6413,
44,
379,
32140,
10160,
8,
888,
12,
2287,
63,
2105,
9,
398,
7256,
14,
740,
8,
1782,
9,
339,
5316,
63,
525,
63,
8327,
8,
6410,
9,
421,
199,
533,
491,
6413,
2773,
10160,
8,
44,
6413,
2510,
304,
272,
408,
20609,
402,
282,
491,
12874,
8778,
367,
2860,
1041,
339,
347,
636,
826,
721,
277,
12,
1101,
12,
2287,
63,
2105,
304,
267,
408,
9345,
314,
491,
12874,
8778,
1041,
267,
1613,
11027,
826,
721,
888,
12,
2287,
63,
2105,
9,
398,
291,
14,
1975,
275,
291,
14,
647,
80,
346,
14,
76,
6413,
63,
8710,
14,
5894,
59,
888,
59,
3103,
63,
10187,
2677,
267,
291,
14,
3248,
275,
291,
14,
647,
80,
346,
14,
76,
6413,
63,
8710,
14,
5894,
5072,
14,
1122,
8,
288,
1101,
59,
3103,
63,
15505,
63,
3359,
63,
31097,
3942,
4479,
566,
398,
291,
423,
585,
275,
488,
339,
5316,
347,
5316,
63,
3270,
63,
475,
63,
5387,
8,
277,
304,
267,
408,
2540,
1380,
4642,
3595,
370,
506,
3483,
370,
6298,
1041,
267,
5517,
1613,
1252,
4146,
63,
3270,
63,
475,
63,
5387,
342,
267,
291,
14,
5387,
14,
4146,
63,
981,
63,
1765,
8,
288,
291,
14,
1562,
63,
2105,
14,
8222,
63,
1205,
63,
1069,
63,
2232,
8,
355,
291,
14,
1975,
430,
339,
768,
1829,
272,
347,
1174,
8,
277,
304,
267,
408,
1767,
314,
1174,
402,
314,
4642,
1041,
267,
372,
291,
423,
585,
339,
768,
1829,
272,
347,
4137,
63,
1618,
63,
17912,
8,
277,
304,
267,
408,
1767,
314,
4137,
402,
18216,
402,
642,
4642,
12,
340,
1263,
1041,
267,
372,
291,
14,
3248,
14,
585,
339,
347,
1324,
63,
9226,
8,
277,
12,
1324,
63,
1113,
304,
267,
408,
1084,
8778,
574,
1380,
491,
12874,
1324,
909,
334,
1531,
9,
365,
3086,
1041,
267,
340,
440,
1228,
8,
1210,
63,
1113,
12,
291,
14,
647,
80,
346,
14,
3711,
14,
9871,
3694,
5894,
9,
503,
971,
355,
1324,
63,
1113,
14,
362,
63,
1391,
342,
1137,
291,
14,
1975,
26,
288,
372,
398,
291,
423,
585,
275,
334,
1210,
63,
1113,
14,
362,
63,
585,
1252,
475,
63,
1391,
63,
3248,
8,
277,
14,
3248,
430,
267,
291,
14,
4146,
63,
7211,
63,
873,
63,
2411,
63,
929,
342,
421,
199,
533,
491,
6413,
44,
379,
32140,
10160,
8,
44,
6413,
2510,
304,
272,
408,
20609,
402,
282,
491,
12874,
8778,
367,
1026,
795,
436,
943,
12802,
1190,
1041,
339,
347,
636,
826,
721,
277,
12,
1101,
12,
2287,
63,
2105,
304,
267,
408,
9345,
314,
491,
12874,
8778,
1041,
267,
1613,
11027,
826,
721,
888,
12,
2287,
63,
2105,
9,
398,
340,
1101,
59,
3103,
63,
10187,
61,
315,
491,
1149,
63,
3657,
51,
26,
288,
291,
14,
1365,
275,
291,
14,
647,
80,
346,
14,
76,
6413,
63,
8710,
14,
44,
379,
4313,
59,
888,
59,
3103,
63,
10187,
2677,
267,
587,
26,
288,
291,
14,
1365,
275,
291,
14,
647,
80,
346,
14,
76,
6413,
63,
8710,
14,
32140,
4619,
4313,
59,
888,
59,
3103,
63,
10187,
2677,
398,
291,
423,
585,
275,
488,
339,
5316,
347,
5316,
63,
3270,
63,
475,
63,
5387,
8,
277,
304,
267,
408,
2540,
1380,
4642,
3595,
370,
506,
3483,
370,
6298,
1041,
267,
5517,
1613,
1252,
4146,
63,
3270,
63,
475,
63,
5387,
342,
267,
291,
14,
5387,
14,
4146,
63,
981,
63,
1765,
8,
288,
291,
14,
1562,
63,
2105,
14,
8222,
63,
1205,
63,
1069,
63,
2232,
8,
355,
291,
14,
1365,
430,
339,
768,
1829,
272,
347,
1174,
8,
277,
304,
267,
408,
1767,
314,
1174,
402,
314,
4642,
1041,
267,
372,
291,
423,
585,
339,
347,
1324,
63,
9226,
8,
277,
12,
1324,
63,
1113,
304,
267,
408,
1084,
8778,
574,
1380,
491,
12874,
1324,
909,
334,
1531,
9,
365,
3086,
1041,
267,
340,
440,
1228,
8,
1210,
63,
1113,
12,
2079,
291,
14,
647,
80,
346,
14,
3711,
14,
9871,
3694,
44,
5923,
3325,
32140,
16452,
304,
288,
372,
398,
340,
291,
14,
1365,
315,
291,
14,
647,
80,
346,
14,
76,
6413,
63,
8710,
14,
44,
379,
4313,
26,
288,
291,
423,
585,
275,
1324,
63,
1113,
14,
362,
63,
1146,
63,
929,
8,
355,
291,
14,
1365,
14,
585,
680,
354,
14,
2325,
342,
267,
916,
291,
14,
1365,
315,
291,
14,
647,
80,
346,
14,
76,
6413,
63
] |
[
11532,
367,
491,
12874,
19678,
1041,
199,
504,
8846,
14,
1297,
492,
6392,
63,
12368,
12,
6392,
63,
15505,
63,
3359,
63,
31097,
3942,
4479,
199,
199,
504,
1275,
492,
491,
6413,
2510,
12,
664,
63,
2105,
199,
504,
1275,
1297,
492,
334,
272,
6392,
63,
14657,
2823,
12,
6392,
63,
10187,
12,
7126,
63,
7027,
46,
12,
491,
1149,
63,
3657,
51,
12,
428,
16,
63,
7321,
51,
12,
11543,
7217,
51,
12,
272,
4221,
15098,
2228,
3177,
12,
30098,
17041,
9,
199,
199,
25743,
9415,
2563,
275,
788,
76,
6413,
418,
421,
199,
4146,
347,
5316,
63,
2758,
63,
3246,
8,
5387,
12,
6298,
63,
888,
12,
5316,
63,
525,
63,
8327,
12,
3044,
13172,
63,
815,
29,
403,
304,
272,
408,
1084,
1536,
314,
491,
12874,
8778,
4298,
1041,
272,
340,
13172,
63,
815,
365,
488,
26,
267,
372,
339,
492,
1134,
80,
346,
339,
7256,
275,
942,
272,
367,
1101,
315,
13172,
63,
815,
26,
267,
2287,
12,
1950,
63,
344,
275,
1101,
59,
3103,
63,
12368,
61,
267,
5552,
275,
1134,
80,
346,
14,
76,
6413,
63,
2697,
14,
44,
6413,
11404,
2031,
1562,
9,
267,
6947,
275,
6298,
14,
576,
59,
3998,
63,
7027,
46,
1527,
3103,
63,
14657,
2823,
61,
267,
1950,
275,
664,
63,
2105,
8,
7995,
12,
1950,
63,
344,
9,
267,
2287,
63,
2105,
275,
1950,
14,
362,
63,
1562,
63,
1631,
8,
2697,
9,
398,
340,
1101,
59,
3103,
63,
10187,
61,
315,
30098,
17041,
435,
11543,
7217,
51,
435,
4221,
15098,
2228,
3177,
435,
971,
355,
428,
16,
63,
7321,
51,
26,
288,
2243,
275,
491,
6413,
2773,
10160,
8,
888,
12,
2287,
63,
2105,
9,
267,
587,
26,
221,
327,
315,
491,
1149,
63,
3657,
51,
435,
5051,
948,
1938,
63,
3657,
51,
288,
2243,
275,
491,
6413,
44,
379,
32140,
10160,
8,
888,
12,
2287,
63,
2105,
9,
398,
7256,
14,
740,
8,
1782,
9,
339,
5316,
63,
525,
63,
8327,
8,
6410,
9,
421,
199,
533,
491,
6413,
2773,
10160,
8,
44,
6413,
2510,
304,
272,
408,
20609,
402,
282,
491,
12874,
8778,
367,
2860,
1041,
339,
347,
636,
826,
721,
277,
12,
1101,
12,
2287,
63,
2105,
304,
267,
408,
9345,
314,
491,
12874,
8778,
1041,
267,
1613,
11027,
826,
721,
888,
12,
2287,
63,
2105,
9,
398,
291,
14,
1975,
275,
291,
14,
647,
80,
346,
14,
76,
6413,
63,
8710,
14,
5894,
59,
888,
59,
3103,
63,
10187,
2677,
267,
291,
14,
3248,
275,
291,
14,
647,
80,
346,
14,
76,
6413,
63,
8710,
14,
5894,
5072,
14,
1122,
8,
288,
1101,
59,
3103,
63,
15505,
63,
3359,
63,
31097,
3942,
4479,
566,
398,
291,
423,
585,
275,
488,
339,
5316,
347,
5316,
63,
3270,
63,
475,
63,
5387,
8,
277,
304,
267,
408,
2540,
1380,
4642,
3595,
370,
506,
3483,
370,
6298,
1041,
267,
5517,
1613,
1252,
4146,
63,
3270,
63,
475,
63,
5387,
342,
267,
291,
14,
5387,
14,
4146,
63,
981,
63,
1765,
8,
288,
291,
14,
1562,
63,
2105,
14,
8222,
63,
1205,
63,
1069,
63,
2232,
8,
355,
291,
14,
1975,
430,
339,
768,
1829,
272,
347,
1174,
8,
277,
304,
267,
408,
1767,
314,
1174,
402,
314,
4642,
1041,
267,
372,
291,
423,
585,
339,
768,
1829,
272,
347,
4137,
63,
1618,
63,
17912,
8,
277,
304,
267,
408,
1767,
314,
4137,
402,
18216,
402,
642,
4642,
12,
340,
1263,
1041,
267,
372,
291,
14,
3248,
14,
585,
339,
347,
1324,
63,
9226,
8,
277,
12,
1324,
63,
1113,
304,
267,
408,
1084,
8778,
574,
1380,
491,
12874,
1324,
909,
334,
1531,
9,
365,
3086,
1041,
267,
340,
440,
1228,
8,
1210,
63,
1113,
12,
291,
14,
647,
80,
346,
14,
3711,
14,
9871,
3694,
5894,
9,
503,
971,
355,
1324,
63,
1113,
14,
362,
63,
1391,
342,
1137,
291,
14,
1975,
26,
288,
372,
398,
291,
423,
585,
275,
334,
1210,
63,
1113,
14,
362,
63,
585,
1252,
475,
63,
1391,
63,
3248,
8,
277,
14,
3248,
430,
267,
291,
14,
4146,
63,
7211,
63,
873,
63,
2411,
63,
929,
342,
421,
199,
533,
491,
6413,
44,
379,
32140,
10160,
8,
44,
6413,
2510,
304,
272,
408,
20609,
402,
282,
491,
12874,
8778,
367,
1026,
795,
436,
943,
12802,
1190,
1041,
339,
347,
636,
826,
721,
277,
12,
1101,
12,
2287,
63,
2105,
304,
267,
408,
9345,
314,
491,
12874,
8778,
1041,
267,
1613,
11027,
826,
721,
888,
12,
2287,
63,
2105,
9,
398,
340,
1101,
59,
3103,
63,
10187,
61,
315,
491,
1149,
63,
3657,
51,
26,
288,
291,
14,
1365,
275,
291,
14,
647,
80,
346,
14,
76,
6413,
63,
8710,
14,
44,
379,
4313,
59,
888,
59,
3103,
63,
10187,
2677,
267,
587,
26,
288,
291,
14,
1365,
275,
291,
14,
647,
80,
346,
14,
76,
6413,
63,
8710,
14,
32140,
4619,
4313,
59,
888,
59,
3103,
63,
10187,
2677,
398,
291,
423,
585,
275,
488,
339,
5316,
347,
5316,
63,
3270,
63,
475,
63,
5387,
8,
277,
304,
267,
408,
2540,
1380,
4642,
3595,
370,
506,
3483,
370,
6298,
1041,
267,
5517,
1613,
1252,
4146,
63,
3270,
63,
475,
63,
5387,
342,
267,
291,
14,
5387,
14,
4146,
63,
981,
63,
1765,
8,
288,
291,
14,
1562,
63,
2105,
14,
8222,
63,
1205,
63,
1069,
63,
2232,
8,
355,
291,
14,
1365,
430,
339,
768,
1829,
272,
347,
1174,
8,
277,
304,
267,
408,
1767,
314,
1174,
402,
314,
4642,
1041,
267,
372,
291,
423,
585,
339,
347,
1324,
63,
9226,
8,
277,
12,
1324,
63,
1113,
304,
267,
408,
1084,
8778,
574,
1380,
491,
12874,
1324,
909,
334,
1531,
9,
365,
3086,
1041,
267,
340,
440,
1228,
8,
1210,
63,
1113,
12,
2079,
291,
14,
647,
80,
346,
14,
3711,
14,
9871,
3694,
44,
5923,
3325,
32140,
16452,
304,
288,
372,
398,
340,
291,
14,
1365,
315,
291,
14,
647,
80,
346,
14,
76,
6413,
63,
8710,
14,
44,
379,
4313,
26,
288,
291,
423,
585,
275,
1324,
63,
1113,
14,
362,
63,
1146,
63,
929,
8,
355,
291,
14,
1365,
14,
585,
680,
354,
14,
2325,
342,
267,
916,
291,
14,
1365,
315,
291,
14,
647,
80,
346,
14,
76,
6413,
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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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
] |
queenp/wakatime
|
wakatime/packages/pygments_py3/pygments/lexers/foxpro.py
|
134
|
26236
|
# -*- coding: utf-8 -*-
"""
pygments.lexers.foxpro
~~~~~~~~~~~~~~~~~~~~~~
Simple lexer for Microsoft Visual FoxPro source code.
:copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
import re
from pygments.lexer import RegexLexer
from pygments.token import Punctuation, Text, Comment, Operator, Keyword, \
Name, String
__all__ = ['FoxProLexer']
class FoxProLexer(RegexLexer):
"""Lexer for Microsoft Visual FoxPro language.
FoxPro syntax allows to shorten all keywords and function names
to 4 characters. Shortened forms are not recognized by this lexer.
.. versionadded:: 1.6
"""
name = 'FoxPro'
aliases = ['foxpro', 'vfp', 'clipper', 'xbase']
filenames = ['*.PRG', '*.prg']
mimetype = []
flags = re.IGNORECASE | re.MULTILINE
tokens = {
'root': [
(r';\s*\n', Punctuation), # consume newline
(r'(^|\n)\s*', Text, 'newline'),
# Square brackets may be used for array indices
# and for string literal. Look for arrays
# before matching string literals.
(r'(?<=\w)\[[0-9, ]+\]', Text),
(r'\'[^\'\n]*\'|"[^"\n]*"|\[[^]*]\]', String),
(r'(^\s*\*|&&|&&).*?\n', Comment.Single),
(r'(ABS|ACLASS|ACOPY|ACOS|ADATABASES|ADBOBJECTS|ADDBS|'
r'ADDPROPERTY|ADEL|ADIR|ADLLS|ADOCKSTATE|AELEMENT|AERROR|'
r'AEVENTS|AFIELDS|AFONT|AGETCLASS|AGETFILEVERSION|AINS|'
r'AINSTANCE|ALANGUAGE|ALEN|ALIAS|ALINES|ALLTRIM|'
r'AMEMBERS|AMOUSEOBJ|ANETRESOURCES|APRINTERS|APROCINFO|'
r'ASC|ASCAN|ASELOBJ|ASESSIONS|ASIN|ASORT|ASQLHANDLES|'
r'ASTACKINFO|ASUBSCRIPT|AT|AT_C|ATAGINFO|ATAN|ATC|ATCC|'
r'ATCLINE|ATLINE|ATN2|AUSED|AVCXCLASSES|BAR|BARCOUNT|'
r'BARPROMPT|BETWEEN|BINDEVENT|BINTOC|BITAND|BITCLEAR|'
r'BITLSHIFT|BITNOT|BITOR|BITRSHIFT|BITSET|BITTEST|BITXOR|'
r'BOF|CANDIDATE|CAPSLOCK|CAST|CDOW|CDX|CEILING|CHR|CHRSAW|'
r'CHRTRAN|CHRTRANC|CLEARRESULTSET|CMONTH|CNTBAR|CNTPAD|COL|'
r'COM|Functions|COMARRAY|COMCLASSINFO|COMPOBJ|COMPROP|'
r'COMRETURNERROR|COS|CPCONVERT|CPCURRENT|CPDBF|CREATEBINARY|'
r'CREATEOBJECT|CREATEOBJECTEX|CREATEOFFLINE|CTOBIN|CTOD|'
r'CTOT|CURDIR|CURSORGETPROP|CURSORSETPROP|CURSORTOXML|'
r'CURVAL|DATE|DATETIME|DAY|DBC|DBF|DBGETPROP|DBSETPROP|'
r'DBUSED|DDEAbortTrans|DDEAdvise|DDEEnabled|DDEExecute|'
r'DDEInitiate|DDELastError|DDEPoke|DDERequest|DDESetOption|'
r'DDESetService|DDESetTopic|DDETerminate|DEFAULTEXT|'
r'DELETED|DESCENDING|DIFFERENCE|DIRECTORY|DISKSPACE|'
r'DisplayPath|DMY|DODEFAULT|DOW|DRIVETYPE|DROPOFFLINE|'
r'DTOC|DTOR|DTOS|DTOT|EDITSOURCE|EMPTY|EOF|ERROR|EVAL(UATE)?|'
r'EVENTHANDLER|EVL|EXECSCRIPT|EXP|FCHSIZE|FCLOSE|FCOUNT|'
r'FCREATE|FDATE|FEOF|FERROR|FFLUSH|FGETS|FIELD|FILE|'
r'FILETOSTR|FILTER|FKLABEL|FKMAX|FLDLIST|FLOCK|FLOOR|'
r'FONTMETRIC|FOPEN|FOR|FORCEEXT|FORCEPATH|FOUND|FPUTS|'
r'FREAD|FSEEK|FSIZE|FTIME|FULLPATH|FV|FWRITE|'
r'GETAUTOINCVALUE|GETBAR|GETCOLOR|GETCP|GETDIR|GETENV|'
r'GETFILE|GETFLDSTATE|GETFONT|GETINTERFACE|'
r'GETNEXTMODIFIED|GETOBJECT|GETPAD|GETPEM|GETPICT|'
r'GETPRINTER|GETRESULTSET|GETWORDCOUNT|GETWORDNUM|'
r'GETCURSORADAPTER|GOMONTH|HEADER|HOME|HOUR|ICASE|'
r'IDXCOLLATE|IIF|IMESTATUS|INDBC|INDEXSEEK|INKEY|INLIST|'
r'INPUTBOX|INSMODE|INT|ISALPHA|ISBLANK|ISCOLOR|ISDIGIT|'
r'ISEXCLUSIVE|ISFLOCKED|ISLEADBYTE|ISLOWER|ISMEMOFETCHED|'
r'ISMOUSE|ISNULL|ISPEN|ISREADONLY|ISRLOCKED|'
r'ISTRANSACTABLE|ISUPPER|JUSTDRIVE|JUSTEXT|JUSTFNAME|'
r'JUSTPATH|JUSTSTEM|KEY|KEYMATCH|LASTKEY|LEFT|LEFTC|LEN|'
r'LENC|LIKE|LIKEC|LINENO|LOADPICTURE|LOCFILE|LOCK|LOG|'
r'LOG10|LOOKUP|LOWER|LTRIM|LUPDATE|MAKETRANSACTABLE|MAX|'
r'MCOL|MDOWN|MDX|MDY|MEMLINES|MEMORY|MENU|MESSAGE|'
r'MESSAGEBOX|MIN|MINUTE|MLINE|MOD|MONTH|MRKBAR|MRKPAD|'
r'MROW|MTON|MWINDOW|NDX|NEWOBJECT|NORMALIZE|NTOM|NUMLOCK|'
r'NVL|OBJNUM|OBJTOCLIENT|OBJVAR|OCCURS|OEMTOANSI|OLDVAL|'
r'ON|ORDER|OS|PAD|PADL|PARAMETERS|PAYMENT|PCOL|PCOUNT|'
r'PEMSTATUS|PI|POPUP|PRIMARY|PRINTSTATUS|PRMBAR|PRMPAD|'
r'PROGRAM|PROMPT|PROPER|PROW|PRTINFO|PUTFILE|PV|QUARTER|'
r'RAISEEVENT|RAND|RAT|RATC|RATLINE|RDLEVEL|READKEY|RECCOUNT|'
r'RECNO|RECSIZE|REFRESH|RELATION|REPLICATE|REQUERY|RGB|'
r'RGBSCHEME|RIGHT|RIGHTC|RLOCK|ROUND|ROW|RTOD|RTRIM|'
r'SAVEPICTURE|SCHEME|SCOLS|SEC|SECONDS|SEEK|SELECT|SET|'
r'SETFLDSTATE|SETRESULTSET|SIGN|SIN|SKPBAR|SKPPAD|SOUNDEX|'
r'SPACE|SQLCANCEL|SQLCOLUMNS|SQLCOMMIT|SQLCONNECT|'
r'SQLDISCONNECT|SQLEXEC|SQLGETPROP|SQLIDLEDISCONNECT|'
r'SQLMORERESULTS|SQLPREPARE|SQLROLLBACK|SQLSETPROP|'
r'SQLSTRINGCONNECT|SQLTABLES|SQRT|SROWS|STR|STRCONV|'
r'STREXTRACT|STRTOFILE|STRTRAN|STUFF|STUFFC|SUBSTR|'
r'SUBSTRC|SYS|SYSMETRIC|TABLEREVERT|TABLEUPDATE|TAG|'
r'TAGCOUNT|TAGNO|TAN|TARGET|TEXTMERGE|TIME|TRANSFORM|'
r'TRIM|TTOC|TTOD|TXNLEVEL|TXTWIDTH|TYPE|UNBINDEVENTS|'
r'UNIQUE|UPDATED|UPPER|USED|VAL|VARREAD|VARTYPE|VERSION|'
r'WBORDER|WCHILD|WCOLS|WDOCKABLE|WEEK|WEXIST|WFONT|WLAST|'
r'WLCOL|WLROW|WMAXIMUM|WMINIMUM|WONTOP|WOUTPUT|WPARENT|'
r'WREAD|WROWS|WTITLE|WVISIBLE|XMLTOCURSOR|XMLUPDATEGRAM|'
r'YEAR)(?=\s*\()', Name.Function),
(r'_ALIGNMENT|_ASCIICOLS|_ASCIIROWS|_ASSIST|_BEAUTIFY|_BOX|'
r'_BROWSER|_BUILDER|_CALCMEM|_CALCVALUE|_CLIPTEXT|_CONVERTER|'
r'_COVERAGE|_CUROBJ|_DBLCLICK|_DIARYDATE|_DOS|_FOXDOC|_FOXREF|'
r'_GALLERY|_GENGRAPH|_GENHTML|_GENMENU|_GENPD|_GENSCRN|'
r'_GENXTAB|_GETEXPR|_INCLUDE|_INCSEEK|_INDENT|_LMARGIN|_MAC|'
r'_MENUDESIGNER|_MLINE|_PADVANCE|_PAGENO|_PAGETOTAL|_PBPAGE|'
r'_PCOLNO|_PCOPIES|_PDRIVER|_PDSETUP|_PECODE|_PEJECT|_PEPAGE|'
r'_PLENGTH|_PLINENO|_PLOFFSET|_PPITCH|_PQUALITY|_PRETEXT|'
r'_PSCODE|_PSPACING|_PWAIT|_RMARGIN|_REPORTBUILDER|'
r'_REPORTOUTPUT|_REPORTPREVIEW|_SAMPLES|_SCCTEXT|_SCREEN|'
r'_SHELL|_SPELLCHK|_STARTUP|_TABS|_TALLY|_TASKPANE|_TEXT|'
r'_THROTTLE|_TOOLBOX|_TOOLTIPTIMEOUT|_TRANSPORT|_TRIGGERLEVEL|'
r'_UNIX|_VFP|_WINDOWS|_WIZARD|_WRAP', Keyword.Pseudo),
(r'THISFORMSET|THISFORM|THIS', Name.Builtin),
(r'Application|CheckBox|Collection|Column|ComboBox|'
r'CommandButton|CommandGroup|Container|Control|CursorAdapter|'
r'Cursor|Custom|DataEnvironment|DataObject|EditBox|'
r'Empty|Exception|Fields|Files|File|FormSet|Form|FoxCode|'
r'Grid|Header|Hyperlink|Image|Label|Line|ListBox|Objects|'
r'OptionButton|OptionGroup|PageFrame|Page|ProjectHook|Projects|'
r'Project|Relation|ReportListener|Separator|Servers|Server|'
r'Session|Shape|Spinner|Tables|TextBox|Timer|ToolBar|'
r'XMLAdapter|XMLField|XMLTable', Name.Class),
(r'm\.[a-z_]\w*', Name.Variable),
(r'\.(F|T|AND|OR|NOT|NULL)\.|\b(AND|OR|NOT|NULL)\b', Operator.Word),
(r'\.(ActiveColumn|ActiveControl|ActiveForm|ActivePage|'
r'ActiveProject|ActiveRow|AddLineFeeds|ADOCodePage|Alias|'
r'Alignment|Align|AllowAddNew|AllowAutoColumnFit|'
r'AllowCellSelection|AllowDelete|AllowHeaderSizing|'
r'AllowInsert|AllowModalMessages|AllowOutput|AllowRowSizing|'
r'AllowSimultaneousFetch|AllowTabs|AllowUpdate|'
r'AlwaysOnBottom|AlwaysOnTop|Anchor|Application|'
r'AutoActivate|AutoCenter|AutoCloseTables|AutoComplete|'
r'AutoCompSource|AutoCompTable|AutoHideScrollBar|'
r'AutoIncrement|AutoOpenTables|AutoRelease|AutoSize|'
r'AutoVerbMenu|AutoYield|BackColor|ForeColor|BackStyle|'
r'BaseClass|BatchUpdateCount|BindControls|BorderColor|'
r'BorderStyle|BorderWidth|BoundColumn|BoundTo|Bound|'
r'BreakOnError|BufferModeOverride|BufferMode|'
r'BuildDateTime|ButtonCount|Buttons|Cancel|Caption|'
r'Centered|Century|ChildAlias|ChildOrder|ChildTable|'
r'ClassLibrary|Class|ClipControls|Closable|CLSID|CodePage|'
r'ColorScheme|ColorSource|ColumnCount|ColumnLines|'
r'ColumnOrder|Columns|ColumnWidths|CommandClauses|'
r'Comment|CompareMemo|ConflictCheckCmd|ConflictCheckType|'
r'ContinuousScroll|ControlBox|ControlCount|Controls|'
r'ControlSource|ConversionFunc|Count|CurrentControl|'
r'CurrentDataSession|CurrentPass|CurrentX|CurrentY|'
r'CursorSchema|CursorSource|CursorStatus|Curvature|'
r'Database|DataSessionID|DataSession|DataSourceType|'
r'DataSource|DataType|DateFormat|DateMark|Debug|'
r'DeclareXMLPrefix|DEClassLibrary|DEClass|DefaultFilePath|'
r'Default|DefOLELCID|DeleteCmdDataSourceType|DeleteCmdDataSource|'
r'DeleteCmd|DeleteMark|Description|Desktop|'
r'Details|DisabledBackColor|DisabledForeColor|'
r'DisabledItemBackColor|DisabledItemForeColor|'
r'DisabledPicture|DisableEncode|DisplayCount|'
r'DisplayValue|Dockable|Docked|DockPosition|'
r'DocumentFile|DownPicture|DragIcon|DragMode|DrawMode|'
r'DrawStyle|DrawWidth|DynamicAlignment|DynamicBackColor|'
r'DynamicForeColor|DynamicCurrentControl|DynamicFontBold|'
r'DynamicFontItalic|DynamicFontStrikethru|'
r'DynamicFontUnderline|DynamicFontName|DynamicFontOutline|'
r'DynamicFontShadow|DynamicFontSize|DynamicInputMask|'
r'DynamicLineHeight|EditorOptions|Enabled|'
r'EnableHyperlinks|Encrypted|ErrorNo|Exclude|Exclusive|'
r'FetchAsNeeded|FetchMemoCmdList|FetchMemoDataSourceType|'
r'FetchMemoDataSource|FetchMemo|FetchSize|'
r'FileClassLibrary|FileClass|FillColor|FillStyle|Filter|'
r'FirstElement|FirstNestedTable|Flags|FontBold|FontItalic|'
r'FontStrikethru|FontUnderline|FontCharSet|FontCondense|'
r'FontExtend|FontName|FontOutline|FontShadow|FontSize|'
r'ForceCloseTag|Format|FormCount|FormattedOutput|Forms|'
r'FractionDigits|FRXDataSession|FullName|GDIPlusGraphics|'
r'GridLineColor|GridLines|GridLineWidth|HalfHeightCaption|'
r'HeaderClassLibrary|HeaderClass|HeaderHeight|Height|'
r'HelpContextID|HideSelection|HighlightBackColor|'
r'HighlightForeColor|HighlightStyle|HighlightRowLineWidth|'
r'HighlightRow|Highlight|HomeDir|Hours|HostName|'
r'HScrollSmallChange|hWnd|Icon|IncrementalSearch|Increment|'
r'InitialSelectedAlias|InputMask|InsertCmdDataSourceType|'
r'InsertCmdDataSource|InsertCmdRefreshCmd|'
r'InsertCmdRefreshFieldList|InsertCmdRefreshKeyFieldList|'
r'InsertCmd|Instancing|IntegralHeight|'
r'Interval|IMEMode|IsAttribute|IsBase64|IsBinary|IsNull|'
r'IsDiffGram|IsLoaded|ItemBackColor,|ItemData|ItemIDData|'
r'ItemTips|IXMLDOMElement|KeyboardHighValue|KeyboardLowValue|'
r'Keyfield|KeyFieldList|KeyPreview|KeySort|LanguageOptions|'
r'LeftColumn|Left|LineContents|LineNo|LineSlant|LinkMaster|'
r'ListCount|ListenerType|ListIndex|ListItemID|ListItem|'
r'List|LockColumnsLeft|LockColumns|LockScreen|MacDesktop|'
r'MainFile|MapN19_4ToCurrency|MapBinary|MapVarchar|Margin|'
r'MaxButton|MaxHeight|MaxLeft|MaxLength|MaxRecords|MaxTop|'
r'MaxWidth|MDIForm|MemberClassLibrary|MemberClass|'
r'MemoWindow|Message|MinButton|MinHeight|MinWidth|'
r'MouseIcon|MousePointer|Movable|MoverBars|MultiSelect|'
r'Name|NestedInto|NewIndex|NewItemID|NextSiblingTable|'
r'NoCpTrans|NoDataOnLoad|NoData|NullDisplay|'
r'NumberOfElements|Object|OLEClass|OLEDragMode|'
r'OLEDragPicture|OLEDropEffects|OLEDropHasData|'
r'OLEDropMode|OLEDropTextInsertion|OLELCID|'
r'OLERequestPendingTimeout|OLEServerBusyRaiseError|'
r'OLEServerBusyTimeout|OLETypeAllowed|OneToMany|'
r'OpenViews|OpenWindow|Optimize|OrderDirection|Order|'
r'OutputPageCount|OutputType|PageCount|PageHeight|'
r'PageNo|PageOrder|Pages|PageTotal|PageWidth|'
r'PanelLink|Panel|ParentAlias|ParentClass|ParentTable|'
r'Parent|Partition|PasswordChar|PictureMargin|'
r'PicturePosition|PictureSpacing|PictureSelectionDisplay|'
r'PictureVal|Picture|Prepared|'
r'PolyPoints|PreserveWhiteSpace|PreviewContainer|'
r'PrintJobName|Procedure|PROCESSID|ProgID|ProjectHookClass|'
r'ProjectHookLibrary|ProjectHook|QuietMode|'
r'ReadCycle|ReadLock|ReadMouse|ReadObject|ReadOnly|'
r'ReadSave|ReadTimeout|RecordMark|RecordSourceType|'
r'RecordSource|RefreshAlias|'
r'RefreshCmdDataSourceType|RefreshCmdDataSource|RefreshCmd|'
r'RefreshIgnoreFieldList|RefreshTimeStamp|RelationalExpr|'
r'RelativeColumn|RelativeRow|ReleaseType|Resizable|'
r'RespectCursorCP|RespectNesting|RightToLeft|RotateFlip|'
r'Rotation|RowColChange|RowHeight|RowSourceType|'
r'RowSource|ScaleMode|SCCProvider|SCCStatus|ScrollBars|'
r'Seconds|SelectCmd|SelectedID|'
r'SelectedItemBackColor|SelectedItemForeColor|Selected|'
r'SelectionNamespaces|SelectOnEntry|SelLength|SelStart|'
r'SelText|SendGDIPlusImage|SendUpdates|ServerClassLibrary|'
r'ServerClass|ServerHelpFile|ServerName|'
r'ServerProject|ShowTips|ShowInTaskbar|ShowWindow|'
r'Sizable|SizeBox|SOM|Sorted|Sparse|SpecialEffect|'
r'SpinnerHighValue|SpinnerLowValue|SplitBar|StackLevel|'
r'StartMode|StatusBarText|StatusBar|Stretch|StrictDateEntry|'
r'Style|TabIndex|Tables|TabOrientation|Tabs|TabStop|'
r'TabStretch|TabStyle|Tag|TerminateRead|Text|Themes|'
r'ThreadID|TimestampFieldList|TitleBar|ToolTipText|'
r'TopIndex|TopItemID|Top|TwoPassProcess|TypeLibCLSID|'
r'TypeLibDesc|TypeLibName|Type|Unicode|UpdatableFieldList|'
r'UpdateCmdDataSourceType|UpdateCmdDataSource|'
r'UpdateCmdRefreshCmd|UpdateCmdRefreshFieldList|'
r'UpdateCmdRefreshKeyFieldList|UpdateCmd|'
r'UpdateGramSchemaLocation|UpdateGram|UpdateNameList|UpdateType|'
r'UseCodePage|UseCursorSchema|UseDeDataSource|UseMemoSize|'
r'UserValue|UseTransactions|UTF8Encoded|Value|VersionComments|'
r'VersionCompany|VersionCopyright|VersionDescription|'
r'VersionNumber|VersionProduct|VersionTrademarks|Version|'
r'VFPXMLProgID|ViewPortHeight|ViewPortLeft|'
r'ViewPortTop|ViewPortWidth|VScrollSmallChange|View|Visible|'
r'VisualEffect|WhatsThisButton|WhatsThisHelpID|WhatsThisHelp|'
r'WhereType|Width|WindowList|WindowState|WindowType|WordWrap|'
r'WrapCharInCDATA|WrapInCDATA|WrapMemoInCDATA|XMLAdapter|'
r'XMLConstraints|XMLNameIsXPath|XMLNamespace|XMLName|'
r'XMLPrefix|XMLSchemaLocation|XMLTable|XMLType|'
r'XSDfractionDigits|XSDmaxLength|XSDtotalDigits|'
r'XSDtype|ZoomBox)', Name.Attribute),
(r'\.(ActivateCell|AddColumn|AddItem|AddListItem|AddObject|'
r'AddProperty|AddTableSchema|AddToSCC|Add|'
r'ApplyDiffgram|Attach|AutoFit|AutoOpen|Box|Build|'
r'CancelReport|ChangesToCursor|CheckIn|CheckOut|Circle|'
r'CleanUp|ClearData|ClearStatus|Clear|CloneObject|CloseTables|'
r'Close|Cls|CursorAttach|CursorDetach|CursorFill|'
r'CursorRefresh|DataToClip|DelayedMemoFetch|DeleteColumn|'
r'Dock|DoMessage|DoScroll|DoStatus|DoVerb|Drag|Draw|Eval|'
r'GetData|GetDockState|GetFormat|GetKey|GetLatestVersion|'
r'GetPageHeight|GetPageWidth|Help|Hide|IncludePageInOutput|'
r'IndexToItemID|ItemIDToIndex|Item|LoadXML|Line|Modify|'
r'MoveItem|Move|Nest|OLEDrag|OnPreviewClose|OutputPage|'
r'Point|Print|PSet|Quit|ReadExpression|ReadMethod|'
r'RecordRefresh|Refresh|ReleaseXML|Release|RemoveFromSCC|'
r'RemoveItem|RemoveListItem|RemoveObject|Remove|'
r'Render|Requery|RequestData|ResetToDefault|Reset|Run|'
r'SaveAsClass|SaveAs|SetAll|SetData|SetFocus|SetFormat|'
r'SetMain|SetVar|SetViewPort|ShowWhatsThis|Show|'
r'SupportsListenerType|TextHeight|TextWidth|ToCursor|'
r'ToXML|UndoCheckOut|Unnest|UpdateStatus|WhatsThisMode|'
r'WriteExpression|WriteMethod|ZOrder)', Name.Function),
(r'\.(Activate|AdjustObjectSize|AfterBand|AfterBuild|'
r'AfterCloseTables|AfterCursorAttach|AfterCursorClose|'
r'AfterCursorDetach|AfterCursorFill|AfterCursorRefresh|'
r'AfterCursorUpdate|AfterDelete|AfterInsert|'
r'AfterRecordRefresh|AfterUpdate|AfterDock|AfterReport|'
r'AfterRowColChange|BeforeBand|BeforeCursorAttach|'
r'BeforeCursorClose|BeforeCursorDetach|BeforeCursorFill|'
r'BeforeCursorRefresh|BeforeCursorUpdate|BeforeDelete|'
r'BeforeInsert|BeforeDock|BeforeOpenTables|'
r'BeforeRecordRefresh|BeforeReport|BeforeRowColChange|'
r'BeforeUpdate|Click|dbc_Activate|dbc_AfterAddTable|'
r'dbc_AfterAppendProc|dbc_AfterCloseTable|dbc_AfterCopyProc|'
r'dbc_AfterCreateConnection|dbc_AfterCreateOffline|'
r'dbc_AfterCreateTable|dbc_AfterCreateView|dbc_AfterDBGetProp|'
r'dbc_AfterDBSetProp|dbc_AfterDeleteConnection|'
r'dbc_AfterDropOffline|dbc_AfterDropTable|'
r'dbc_AfterModifyConnection|dbc_AfterModifyProc|'
r'dbc_AfterModifyTable|dbc_AfterModifyView|dbc_AfterOpenTable|'
r'dbc_AfterRemoveTable|dbc_AfterRenameConnection|'
r'dbc_AfterRenameTable|dbc_AfterRenameView|'
r'dbc_AfterValidateData|dbc_BeforeAddTable|'
r'dbc_BeforeAppendProc|dbc_BeforeCloseTable|'
r'dbc_BeforeCopyProc|dbc_BeforeCreateConnection|'
r'dbc_BeforeCreateOffline|dbc_BeforeCreateTable|'
r'dbc_BeforeCreateView|dbc_BeforeDBGetProp|'
r'dbc_BeforeDBSetProp|dbc_BeforeDeleteConnection|'
r'dbc_BeforeDropOffline|dbc_BeforeDropTable|'
r'dbc_BeforeModifyConnection|dbc_BeforeModifyProc|'
r'dbc_BeforeModifyTable|dbc_BeforeModifyView|'
r'dbc_BeforeOpenTable|dbc_BeforeRemoveTable|'
r'dbc_BeforeRenameConnection|dbc_BeforeRenameTable|'
r'dbc_BeforeRenameView|dbc_BeforeValidateData|'
r'dbc_CloseData|dbc_Deactivate|dbc_ModifyData|dbc_OpenData|'
r'dbc_PackData|DblClick|Deactivate|Deleted|Destroy|DoCmd|'
r'DownClick|DragDrop|DragOver|DropDown|ErrorMessage|Error|'
r'EvaluateContents|GotFocus|Init|InteractiveChange|KeyPress|'
r'LoadReport|Load|LostFocus|Message|MiddleClick|MouseDown|'
r'MouseEnter|MouseLeave|MouseMove|MouseUp|MouseWheel|Moved|'
r'OLECompleteDrag|OLEDragOver|OLEGiveFeedback|OLESetData|'
r'OLEStartDrag|OnMoveItem|Paint|ProgrammaticChange|'
r'QueryAddFile|QueryModifyFile|QueryNewFile|QueryRemoveFile|'
r'QueryRunFile|QueryUnload|RangeHigh|RangeLow|ReadActivate|'
r'ReadDeactivate|ReadShow|ReadValid|ReadWhen|Resize|'
r'RightClick|SCCInit|SCCDestroy|Scrolled|Timer|UIEnable|'
r'UnDock|UnloadReport|Unload|UpClick|Valid|When)', Name.Function),
(r'\s+', Text),
# everything else is not colored
(r'.', Text),
],
'newline': [
(r'\*.*?$', Comment.Single, '#pop'),
(r'(ACCEPT|ACTIVATE\s*MENU|ACTIVATE\s*POPUP|ACTIVATE\s*SCREEN|'
r'ACTIVATE\s*WINDOW|APPEND|APPEND\s*FROM|APPEND\s*FROM\s*ARRAY|'
r'APPEND\s*GENERAL|APPEND\s*MEMO|ASSIST|AVERAGE|BLANK|BROWSE|'
r'BUILD\s*APP|BUILD\s*EXE|BUILD\s*PROJECT|CALCULATE|CALL|'
r'CANCEL|CHANGE|CLEAR|CLOSE|CLOSE\s*MEMO|COMPILE|CONTINUE|'
r'COPY\s*FILE|COPY\s*INDEXES|COPY\s*MEMO|COPY\s*STRUCTURE|'
r'COPY\s*STRUCTURE\s*EXTENDED|COPY\s*TAG|COPY\s*TO|'
r'COPY\s*TO\s*ARRAY|COUNT|CREATE|CREATE\s*COLOR\s*SET|'
r'CREATE\s*CURSOR|CREATE\s*FROM|CREATE\s*LABEL|CREATE\s*MENU|'
r'CREATE\s*PROJECT|CREATE\s*QUERY|CREATE\s*REPORT|'
r'CREATE\s*SCREEN|CREATE\s*TABLE|CREATE\s*VIEW|DDE|'
r'DEACTIVATE\s*MENU|DEACTIVATE\s*POPUP|DEACTIVATE\s*WINDOW|'
r'DECLARE|DEFINE\s*BAR|DEFINE\s*BOX|DEFINE\s*MENU|'
r'DEFINE\s*PAD|DEFINE\s*POPUP|DEFINE\s*WINDOW|DELETE|'
r'DELETE\s*FILE|DELETE\s*TAG|DIMENSION|DIRECTORY|DISPLAY|'
r'DISPLAY\s*FILES|DISPLAY\s*MEMORY|DISPLAY\s*STATUS|'
r'DISPLAY\s*STRUCTURE|DO|EDIT|EJECT|EJECT\s*PAGE|ERASE|'
r'EXIT|EXPORT|EXTERNAL|FILER|FIND|FLUSH|FUNCTION|GATHER|'
r'GETEXPR|GO|GOTO|HELP|HIDE\s*MENU|HIDE\s*POPUP|'
r'HIDE\s*WINDOW|IMPORT|INDEX|INPUT|INSERT|JOIN|KEYBOARD|'
r'LABEL|LIST|LOAD|LOCATE|LOOP|MENU|MENU\s*TO|MODIFY\s*COMMAND|'
r'MODIFY\s*FILE|MODIFY\s*GENERAL|MODIFY\s*LABEL|MODIFY\s*MEMO|'
r'MODIFY\s*MENU|MODIFY\s*PROJECT|MODIFY\s*QUERY|'
r'MODIFY\s*REPORT|MODIFY\s*SCREEN|MODIFY\s*STRUCTURE|'
r'MODIFY\s*WINDOW|MOVE\s*POPUP|MOVE\s*WINDOW|NOTE|'
r'ON\s*APLABOUT|ON\s*BAR|ON\s*ERROR|ON\s*ESCAPE|'
r'ON\s*EXIT\s*BAR|ON\s*EXIT\s*MENU|ON\s*EXIT\s*PAD|'
r'ON\s*EXIT\s*POPUP|ON\s*KEY|ON\s*KEY\s*=|ON\s*KEY\s*LABEL|'
r'ON\s*MACHELP|ON\s*PAD|ON\s*PAGE|ON\s*READERROR|'
r'ON\s*SELECTION\s*BAR|ON\s*SELECTION\s*MENU|'
r'ON\s*SELECTION\s*PAD|ON\s*SELECTION\s*POPUP|ON\s*SHUTDOWN|'
r'PACK|PARAMETERS|PLAY\s*MACRO|POP\s*KEY|POP\s*MENU|'
r'POP\s*POPUP|PRIVATE|PROCEDURE|PUBLIC|PUSH\s*KEY|'
r'PUSH\s*MENU|PUSH\s*POPUP|QUIT|READ|READ\s*MENU|RECALL|'
r'REINDEX|RELEASE|RELEASE\s*MODULE|RENAME|REPLACE|'
r'REPLACE\s*FROM\s*ARRAY|REPORT|RESTORE\s*FROM|'
r'RESTORE\s*MACROS|RESTORE\s*SCREEN|RESTORE\s*WINDOW|'
r'RESUME|RETRY|RETURN|RUN|RUN\s*\/N"|RUNSCRIPT|'
r'SAVE\s*MACROS|SAVE\s*SCREEN|SAVE\s*TO|SAVE\s*WINDOWS|'
r'SCATTER|SCROLL|SEEK|SELECT|SET|SET\s*ALTERNATE|'
r'SET\s*ANSI|SET\s*APLABOUT|SET\s*AUTOSAVE|SET\s*BELL|'
r'SET\s*BLINK|SET\s*BLOCKSIZE|SET\s*BORDER|SET\s*BRSTATUS|'
r'SET\s*CARRY|SET\s*CENTURY|SET\s*CLEAR|SET\s*CLOCK|'
r'SET\s*COLLATE|SET\s*COLOR\s*OF|SET\s*COLOR\s*OF\s*SCHEME|'
r'SET\s*COLOR\s*SET|SET\s*COLOR\s*TO|SET\s*COMPATIBLE|'
r'SET\s*CONFIRM|SET\s*CONSOLE|SET\s*CURRENCY|SET\s*CURSOR|'
r'SET\s*DATE|SET\s*DEBUG|SET\s*DECIMALS|SET\s*DEFAULT|'
r'SET\s*DELETED|SET\s*DELIMITERS|SET\s*DEVELOPMENT|'
r'SET\s*DEVICE|SET\s*DISPLAY|SET\s*DOHISTORY|SET\s*ECHO|'
r'SET\s*ESCAPE|SET\s*EXACT|SET\s*EXCLUSIVE|SET\s*FIELDS|'
r'SET\s*FILTER|SET\s*FIXED|SET\s*FORMAT|SET\s*FULLPATH|'
r'SET\s*FUNCTION|SET\s*HEADINGS|SET\s*HELP|SET\s*HELPFILTER|'
r'SET\s*HOURS|SET\s*INDEX|SET\s*INTENSITY|SET\s*KEY|'
r'SET\s*KEYCOMP|SET\s*LIBRARY|SET\s*LOCK|SET\s*LOGERRORS|'
r'SET\s*MACDESKTOP|SET\s*MACHELP|SET\s*MACKEY|SET\s*MARGIN|'
r'SET\s*MARK\s*OF|SET\s*MARK\s*TO|SET\s*MEMOWIDTH|'
r'SET\s*MESSAGE|SET\s*MOUSE|SET\s*MULTILOCKS|SET\s*NEAR|'
r'SET\s*NOCPTRANS|SET\s*NOTIFY|SET\s*ODOMETER|SET\s*OPTIMIZE|'
r'SET\s*ORDER|SET\s*PALETTE|SET\s*PATH|SET\s*PDSETUP|'
r'SET\s*POINT|SET\s*PRINTER|SET\s*PROCEDURE|SET\s*READBORDER|'
r'SET\s*REFRESH|SET\s*RELATION|SET\s*RELATION\s*OFF|'
r'SET\s*REPROCESS|SET\s*RESOURCE|SET\s*SAFETY|SET\s*SCOREBOARD|'
r'SET\s*SEPARATOR|SET\s*SHADOWS|SET\s*SKIP|SET\s*SKIP\s*OF|'
r'SET\s*SPACE|SET\s*STATUS|SET\s*STATUS\s*BAR|SET\s*STEP|'
r'SET\s*STICKY|SET\s*SYSMENU|SET\s*TALK|SET\s*TEXTMERGE|'
r'SET\s*TEXTMERGE\s*DELIMITERS|SET\s*TOPIC|SET\s*TRBETWEEN|'
r'SET\s*TYPEAHEAD|SET\s*UDFPARMS|SET\s*UNIQUE|SET\s*VIEW|'
r'SET\s*VOLUME|SET\s*WINDOW\s*OF\s*MEMO|SET\s*XCMDFILE|'
r'SHOW\s*GET|SHOW\s*GETS|SHOW\s*MENU|SHOW\s*OBJECT|'
r'SHOW\s*POPUP|SHOW\s*WINDOW|SIZE\s*POPUP|SKIP|SORT|'
r'STORE|SUM|SUSPEND|TOTAL|TYPE|UNLOCK|UPDATE|USE|WAIT|'
r'ZAP|ZOOM\s*WINDOW|DO\s*CASE|CASE|OTHERWISE|ENDCASE|'
r'DO\s*WHILE|ENDDO|FOR|ENDFOR|NEXT|IF|ELSE|ENDIF|PRINTJOB|'
r'ENDPRINTJOB|SCAN|ENDSCAN|TEXT|ENDTEXT|=)',
Keyword.Reserved, '#pop'),
(r'#\s*(IF|ELIF|ELSE|ENDIF|DEFINE|IFDEF|IFNDEF|INCLUDE)',
Comment.Preproc, '#pop'),
(r'(m\.)?[a-z_]\w*', Name.Variable, '#pop'),
(r'.', Text, '#pop'),
],
}
|
bsd-3-clause
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
13277,
14,
12245,
14,
9849,
496,
272,
18294,
2878,
1714,
339,
5870,
10426,
367,
15332,
14702,
481,
19131,
919,
1350,
1233,
14,
339,
520,
7307,
26,
1898,
8315,
13,
7280,
701,
314,
14493,
8099,
12,
1937,
10610,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
2436,
14,
199,
624,
199,
199,
646,
295,
199,
199,
504,
13277,
14,
11729,
492,
12939,
5838,
199,
504,
13277,
14,
1418,
492,
10357,
12,
4516,
12,
6819,
12,
11013,
12,
6431,
12,
971,
1362,
2812,
12,
2624,
199,
199,
363,
452,
363,
275,
788,
15563,
88,
919,
5838,
418,
421,
199,
533,
481,
19131,
919,
5838,
8,
19856,
304,
272,
408,
5838,
367,
15332,
14702,
481,
19131,
919,
2637,
14,
339,
481,
19131,
919,
6302,
6127,
370,
25123,
1006,
7681,
436,
805,
1561,
272,
370,
841,
4110,
14,
221,
5244,
269,
724,
379,
4513,
787,
440,
18054,
701,
642,
10426,
14,
339,
2508,
7445,
447,
413,
14,
22,
272,
408,
339,
536,
275,
283,
15563,
88,
919,
7,
272,
5481,
275,
788,
9849,
496,
297,
283,
86,
3997,
297,
283,
7548,
529,
297,
283,
88,
1095,
418,
272,
6203,
275,
17855,
3311,
39,
297,
11937,
26233,
418,
272,
12200,
275,
942,
339,
3285,
275,
295,
14,
15434,
1204,
295,
14,
16661,
339,
4645,
275,
469,
267,
283,
1231,
356,
359,
288,
334,
82,
7,
3779,
83,
7590,
78,
297,
10357,
395,
327,
9451,
8057,
288,
334,
82,
6774,
62,
6113,
78,
2862,
83,
7693,
4516,
12,
283,
12210,
659,
953,
327,
428,
5937,
21873,
1443,
506,
1202,
367,
1625,
4918,
288,
327,
436,
367,
1059,
8785,
14,
221,
12077,
367,
6572,
288,
327,
2544,
4877,
1059,
18041,
14,
288,
334,
82,
10120,
28,
9529,
87,
2862,
9046,
16,
13,
25,
12,
1622,
7896,
4300,
4516,
395,
288,
334,
82,
1154,
29538,
1154,
78,
3672,
3985,
25576,
4735,
3212,
78,
3672,
2,
6113,
59,
4735,
3672,
7272,
4300,
2624,
395,
288,
334,
82,
6774,
12773,
83,
27804,
92,
12574,
92,
6,
5282,
15337,
5282,
27,
680,
10,
8995,
78,
297,
6819,
14,
7200,
395,
953,
334,
82,
6774,
27851,
92,
18765,
3755,
92,
1348,
1938,
57,
92,
1348,
3100,
92,
1554,
619,
1217,
21983,
92,
1554,
3973,
34,
5550,
51,
92,
1554,
2846,
51,
5227,
1467,
519,
7,
9732,
25091,
92,
33,
4424,
92,
1554,
3927,
92,
1554,
4464,
51,
92,
1554,
47,
2504,
6689,
92,
12500,
10320,
92,
33,
3170,
5227,
1467,
519,
7,
33,
8193,
51,
92,
33,
12767,
92,
5699,
5994,
92,
1254,
775,
6885,
92,
1254,
775,
3817,
4612,
92,
9021,
51,
5227,
1467,
519,
7,
33,
18235,
92,
748,
3986,
53,
2962,
92,
748,
742,
92,
12644,
92,
748,
568,
654,
92,
1761,
1766,
1469,
5227,
1467,
519,
7,
1991,
4567,
3960,
92,
1156,
47,
4701,
15862,
92,
879,
775,
3830,
11237,
16734,
92,
1282,
50,
3843,
51,
92,
1282,
24762,
4531,
5227,
1467,
519,
7,
22767,
92,
1179,
18988,
92,
8162,
9376,
42,
92,
1179,
1608,
2823,
92,
1179,
568,
92,
1179,
2596,
92,
1179,
2940,
10854,
11344,
5227,
1467,
519,
7,
11307,
3099,
4531,
92,
1179,
2533,
10484,
92,
619,
92,
619,
63,
35,
92,
619,
1254,
4531,
92,
619,
879,
92,
24355,
92,
619,
2571,
5227,
1467,
519,
7,
619,
1981,
3565,
92,
619,
6174,
92,
619,
46,
18,
92,
33,
8558,
92,
6087,
26001,
13748,
92,
13895,
92,
13895,
8760,
5227,
1467,
519,
7,
13895,
2514,
26178,
92,
34,
29056,
92,
9431,
1093,
4554,
92,
9431,
31634,
92,
11970,
3649,
92,
11970,
20706,
5227,
1467,
519,
7,
11970,
44,
18013,
92,
11970,
4609,
92,
11970,
726,
92,
11970,
50,
18013,
92,
11970,
3597,
92,
11970,
2864,
92,
11970,
56,
726,
5227,
1467,
519,
7,
34,
3359,
92,
35,
3649,
998,
1951,
92,
8549,
51,
4406,
92,
18898,
92,
35,
1649,
55,
92,
7695,
56,
92,
2089,
1193,
1206,
92,
1244,
50,
92,
1244,
12115,
55,
5227,
1467,
519,
7,
1244,
50,
17433,
92,
1244,
50,
17433,
35,
92,
12507,
1920,
654,
2233,
3597,
92,
9249,
615,
2080,
92,
35,
12460,
13895,
92,
12874,
6495,
1554,
92,
3978,
5227,
1467,
519,
7,
11265,
92,
13967,
92,
11265,
12322,
92,
11265,
6885,
4531,
92,
11265,
1512,
16262,
92,
6790,
10510,
5227,
1467,
519,
7,
11265,
9677,
3170,
92,
1439,
51,
92,
2890,
1864,
8851,
92,
2890,
14211,
92,
2890,
2846,
38,
92,
8366,
13246,
5227,
1467,
519,
7,
8366,
9868,
92,
8366,
9868,
1438,
92,
8366,
7517,
6174,
92,
1028,
5488,
568,
92,
1028,
22041,
5227,
1467,
519,
7,
1028,
1387,
92,
7013,
3022,
92,
31321,
2970,
19926,
92,
31321,
3597,
19926,
92,
31321,
2566,
4317,
5227,
1467,
519,
7,
7013,
3204,
92,
5390,
92,
12488,
92,
11655,
92,
23317,
92,
2846,
38,
92,
2846,
2970,
19926,
92,
2846,
3597,
19926,
5227,
1467,
519,
7,
2846,
8558,
92,
36,
1093,
16682,
3188,
92,
36,
1093,
2767,
433,
261,
92,
36,
1093,
6589,
92,
36,
1093,
12049,
5227,
1467,
519,
7,
36,
1093,
607,
5277,
323,
92,
36,
4424,
1810,
547,
92,
36,
1093,
1575,
415,
92,
36,
1093,
2017,
92,
36,
4448,
386,
2602,
5227,
1467,
519,
7,
36,
4448,
386,
3167,
92,
36,
4448,
386,
12157,
92,
5745,
775,
281,
827,
323,
92,
3472,
2472,
5227,
1467,
519,
7,
27408,
92,
15119,
15219,
92,
10596,
540,
6013,
92,
16436,
92,
20492,
11658,
5227,
1467,
519,
7,
7687,
2042,
92,
36,
12339,
92,
1649,
3472,
92,
1649,
55,
92,
4564,
6882,
17509,
92,
36,
1092,
1512,
1665,
6174,
5227,
1467,
519,
7,
36,
31634,
92,
7438,
726,
92,
36,
2566,
51,
92,
7438,
1387,
92,
17929,
10187,
92,
13993,
92,
13178,
92,
3170,
92,
28805,
8,
53,
1951,
5547,
5227,
1467,
519,
7,
8193,
30872,
92,
18015,
44,
92,
23017,
3298,
4461,
92,
11992,
92,
38,
1244,
4305,
92,
4161,
1484,
899,
92,
38,
8760,
5227,
1467,
519,
7,
4161,
907,
1951,
92,
38,
5390,
92,
5100,
3359,
92,
38,
3170,
92,
1665,
44,
14527,
92,
38,
2970,
51,
92,
8609,
92,
3817,
5227,
1467,
519,
7,
5110,
26614,
3027,
92,
9905,
92,
21490,
13837,
92,
21490,
4283,
92,
3143,
36,
4924,
92,
38,
4406,
92,
38,
1484,
726
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
13277,
14,
12245,
14,
9849,
496,
272,
18294,
2878,
1714,
339,
5870,
10426,
367,
15332,
14702,
481,
19131,
919,
1350,
1233,
14,
339,
520,
7307,
26,
1898,
8315,
13,
7280,
701,
314,
14493,
8099,
12,
1937,
10610,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
2436,
14,
199,
624,
199,
199,
646,
295,
199,
199,
504,
13277,
14,
11729,
492,
12939,
5838,
199,
504,
13277,
14,
1418,
492,
10357,
12,
4516,
12,
6819,
12,
11013,
12,
6431,
12,
971,
1362,
2812,
12,
2624,
199,
199,
363,
452,
363,
275,
788,
15563,
88,
919,
5838,
418,
421,
199,
533,
481,
19131,
919,
5838,
8,
19856,
304,
272,
408,
5838,
367,
15332,
14702,
481,
19131,
919,
2637,
14,
339,
481,
19131,
919,
6302,
6127,
370,
25123,
1006,
7681,
436,
805,
1561,
272,
370,
841,
4110,
14,
221,
5244,
269,
724,
379,
4513,
787,
440,
18054,
701,
642,
10426,
14,
339,
2508,
7445,
447,
413,
14,
22,
272,
408,
339,
536,
275,
283,
15563,
88,
919,
7,
272,
5481,
275,
788,
9849,
496,
297,
283,
86,
3997,
297,
283,
7548,
529,
297,
283,
88,
1095,
418,
272,
6203,
275,
17855,
3311,
39,
297,
11937,
26233,
418,
272,
12200,
275,
942,
339,
3285,
275,
295,
14,
15434,
1204,
295,
14,
16661,
339,
4645,
275,
469,
267,
283,
1231,
356,
359,
288,
334,
82,
7,
3779,
83,
7590,
78,
297,
10357,
395,
327,
9451,
8057,
288,
334,
82,
6774,
62,
6113,
78,
2862,
83,
7693,
4516,
12,
283,
12210,
659,
953,
327,
428,
5937,
21873,
1443,
506,
1202,
367,
1625,
4918,
288,
327,
436,
367,
1059,
8785,
14,
221,
12077,
367,
6572,
288,
327,
2544,
4877,
1059,
18041,
14,
288,
334,
82,
10120,
28,
9529,
87,
2862,
9046,
16,
13,
25,
12,
1622,
7896,
4300,
4516,
395,
288,
334,
82,
1154,
29538,
1154,
78,
3672,
3985,
25576,
4735,
3212,
78,
3672,
2,
6113,
59,
4735,
3672,
7272,
4300,
2624,
395,
288,
334,
82,
6774,
12773,
83,
27804,
92,
12574,
92,
6,
5282,
15337,
5282,
27,
680,
10,
8995,
78,
297,
6819,
14,
7200,
395,
953,
334,
82,
6774,
27851,
92,
18765,
3755,
92,
1348,
1938,
57,
92,
1348,
3100,
92,
1554,
619,
1217,
21983,
92,
1554,
3973,
34,
5550,
51,
92,
1554,
2846,
51,
5227,
1467,
519,
7,
9732,
25091,
92,
33,
4424,
92,
1554,
3927,
92,
1554,
4464,
51,
92,
1554,
47,
2504,
6689,
92,
12500,
10320,
92,
33,
3170,
5227,
1467,
519,
7,
33,
8193,
51,
92,
33,
12767,
92,
5699,
5994,
92,
1254,
775,
6885,
92,
1254,
775,
3817,
4612,
92,
9021,
51,
5227,
1467,
519,
7,
33,
18235,
92,
748,
3986,
53,
2962,
92,
748,
742,
92,
12644,
92,
748,
568,
654,
92,
1761,
1766,
1469,
5227,
1467,
519,
7,
1991,
4567,
3960,
92,
1156,
47,
4701,
15862,
92,
879,
775,
3830,
11237,
16734,
92,
1282,
50,
3843,
51,
92,
1282,
24762,
4531,
5227,
1467,
519,
7,
22767,
92,
1179,
18988,
92,
8162,
9376,
42,
92,
1179,
1608,
2823,
92,
1179,
568,
92,
1179,
2596,
92,
1179,
2940,
10854,
11344,
5227,
1467,
519,
7,
11307,
3099,
4531,
92,
1179,
2533,
10484,
92,
619,
92,
619,
63,
35,
92,
619,
1254,
4531,
92,
619,
879,
92,
24355,
92,
619,
2571,
5227,
1467,
519,
7,
619,
1981,
3565,
92,
619,
6174,
92,
619,
46,
18,
92,
33,
8558,
92,
6087,
26001,
13748,
92,
13895,
92,
13895,
8760,
5227,
1467,
519,
7,
13895,
2514,
26178,
92,
34,
29056,
92,
9431,
1093,
4554,
92,
9431,
31634,
92,
11970,
3649,
92,
11970,
20706,
5227,
1467,
519,
7,
11970,
44,
18013,
92,
11970,
4609,
92,
11970,
726,
92,
11970,
50,
18013,
92,
11970,
3597,
92,
11970,
2864,
92,
11970,
56,
726,
5227,
1467,
519,
7,
34,
3359,
92,
35,
3649,
998,
1951,
92,
8549,
51,
4406,
92,
18898,
92,
35,
1649,
55,
92,
7695,
56,
92,
2089,
1193,
1206,
92,
1244,
50,
92,
1244,
12115,
55,
5227,
1467,
519,
7,
1244,
50,
17433,
92,
1244,
50,
17433,
35,
92,
12507,
1920,
654,
2233,
3597,
92,
9249,
615,
2080,
92,
35,
12460,
13895,
92,
12874,
6495,
1554,
92,
3978,
5227,
1467,
519,
7,
11265,
92,
13967,
92,
11265,
12322,
92,
11265,
6885,
4531,
92,
11265,
1512,
16262,
92,
6790,
10510,
5227,
1467,
519,
7,
11265,
9677,
3170,
92,
1439,
51,
92,
2890,
1864,
8851,
92,
2890,
14211,
92,
2890,
2846,
38,
92,
8366,
13246,
5227,
1467,
519,
7,
8366,
9868,
92,
8366,
9868,
1438,
92,
8366,
7517,
6174,
92,
1028,
5488,
568,
92,
1028,
22041,
5227,
1467,
519,
7,
1028,
1387,
92,
7013,
3022,
92,
31321,
2970,
19926,
92,
31321,
3597,
19926,
92,
31321,
2566,
4317,
5227,
1467,
519,
7,
7013,
3204,
92,
5390,
92,
12488,
92,
11655,
92,
23317,
92,
2846,
38,
92,
2846,
2970,
19926,
92,
2846,
3597,
19926,
5227,
1467,
519,
7,
2846,
8558,
92,
36,
1093,
16682,
3188,
92,
36,
1093,
2767,
433,
261,
92,
36,
1093,
6589,
92,
36,
1093,
12049,
5227,
1467,
519,
7,
36,
1093,
607,
5277,
323,
92,
36,
4424,
1810,
547,
92,
36,
1093,
1575,
415,
92,
36,
1093,
2017,
92,
36,
4448,
386,
2602,
5227,
1467,
519,
7,
36,
4448,
386,
3167,
92,
36,
4448,
386,
12157,
92,
5745,
775,
281,
827,
323,
92,
3472,
2472,
5227,
1467,
519,
7,
27408,
92,
15119,
15219,
92,
10596,
540,
6013,
92,
16436,
92,
20492,
11658,
5227,
1467,
519,
7,
7687,
2042,
92,
36,
12339,
92,
1649,
3472,
92,
1649,
55,
92,
4564,
6882,
17509,
92,
36,
1092,
1512,
1665,
6174,
5227,
1467,
519,
7,
36,
31634,
92,
7438,
726,
92,
36,
2566,
51,
92,
7438,
1387,
92,
17929,
10187,
92,
13993,
92,
13178,
92,
3170,
92,
28805,
8,
53,
1951,
5547,
5227,
1467,
519,
7,
8193,
30872,
92,
18015,
44,
92,
23017,
3298,
4461,
92,
11992,
92,
38,
1244,
4305,
92,
4161,
1484,
899,
92,
38,
8760,
5227,
1467,
519,
7,
4161,
907,
1951,
92,
38,
5390,
92,
5100,
3359,
92,
38,
3170,
92,
1665,
44,
14527,
92,
38,
2970,
51,
92,
8609,
92,
3817,
5227,
1467,
519,
7,
5110,
26614,
3027,
92,
9905,
92,
21490,
13837,
92,
21490,
4283,
92,
3143,
36,
4924,
92,
38,
4406,
92,
38,
1484,
726,
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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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
Bulochkin/tensorflow_pack
|
tensorflow/contrib/keras/python/keras/metrics_test.py
|
36
|
2470
|
# 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 metrics functions."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import numpy as np
from tensorflow.contrib.keras.python import keras
from tensorflow.python.platform import test
class KerasMetricsTest(test.TestCase):
def test_metrics(self):
with self.test_session():
y_a = keras.backend.variable(np.random.random((6, 7)))
y_b = keras.backend.variable(np.random.random((6, 7)))
for metric in [keras.metrics.binary_accuracy,
keras.metrics.categorical_accuracy]:
output = metric(y_a, y_b)
self.assertEqual(keras.backend.eval(output).shape, (6,))
def test_sparse_categorical_accuracy(self):
with self.test_session():
metric = keras.metrics.sparse_categorical_accuracy
y_a = keras.backend.variable(np.random.randint(0, 7, (6,)))
y_b = keras.backend.variable(np.random.random((6, 7)))
self.assertEqual(keras.backend.eval(metric(y_a, y_b)).shape, (6,))
def test_top_k_categorical_accuracy(self):
with self.test_session():
y_pred = keras.backend.variable(np.array([[0.3, 0.2, 0.1],
[0.1, 0.2, 0.7]]))
y_true = keras.backend.variable(np.array([[0, 1, 0], [1, 0, 0]]))
result = keras.backend.eval(
keras.metrics.top_k_categorical_accuracy(y_true, y_pred, k=3))
self.assertEqual(result, 1)
result = keras.backend.eval(
keras.metrics.top_k_categorical_accuracy(y_true, y_pred, k=2))
self.assertEqual(result, 0.5)
result = keras.backend.eval(
keras.metrics.top_k_categorical_accuracy(y_true, y_pred, k=1))
self.assertEqual(result, 0.)
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,
7186,
3423,
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,
2828,
14,
8811,
14,
1548,
492,
11708,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
421,
199,
533,
1804,
30037,
17213,
774,
8,
396,
14,
1746,
304,
819,
347,
511,
63,
6759,
8,
277,
304,
272,
543,
291,
14,
396,
63,
1730,
837,
489,
612,
63,
65,
275,
11708,
14,
4620,
14,
1975,
8,
1590,
14,
2355,
14,
2355,
1332,
22,
12,
1520,
1724,
489,
612,
63,
66,
275,
11708,
14,
4620,
14,
1975,
8,
1590,
14,
2355,
14,
2355,
1332,
22,
12,
1520,
1724,
489,
367,
6370,
315,
359,
8811,
14,
6759,
14,
3008,
63,
13374,
12,
2151,
11708,
14,
6759,
14,
16810,
63,
13374,
2189,
267,
1072,
275,
6370,
8,
89,
63,
65,
12,
612,
63,
66,
9,
267,
291,
14,
629,
8,
8811,
14,
4620,
14,
2579,
8,
1199,
680,
1392,
12,
334,
22,
4641,
819,
347,
511,
63,
4421,
63,
16810,
63,
13374,
8,
277,
304,
272,
543,
291,
14,
396,
63,
1730,
837,
489,
6370,
275,
11708,
14,
6759,
14,
4421,
63,
16810,
63,
13374,
489,
612,
63,
65,
275,
11708,
14,
4620,
14,
1975,
8,
1590,
14,
2355,
14,
8393,
8,
16,
12,
1520,
12,
334,
22,
20097,
489,
612,
63,
66,
275,
11708,
14,
4620,
14,
1975,
8,
1590,
14,
2355,
14,
2355,
1332,
22,
12,
1520,
1724,
489,
291,
14,
629,
8,
8811,
14,
4620,
14,
2579,
8,
5165,
8,
89,
63,
65,
12,
612,
63,
66,
4992,
1392,
12,
334,
22,
4641,
819,
347,
511,
63,
2119,
63,
75,
63,
16810,
63,
13374,
8,
277,
304,
272,
543,
291,
14,
396,
63,
1730,
837,
489,
612,
63,
5991,
275,
11708,
14,
4620,
14,
1975,
8,
1590,
14,
1144,
4038,
16,
14,
19,
12,
378,
14,
18,
12,
378,
14,
17,
467,
6059,
359,
16,
14,
17,
12,
378,
14,
18,
12,
378,
14,
23,
17723,
489,
612,
63,
2052,
275,
11708,
14,
4620,
14,
1975,
8,
1590,
14,
1144,
4038,
16,
12,
413,
12,
378,
467,
359,
17,
12,
378,
12,
378,
17723,
489,
754,
275,
11708,
14,
4620,
14,
2579,
8,
881,
11708,
14,
6759,
14,
2119,
63,
75,
63,
16810,
63,
13374,
8,
89,
63,
2052,
12,
612,
63,
5991,
12,
1022,
29,
19,
430,
489,
291,
14,
629,
8,
1099,
12,
413,
9,
489,
754,
275,
11708,
14,
4620,
14,
2579,
8,
881,
11708,
14,
6759,
14,
2119,
63,
75,
63,
16810,
63,
13374,
8,
89,
63,
2052,
12,
612,
63,
5991,
12,
1022,
29,
18,
430,
489,
291,
14,
629,
8,
1099,
12,
378,
14,
21,
9,
489,
754,
275,
11708,
14,
4620,
14,
2579,
8,
881,
11708,
14,
6759,
14,
2119,
63,
75,
63,
16810,
63,
13374,
8,
89,
63,
2052,
12,
612,
63,
5991,
12,
1022,
29,
17,
430,
489,
291,
14,
629,
8,
1099,
12,
378,
4959,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
511,
14,
973,
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
] |
[
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,
7186,
3423,
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,
2828,
14,
8811,
14,
1548,
492,
11708,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
421,
199,
533,
1804,
30037,
17213,
774,
8,
396,
14,
1746,
304,
819,
347,
511,
63,
6759,
8,
277,
304,
272,
543,
291,
14,
396,
63,
1730,
837,
489,
612,
63,
65,
275,
11708,
14,
4620,
14,
1975,
8,
1590,
14,
2355,
14,
2355,
1332,
22,
12,
1520,
1724,
489,
612,
63,
66,
275,
11708,
14,
4620,
14,
1975,
8,
1590,
14,
2355,
14,
2355,
1332,
22,
12,
1520,
1724,
489,
367,
6370,
315,
359,
8811,
14,
6759,
14,
3008,
63,
13374,
12,
2151,
11708,
14,
6759,
14,
16810,
63,
13374,
2189,
267,
1072,
275,
6370,
8,
89,
63,
65,
12,
612,
63,
66,
9,
267,
291,
14,
629,
8,
8811,
14,
4620,
14,
2579,
8,
1199,
680,
1392,
12,
334,
22,
4641,
819,
347,
511,
63,
4421,
63,
16810,
63,
13374,
8,
277,
304,
272,
543,
291,
14,
396,
63,
1730,
837,
489,
6370,
275,
11708,
14,
6759,
14,
4421,
63,
16810,
63,
13374,
489,
612,
63,
65,
275,
11708,
14,
4620,
14,
1975,
8,
1590,
14,
2355,
14,
8393,
8,
16,
12,
1520,
12,
334,
22,
20097,
489,
612,
63,
66,
275,
11708,
14,
4620,
14,
1975,
8,
1590,
14,
2355,
14,
2355,
1332,
22,
12,
1520,
1724,
489,
291,
14,
629,
8,
8811,
14,
4620,
14,
2579,
8,
5165,
8,
89,
63,
65,
12,
612,
63,
66,
4992,
1392,
12,
334,
22,
4641,
819,
347,
511,
63,
2119,
63,
75,
63,
16810,
63,
13374,
8,
277,
304,
272,
543,
291,
14,
396,
63,
1730,
837,
489,
612,
63,
5991,
275,
11708,
14,
4620,
14,
1975,
8,
1590,
14,
1144,
4038,
16,
14,
19,
12,
378,
14,
18,
12,
378,
14,
17,
467,
6059,
359,
16,
14,
17,
12,
378,
14,
18,
12,
378,
14,
23,
17723,
489,
612,
63,
2052,
275,
11708,
14,
4620,
14,
1975,
8,
1590,
14,
1144,
4038,
16,
12,
413,
12,
378,
467,
359,
17,
12,
378,
12,
378,
17723,
489,
754,
275,
11708,
14,
4620,
14,
2579,
8,
881,
11708,
14,
6759,
14,
2119,
63,
75,
63,
16810,
63,
13374,
8,
89,
63,
2052,
12,
612,
63,
5991,
12,
1022,
29,
19,
430,
489,
291,
14,
629,
8,
1099,
12,
413,
9,
489,
754,
275,
11708,
14,
4620,
14,
2579,
8,
881,
11708,
14,
6759,
14,
2119,
63,
75,
63,
16810,
63,
13374,
8,
89,
63,
2052,
12,
612,
63,
5991,
12,
1022,
29,
18,
430,
489,
291,
14,
629,
8,
1099,
12,
378,
14,
21,
9,
489,
754,
275,
11708,
14,
4620,
14,
2579,
8,
881,
11708,
14,
6759,
14,
2119,
63,
75,
63,
16810,
63,
13374,
8,
89,
63,
2052,
12,
612,
63,
5991,
12,
1022,
29,
17,
430,
489,
291,
14,
629,
8,
1099,
12,
378,
4959,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
511,
14,
973,
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,
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,
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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
] |
mbj4668/pyang
|
pyang/plugins/jtox.py
|
1
|
4332
|
# Copyright (c) 2015 by Ladislav Lhotka, CZ.NIC <lhotka@nic.cz>
#
# Pyang plugin generating a driver file for JSON->XML translation.
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
"""JTOX output plugin
This plugin takes a YANG data model and produces a JSON driver file
that can be used by the *json2xml* script for translating a valid JSON
configuration or state data to XML.
"""
import json
from pyang import plugin, error
from pyang.util import unique_prefixes
def pyang_plugin_init():
plugin.register_plugin(JtoXPlugin())
class JtoXPlugin(plugin.PyangPlugin):
def add_output_format(self, fmts):
self.multiple_modules = True
fmts['jtox'] = self
def setup_fmt(self, ctx):
ctx.implicit_errors = False
def emit(self, ctx, modules, fd):
"""Main control function.
"""
for epos, etag, eargs in ctx.errors:
if error.is_error(error.err_level(etag)):
raise error.EmitError("JTOX plugin needs a valid module")
tree = {}
mods = {}
annots = {}
for m,p in unique_prefixes(ctx).items():
mods[m.i_modulename] = [p, m.search_one("namespace").arg]
for module in modules:
for ann in module.search(("ietf-yang-metadata", "annotation")):
typ = ann.search_one("type")
annots[module.arg + ":" + ann.arg] = (
"string" if typ is None else self.base_type(ann, typ))
for module in modules:
self.process_children(module, tree, None)
json.dump({"modules": mods, "tree": tree, "annotations": annots}, fd)
def process_children(self, node, parent, pmod):
"""Process all children of `node`, except "rpc" and "notification".
"""
for ch in node.i_children:
if ch.keyword in ["rpc", "notification"]:
continue
if ch.keyword in ["choice", "case"]:
self.process_children(ch, parent, pmod)
continue
if ch.i_module.i_modulename == pmod:
nmod = pmod
nodename = ch.arg
else:
nmod = ch.i_module.i_modulename
nodename = "%s:%s" % (nmod, ch.arg)
ndata = [ch.keyword]
if ch.keyword == "container":
ndata.append({})
self.process_children(ch, ndata[1], nmod)
elif ch.keyword == "list":
ndata.append({})
self.process_children(ch, ndata[1], nmod)
ndata.append([(k.i_module.i_modulename, k.arg)
for k in ch.i_key])
elif ch.keyword in ["leaf", "leaf-list"]:
ndata.append(self.base_type(ch, ch.search_one("type")))
modname = ch.i_module.i_modulename
parent[nodename] = ndata
def base_type(self, ch, of_type):
"""Return the base type of `of_type`."""
while 1:
if of_type.arg == "leafref":
if of_type.i_module.i_version == "1":
node = of_type.i_type_spec.i_target_node
else:
node = ch.i_leafref.i_target_node
elif of_type.i_typedef is None:
break
else:
node = of_type.i_typedef
of_type = node.search_one("type")
if of_type.arg == "decimal64":
return [of_type.arg, int(of_type.search_one("fraction-digits").arg)]
elif of_type.arg == "union":
return [of_type.arg, [self.base_type(ch, x) for x in of_type.i_type_spec.types]]
else:
return of_type.arg
|
isc
|
[
3,
1898,
334,
67,
9,
6900,
701,
7964,
2297,
3783,
491,
8885,
7351,
12,
445,
58,
14,
30374,
665,
76,
8885,
7351,
32,
12165,
14,
16823,
30,
199,
3,
199,
3,
1611,
621,
3589,
12999,
282,
5253,
570,
367,
4840,
5118,
4317,
7761,
14,
199,
3,
199,
3,
8779,
370,
675,
12,
1331,
12,
2811,
12,
436,
15,
269,
11207,
642,
2032,
367,
1263,
199,
3,
12016,
543,
503,
1928,
14751,
365,
11882,
10009,
12,
2741,
626,
314,
3432,
199,
3,
4248,
4245,
436,
642,
4983,
4245,
7468,
315,
1006,
6866,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
2,
2401,
2334,
17632,
8990,
51,
11727,
2990,
199,
3,
1663,
14142,
7816,
2296,
5749,
4141,
6931,
11727,
5292,
2990,
1634,
199,
3,
3169,
2401,
3092,
14,
1621,
4825,
6461,
7000,
2334,
17632,
6262,
7024,
2381,
199,
3,
1821,
8820,
12,
8703,
12,
9168,
12,
1549,
9110,
6736,
1549,
1821,
6736,
199,
3,
28752,
4118,
27362,
20668,
1206,
4442,
9102,
1634,
4815,
12,
7126,
1549,
9206,
12,
7061,
1621,
1261,
199,
3,
9612,
1634,
7066,
12,
9254,
1549,
5010,
7056,
25657,
9612,
12,
7043,
5738,
1634,
199,
3,
1549,
1621,
11287,
1663,
2334,
4815,
1549,
13873,
30340,
1634,
5749,
4141,
14,
199,
199,
624,
42,
2566,
56,
1072,
3589,
199,
199,
2765,
3589,
6181,
282,
29332,
666,
1402,
436,
16904,
282,
4840,
5253,
570,
199,
9099,
883,
506,
1202,
701,
314,
627,
1001,
18,
1652,
10,
2884,
367,
1752,
24615,
282,
1686,
4840,
199,
4758,
503,
1174,
666,
370,
4692,
14,
199,
624,
199,
199,
646,
2022,
199,
199,
504,
1134,
621,
492,
3589,
12,
1125,
199,
504,
1134,
621,
14,
1974,
492,
3747,
63,
14124,
199,
199,
318,
1134,
621,
63,
2718,
63,
826,
837,
272,
3589,
14,
2683,
63,
2718,
8,
42,
475,
56,
5061,
1012,
199,
199,
533,
1603,
475,
56,
5061,
8,
2718,
14,
2713,
621,
5061,
304,
272,
347,
1050,
63,
1199,
63,
908,
8,
277,
12,
20831,
1086,
304,
267,
291,
14,
6048,
63,
3112,
275,
715,
267,
20831,
1086,
459,
74,
475,
88,
418,
275,
291,
339,
347,
3272,
63,
5045,
8,
277,
12,
4027,
304,
267,
4027,
14,
11886,
63,
2550,
275,
756,
339,
347,
8689,
8,
277,
12,
4027,
12,
4621,
12,
6111,
304,
267,
408,
6756,
3304,
805,
14,
267,
408,
267,
367,
325,
1712,
12,
13677,
12,
325,
589,
315,
4027,
14,
2550,
26,
288,
340,
1125,
14,
374,
63,
705,
8,
705,
14,
1508,
63,
1896,
8,
11304,
2298,
355,
746,
1125,
14,
37,
1147,
547,
480,
42,
2566,
56,
3589,
4839,
282,
1686,
859,
531,
267,
3123,
275,
1052,
267,
24496,
275,
1052,
267,
7032,
83,
275,
1052,
267,
367,
333,
12,
80,
315,
3747,
63,
14124,
8,
3799,
680,
1744,
837,
288,
24496,
59,
77,
14,
73,
63,
22582,
61,
275,
359,
80,
12,
333,
14,
1733,
63,
368,
480,
3251,
3471,
1273,
61,
267,
367,
859,
315,
4621,
26,
288,
367,
21172,
315,
859,
14,
1733,
9313,
15799,
13,
11912,
13,
2343,
401,
298,
9340,
14150,
355,
6211,
275,
21172,
14,
1733,
63,
368,
480,
466,
531,
355,
7032,
83,
59,
578,
14,
1273,
435,
14725,
435,
21172,
14,
1273,
61,
275,
334,
490,
298,
875,
2,
340,
6211,
365,
488,
587,
291,
14,
1095,
63,
466,
8,
1189,
12,
6211,
430,
267,
367,
859,
315,
4621,
26,
288,
291,
14,
1412,
63,
3223,
8,
578,
12,
3123,
12,
488,
9,
267,
2022,
14,
2724,
6333,
3112,
582,
24496,
12,
298,
2350,
582,
3123,
12,
298,
11270,
582,
7032,
83,
1386,
6111,
9,
339,
347,
2112,
63,
3223,
8,
277,
12,
1031,
12,
1676,
12,
299,
1494,
304,
267,
408,
3498,
1006,
4978,
402,
658,
932,
3559,
871,
298,
4354,
2,
436,
298,
6761,
1674,
267,
408,
267,
367,
682,
315,
1031,
14,
73,
63,
3223,
26,
288,
340,
682,
14,
6691,
315,
2097,
4354,
401,
298,
6761,
6229,
355,
1980,
288,
340,
682,
14,
6691,
315,
2097,
5095,
401,
298,
2546,
6229,
355,
291,
14,
1412,
63,
3223,
8,
335,
12,
1676,
12,
299,
1494,
9,
355,
1980,
288,
340,
682,
14,
73,
63,
578,
14,
73,
63,
22582,
508,
299,
1494,
26,
355,
302,
1494,
275,
299,
1494,
355,
1031,
354,
275,
682,
14,
1273,
288,
587,
26,
355,
302,
1494,
275,
682,
14,
73,
63,
578,
14,
73,
63,
22582,
355,
1031,
354,
275,
2071,
83,
2689,
83,
2,
450,
334,
78,
1494,
12,
682,
14,
1273,
9,
288,
302,
576,
275,
359,
335,
14,
6691,
61,
288,
340,
682,
14,
6691,
508,
298,
3600,
582,
355,
302,
576,
14,
740,
14079,
355,
291,
14,
1412,
63,
3223,
8,
335,
12,
302,
576,
59,
17,
467,
302,
1494,
9,
288,
916,
682,
14,
6691,
508,
298,
513,
582,
355,
302,
576,
14,
740,
14079,
355,
291,
14,
1412,
63,
3223,
8,
335,
12,
302,
576,
59,
17,
467,
302,
1494,
9,
355,
302,
576,
14,
740,
7694,
75,
14,
73,
63,
578,
14,
73,
63,
22582,
12,
1022,
14,
1273,
9,
2892,
367,
1022,
315,
682,
14,
73,
63,
498,
566,
288,
916,
682,
14,
6691,
315,
2097,
8914,
401,
298,
8914,
13,
513,
6229,
355,
302,
576,
14,
740,
8,
277,
14,
1095,
63,
466,
8,
335,
12,
682,
14,
1733,
63,
368,
480,
466,
13324,
288,
13526,
275,
682,
14,
73,
63,
578,
14,
73,
63,
22582,
288,
1676,
59,
932,
354,
61,
275,
302,
576,
339,
347,
1300,
63,
466,
8,
277,
12,
682,
12,
402,
63,
466,
304,
267,
408,
1767,
314,
1300,
730,
402,
658,
1618,
63,
466,
17105,
267,
1830,
413,
26,
288,
340,
402,
63,
466,
14,
1273,
508,
298,
8914,
1121,
582,
355,
340,
402,
63,
466,
14,
73,
63,
578,
14,
73,
63,
1023,
508,
298,
17,
582,
490,
1031,
275,
402,
63,
466,
14,
73,
63,
466,
63,
1650,
14,
73,
63,
1375,
63,
932,
355,
587,
26,
490,
1031,
275,
682,
14,
73,
63,
8914,
1121,
14,
73,
63,
1375,
63,
932,
288,
916,
402,
63,
466,
14,
73,
63,
9594,
365,
488,
26,
355,
2059,
288,
587,
26,
355,
1031,
275,
402,
63,
466,
14,
73,
63,
9594,
288,
402,
63
] |
[
1898,
334,
67,
9,
6900,
701,
7964,
2297,
3783,
491,
8885,
7351,
12,
445,
58,
14,
30374,
665,
76,
8885,
7351,
32,
12165,
14,
16823,
30,
199,
3,
199,
3,
1611,
621,
3589,
12999,
282,
5253,
570,
367,
4840,
5118,
4317,
7761,
14,
199,
3,
199,
3,
8779,
370,
675,
12,
1331,
12,
2811,
12,
436,
15,
269,
11207,
642,
2032,
367,
1263,
199,
3,
12016,
543,
503,
1928,
14751,
365,
11882,
10009,
12,
2741,
626,
314,
3432,
199,
3,
4248,
4245,
436,
642,
4983,
4245,
7468,
315,
1006,
6866,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
2,
2401,
2334,
17632,
8990,
51,
11727,
2990,
199,
3,
1663,
14142,
7816,
2296,
5749,
4141,
6931,
11727,
5292,
2990,
1634,
199,
3,
3169,
2401,
3092,
14,
1621,
4825,
6461,
7000,
2334,
17632,
6262,
7024,
2381,
199,
3,
1821,
8820,
12,
8703,
12,
9168,
12,
1549,
9110,
6736,
1549,
1821,
6736,
199,
3,
28752,
4118,
27362,
20668,
1206,
4442,
9102,
1634,
4815,
12,
7126,
1549,
9206,
12,
7061,
1621,
1261,
199,
3,
9612,
1634,
7066,
12,
9254,
1549,
5010,
7056,
25657,
9612,
12,
7043,
5738,
1634,
199,
3,
1549,
1621,
11287,
1663,
2334,
4815,
1549,
13873,
30340,
1634,
5749,
4141,
14,
199,
199,
624,
42,
2566,
56,
1072,
3589,
199,
199,
2765,
3589,
6181,
282,
29332,
666,
1402,
436,
16904,
282,
4840,
5253,
570,
199,
9099,
883,
506,
1202,
701,
314,
627,
1001,
18,
1652,
10,
2884,
367,
1752,
24615,
282,
1686,
4840,
199,
4758,
503,
1174,
666,
370,
4692,
14,
199,
624,
199,
199,
646,
2022,
199,
199,
504,
1134,
621,
492,
3589,
12,
1125,
199,
504,
1134,
621,
14,
1974,
492,
3747,
63,
14124,
199,
199,
318,
1134,
621,
63,
2718,
63,
826,
837,
272,
3589,
14,
2683,
63,
2718,
8,
42,
475,
56,
5061,
1012,
199,
199,
533,
1603,
475,
56,
5061,
8,
2718,
14,
2713,
621,
5061,
304,
272,
347,
1050,
63,
1199,
63,
908,
8,
277,
12,
20831,
1086,
304,
267,
291,
14,
6048,
63,
3112,
275,
715,
267,
20831,
1086,
459,
74,
475,
88,
418,
275,
291,
339,
347,
3272,
63,
5045,
8,
277,
12,
4027,
304,
267,
4027,
14,
11886,
63,
2550,
275,
756,
339,
347,
8689,
8,
277,
12,
4027,
12,
4621,
12,
6111,
304,
267,
408,
6756,
3304,
805,
14,
267,
408,
267,
367,
325,
1712,
12,
13677,
12,
325,
589,
315,
4027,
14,
2550,
26,
288,
340,
1125,
14,
374,
63,
705,
8,
705,
14,
1508,
63,
1896,
8,
11304,
2298,
355,
746,
1125,
14,
37,
1147,
547,
480,
42,
2566,
56,
3589,
4839,
282,
1686,
859,
531,
267,
3123,
275,
1052,
267,
24496,
275,
1052,
267,
7032,
83,
275,
1052,
267,
367,
333,
12,
80,
315,
3747,
63,
14124,
8,
3799,
680,
1744,
837,
288,
24496,
59,
77,
14,
73,
63,
22582,
61,
275,
359,
80,
12,
333,
14,
1733,
63,
368,
480,
3251,
3471,
1273,
61,
267,
367,
859,
315,
4621,
26,
288,
367,
21172,
315,
859,
14,
1733,
9313,
15799,
13,
11912,
13,
2343,
401,
298,
9340,
14150,
355,
6211,
275,
21172,
14,
1733,
63,
368,
480,
466,
531,
355,
7032,
83,
59,
578,
14,
1273,
435,
14725,
435,
21172,
14,
1273,
61,
275,
334,
490,
298,
875,
2,
340,
6211,
365,
488,
587,
291,
14,
1095,
63,
466,
8,
1189,
12,
6211,
430,
267,
367,
859,
315,
4621,
26,
288,
291,
14,
1412,
63,
3223,
8,
578,
12,
3123,
12,
488,
9,
267,
2022,
14,
2724,
6333,
3112,
582,
24496,
12,
298,
2350,
582,
3123,
12,
298,
11270,
582,
7032,
83,
1386,
6111,
9,
339,
347,
2112,
63,
3223,
8,
277,
12,
1031,
12,
1676,
12,
299,
1494,
304,
267,
408,
3498,
1006,
4978,
402,
658,
932,
3559,
871,
298,
4354,
2,
436,
298,
6761,
1674,
267,
408,
267,
367,
682,
315,
1031,
14,
73,
63,
3223,
26,
288,
340,
682,
14,
6691,
315,
2097,
4354,
401,
298,
6761,
6229,
355,
1980,
288,
340,
682,
14,
6691,
315,
2097,
5095,
401,
298,
2546,
6229,
355,
291,
14,
1412,
63,
3223,
8,
335,
12,
1676,
12,
299,
1494,
9,
355,
1980,
288,
340,
682,
14,
73,
63,
578,
14,
73,
63,
22582,
508,
299,
1494,
26,
355,
302,
1494,
275,
299,
1494,
355,
1031,
354,
275,
682,
14,
1273,
288,
587,
26,
355,
302,
1494,
275,
682,
14,
73,
63,
578,
14,
73,
63,
22582,
355,
1031,
354,
275,
2071,
83,
2689,
83,
2,
450,
334,
78,
1494,
12,
682,
14,
1273,
9,
288,
302,
576,
275,
359,
335,
14,
6691,
61,
288,
340,
682,
14,
6691,
508,
298,
3600,
582,
355,
302,
576,
14,
740,
14079,
355,
291,
14,
1412,
63,
3223,
8,
335,
12,
302,
576,
59,
17,
467,
302,
1494,
9,
288,
916,
682,
14,
6691,
508,
298,
513,
582,
355,
302,
576,
14,
740,
14079,
355,
291,
14,
1412,
63,
3223,
8,
335,
12,
302,
576,
59,
17,
467,
302,
1494,
9,
355,
302,
576,
14,
740,
7694,
75,
14,
73,
63,
578,
14,
73,
63,
22582,
12,
1022,
14,
1273,
9,
2892,
367,
1022,
315,
682,
14,
73,
63,
498,
566,
288,
916,
682,
14,
6691,
315,
2097,
8914,
401,
298,
8914,
13,
513,
6229,
355,
302,
576,
14,
740,
8,
277,
14,
1095,
63,
466,
8,
335,
12,
682,
14,
1733,
63,
368,
480,
466,
13324,
288,
13526,
275,
682,
14,
73,
63,
578,
14,
73,
63,
22582,
288,
1676,
59,
932,
354,
61,
275,
302,
576,
339,
347,
1300,
63,
466,
8,
277,
12,
682,
12,
402,
63,
466,
304,
267,
408,
1767,
314,
1300,
730,
402,
658,
1618,
63,
466,
17105,
267,
1830,
413,
26,
288,
340,
402,
63,
466,
14,
1273,
508,
298,
8914,
1121,
582,
355,
340,
402,
63,
466,
14,
73,
63,
578,
14,
73,
63,
1023,
508,
298,
17,
582,
490,
1031,
275,
402,
63,
466,
14,
73,
63,
466,
63,
1650,
14,
73,
63,
1375,
63,
932,
355,
587,
26,
490,
1031,
275,
682,
14,
73,
63,
8914,
1121,
14,
73,
63,
1375,
63,
932,
288,
916,
402,
63,
466,
14,
73,
63,
9594,
365,
488,
26,
355,
2059,
288,
587,
26,
355,
1031,
275,
402,
63,
466,
14,
73,
63,
9594,
288,
402,
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,
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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
] |
Jumpscale/jumpscale_core8
|
lib/JumpScale/sal/fs/SystemFS.py
|
1
|
84169
|
import sys
import os
import os.path
import hashlib
import re
import fnmatch
import time
import shutil
import errno
import tempfile
import codecs
import pickle as pickle
import stat
from stat import ST_MTIME
from SystemFSWalker import *
# We import only jumpscale as the j.sal.fs is used before jumpscale is
# initialized. Thus the q cannot be imported yet
from JumpScale import j
# import JumpScale.baselib.codetools #requirement for parsePath
# from text import Text
toStr = j.data.text.toStr
#from JumpScale.core.decorators import deprecated
# We do not use the j.core.platformtype here nor do we import the PlatformType as this would
# lead to circular imports and raise an exception
if not sys.platform.startswith('win'):
try:
import fcntl
except ImportError:
pass
_LOCKDICTIONARY = dict()
logger = j.logger.get('j.sal.fs')
class LockException(Exception):
def __init__(self, message='Failed to get lock', innerException=None):
if innerException:
message += '\nProblem caused by:\n%s' % innerException
Exception.__init__(self, message)
self.innerException = innerException
class LockTimeoutException(LockException):
def __init__(self, message='Lock request timed out', innerException=None):
LockException.__init__(self, message, innerException)
class Exceptions:
LockException = LockException
LockTimeoutException = LockTimeoutException
def cleanupString(string, replacewith="_", regex="([^A-Za-z0-9])"):
'''Remove all non-numeric or alphanumeric characters'''
# Please don't use the logging system here. The logging system
# needs this method, using the logging system here would
# introduce a circular dependency. Be careful not to call other
# functions that use the logging system.
return re.sub(regex, replacewith, string)
def lock(lockname, locktimeout=60, reentry=False):
'''Take a system-wide interprocess exclusive lock. Default timeout is 60 seconds'''
logger.debug('Lock with name: %s' % lockname)
try:
result = lock_(lockname, locktimeout, reentry)
except Exception as e:
raise LockException(innerException=e)
else:
if not result:
raise LockTimeoutException(
message="Cannot acquire lock [%s]" % (lockname))
else:
return result
def lock_(lockname, locktimeout=60, reentry=False):
'''Take a system-wide interprocess exclusive lock.
Works similar to j.sal.fs.lock but uses return values to denote lock
success instead of raising fatal errors.
This refactoring was mainly done to make the lock implementation easier
to unit-test.
'''
# TODO This no longer uses fnctl on Unix, why?
LOCKPATH = os.path.join(j.dirs.tmpDir, 'locks')
lockfile = os.path.join(LOCKPATH, cleanupString(lockname))
if reentry:
_LOCKDICTIONARY[lockname] = _LOCKDICTIONARY.setdefault(lockname, 0) + 1
if not islocked(lockname, reentry=reentry):
if not j.sal.fs.exists(LOCKPATH):
j.sal.fs.createDir(LOCKPATH)
j.sal.fs.writeFile(lockfile, str(os.getpid()))
return True
else:
locked = False
for i in range(locktimeout + 1):
locked = islocked(lockname, reentry)
if not locked:
break
else:
time.sleep(1)
if not locked:
return lock_(lockname, locktimeout, reentry)
else:
return False
def islocked(lockname, reentry=False):
'''Check if a system-wide interprocess exclusive lock is set'''
isLocked = True
LOCKPATH = os.path.join(j.dirs.tmpDir, 'locks')
lockfile = os.path.join(LOCKPATH, cleanupString(lockname))
try:
# read the pid from the lockfile
if j.sal.fs.exists(lockfile):
pid = open(lockfile, 'rb').read()
else:
return False
except (OSError, IOError) as e:
# failed to read the lockfile
if e.errno != errno.ENOENT: # exception is not 'file or directory not found' -> file probably locked
raise
else:
# open succeeded without exceptions, continue
# check if a process with pid is still running
if pid and pid.isdigit():
pid = int(pid)
if reentry and pid == os.getpid():
return False
if j.sal.fs.exists(lockfile) and (not pid or not j.sal.process.isPidAlive(pid)):
# cleanup system, pid not active, remove the lockfile
j.sal.fs.remove(lockfile)
isLocked = False
return isLocked
def unlock(lockname):
"""Unlock system-wide interprocess lock"""
logger.debug('Unlock with name: %s' % lockname)
try:
unlock_(lockname)
except Exception as msg:
raise j.exceptions.RuntimeError(
"Cannot unlock [%s] with ERROR: %s" % (lockname, str(msg)))
def unlock_(lockname):
'''Unlock system-wide interprocess lock
Works similar to j.sal.fs.unlock but uses return values to denote unlock
success instead of raising fatal errors.
This refactoring was mainly done to make the lock implementation easier
to unit-test.
'''
LOCKPATH = os.path.join(j.dirs.tmpDir, 'locks')
lockfile = os.path.join(LOCKPATH, cleanupString(lockname))
if lockname in _LOCKDICTIONARY:
_LOCKDICTIONARY[lockname] -= 1
if _LOCKDICTIONARY[lockname] > 0:
return
# read the pid from the lockfile
if j.sal.fs.exists(lockfile):
try:
pid = open(lockfile, 'rb').read()
except:
return
if int(pid) != os.getpid():
j.errorconditionhandler.raiseWarning(
"Lock %r not owned by this process" % lockname)
return
j.sal.fs.remove(lockfile)
# else:
# j.tools.console.echo("Lock %r not found"%lockname)
class FileLock:
'''Context manager for file-based locks
Context managers were introduced in Python 2.5, see the documentation on the
'with' statement for more information:
* http://www.python.org/dev/peps/pep-0343/
* http://pyref.infogami.com/with
@see: L{lock}
@see: L{unlock}
'''
def __init__(self, lock_name, reentry=False, locktimeout=60):
self.lock_name = lock_name
self.reentry = reentry
self.locktimeout = locktimeout
def __enter__(self):
lock(self.lock_name, reentry=self.reentry, locktimeout=self.locktimeout)
def __exit__(self, *exc_info):
unlock(self.lock_name)
def __call__(self, func):
def wrapper(*args, **kwargs):
lock(self.lock_name, reentry=self.reentry, locktimeout=self.locktimeout)
try:
return func(*args, **kwargs)
finally:
unlock(self.lock_name)
return wrapper
class SystemFS:
exceptions = Exceptions
def __init__(self):
self.__jslocation__ = "j.sal.fs"
self.logger = j.logger.get("j.sal.fs")
self.logger.disabled = True
self.walker = SystemFSWalker()
def copyFile(self, fileFrom, to, createDirIfNeeded=False, overwriteFile=True):
"""Copy file
Copies the file from C{fileFrom} to the file or directory C{to}.
If C{to} is a directory, a file with the same basename as C{fileFrom} is
created (or overwritten) in the directory specified.
Permission bits are copied.
@param fileFrom: Source file path name
@type fileFrom: string
@param to: Destination file or folder path name
@type to: string
@autocomplete
"""
if ((fileFrom is None) or (to is None)):
raise TypeError(
"No parameters given to system.fs.copyFile from %s, to %s" % (fileFrom, to))
if j.sal.fs.isFile(fileFrom):
# Create target folder first, otherwise copy fails
target_folder = os.path.dirname(to)
if createDirIfNeeded:
self.createDir(target_folder)
if overwriteFile is False:
if self.exists(to) and os.path.samefile(to, target_folder):
destfilename = os.path.join(to, os.path.basename(fileFrom))
if self.exists(destfilename):
return
elif self.exists(to):
return
elif self.isFile(to):
# overwriting some open files is frustrating and may not work
# due to locking [delete/copy is a better strategy]
self.remove(to)
try:
shutil.copy(fileFrom, to)
self.logger.debug("Copied file from %s to %s" % (fileFrom, to))
except Exception as e:
raise j.exceptions.RuntimeError(
"Could not copy file from %s to %s, error %s" % (fileFrom, to, e))
else:
raise j.exceptions.RuntimeError(
"Can not copy file, file: %s does not exist in system.fs.copyFile" % (fileFrom))
def moveFile(self, source, destin):
"""Move a File from source path to destination path
@param source: string (Source file path)
@param destination: string (Destination path the file should be moved to )
"""
self.logger.debug('Move file from %s to %s' % (source, destin))
if ((source is None) or (destin is None)):
raise TypeError(
"Not enough parameters given to system.fs.moveFile: move from %s, to %s" % (source, destin))
if not j.sal.fs.isFile(source):
raise j.exceptions.RuntimeError(
"The specified source path in system.fs.moveFile does not exist or is no file: %s" % source)
try:
self.move(source, destin)
except Exception as e:
raise j.exceptions.RuntimeError(
"File could not be moved...in system.fs.moveFile: from %s to %s , Error %s" % (source, destin, str(e)))
def renameFile(self, filePath, new_name):
"""
OBSOLETE
"""
self.logger.debug("WARNING: renameFIle should not be used")
return self.move(filePath, new_name)
def removeIrrelevantFiles(self, path, followSymlinks=True):
ext = ["pyc", "bak"]
for path in self.listFilesInDir(path, recursive=True, followSymlinks=followSymlinks):
if self.getFileExtension(path) in ext:
self.remove(path)
def remove(self, path):
"""Remove a File
@param path: string (File path required to be removed
"""
self.logger.debug('Remove file with path: %s' % path)
if len(path) > 0 and path[-1] == os.sep:
path = path[:-1]
if path is None:
raise TypeError(
'Not enough parameters passed to system.fs.removeFile: %s' % path)
if os.path.islink(path):
os.unlink(path)
if self.exists(path):
try:
os.remove(path)
except Exception as e:
raise j.exceptions.RuntimeError(
"File with path: %s could not be removed\nDetails: %s\n%s" % (path, e, sys.exc_info()[0]))
self.logger.debug('Done removing file with path: %s' % path)
def createEmptyFile(self, filename):
"""Create an empty file
@param filename: string (file path name to be created)
"""
self.logger.debug(
'creating an empty file with name & path: %s' % filename)
if filename is None:
raise ArithmeticError(
'Not enough parameters passed to system.fs.createEmptyFile: %s' % filename)
try:
open(filename, "w").close()
self.logger.debug(
'Empty file %s has been successfully created' % filename)
except Exception:
raise j.exceptions.RuntimeError(
"Failed to create an empty file with the specified filename: %s" % filename)
def createDir(self, newdir):
"""Create new Directory
@param newdir: string (Directory path/name)
if newdir was only given as a directory name, the new directory will be created on the default path,
if newdir was given as a complete path with the directory name, the new directory will be created in the specified path
"""
if newdir.find("file://") != -1:
raise j.exceptions.RuntimeError("Cannot use file notation here")
self.logger.debug(
'Creating directory if not exists %s' % toStr(newdir))
if newdir == '' or newdir is None:
raise TypeError(
'The newdir-parameter of system.fs.createDir() is None or an empty string.')
if self.isLink(newdir):
self.unlink(newdir)
if self.isDir(newdir):
self.logger.debug(
'Directory trying to create: [%s] already exists' % toStr(newdir))
else:
head, tail = os.path.split(newdir)
if head and not j.sal.fs.isDir(head):
self.createDir(head)
if tail:
try:
os.mkdir(newdir)
# print "mkdir:%s"%newdir
except OSError as e:
if e.errno != os.errno.EEXIST: # File exists
raise
self.logger.debug('Created the directory [%s]' % toStr(newdir))
def copyDirTree(self, src, dst, keepsymlinks=False, deletefirst=False,
overwriteFiles=True, ignoredir=[".egg-info", ".dist-info"], ignorefiles=[".egg-info"], rsync=True,
ssh=False, sshport=22, recursive=True, rsyncdelete=True, createdir=False, applyHrdOnDestPaths=None):
"""Recursively copy an entire directory tree rooted at src.
The dst directory may already exist; if not,
it will be created as well as missing parent directories
@param src: string (source of directory tree to be copied)
@param rsyncdelete will remove files on dest which are not on source (default)
@param dst: string (path directory to be copied to...should not already exist)
@param keepsymlinks: bool (True keeps symlinks instead of copying the content of the file)
@param deletefirst: bool (Set to True if you want to erase destination first, be carefull, this can erase directories)
@param overwriteFiles: if True will overwrite files, otherwise will not overwrite when destination exists
"""
if not ssh:
if src.find("file://") != -1 or dst.find("file://") != -1:
raise j.exceptions.RuntimeError(
"Cannot use file notation here")
self.logger.debug('Copy directory tree from %s to %s' % (src, dst))
if ((src is None) or (dst is None)):
raise TypeError(
'Not enough parameters passed in system.fs.copyDirTree to copy directory from %s to %s ' % (src, dst))
if j.sal.fs.isDir(src):
names = os.listdir(src)
if not j.sal.fs.exists(dst):
self.createDir(dst)
errors = []
for name in names:
# is only for the name
if applyHrdOnDestPaths is not None:
name2 = applyHrdOnDestPaths.applyOnContent(name)
else:
name2 = name
srcname = j.sal.fs.joinPaths(src, name)
dstname = j.sal.fs.joinPaths(dst, name2)
if deletefirst and self.exists(dstname):
if self.isDir(dstname, False):
self.removeDirTree(dstname)
if self.isLink(dstname):
self.unlink(dstname)
if keepsymlinks and j.sal.fs.isLink(srcname):
linkto = j.sal.fs.readlink(srcname)
j.sal.fs.symlink(linkto, dstname, overwriteFiles)
elif j.sal.fs.isDir(srcname):
# print "1:%s %s"%(srcname,dstname)
j.sal.fs.copyDirTree(srcname, dstname, keepsymlinks, deletefirst,
overwriteFiles=overwriteFiles, applyHrdOnDestPaths=applyHrdOnDestPaths)
else:
# print "2:%s %s"%(srcname,dstname)
self.copyFile(
srcname, dstname, createDirIfNeeded=False, overwriteFile=overwriteFiles)
else:
raise j.exceptions.RuntimeError(
'Source path %s in system.fs.copyDirTree is not a directory' % src)
else:
# didnt use j.sal.rsync because its not complete and doesnt work
# properly
excl = ""
for item in ignoredir:
excl += "--exclude '*%s*/' " % item
for item in ignorefiles:
excl += "--exclude '*%s*' " % item
excl += "--exclude '*.pyc' "
excl += "--exclude '*.bak' "
excl += "--exclude '*__pycache__*' "
if self.isDir(src):
if dst[-1] != "/":
dst += "/"
if src[-1] != "/":
src += "/"
dstpath = dst.split(':')[1] if ':' in dst else dst
cmd = "rsync "
if keepsymlinks:
#-l is keep symlinks, -L follow
cmd += " -rlptgo --partial %s" % excl
else:
cmd += " -rLptgo --partial %s" % excl
if not recursive:
cmd += " --exclude \"*/\""
if rsyncdelete:
cmd += " --delete"
if ssh:
cmd += " -e 'ssh -o StrictHostKeyChecking=no -p %s' " % sshport
if createdir:
cmd += "--rsync-path='mkdir -p %s && rsync' " % self.getParent(
dstpath)
cmd += " '%s' '%s'" % (src, dst)
print(cmd)
return j.tools.cuisine.local.core.run(cmd)[1]
def removeDirTree(self, path, onlyLogWarningOnRemoveError=False):
"""Recursively delete a directory tree.
@param path: the path to be removed
"""
if path is None:
raise ValueError('Path is None in system.fs.removeDir')
self.logger.debug('Removing directory tree with path: %s' % path)
if self.isLink(path):
self.remove(path)
if self.isFile(path):
self.remove(path)
if(j.sal.fs.exists(path)):
if(self.isDir(path)):
if onlyLogWarningOnRemoveError:
def errorHandler(shutilFunc, shutilPath, shutilExc_info):
self.logger.debug(
'WARNING: could not remove %s while recursively deleting %s' % (shutilPath, path))
self.logger.debug(
'Trying to remove Directory tree with path: %s (warn on errors)' % path)
shutil.rmtree(path, onerror=errorHandler)
else:
self.logger.debug(
'Trying to remove Directory tree with path: %s' % path)
shutil.rmtree(path)
self.logger.debug(
'Directory tree with path: %s is successfully removed' % path)
else:
raise ValueError(
"Specified path: %s is not a Directory in system.fs.removeDirTree" % path)
def removeDir(self, path):
"""Remove a Directory
@param path: string (Directory path that should be removed)
"""
self.logger.debug('Removing the directory with path: %s' % path)
if path is None:
raise TypeError('Path is None in system.fs.removeDir')
if(j.sal.fs.exists(path)):
if(j.sal.fs.isDir(path)):
os.rmdir(path)
self.logger.debug(
'Directory with path: %s is successfully removed' % path)
else:
raise ValueError(
"Path: %s is not a Directory in system.fs.removeDir" % path)
else:
raise j.exceptions.RuntimeError(
"Path: %s does not exist in system.fs.removeDir" % path)
def changeDir(self, path):
"""Changes Current Directory
@param path: string (Directory path to be changed to)
"""
self.logger.debug('Changing directory to: %s' % path)
if path is None:
raise TypeError('Path is not given in system.fs.changeDir')
if(j.sal.fs.exists(path)):
if(j.sal.fs.isDir(path)):
os.chdir(path)
newcurrentPath = os.getcwd()
self.logger.debug(
'Directory successfully changed to %s' % path)
return newcurrentPath
else:
raise ValueError(
"Path: %s in system.fs.changeDir is not a Directory" % path)
else:
raise j.exceptions.RuntimeError(
"Path: %s in system.fs.changeDir does not exist" % path)
def moveDir(self, source, destin):
"""Move Directory from source to destination
@param source: string (Source path where the directory should be removed from)
@param destin: string (Destination path where the directory should be moved into)
"""
self.logger.debug('Moving directory from %s to %s' % (source, destin))
if ((source is None) or (destin is None)):
raise TypeError(
'Not enough passed parameters to moveDirectory from %s to %s in system.fs.moveDir ' % (source, destin))
if(j.sal.fs.isDir(source)):
j.sal.fs.move(source, destin)
self.logger.debug(
'Directory is successfully moved from %s to %s' % (source, destin))
else:
raise j.exceptions.RuntimeError(
"Specified Source path: %s does not exist in system.fs.moveDir" % source)
def joinPaths(self, *args):
"""Join one or more path components.
If any component is an absolute path, all previous components are thrown away, and joining continues.
@param path1: string
@param path2: string
@param path3: string
@param .... : string
@rtype: Concatenation of path1, and optionally path2, etc...,
with exactly one directory separator (os.sep) inserted between components, unless path2 is empty.
"""
args = [toStr(x) for x in args]
self.logger.debug('Join paths %s' % (str(args)))
if args is None:
raise TypeError('Not enough parameters %s' % (str(args)))
if os.sys.platform.startswith("win"):
args2 = []
for item in args:
item = item.replace("/", "\\")
while len(item) > 0 and item[0] == "\\":
item = item[1:]
args2.append(item)
args = args2
try:
return os.path.join(*args)
except Exception as e:
raise j.exceptions.RuntimeError(
"Failed to join paths: %s, Error %s " % (str(args), str(e)))
def getDirName(self, path, lastOnly=False, levelsUp=None):
"""
Return a directory name from pathname path.
@param path the path to find a directory within
@param lastOnly means only the last part of the path which is a dir (overrides levelsUp to 0)
@param levelsUp means, return the parent dir levelsUp levels up
e.g. ...getDirName("/opt/qbase/bin/something/test.py", levelsUp=0) would return something
e.g. ...getDirName("/opt/qbase/bin/something/test.py", levelsUp=1) would return bin
e.g. ...getDirName("/opt/qbase/bin/something/test.py", levelsUp=10) would raise an error
"""
self.logger.debug('Get directory name of path: %s' % path)
if path is None:
raise TypeError('Path is not passed in system.fs.getDirName')
dname = os.path.dirname(path)
dname = dname.replace("/", os.sep)
dname = dname.replace("//", os.sep)
dname = dname.replace("\\", os.sep)
if lastOnly:
dname = dname.split(os.sep)[-1]
return dname
if levelsUp is not None:
parts = dname.split(os.sep)
if len(parts) - levelsUp > 0:
return parts[len(parts) - levelsUp - 1]
else:
raise j.exceptions.RuntimeError(
"Cannot find part of dir %s levels up, path %s is not long enough" % (levelsUp, path))
return dname + os.sep
def getBaseName(self, path):
"""Return the base name of pathname path."""
self.logger.debug('Get basename for path: %s' % path)
if path is None:
raise TypeError('Path is not passed in system.fs.getDirName')
try:
return os.path.basename(path.rstrip(os.path.sep))
except Exception as e:
raise j.exceptions.RuntimeError(
'Failed to get base name of the given path: %s, Error: %s' % (path, str(e)))
def pathShorten(self, path):
"""
Clean path (change /var/www/../lib to /var/lib). On Windows, if the
path exists, the short path name is returned.
@param path: Path to clean
@type path: string
@return: Cleaned (short) path
@rtype: string
"""
cleanedPath = os.path.normpath(path)
if j.core.platformtype.myplatform.isWindows() and self.exists(cleanedPath):
# Only execute on existing paths, otherwise an error will be raised
import win32api
cleanedPath = win32api.GetShortPathName(cleanedPath)
# Re-add '\' if original path had one
sep = os.path.sep
if path and path[-1] == sep and cleanedPath[-1] != sep:
cleanedPath = "%s%s" % (cleanedPath, sep)
return cleanedPath
def pathClean(self, path):
"""
goal is to get a equal representation in / & \ in relation to os.sep
"""
path = path.replace("/", os.sep)
path = path.replace("//", os.sep)
path = path.replace("\\", os.sep)
path = path.replace("\\\\", os.sep)
# path=self.pathNormalize(path)
path = path.strip()
return path
def pathDirClean(self, path):
path = path + os.sep
return self.pathClean(path)
def dirEqual(self, path1, path2):
return self.pathDirClean(path1) == self.pathDirClean(path2)
def pathNormalize(self, path, root=""):
"""
paths are made absolute & made sure they are in line with os.sep
@param path: path to normalize
@root is std the application you are in, can overrule
"""
if root == "":
root = self.getcwd()
path = self.pathClean(path)
if len(path) > 0 and path[0] != os.sep:
path = self.joinPaths(root, path)
return path
def pathRemoveDirPart(self, path, toremove, removeTrailingSlash=False):
"""
goal remove dirparts of a dirpath e,g, a basepath which is not needed
will look for part to remove in full path but only full dirs
"""
path = self.pathNormalize(path)
toremove = self.pathNormalize(toremove)
if self.pathClean(toremove) == self.pathClean(path):
return ""
path = self.pathClean(path)
path = path.replace(self.pathDirClean(toremove), "")
if removeTrailingSlash:
if len(path) > 0 and path[0] == os.sep:
path = path[1:]
path = self.pathClean(path)
return path
def processPathForDoubleDots(self, path):
"""
/root/somepath/.. would become /root
/root/../somepath/ would become /somepath
result will always be with / slashes
"""
# print "processPathForDoubleDots:%s"%path
path = self.pathClean(path)
path = path.replace("\\", "/")
result = []
for item in path.split("/"):
if item == "..":
if result == []:
raise j.exceptions.RuntimeError(
"Cannot processPathForDoubleDots for paths with only ..")
else:
result.pop()
else:
result.append(item)
return "/".join(result)
def getParent(self, path):
"""
Returns the parent of the path:
/dir1/dir2/file_or_dir -> /dir1/dir2/
/dir1/dir2/ -> /dir1/
"""
parts = path.split(os.sep)
if parts[-1] == '':
parts = parts[:-1]
parts = parts[:-1]
if parts == ['']:
return os.sep
return os.sep.join(parts)
def getFileExtension(self, path):
ext = os.path.splitext(path)[1]
return ext.strip('.')
def chown(self, path, user, group=None):
from pwd import getpwnam
from grp import getgrnam
getpwnam(user)[2]
uid = getpwnam(user).pw_uid
if group is not None:
gid = getgrnam(group).gr_gid
else:
gid = getpwnam(user).pw_gid
os.chown(path, uid, gid)
for root, dirs, files in os.walk(path):
for ddir in dirs:
path = os.path.join(root, ddir)
try:
os.chown(path, uid, gid)
except Exception as e:
if str(e).find("No such file or directory") == -1:
raise j.exceptions.RuntimeError("%s" % e)
for file in files:
path = os.path.join(root, file)
try:
os.chown(path, uid, gid)
except Exception as e:
if str(e).find("No such file or directory") == -1:
raise j.exceptions.RuntimeError("%s" % e)
def chmod(self, path, permissions):
"""
@param permissions e.g. 0o660 (USE OCTAL !!!)
"""
os.chmod(path, permissions)
for root, dirs, files in os.walk(path):
for ddir in dirs:
path = os.path.join(root, ddir)
try:
os.chmod(path, permissions)
except Exception as e:
if str(e).find("No such file or directory") == -1:
raise j.exceptions.RuntimeError("%s" % e)
for file in files:
path = os.path.join(root, file)
try:
os.chmod(path, permissions)
except Exception as e:
if str(e).find("No such file or directory") == -1:
raise j.exceptions.RuntimeError("%s" % e)
def parsePath(self, path, baseDir="", existCheck=True, checkIsFile=False):
"""
parse paths of form /root/tmp/33_adoc.doc into the path, priority which is numbers before _ at beginning of path
also returns filename
checks if path can be found, if not will fail
when filename="" then is directory which has been parsed
if basedir specified that part of path will be removed
example:
j.sal.fs.parsePath("/opt/qbase3/apps/specs/myspecs/definitions/cloud/datacenter.txt","/opt/qbase3/apps/specs/myspecs/",existCheck=False)
@param path is existing path to a file
@param baseDir, is the absolute part of the path not required
@return list of dirpath,filename,extension,priority
priority = 0 if not specified
"""
# make sure only clean path is left and the filename is out
if existCheck and not self.exists(path):
raise j.exceptions.RuntimeError(
"Cannot find file %s when importing" % path)
if checkIsFile and not self.isFile(path):
raise j.exceptions.RuntimeError(
"Path %s should be a file (not e.g. a dir), error when importing" % path)
extension = ""
if self.isDir(path):
name = ""
path = self.pathClean(path)
else:
name = self.getBaseName(path)
path = self.pathClean(path)
# make sure only clean path is left and the filename is out
path = self.getDirName(path)
# find extension
regexToFindExt = "\.\w*$"
if j.tools.code.regex.match(regexToFindExt, name):
extension = j.tools.code.regex.findOne(
regexToFindExt, name).replace(".", "")
# remove extension from name
name = j.tools.code.regex.replace(
regexToFindExt, regexFindsubsetToReplace=regexToFindExt, replaceWith="", text=name)
if baseDir != "":
path = self.pathRemoveDirPart(path, baseDir)
if name == "":
dirOrFilename = j.sal.fs.getDirName(path, lastOnly=True)
else:
dirOrFilename = name
# check for priority
regexToFindPriority = "^\d*_"
if j.tools.code.regex.match(regexToFindPriority, dirOrFilename):
# found priority in path
priority = j.tools.code.regex.findOne(
regexToFindPriority, dirOrFilename).replace("_", "")
# remove priority from path
name = j.tools.code.regex.replace(
regexToFindPriority, regexFindsubsetToReplace=regexToFindPriority, replaceWith="", text=name)
else:
priority = 0
return path, name, extension, priority # if name =="" then is dir
def getcwd(self):
"""get current working directory
@rtype: string (current working directory path)
"""
self.logger.debug('Get current working directory')
try:
return os.getcwd()
except Exception as e:
raise j.exceptions.RuntimeError(
'Failed to get current working directory')
def readlink(self, path, absolute=True):
"""Works only for unix
Return a string representing the path to which the symbolic link points.
@param absolute, if True then look for absolute source location
returns the source location
"""
while path[-1] == "/" or path[-1] == "\\":
path = path[:-1]
self.logger.debug('Read link with path: %s' % path)
if path is None:
raise TypeError('Path is not passed in system.fs.readLink')
if j.core.platformtype.myplatform.isUnix():
try:
res = os.readlink(path)
except Exception as e:
raise j.exceptions.RuntimeError(
'Failed to read link with path: %s \nERROR: %s' % (path, str(e)))
elif j.core.platformtype.myplatform.isWindows():
raise j.exceptions.RuntimeError('Cannot readLink on windows')
if res.startswith("..") and absolute:
if self.isFile(path):
srcDir = self.getDirName(path)
elif self.isDir(path):
srcDir = res
else:
raise j.exceptions.Input(message="link can only be file or dir", level=1, source="", tags="", msgpub="")
path = self.joinPaths(srcDir, res)
res = os.path.abspath(path)
return res
def removeLinks(self, path):
"""
find all links & remove
"""
if not self.exists(path):
return
items = self._listAllInDir(
path=path, recursive=True, followSymlinks=False, listSymlinks=True)
items = [item for item in items[0] if j.sal.fs.isLink(item)]
for item in items:
j.sal.fs.unlink(item)
def _listInDir(self, path, followSymlinks=True):
"""returns array with dirs & files in directory
@param path: string (Directory path to list contents under)
"""
if path is None:
raise TypeError('Path is not passed in system.fs.listDir')
if(j.sal.fs.exists(path)):
if(j.sal.fs.isDir(path)) or (followSymlinks and self.checkDirOrLink(path)):
names = os.listdir(path)
return names
else:
raise ValueError(
"Specified path: %s is not a Directory in system.fs.listDir" % path)
else:
raise j.exceptions.RuntimeError(
"Specified path: %s does not exist in system.fs.listDir" % path)
def listFilesInDir(self, path, recursive=False, filter=None, minmtime=None, maxmtime=None,
depth=None, case_sensitivity='os', exclude=[], followSymlinks=True, listSymlinks=False):
"""Retrieves list of files found in the specified directory
@param path: directory path to search in
@type path: string
@param recursive: recursively look in all subdirs
@type recursive: boolean
@param filter: unix-style wildcard (e.g. *.py) - this is not a regular expression
@type filter: string
@param minmtime: if not None, only return files whose last modification time > minmtime (epoch in seconds)
@type minmtime: integer
@param maxmtime: if not None, only return files whose last modification time < maxmtime (epoch in seconds)
@Param depth: is levels deep wich we need to go
@type maxmtime: integer
@Param exclude: list of std filters if matches then exclude
@rtype: list
"""
if depth is not None:
depth = int(depth)
self.logger.debug('List files in directory with path: %s' % path)
if depth == 0:
depth = None
# if depth is not None:
# depth+=1
filesreturn, depth = self._listAllInDir(path, recursive, filter, minmtime, maxmtime, depth, type="f", case_sensitivity=case_sensitivity,
exclude=exclude, followSymlinks=followSymlinks, listSymlinks=listSymlinks)
return filesreturn
def listFilesAndDirsInDir(self, path, recursive=False, filter=None, minmtime=None,
maxmtime=None, depth=None, type="fd", followSymlinks=True, listSymlinks=False):
"""Retrieves list of files found in the specified directory
@param path: directory path to search in
@type path: string
@param recursive: recursively look in all subdirs
@type recursive: boolean
@param filter: unix-style wildcard (e.g. *.py) - this is not a regular expression
@type filter: string
@param minmtime: if not None, only return files whose last modification time > minmtime (epoch in seconds)
@type minmtime: integer
@param maxmtime: if not None, only return files whose last modification time < maxmtime (epoch in seconds)
@Param depth: is levels deep wich we need to go
@type maxmtime: integer
@param type is string with f & d inside (f for when to find files, d for when to find dirs)
@rtype: list
"""
if depth is not None:
depth = int(depth)
self.logger.debug('List files in directory with path: %s' % path)
if depth == 0:
depth = None
# if depth is not None:
# depth+=1
filesreturn, depth = self._listAllInDir(
path, recursive, filter, minmtime, maxmtime, depth, type=type, followSymlinks=followSymlinks, listSymlinks=listSymlinks)
return filesreturn
def _listAllInDir(self, path, recursive, filter=None, minmtime=None, maxmtime=None, depth=None,
type="df", case_sensitivity='os', exclude=[], followSymlinks=True, listSymlinks=True):
"""
# There are 3 possible options for case-sensitivity for file names
# 1. `os`: the same behavior as the OS
# 2. `sensitive`: case-sensitive comparison
# 3. `insensitive`: case-insensitive comparison
"""
dircontent = self._listInDir(path)
filesreturn = []
if case_sensitivity.lower() == 'sensitive':
matcher = fnmatch.fnmatchcase
elif case_sensitivity.lower() == 'insensitive':
def matcher(fname, pattern):
return fnmatch.fnmatchcase(fname.lower(), pattern.lower())
else:
matcher = fnmatch.fnmatch
for direntry in dircontent:
fullpath = self.joinPaths(path, direntry)
# if followSymlinks:
# if self.isLink(fullpath):
# fullpath=self.readlink(fullpath)
if self.isFile(fullpath) and "f" in type:
includeFile = False
if (filter is None) or matcher(direntry, filter):
if (minmtime is not None) or (maxmtime is not None):
mymtime = os.stat(fullpath)[ST_MTIME]
if (minmtime is None) or (mymtime > minmtime):
if (maxmtime is None) or (mymtime < maxmtime):
includeFile = True
else:
includeFile = True
if includeFile:
if exclude != []:
for excludeItem in exclude:
if matcher(direntry, excludeItem):
includeFile = False
if includeFile:
filesreturn.append(fullpath)
elif self.isDir(fullpath):
if "d" in type:
# if not(listSymlinks==False and self.isLink(fullpath)):
filesreturn.append(fullpath)
if recursive:
if depth is not None and depth != 0:
depth = depth - 1
if depth is None or depth != 0:
exclmatch = False
if exclude != []:
for excludeItem in exclude:
if matcher(fullpath, excludeItem):
exclmatch = True
if exclmatch is False:
if not(followSymlinks is False and self.isLink(fullpath)):
r, depth = self._listAllInDir(fullpath, recursive, filter, minmtime, maxmtime, depth=depth, type=type,
exclude=exclude, followSymlinks=followSymlinks, listSymlinks=listSymlinks)
if len(r) > 0:
filesreturn.extend(r)
# and followSymlinks==False and listSymlinks:
elif self.isLink(fullpath):
filesreturn.append(fullpath)
return filesreturn, depth
def checkDirOrLink(self, fullpath):
"""
check if path is dir or link to a dir
"""
return self.checkDirOrLinkToDir(fullpath)
def checkDirOrLinkToDir(self, fullpath):
"""
check if path is dir or link to a dir
"""
if not self.isLink(fullpath) and os.path.isdir(fullpath):
return True
if self.isLink(fullpath):
link = self.readlink(fullpath)
path = self.joinPaths(self.getDirName(fullpath), link)
if self.isDir(path):
return True
return False
def changeFileNames(self, toReplace, replaceWith, pathToSearchIn,
recursive=True, filter=None, minmtime=None, maxmtime=None):
"""
@param toReplace e.g. {name}
@param replace with e.g. "jumpscale"
"""
paths = self.listFilesInDir(
pathToSearchIn, recursive, filter, minmtime, maxmtime)
for path in paths:
path2 = path.replace(toReplace, replaceWith)
if path2 != path:
self.renameFile(path, path2)
def replaceWordsInFiles(self, pathToSearchIn, templateengine, recursive=True,
filter=None, minmtime=None, maxmtime=None):
"""
apply templateengine to list of found files
@param templateengine =te #example below
te=j.tools.code.templateengine.new()
te.add("name",self.a.name)
te.add("description",self.ayses.description)
te.add("version",self.ayses.version)
"""
paths = self.listFilesInDir(
pathToSearchIn, recursive, filter, minmtime, maxmtime)
for path in paths:
templateengine.replaceInsideFile(path)
def listDirsInDir(self, path, recursive=False, dirNameOnly=False, findDirectorySymlinks=True):
""" Retrieves list of directories found in the specified directory
@param path: string represents directory path to search in
@rtype: list
"""
self.logger.debug('List directories in directory with path: %s, recursive = %s' % (
path, str(recursive)))
# if recursive:
# if not j.sal.fs.exists(path):
#raise ValueError('Specified path: %s does not exist' % path)
# if not j.sal.fs.isDir(path):
#raise ValueError('Specified path: %s is not a directory' % path)
#result = []
#os.path.walk(path, lambda a, d, f: a.append('%s%s' % (d, os.path.sep)), result)
# return result
files = self._listInDir(path, followSymlinks=True)
filesreturn = []
for file in files:
fullpath = os.path.join(path, file)
if (findDirectorySymlinks and self.checkDirOrLink(fullpath)) or self.isDir(fullpath):
if dirNameOnly:
filesreturn.append(file)
else:
filesreturn.append(fullpath)
if recursive:
filesreturn.extend(self.listDirsInDir(
fullpath, recursive, dirNameOnly, findDirectorySymlinks))
return filesreturn
def listPyScriptsInDir(self, path, recursive=True, filter="*.py"):
""" Retrieves list of python scripts (with extension .py) in the specified directory
@param path: string represents the directory path to search in
@rtype: list
"""
result = []
for file in j.sal.fs.listFilesInDir(path, recursive=recursive, filter=filter):
if file.endswith(".py"):
filename = file.split(os.sep)[-1]
scriptname = filename.rsplit(".", 1)[0]
result.append(scriptname)
return result
def move(self, source, destin):
"""Main Move function
@param source: string (If the specified source is a File....Calls moveFile function)
(If the specified source is a Directory....Calls moveDir function)
"""
if not j.sal.fs.exists(source):
raise IOError('%s does not exist' % source)
shutil.move(source, destin)
def exists(self, path, followlinks=True):
"""Check if the specified path exists
@param path: string
@rtype: boolean (True if path refers to an existing path)
"""
if path is None:
raise TypeError('Path is not passed in system.fs.exists')
if os.path.exists(path) or os.path.islink(path):
if self.isLink(path) and followlinks:
self.logger.debug('path %s exists' % str(path.encode("utf-8")))
relativelink = self.readlink(path)
newpath = self.joinPaths(self.getParent(path), relativelink)
return self.exists(newpath)
else:
return True
self.logger.debug('path %s does not exist' % str(path.encode("utf-8")))
return False
def symlink(self, path, target, overwriteTarget=False):
"""Create a symbolic link
@param path: source path desired to create a symbolic link for
@param target: destination path required to create the symbolic link at
@param overwriteTarget: boolean indicating whether target can be overwritten
"""
self.logger.debug(
'Getting symlink for path: %s to target %s' % (path, target))
if (path is None):
raise TypeError('Path is None in system.fs.symlink')
if target[-1] == "/":
target = target[:-1]
if overwriteTarget and (self.exists(target) or self.isLink(target)):
if self.isLink(target):
self.unlink(target)
elif self.isDir(target):
self.removeDirTree(target)
else:
self.remove(target)
dir = j.sal.fs.getDirName(target)
if not j.sal.fs.exists(dir):
j.sal.fs.createDir(dir)
if j.core.platformtype.myplatform.isUnix():
self.logger.debug("Creating link from %s to %s" % (path, target))
os.symlink(path, target)
elif j.core.platformtype.myplatform.isWindows():
path = path.replace("+", ":")
cmd = "junction \"%s\" \"%s\"" % (self.pathNormalize(target).replace(
"\\", "/"), self.pathNormalize(path).replace("\\", "/"))
print(cmd)
j.sal.process.execute(cmd)
def hardlinkFile(self, source, destin):
"""Create a hard link pointing to source named destin. Availability: Unix.
@param source: string
@param destin: string
@rtype: concatenation of dirname, and optionally linkname, etc.
with exactly one directory separator (os.sep) inserted between components, unless path2 is empty
"""
self.logger.debug(
'Create a hard link pointing to %s named %s' % (source, destin))
if (source is None):
raise TypeError(
'Source path is not passed in system.fs.hardlinkFile')
try:
if j.core.platformtype.myplatform.isUnix():
return os.link(source, destin)
else:
raise j.exceptions.RuntimeError(
'Cannot create a hard link on windows')
except:
raise j.exceptions.RuntimeError(
'Failed to hardLinkFile from %s to %s' % (source, destin))
def checkDirParam(self, path):
if(path.strip() == ""):
raise TypeError("path parameter cannot be empty.")
path = path.replace("//", "/")
path = path.replace("\\\\", "/")
path = path.replace("\\", "/")
if path[-1] != "/":
path = path + "/"
path = path.replace("/", os.sep)
return path
def isDir(self, path, followSoftlink=True):
"""Check if the specified Directory path exists
@param path: string
@param followSoftlink: boolean
@rtype: boolean (True if directory exists)
"""
if (path is None):
raise TypeError('Directory path is None in system.fs.isDir')
if not followSoftlink and self.isLink(path):
return False
return self.checkDirOrLinkToDir(path)
def isEmptyDir(self, path):
"""Check if the specified directory path is empty
@param path: string
@rtype: boolean (True if directory is empty)
"""
if (path is None):
raise TypeError('Directory path is None in system.fs.isEmptyDir')
try:
if(self._listInDir(path) == []):
self.logger.debug('path %s is an empty directory' % path)
return True
self.logger.debug('path %s is not an empty directory' % path)
return False
except:
raise j.exceptions.RuntimeError(
'Failed to check if the specified path: %s is an empty directory...in system.fs.isEmptyDir' % path)
def isFile(self, path, followSoftlink=True):
"""Check if the specified file exists for the given path
@param path: string
@param followSoftlink: boolean
@rtype: boolean (True if file exists for the given path)
"""
self.logger.debug("isfile:%s" % path)
if (path is None):
raise TypeError('File path is None in system.fs.isFile')
try:
if not followSoftlink and self.isLink(path):
self.logger.debug('path %s is a file' % path)
return True
if(os.path.isfile(path)):
self.logger.debug('path %s is a file' % path)
return True
self.logger.debug('path %s is not a file' % path)
return False
except:
raise j.exceptions.RuntimeError(
'Failed to check if the specified path: %s is a file...in system.fs.isFile' % path)
def isExecutable(self, path):
statobj = self.statPath(path)
return not (stat.S_IXUSR & statobj.st_mode == 0)
def isLink(self, path, checkJunction=False):
"""Check if the specified path is a link
@param path: string
@rtype: boolean (True if the specified path is a link)
"""
if path[-1] == os.sep:
path = path[:-1]
if (path is None):
raise TypeError('Link path is None in system.fs.isLink')
if checkJunction and j.core.platformtype.myplatform.isWindows():
cmd = "junction %s" % path
try:
result = j.sal.process.execute(cmd)
except Exception as e:
raise j.exceptions.RuntimeError(
"Could not execute junction cmd, is junction installed? Cmd was %s." % cmd)
if result[0] != 0:
raise j.exceptions.RuntimeError(
"Could not execute junction cmd, is junction installed? Cmd was %s." % cmd)
if result[1].lower().find("substitute name") != -1:
return True
else:
return False
if(os.path.islink(path)):
self.logger.debug('path %s is a link' % path)
return True
self.logger.debug('path %s is not a link' % path)
return False
def isMount(self, path):
"""Return true if pathname path is a mount point:
A point in a file system where a different file system has been mounted.
"""
self.logger.debug('Check if path %s is a mount point' % path)
if path is None:
raise TypeError('Path is passed null in system.fs.isMount')
return os.path.ismount(path)
def statPath(self, path):
"""Perform a stat() system call on the given path
@rtype: object whose attributes correspond to the members of the stat structure
"""
if path is None:
raise TypeError('Path is None in system.fs.statPath')
try:
return os.stat(path)
except:
raise OSError(
'Failed to perform stat system call on the specific path: %s in system.fs.statPath' % (path))
def renameDir(self, dirname, newname, overwrite=False):
"""Rename Directory from dirname to newname
@param dirname: string (Directory original name)
@param newname: string (Directory new name to be changed to)
"""
self.logger.debug('Renaming directory %s to %s' % (dirname, newname))
if dirname == newname:
return
if ((dirname is None) or (newname is None)):
raise TypeError(
'Not enough parameters passed to system.fs.renameDir...[%s, %s]' % (dirname, newname))
if(self.isDir(dirname)):
if overwrite and self.exists(dirname):
self.removeDirTree(dirname)
os.rename(dirname, newname)
else:
raise ValueError(
'Path: %s is not a directory in system.fs.renameDir' % dirname)
def unlinkFile(self, filename):
"""Remove the file path (only for files, not for symlinks)
@param filename: File path to be removed
"""
self.logger.debug('Unlink file with path: %s' % filename)
if (filename is None):
raise TypeError('File name is None in QSstem.unlinkFile')
if not self.isFile(filename):
raise j.exceptions.RuntimeError(
"filename is not a file so cannot unlink")
try:
os.unlink(filename)
except:
raise OSError(
'Failed to unlink the specified file path: %s in system.fs.unlinkFile' % filename)
def unlink(self, filename):
'''Remove the given file if it's a file or a symlink
@param filename: File path to be removed
@type filename: string
'''
self.logger.debug('Unlink path: %s' % filename)
if not filename:
raise TypeError('File name is None in system.fs.unlink')
try:
os.unlink(filename)
except:
raise OSError(
'Failed to unlink the specified file path: [%s] in system.ds.unlink' % filename)
def fileGetContents(self, filename):
"""Read a file and get contents of that file
@param filename: string (filename to open for reading )
@rtype: string representing the file contents
"""
if filename is None:
raise TypeError('File name is None in system.fs.fileGetContents')
self.logger.debug('Opened file %s for reading' % filename)
self.logger.debug('Reading file %s' % filename)
with open(filename) as fp:
data = fp.read()
self.logger.debug('File %s is closed after reading' % filename)
return data
def fileGetBinaryContents(self, filename):
"""Read a file in binary mode and get contents of that file
@param filename: string (filename to open for reading )
@rtype: string representing the file contents
"""
if filename is None:
raise TypeError('File name is None in system.fs.fileGetContents')
self.logger.debug('Opened file %s for reading' % filename)
self.logger.debug('Reading file %s' % filename)
with open(filename, mode='rb') as fp:
data = fp.read()
self.logger.debug('File %s is closed after reading' % filename)
return data
def readFile(self, filename):
"""
Get contents as string from filename.
@param filename str: file path to read from.
"""
return self.fileGetContents(filename)
def fileGetUncommentedContents(self, filename):
"""Read a file and get uncommented contents of that file
@param filename: string (filename to open for reading )
@rtype: list of lines of uncommented file contents
"""
if filename is None:
raise TypeError('File name is None in system.fs.fileGetContents')
self.logger.debug('Opened file %s for reading' % filename)
# self.logger.debug('Reading file %s'% filename,9)
with open(filename) as fp:
data = fp.readlines()
uncommented = list()
for line in data:
if not line.strip().startswith('#') and not line.startswith('\n'):
line = line.replace('\n', '')
uncommented.append(line)
self.logger.debug('File %s is closed after reading' % filename)
return uncommented
def fileGetTextContents(self, filename):
"""Read a UTF-8 file and get contents of that file. Takes care of the [BOM](http://en.wikipedia.org/wiki/Byte_order_mark)
@param filename: string (filename to open for reading)
@rtype: string representing the file contents
"""
if filename is None:
raise TypeError(
'File name is None in system.fs.fileGetTextContents')
with open(filename, encoding='utf8') as f: # enforce utf8 encoding
s = f.read()
boms = [codecs.BOM_UTF8]
for bom in boms: # we can add more BOMs later:
if s.startswith(bom.decode()):
s = s.replace(bom.decode(), '', 1)
break
return s
def touch(self, paths, overwrite=True):
"""
can be single path or multiple (then list)
"""
if j.data.types.list.check(paths):
for item in paths:
self.touch(item, overwrite=overwrite)
path = paths
self.createDir(j.sal.fs.getDirName(path))
if overwrite:
self.remove(path)
if not self.exists(path=path):
self.writeFile(path, "")
def writeFile(self, filename, contents, append=False):
"""
Open a file and write file contents, close file afterwards
@param contents: string (file contents to be written)
"""
if (filename is None) or (contents is None):
raise TypeError('Passed None parameters in system.fs.writeFile')
self.logger.debug('Opened file %s for writing' % filename)
if append is False:
fp = open(filename, "wb")
else:
fp = open(filename, "ab")
self.logger.debug('Writing contents in file %s' % filename)
if j.data.types.string.check(contents):
fp.write(bytes(contents, 'UTF-8'))
else:
fp.write(contents)
# fp.write(contents)
fp.close()
def fileSize(self, filename):
"""Get Filesize of file in bytes
@param filename: the file u want to know the filesize of
@return: int representing file size
"""
self.logger.debug('Getting filesize of file: %s' % filename)
if not self.exists(filename):
raise j.exceptions.RuntimeError(
"Specified file: %s does not exist" % filename)
try:
return os.path.getsize(filename)
except Exception as e:
raise OSError("Could not get filesize of %s\nError: %s" %
(filename, str(e)))
def writeObjectToFile(self, filelocation, obj):
"""
Write a object to a file(pickle format)
@param filelocation: location of the file to which we write
@param obj: object to pickle and write to a file
"""
if not filelocation or not obj:
raise ValueError(
"You should provide a filelocation or a object as parameters")
self.logger.debug(
"Creating pickle and write it to file: %s" % filelocation)
try:
pcl = pickle.dumps(obj)
except Exception as e:
raise Exception(
"Could not create pickle from the object \nError: %s" % (str(e)))
j.sal.fs.writeFile(filelocation, pcl)
if not self.exists(filelocation):
raise Exception("File isn't written to the filesystem")
def readObjectFromFile(self, filelocation):
"""
Read a object from a file(file contents in pickle format)
@param filelocation: location of the file
@return: object
"""
if not filelocation:
raise ValueError(
"You should provide a filelocation as a parameter")
self.logger.debug("Opening file %s for reading" % filelocation)
contents = j.sal.fs.fileGetContents(filelocation)
self.logger.debug("creating object")
try:
obj = pickle.loads(contents)
except Exception as e:
raise Exception(
"Could not create the object from the file contents \n Error: %s" % (str(e)))
return obj
def md5sum(self, filename):
"""Return the hex digest of a file without loading it all into memory
@param filename: string (filename to get the hex digest of it) or list of files
@rtype: md5 of the file
"""
self.logger.debug(
'Get the hex digest of file %s without loading it all into memory' % filename)
if filename is None:
raise('File name is None in system.fs.md5sum')
if not isinstance(filename, list):
filename = [filename]
digest = hashlib.md5()
try:
for filepath in filename:
with open(filepath, 'rb') as fh:
while True:
buf = fh.read(4096)
if buf == b"":
break
digest.update(buf)
return digest.hexdigest()
except Exception as e:
raise j.exceptions.RuntimeError(
"Failed to get the hex digest of the file %sin system.fs.md5sum. Error: %s" % (filename, str(e)))
def getFolderMD5sum(self, folder):
files = sorted(self.walk(folder, recurse=1))
return self.md5sum(files)
def walkExtended(self, root, recurse=0, dirPattern='*', filePattern='*',
followSoftLinks=True, dirs=True, files=True):
"""
Extended Walk version: seperate dir and file pattern
@param root : start directory to start the search.
@type root : string
@param recurse : search also in subdirectories.
@type recurse : number
@param dirPattern : search pattern to match directory names. Wildcards can be included.
@type dirPattern : string
@param filePattern : search pattern to match file names. Wildcards can be included.
@type filePattern : string
@param followSoftLinks : determine if links must be followed.
@type followSoftLinks : boolean
@param dirs : determine to return dir results.
@type dirs : boolean
@param files : determine to return file results.
@type files : boolean
@return : List of files and / or directories that match the search patterns.
@rtype : list of strings
General guidelines in the usage of the method be means of some examples come next. For the example in /tmp there is
* a file test.rtt
* and ./folder1/subfolder/subsubfolder/small_test/test.rtt
To find the first test you can use
j.sal.fs.walkExtended('/tmp/', dirPattern="*tmp*", filePattern="*.rtt")
To find only the second one you could use
j.sal.fs.walkExtended('tmp', recurse=0, dirPattern="*small_test*", filePattern="*.rtt", dirs=False)
"""
self.logger.debug('Scanning directory (walk) %s' % root, 6)
result = []
try:
names = os.listdir(root)
except os.error:
return result # TODO: P2 is this correct?
dirPattern = dirPattern or '*'
dirPatList = dirPattern.split(';')
filePattern = filePattern or '*'
filePatList = filePattern.split(';')
for name in names:
fullname = os.path.normpath(os.path.join(root, name))
if self.isFile(fullname, followSoftLinks):
fileOK = False
dirOK = False
for fPat in filePatList:
if (fnmatch.fnmatch(name, fPat)):
fileOK = True
for dPat in dirPatList:
if (fnmatch.fnmatch(os.path.dirname(fullname), dPat)):
dirOK = True
if fileOK and dirOK and files:
result.append(fullname)
if self.isDir(fullname, followSoftLinks):
for dPat in dirPatList:
if (fnmatch.fnmatch(name, dPat) and dirs):
result.append(fullname)
if recurse:
result = result + self.walkExtended(root=fullname,
recurse=recurse,
dirPattern=dirPattern,
filePattern=filePattern,
followSoftLinks=followSoftLinks,
dirs=dirs,
files=files)
return result
def walk(self, root, recurse=0, pattern='*', return_folders=0,
return_files=1, followSoftlinks=True, str=False, depth=None):
"""This is to provide ScanDir similar function
It is going to be used wherever some one wants to list all files and subfolders
under one given directly with specific or none matchers
"""
# initialize
result = []
if depth is not None:
if depth == 0:
return result
depth -= 1
if str:
os.path.supports_unicode_filenames = True
self.logger.debug('Scanning directory (walk)%s' % root)
# initialize
result = []
# must have at least root folder
try:
names = os.listdir(root)
except os.error:
return result
# expand pattern
pattern = pattern or '*'
pat_list = pattern.split(';')
# check each file
for name in names:
fullname = os.path.normpath(os.path.join(root, name))
# grab if it matches our pattern and entry type
for pat in pat_list:
if (fnmatch.fnmatch(name, pat)):
if (self.isFile(fullname, followSoftlinks) and return_files) or (
return_folders and self.isDir(fullname, followSoftlinks)):
result.append(fullname)
continue
# recursively scan other folders, appending results
if recurse:
if self.isDir(fullname) and not self.isLink(fullname):
result = result + \
self.walk(fullname, recurse, pattern, return_folders,
return_files, followSoftlinks, depth=depth)
return result
def getTmpDirPath(self, create=True):
"""
create a tmp dir name and makes sure the dir exists
"""
tmpdir = j.sal.fs.joinPaths(j.dirs.tmpDir, j.data.idgenerator.generateXCharID(10))
if create is True:
j.sal.fs.createDir(tmpdir)
return tmpdir
def getTmpFilePath(self, cygwin=False):
"""Generate a temp file path
Located in temp dir of qbase
@rtype: string representing the path of the temp file generated
"""
# return tempfile.mktemp())
tmpdir = j.dirs.tmpDir
fd, path = tempfile.mkstemp(dir=tmpdir)
try:
real_fd = os.fdopen(fd)
real_fd.close()
except (IOError, OSError):
pass
if cygwin:
path = path.replace("\\", "/")
path = path.replace("//", "/")
return path
def getTempFileName(self, dir=None, prefix=''):
"""Generates a temp file for the directory specified
@param dir: Directory to generate the temp file
@param prefix: string to start the generated name with
@rtype: string representing the generated temp file path
"""
if dir is None:
return j.sal.fs.joinPaths(j.dirs.tmpDir, prefix +
str(j.data.idgenerator.generateRandomInt(0, 1000000000000)) + ".tmp")
else:
dir = dir or j.dirs.tmpDir
return tempfile.mktemp('', prefix, dir)
def isAsciiFile(self, filename, checksize=4096):
# TODO: let's talk about checksize feature.
try:
with open(filename, encoding='ascii') as f:
f.read()
return True
except UnicodeDecodeError:
return False
def isBinaryFile(self, filename, checksize=4096):
return not self.isAsciiFile(filename, checksize)
def isAbsolute(self, path):
return os.path.isabs(path)
lock = staticmethod(lock)
lock_ = staticmethod(lock_)
islocked = staticmethod(islocked)
unlock = staticmethod(unlock)
unlock_ = staticmethod(unlock_)
def validateFilename(self, filename, platform=None):
'''Validate a filename for a given (or current) platform
Check whether a given filename is valid on a given platform, or the
current platform if no platform is specified.
Rules
=====
Generic
-------
Zero-length filenames are not allowed
Unix
----
Filenames can contain any character except 0x00. We also disallow a
forward slash ('/') in filenames.
Filenames can be up to 255 characters long.
Windows
-------
Filenames should not contain any character in the 0x00-0x1F range, '<',
'>', ':', '"', '/', '\', '|', '?' or '*'. Names should not end with a
dot ('.') or a space (' ').
Several basenames are not allowed, including CON, PRN, AUX, CLOCK$,
NUL, COM[1-9] and LPT[1-9].
Filenames can be up to 255 characters long.
Information sources
===================
Restrictions are based on information found at these URLs:
* http://en.wikipedia.org/wiki/Filename
* http://msdn.microsoft.com/en-us/library/aa365247.aspx
* http://www.boost.org/doc/libs/1_35_0/libs/filesystem/doc/portability_guide.htm
* http://blogs.msdn.com/brian_dewey/archive/2004/01/19/60263.aspx
@param filename: Filename to check
@type filename: string
@param platform: Platform to validate against
@type platform: L{PlatformType}
@returns: Whether the filename is valid on the given platform
@rtype: bool
'''
platform = platform or j.core.platformtype.myplatform
if not filename:
return False
# When adding more restrictions to check_unix or check_windows, please
# update the validateFilename documentation accordingly
def check_unix(filename):
if len(filename) > 255:
return False
if '\0' in filename or '/' in filename:
return False
return True
def check_windows(filename):
if len(filename) > 255:
return False
if os.path.splitext(filename)[0] in ('CON', 'PRN', 'AUX', 'CLOCK$', 'NUL'):
return False
if os.path.splitext(filename)[0] in ('COM%d' % i for i in range(1, 9)):
return False
if os.path.splitext(filename)[0] in ('LPT%d' % i for i in range(1, 9)):
return False
# ASCII characters 0x00 - 0x1F are invalid in a Windows filename
# We loop from 0x00 to 0x20 (xrange is [a, b[), and check whether
# the corresponding ASCII character (which we get through the chr(i)
# function) is in the filename
for c in range(0x00, 0x20):
if chr(c) in filename:
return False
for c in ('<', '>', ':', '"', '/', '\\', '|', '?', '*'):
if c in filename:
return False
if filename.endswith((' ', '.', )):
return False
return True
if platform.isWindows():
return check_windows(filename)
if platform.isUnix():
return check_unix(filename)
raise NotImplementedError(
'Filename validation on given platform not supported')
def find(self, startDir, fileregex):
"""Search for files or folders matching a given pattern
this is a very weard function, don't use is better to use the list functions
make sure you do changedir to the starting dir first
example: find("*.pyc")
@param fileregex: The regex pattern to match
@type fileregex: string
"""
pwd = j.sal.fs.getcwd()
try:
self.changeDir(startDir)
import glob
return glob.glob(fileregex)
finally:
self.changeDir(pwd)
def grep(self, fileregex, lineregex):
"""Search for lines matching a given regex in all files matching a regex
@param fileregex: Files to search in
@type fileregex: string
@param lineregex: Regex pattern to search for in each file
@type lineregex: string
"""
import glob
import re
import os
for filename in glob.glob(fileregex):
if os.path.isfile(filename):
f = open(filename, 'r')
for line in f:
if re.match(lineregex, line):
print(("%s: %s" % (filename, line)))
cleanupString = staticmethod(cleanupString)
def constructDirPathFromArray(self, array):
"""
Create a path using os specific seperators from a list being passed with directoy.
@param array str: list of dirs in the path.
"""
path = ""
for item in array:
path = path + os.sep + item
path = path + os.sep
if j.core.platformtype.myplatform.isUnix():
path = path.replace("//", "/")
path = path.replace("//", "/")
return path
def constructFilePathFromArray(self, array):
"""
Add file name to dir path.
@param array str: list including dir path then file name
"""
path = self.constructDirPathFromArray(array)
if path[-1] == "/":
path = path[0:-1]
return path
def pathToUnicode(self, path):
"""
Convert path to unicode. Use the local filesystem encoding. Will return
path unmodified if path already is unicode.
Use this to convert paths you received from the os module to unicode.
@param path: path to convert to unicode
@type path: basestring
@return: unicode path
@rtype: unicode
"""
from JumpScale.core.main import Dirs
return Dirs.pathToUnicode(path)
def targzCompress(self, sourcepath, destinationpath, followlinks=False, destInTar="", pathRegexIncludes=['.[a-zA-Z0-9]*'],
pathRegexExcludes=[], contentRegexIncludes=[], contentRegexExcludes=[], depths=[],
extrafiles=[]):
"""
@param sourcepath: Source directory .
@param destination: Destination filename.
@param followlinks: do not tar the links, follow the link and add that file or content of directory to the tar
@param pathRegexIncludes: / Excludes match paths to array of regex expressions (array(strings))
@param contentRegexIncludes: / Excludes match content of files to array of regex expressions (array(strings))
@param depths: array of depth values e.g. only return depth 0 & 1 (would mean first dir depth and then 1 more deep) (array(int))
@param destInTar when not specified the dirs, files under sourcedirpath will be added to root of
tar.gz with this param can put something in front e.g. /qbase3/ prefix to dest in tgz
@param extrafiles is array of array [[source,destpath],[source,destpath],...] adds extra files to tar
(TAR-GZ-Archive *.tar.gz)
"""
import os.path
import tarfile
if not j.sal.fs.isDir(sourcepath):
raise j.exceptions.RuntimeError(
"Cannot find file (exists but is not a file or dir) %s" % sourcepath)
self.logger.debug("Compressing directory %s to %s" %
(sourcepath, destinationpath))
if not j.sal.fs.exists(j.sal.fs.getDirName(destinationpath)):
j.sal.fs.createDir(j.sal.fs.getDirName(destinationpath))
t = tarfile.open(name=destinationpath, mode='w:gz')
if not(followlinks != False or destInTar != "" or pathRegexIncludes != ['.*'] or pathRegexExcludes != []
or contentRegexIncludes != [] or contentRegexExcludes != [] or depths != []):
t.add(sourcepath, "/")
else:
def addToTar(params, path):
tarfile = params["t"]
destInTar = params["destintar"]
destpath = j.sal.fs.joinPaths(
destInTar, j.sal.fs.pathRemoveDirPart(path, sourcepath))
if j.sal.fs.isLink(path) and followlinks:
path = j.sal.fs.readlink(path)
self.logger.debug("fs.tar: add file %s to tar" % path)
# print "fstar: add file %s to tar" % path
if not (j.core.platformtype.myplatform.isWindows() and j.sal.windows.checkFileToIgnore(path)):
if self.isFile(path) or self.isLink(path):
tarfile.add(path, destpath)
else:
raise j.exceptions.RuntimeError(
"Cannot add file %s to destpath" % destpath)
params = {}
params["t"] = t
params["destintar"] = destInTar
j.sal.fs.walker.walk(root=sourcepath, callback=addToTar, arg=params,
recursive=True, includeFolders=False,
pathRegexIncludes=pathRegexIncludes, pathRegexExcludes=pathRegexExcludes, contentRegexIncludes=contentRegexIncludes,
contentRegexExcludes=contentRegexExcludes, depths=depths, followlinks=False)
if extrafiles != []:
for extrafile in extrafiles:
source = extrafile[0]
destpath = extrafile[1]
t.add(source, j.sal.fs.joinPaths(destInTar, destpath))
t.close()
def gzip(self, sourceFile, destFile):
"""
Gzip source file into destination zip
@param sourceFile str: path to file to be Gzipped.
@param destFile str: path to destination Gzip file.
"""
import gzip
f_in = open(sourceFile, 'rb')
f_out = gzip.open(destFile, 'wb')
f_out.writelines(f_in)
f_out.close()
f_in.close()
def gunzip(self, sourceFile, destFile):
"""
Gunzip gzip sourcefile into destination file
@param sourceFile str: path to gzip file to be unzipped.
@param destFile str: path to destination folder to unzip folder.
"""
import gzip
self.createDir(self.getDirName(destFile))
f_in = gzip.open(sourceFile, 'rb')
f_out = open(destFile, 'wb')
f_out.writelines(f_in)
f_out.close()
f_in.close()
def targzUncompress(self, sourceFile, destinationdir, removeDestinationdir=True):
"""
compress dirname recursive
@param sourceFile: file to uncompress
@param destinationpath: path of to destiniation dir, sourcefile will end up uncompressed in destination dir
"""
if removeDestinationdir:
j.sal.fs.removeDirTree(destinationdir)
if not j.sal.fs.exists(destinationdir):
j.sal.fs.createDir(destinationdir)
import tarfile
if not j.sal.fs.exists(destinationdir):
j.sal.fs.createDir(destinationdir)
# The tar of python does not create empty directories.. this causes
# manny problem while installing so we choose to use the linux tar here
if j.core.platformtype.myplatform.isWindows():
tar = tarfile.open(sourceFile)
tar.extractall(destinationdir)
tar.close()
# todo find better alternative for windows
else:
cmd = "tar xzf '%s' -C '%s'" % (sourceFile, destinationdir)
j.sal.process.execute(cmd)
|
apache-2.0
|
[
646,
984,
199,
646,
747,
199,
646,
747,
14,
515,
199,
646,
8337,
199,
646,
295,
199,
646,
15951,
199,
646,
900,
199,
646,
5145,
199,
646,
7554,
199,
646,
5549,
199,
646,
6010,
199,
646,
5927,
465,
5927,
199,
646,
5672,
199,
504,
5672,
492,
4384,
63,
45,
4961,
199,
504,
6187,
7079,
26020,
492,
627,
421,
199,
3,
2136,
492,
1454,
14882,
3467,
465,
314,
1335,
14,
6327,
14,
2319,
365,
1202,
2544,
14882,
3467,
365,
199,
3,
10038,
14,
20227,
314,
1894,
3913,
506,
8439,
5966,
421,
199,
504,
1603,
1220,
9944,
492,
1335,
199,
3,
492,
1603,
1220,
9944,
14,
1095,
773,
14,
600,
2537,
327,
12434,
367,
2198,
2042,
199,
3,
687,
1318,
492,
4516,
199,
199,
475,
2848,
275,
1335,
14,
576,
14,
505,
14,
475,
2848,
199,
199,
3,
504,
1603,
1220,
9944,
14,
1018,
14,
11582,
492,
5906,
199,
199,
3,
2136,
886,
440,
675,
314,
1335,
14,
1018,
14,
3246,
466,
2348,
6590,
886,
781,
492,
314,
16078,
804,
465,
642,
3955,
199,
3,
12690,
370,
15032,
8925,
436,
746,
376,
1919,
199,
692,
440,
984,
14,
3246,
14,
2460,
360,
2676,
735,
272,
862,
26,
267,
492,
12871,
272,
871,
3545,
26,
267,
986,
199,
199,
63,
4406,
12511,
1075,
4392,
275,
1211,
342,
199,
199,
2921,
275,
1335,
14,
2921,
14,
362,
360,
74,
14,
6327,
14,
2319,
358,
421,
199,
533,
15536,
1726,
8,
1726,
304,
339,
347,
636,
826,
721,
277,
12,
1245,
534,
4276,
370,
664,
4650,
297,
6506,
1726,
29,
403,
304,
267,
340,
6506,
1726,
26,
288,
1245,
847,
1557,
78,
16467,
18104,
701,
3427,
78,
5,
83,
7,
450,
6506,
1726,
267,
2186,
855,
826,
721,
277,
12,
1245,
9,
267,
291,
14,
5216,
1726,
275,
6506,
1726,
421,
199,
533,
15536,
6372,
1726,
8,
6432,
1726,
304,
339,
347,
636,
826,
721,
277,
12,
1245,
534,
6432,
1056,
18590,
734,
297,
6506,
1726,
29,
403,
304,
267,
15536,
1726,
855,
826,
721,
277,
12,
1245,
12,
6506,
1726,
9,
421,
199,
533,
24873,
26,
272,
15536,
1726,
275,
15536,
1726,
272,
15536,
6372,
1726,
275,
15536,
6372,
1726,
421,
199,
318,
9058,
1558,
8,
875,
12,
3350,
1045,
19667,
401,
5163,
628,
7059,
33,
13,
13163,
13,
90,
16,
13,
25,
566,
2349,
272,
1449,
5587,
1006,
2222,
13,
6677,
503,
27964,
4110,
2344,
272,
327,
7754,
2793,
1133,
675,
314,
2050,
2656,
2348,
14,
710,
2050,
2656,
272,
327,
4839,
642,
1083,
12,
1808,
314,
2050,
2656,
2348,
3955,
272,
327,
13318,
3402,
282,
15032,
5936,
14,
6423,
25082,
440,
370,
1240,
1163,
272,
327,
3423,
626,
675,
314,
2050,
2656,
14,
272,
372,
295,
14,
954,
8,
3821,
12,
3350,
1045,
12,
1059,
9,
421,
199,
318,
4650,
8,
831,
354,
12,
4650,
2593,
29,
2259,
12,
295,
2373,
29,
797,
304,
272,
1449,
27200,
282,
2656,
13,
13062,
1640,
1412,
13914,
4650,
14,
3758,
2653,
365,
5212,
4696,
2344,
272,
2512,
14,
1757,
360,
6432,
543,
536,
26,
450,
83,
7,
450,
4650,
354,
9,
272,
862,
26,
267,
754,
275,
4650,
2531,
831,
354,
12,
4650,
2593,
12,
295,
2373,
9,
272,
871,
2186,
465,
325,
26,
267,
746,
15536,
1726,
8,
5216,
1726,
29,
69,
9,
272,
587,
26,
267,
340,
440,
754,
26,
288,
746,
15536,
6372,
1726,
8,
355,
1245,
628,
6612,
16919,
4650,
8978,
83,
8480,
450,
334,
831,
354,
430,
267,
587,
26,
288,
372,
754,
421,
199,
318,
4650,
2531,
831,
354,
12,
4650,
2593,
29,
2259,
12,
295,
2373,
29,
797,
304,
272,
1449,
27200,
282,
2656,
13,
13062,
1640,
1412,
13914,
4650,
14,
339,
28099,
8545,
370,
1335,
14,
6327,
14,
2319,
14,
831,
1325,
4440,
372,
1338,
370,
477,
4610,
4650,
272,
3182,
3140,
402,
17026,
14294,
2552,
14,
339,
961,
24200,
316,
1990,
27580,
4224,
370,
1852,
314,
4650,
4514,
14905,
272,
370,
4137,
13,
396,
14,
272,
1449,
272,
327,
3254,
961,
949,
8088,
4440,
4325,
8077,
641,
13074,
12,
10842,
31,
272,
3412,
2504,
3243,
275,
747,
14,
515,
14,
904,
8,
74,
14,
3220,
14,
2791,
3567,
12,
283,
20218,
358,
272,
4650,
493,
275,
747,
14,
515,
14,
904,
8,
4406,
3243,
12,
9058,
1558,
8,
831,
354,
430,
272,
340,
295,
2373,
26,
267,
485,
4406,
12511,
1075,
4392,
59,
831,
354,
61,
275,
485,
4406,
12511,
1075,
4392,
14,
5486,
8,
831,
354,
12,
378,
9,
435,
413,
339,
340,
440,
365,
9325,
8,
831,
354,
12,
295,
2373,
29,
264,
2373,
304,
267,
340,
440,
1335,
14,
6327,
14,
2319,
14,
2444,
8,
4406,
3243,
304,
288,
1335,
14,
6327,
14,
2319,
14,
981,
3567,
8,
4406,
3243,
9,
398,
1335,
14,
6327,
14,
2319,
14,
952,
1173,
8,
26204,
12,
620,
8,
736,
14,
17829,
4059,
267,
372,
715,
272,
587,
26,
267,
14233,
275,
756,
267,
367,
284,
315,
1425,
8,
831,
2593,
435,
413,
304,
288,
14233,
275,
365,
9325,
8,
831,
354,
12,
295,
2373,
9,
288,
340,
440,
14233,
26,
355,
2059,
288,
587,
26,
355,
900,
14,
4532,
8,
17,
9,
398,
340,
440,
14233,
26,
288,
372,
4650,
2531,
831,
354,
12,
4650,
2593,
12,
295,
2373,
9,
267,
587,
26,
288,
372,
756,
421,
199,
318,
365,
9325,
8,
831,
354,
12,
295,
2373,
29,
797,
304,
272,
1449,
1799,
340,
282,
2656,
13,
13062,
1640,
1412,
13914,
4650,
365,
663,
2344,
272,
365,
22408,
275,
715,
272,
3412,
2504,
3243,
275,
747,
14,
515,
14,
904,
8,
74,
14,
3220,
14,
2791,
3567,
12,
283,
20218,
358,
272,
4650,
493,
275,
747,
14,
515,
14,
904,
8,
4406,
3243,
12,
9058,
1558,
8,
831,
354,
430,
339,
862,
26,
267,
327,
1586,
314,
4422,
687,
314,
4650,
493,
267,
340,
1335,
14,
6327,
14,
2319,
14,
2444,
8,
26204,
304,
288,
4422,
275,
1551,
8,
26204,
12,
283,
4848,
1959,
739,
342,
267,
587,
26,
288,
372,
756,
339,
871,
334,
16719,
12,
5925,
9,
465,
325,
26,
267,
327,
3405,
370,
1586,
314,
4650,
493,
267,
340,
325,
14,
7931,
1137,
7554,
14,
20465,
26,
221,
327,
1919,
365,
440,
283,
493,
503,
2082,
440
] |
[
984,
199,
646,
747,
199,
646,
747,
14,
515,
199,
646,
8337,
199,
646,
295,
199,
646,
15951,
199,
646,
900,
199,
646,
5145,
199,
646,
7554,
199,
646,
5549,
199,
646,
6010,
199,
646,
5927,
465,
5927,
199,
646,
5672,
199,
504,
5672,
492,
4384,
63,
45,
4961,
199,
504,
6187,
7079,
26020,
492,
627,
421,
199,
3,
2136,
492,
1454,
14882,
3467,
465,
314,
1335,
14,
6327,
14,
2319,
365,
1202,
2544,
14882,
3467,
365,
199,
3,
10038,
14,
20227,
314,
1894,
3913,
506,
8439,
5966,
421,
199,
504,
1603,
1220,
9944,
492,
1335,
199,
3,
492,
1603,
1220,
9944,
14,
1095,
773,
14,
600,
2537,
327,
12434,
367,
2198,
2042,
199,
3,
687,
1318,
492,
4516,
199,
199,
475,
2848,
275,
1335,
14,
576,
14,
505,
14,
475,
2848,
199,
199,
3,
504,
1603,
1220,
9944,
14,
1018,
14,
11582,
492,
5906,
199,
199,
3,
2136,
886,
440,
675,
314,
1335,
14,
1018,
14,
3246,
466,
2348,
6590,
886,
781,
492,
314,
16078,
804,
465,
642,
3955,
199,
3,
12690,
370,
15032,
8925,
436,
746,
376,
1919,
199,
692,
440,
984,
14,
3246,
14,
2460,
360,
2676,
735,
272,
862,
26,
267,
492,
12871,
272,
871,
3545,
26,
267,
986,
199,
199,
63,
4406,
12511,
1075,
4392,
275,
1211,
342,
199,
199,
2921,
275,
1335,
14,
2921,
14,
362,
360,
74,
14,
6327,
14,
2319,
358,
421,
199,
533,
15536,
1726,
8,
1726,
304,
339,
347,
636,
826,
721,
277,
12,
1245,
534,
4276,
370,
664,
4650,
297,
6506,
1726,
29,
403,
304,
267,
340,
6506,
1726,
26,
288,
1245,
847,
1557,
78,
16467,
18104,
701,
3427,
78,
5,
83,
7,
450,
6506,
1726,
267,
2186,
855,
826,
721,
277,
12,
1245,
9,
267,
291,
14,
5216,
1726,
275,
6506,
1726,
421,
199,
533,
15536,
6372,
1726,
8,
6432,
1726,
304,
339,
347,
636,
826,
721,
277,
12,
1245,
534,
6432,
1056,
18590,
734,
297,
6506,
1726,
29,
403,
304,
267,
15536,
1726,
855,
826,
721,
277,
12,
1245,
12,
6506,
1726,
9,
421,
199,
533,
24873,
26,
272,
15536,
1726,
275,
15536,
1726,
272,
15536,
6372,
1726,
275,
15536,
6372,
1726,
421,
199,
318,
9058,
1558,
8,
875,
12,
3350,
1045,
19667,
401,
5163,
628,
7059,
33,
13,
13163,
13,
90,
16,
13,
25,
566,
2349,
272,
1449,
5587,
1006,
2222,
13,
6677,
503,
27964,
4110,
2344,
272,
327,
7754,
2793,
1133,
675,
314,
2050,
2656,
2348,
14,
710,
2050,
2656,
272,
327,
4839,
642,
1083,
12,
1808,
314,
2050,
2656,
2348,
3955,
272,
327,
13318,
3402,
282,
15032,
5936,
14,
6423,
25082,
440,
370,
1240,
1163,
272,
327,
3423,
626,
675,
314,
2050,
2656,
14,
272,
372,
295,
14,
954,
8,
3821,
12,
3350,
1045,
12,
1059,
9,
421,
199,
318,
4650,
8,
831,
354,
12,
4650,
2593,
29,
2259,
12,
295,
2373,
29,
797,
304,
272,
1449,
27200,
282,
2656,
13,
13062,
1640,
1412,
13914,
4650,
14,
3758,
2653,
365,
5212,
4696,
2344,
272,
2512,
14,
1757,
360,
6432,
543,
536,
26,
450,
83,
7,
450,
4650,
354,
9,
272,
862,
26,
267,
754,
275,
4650,
2531,
831,
354,
12,
4650,
2593,
12,
295,
2373,
9,
272,
871,
2186,
465,
325,
26,
267,
746,
15536,
1726,
8,
5216,
1726,
29,
69,
9,
272,
587,
26,
267,
340,
440,
754,
26,
288,
746,
15536,
6372,
1726,
8,
355,
1245,
628,
6612,
16919,
4650,
8978,
83,
8480,
450,
334,
831,
354,
430,
267,
587,
26,
288,
372,
754,
421,
199,
318,
4650,
2531,
831,
354,
12,
4650,
2593,
29,
2259,
12,
295,
2373,
29,
797,
304,
272,
1449,
27200,
282,
2656,
13,
13062,
1640,
1412,
13914,
4650,
14,
339,
28099,
8545,
370,
1335,
14,
6327,
14,
2319,
14,
831,
1325,
4440,
372,
1338,
370,
477,
4610,
4650,
272,
3182,
3140,
402,
17026,
14294,
2552,
14,
339,
961,
24200,
316,
1990,
27580,
4224,
370,
1852,
314,
4650,
4514,
14905,
272,
370,
4137,
13,
396,
14,
272,
1449,
272,
327,
3254,
961,
949,
8088,
4440,
4325,
8077,
641,
13074,
12,
10842,
31,
272,
3412,
2504,
3243,
275,
747,
14,
515,
14,
904,
8,
74,
14,
3220,
14,
2791,
3567,
12,
283,
20218,
358,
272,
4650,
493,
275,
747,
14,
515,
14,
904,
8,
4406,
3243,
12,
9058,
1558,
8,
831,
354,
430,
272,
340,
295,
2373,
26,
267,
485,
4406,
12511,
1075,
4392,
59,
831,
354,
61,
275,
485,
4406,
12511,
1075,
4392,
14,
5486,
8,
831,
354,
12,
378,
9,
435,
413,
339,
340,
440,
365,
9325,
8,
831,
354,
12,
295,
2373,
29,
264,
2373,
304,
267,
340,
440,
1335,
14,
6327,
14,
2319,
14,
2444,
8,
4406,
3243,
304,
288,
1335,
14,
6327,
14,
2319,
14,
981,
3567,
8,
4406,
3243,
9,
398,
1335,
14,
6327,
14,
2319,
14,
952,
1173,
8,
26204,
12,
620,
8,
736,
14,
17829,
4059,
267,
372,
715,
272,
587,
26,
267,
14233,
275,
756,
267,
367,
284,
315,
1425,
8,
831,
2593,
435,
413,
304,
288,
14233,
275,
365,
9325,
8,
831,
354,
12,
295,
2373,
9,
288,
340,
440,
14233,
26,
355,
2059,
288,
587,
26,
355,
900,
14,
4532,
8,
17,
9,
398,
340,
440,
14233,
26,
288,
372,
4650,
2531,
831,
354,
12,
4650,
2593,
12,
295,
2373,
9,
267,
587,
26,
288,
372,
756,
421,
199,
318,
365,
9325,
8,
831,
354,
12,
295,
2373,
29,
797,
304,
272,
1449,
1799,
340,
282,
2656,
13,
13062,
1640,
1412,
13914,
4650,
365,
663,
2344,
272,
365,
22408,
275,
715,
272,
3412,
2504,
3243,
275,
747,
14,
515,
14,
904,
8,
74,
14,
3220,
14,
2791,
3567,
12,
283,
20218,
358,
272,
4650,
493,
275,
747,
14,
515,
14,
904,
8,
4406,
3243,
12,
9058,
1558,
8,
831,
354,
430,
339,
862,
26,
267,
327,
1586,
314,
4422,
687,
314,
4650,
493,
267,
340,
1335,
14,
6327,
14,
2319,
14,
2444,
8,
26204,
304,
288,
4422,
275,
1551,
8,
26204,
12,
283,
4848,
1959,
739,
342,
267,
587,
26,
288,
372,
756,
339,
871,
334,
16719,
12,
5925,
9,
465,
325,
26,
267,
327,
3405,
370,
1586,
314,
4650,
493,
267,
340,
325,
14,
7931,
1137,
7554,
14,
20465,
26,
221,
327,
1919,
365,
440,
283,
493,
503,
2082,
440,
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,
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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
] |
franckverrot/live-note
|
waveapi/commandline_robot_runner_test.py
|
10
|
2549
|
#!/usr/bin/python2.4
#
# Copyright 2009 Google Inc. All Rights Reserved.
"""Tests for google3.walkabout.externalagents.api.commandline_robot_runner."""
__author__ = 'douwe@google.com (Douwe Osinga)'
import StringIO
from google3.pyglib import app
from google3.pyglib import flags
from google3.testing.pybase import googletest
from google3.walkabout.externalagents.api import commandline_robot_runner
from google3.walkabout.externalagents.api import events
FLAGS = flags.FLAGS
BLIP_JSON = ('{"wdykLROk*13":'
'{"lastModifiedTime":1242079608457,'
'"contributors":["someguy@test.com"],'
'"waveletId":"test.com!conv+root",'
'"waveId":"test.com!wdykLROk*11",'
'"parentBlipId":null,'
'"version":3,'
'"creator":"someguy@test.com",'
'"content":"\\nContent!",'
'"blipId":"wdykLROk*13",'
'"annotations":[{"range":{"start":0,"end":1},'
'"name":"user/e/otherguy@test.com","value":"Other"}],'
'"elements":{},'
'"childBlipIds":[]}'
'}')
WAVELET_JSON = ('{"lastModifiedTime":1242079611003,'
'"title":"A title",'
'"waveletId":"test.com!conv+root",'
'"rootBlipId":"wdykLROk*13",'
'"dataDocuments":null,'
'"creationTime":1242079608457,'
'"waveId":"test.com!wdykLROk*11",'
'"participants":["someguy@test.com","monty@appspot.com"],'
'"creator":"someguy@test.com",'
'"version":5}')
EVENTS_JSON = ('[{"timestamp":1242079611003,'
'"modifiedBy":"someguy@test.com",'
'"properties":{"participantsRemoved":[],'
'"participantsAdded":["monty@appspot.com"]},'
'"type":"WAVELET_PARTICIPANTS_CHANGED"}]')
TEST_JSON = '{"blips":%s,"wavelet":%s,"events":%s}' % (
BLIP_JSON, WAVELET_JSON, EVENTS_JSON)
class CommandlineRobotRunnerTest(googletest.TestCase):
def testSimpleFlow(self):
FLAGS.eventdef_wavelet_participants_changed = 'x'
flag = 'eventdef_' + events.WaveletParticipantsChanged.type.lower()
setattr(FLAGS, flag, 'w.title="New title!"')
input_stream = StringIO.StringIO(TEST_JSON)
output_stream = StringIO.StringIO()
commandline_robot_runner.run_bot(input_stream, output_stream)
res = output_stream.getvalue()
self.assertTrue('wavelet.setTitle' in res)
def main(unused_argv):
googletest.main()
if __name__ == '__main__':
app.run()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
18,
14,
20,
199,
3,
199,
3,
1898,
8937,
4475,
3277,
14,
2900,
5924,
5702,
14,
199,
199,
624,
2925,
367,
6233,
19,
14,
7757,
10254,
14,
5159,
14250,
14,
1246,
14,
1531,
604,
63,
9751,
63,
5933,
1041,
199,
199,
363,
2502,
363,
275,
283,
68,
810,
1129,
32,
3098,
14,
957,
334,
36,
810,
1129,
593,
1044,
65,
3171,
199,
199,
646,
5228,
199,
199,
504,
6233,
19,
14,
647,
30816,
492,
1145,
199,
504,
6233,
19,
14,
647,
30816,
492,
3285,
199,
199,
504,
6233,
19,
14,
4776,
14,
647,
1095,
492,
31141,
199,
504,
6233,
19,
14,
7757,
10254,
14,
5159,
14250,
14,
1246,
492,
28279,
63,
9751,
63,
5933,
199,
504,
6233,
19,
14,
7757,
10254,
14,
5159,
14250,
14,
1246,
492,
4474,
199,
199,
4831,
275,
3285,
14,
4831,
421,
199,
7847,
1772,
63,
6243,
275,
661,
6641,
2989,
89,
75,
44,
1092,
75,
10,
969,
582,
7,
1467,
17137,
2019,
11911,
1366,
582,
7214,
1165,
1965,
2259,
1349,
1641,
2584,
1467,
5522,
21630,
582,
905,
3972,
6051,
89,
32,
396,
14,
957,
2255,
7,
1467,
5522,
10024,
2723,
1304,
5122,
396,
14,
957,
1,
5598,
11,
1231,
21891,
1467,
5522,
10024,
1304,
5122,
396,
14,
957,
1,
2989,
89,
75,
44,
1092,
75,
10,
845,
21891,
1467,
5522,
1708,
34,
3587,
1304,
582,
2307,
2584,
1467,
5522,
1023,
582,
19,
2584,
1467,
5522,
9986,
5122,
3972,
6051,
89,
32,
396,
14,
957,
21891,
1467,
5522,
1317,
5122,
1103,
78,
2714,
17716,
7,
1467,
5522,
66,
3587,
1304,
5122,
2989,
89,
75,
44,
1092,
75,
10,
969,
21891,
1467,
5522,
11270,
19086,
6641,
1842,
18517,
928,
582,
16,
4589,
500,
582,
17,
1386,
7,
1467,
5522,
354,
5122,
751,
15,
69,
15,
1848,
6051,
89,
32,
396,
14,
957,
2266,
585,
5122,
8632,
3570,
26801,
1467,
5522,
5527,
582,
27125,
7,
1467,
5522,
1739,
34,
3587,
11506,
582,
8607,
6834,
1467,
283,
12216,
199,
199,
9004,
10429,
775,
63,
6243,
275,
661,
6641,
2019,
11911,
1366,
582,
7214,
1165,
21655,
845,
8262,
2584,
355,
5522,
1213,
5122,
33,
2538,
21891,
355,
5522,
10024,
2723,
1304,
5122,
396,
14,
957,
1,
5598,
11,
1231,
21891,
355,
5522,
1231,
34,
3587,
1304,
5122,
2989,
89,
75,
44,
1092,
75,
10,
969,
21891,
355,
5522,
576,
26872,
582,
2307,
2584,
355,
5522,
8782,
1366,
582,
7214,
1165,
1965,
2259,
1349,
1641,
2584,
355,
5522,
10024,
1304,
5122,
396,
14,
957,
1,
2989,
89,
75,
44,
1092,
75,
10,
845,
21891,
355,
5522,
31790,
582,
905,
3972,
6051,
89,
32,
396,
14,
957,
2266,
2106,
369,
32,
571,
15185,
14,
957,
2255,
7,
355,
5522,
9986,
5122,
3972,
6051,
89,
32,
396,
14,
957,
21891,
355,
5522,
1023,
582,
21,
12216,
199,
199,
8193,
51,
63,
6243,
275,
23734,
6641,
3954,
582,
7214,
1165,
21655,
845,
8262,
2584,
2049,
5522,
5540,
2175,
5122,
3972,
6051,
89,
32,
396,
14,
957,
21891,
2049,
5522,
3282,
18517,
31790,
23407,
19086,
26801,
2049,
5522,
31790,
20201,
582,
905,
2106,
369,
32,
571,
15185,
14,
957,
19057,
7,
2049,
5522,
466,
5122,
9004,
10429,
775,
63,
14848,
948,
1772,
1441,
51,
63,
21488,
3570,
10374,
199,
199,
2864,
63,
6243,
275,
17137,
66,
317,
1190,
582,
5,
83,
4589,
10024,
2723,
582,
5,
83,
4589,
4368,
582,
5,
83,
6834,
450,
334,
272,
15979,
1772,
63,
6243,
12,
644,
33,
10429,
775,
63,
6243,
12,
6461,
51,
63,
6243,
9,
421,
199,
533,
5817,
604,
21823,
7446,
774,
8,
3098,
396,
14,
1746,
304,
819,
347,
511,
3184,
5060,
8,
277,
304,
272,
12846,
14,
1430,
318,
63,
10024,
2723,
63,
31790,
63,
2489,
275,
283,
88,
7,
272,
3305,
275,
283,
1430,
318,
8650,
435,
4474,
14,
21393,
2723,
1262,
20989,
6970,
14,
466,
14,
2325,
342,
272,
5371,
8,
4831,
12,
3305,
12,
283,
87,
14,
1213,
628,
4665,
2538,
1,
9008,
272,
1324,
63,
1745,
275,
5228,
14,
6424,
8,
2864,
63,
6243,
9,
272,
1072,
63,
1745,
275,
5228,
14,
6424,
342,
272,
28279,
63,
9751,
63,
5933,
14,
1065,
63,
3018,
8,
1210,
63,
1745,
12,
1072,
63,
1745,
9,
272,
522,
275,
1072,
63,
1745,
14,
7150,
342,
272,
291,
14,
1815,
360,
10024,
2723,
14,
31675,
7,
315,
522,
9,
421,
199,
318,
2446,
8,
8618,
63,
3020,
304,
523,
31141,
14,
973,
342,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
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
] |
[
2647,
15,
1393,
15,
1548,
18,
14,
20,
199,
3,
199,
3,
1898,
8937,
4475,
3277,
14,
2900,
5924,
5702,
14,
199,
199,
624,
2925,
367,
6233,
19,
14,
7757,
10254,
14,
5159,
14250,
14,
1246,
14,
1531,
604,
63,
9751,
63,
5933,
1041,
199,
199,
363,
2502,
363,
275,
283,
68,
810,
1129,
32,
3098,
14,
957,
334,
36,
810,
1129,
593,
1044,
65,
3171,
199,
199,
646,
5228,
199,
199,
504,
6233,
19,
14,
647,
30816,
492,
1145,
199,
504,
6233,
19,
14,
647,
30816,
492,
3285,
199,
199,
504,
6233,
19,
14,
4776,
14,
647,
1095,
492,
31141,
199,
504,
6233,
19,
14,
7757,
10254,
14,
5159,
14250,
14,
1246,
492,
28279,
63,
9751,
63,
5933,
199,
504,
6233,
19,
14,
7757,
10254,
14,
5159,
14250,
14,
1246,
492,
4474,
199,
199,
4831,
275,
3285,
14,
4831,
421,
199,
7847,
1772,
63,
6243,
275,
661,
6641,
2989,
89,
75,
44,
1092,
75,
10,
969,
582,
7,
1467,
17137,
2019,
11911,
1366,
582,
7214,
1165,
1965,
2259,
1349,
1641,
2584,
1467,
5522,
21630,
582,
905,
3972,
6051,
89,
32,
396,
14,
957,
2255,
7,
1467,
5522,
10024,
2723,
1304,
5122,
396,
14,
957,
1,
5598,
11,
1231,
21891,
1467,
5522,
10024,
1304,
5122,
396,
14,
957,
1,
2989,
89,
75,
44,
1092,
75,
10,
845,
21891,
1467,
5522,
1708,
34,
3587,
1304,
582,
2307,
2584,
1467,
5522,
1023,
582,
19,
2584,
1467,
5522,
9986,
5122,
3972,
6051,
89,
32,
396,
14,
957,
21891,
1467,
5522,
1317,
5122,
1103,
78,
2714,
17716,
7,
1467,
5522,
66,
3587,
1304,
5122,
2989,
89,
75,
44,
1092,
75,
10,
969,
21891,
1467,
5522,
11270,
19086,
6641,
1842,
18517,
928,
582,
16,
4589,
500,
582,
17,
1386,
7,
1467,
5522,
354,
5122,
751,
15,
69,
15,
1848,
6051,
89,
32,
396,
14,
957,
2266,
585,
5122,
8632,
3570,
26801,
1467,
5522,
5527,
582,
27125,
7,
1467,
5522,
1739,
34,
3587,
11506,
582,
8607,
6834,
1467,
283,
12216,
199,
199,
9004,
10429,
775,
63,
6243,
275,
661,
6641,
2019,
11911,
1366,
582,
7214,
1165,
21655,
845,
8262,
2584,
355,
5522,
1213,
5122,
33,
2538,
21891,
355,
5522,
10024,
2723,
1304,
5122,
396,
14,
957,
1,
5598,
11,
1231,
21891,
355,
5522,
1231,
34,
3587,
1304,
5122,
2989,
89,
75,
44,
1092,
75,
10,
969,
21891,
355,
5522,
576,
26872,
582,
2307,
2584,
355,
5522,
8782,
1366,
582,
7214,
1165,
1965,
2259,
1349,
1641,
2584,
355,
5522,
10024,
1304,
5122,
396,
14,
957,
1,
2989,
89,
75,
44,
1092,
75,
10,
845,
21891,
355,
5522,
31790,
582,
905,
3972,
6051,
89,
32,
396,
14,
957,
2266,
2106,
369,
32,
571,
15185,
14,
957,
2255,
7,
355,
5522,
9986,
5122,
3972,
6051,
89,
32,
396,
14,
957,
21891,
355,
5522,
1023,
582,
21,
12216,
199,
199,
8193,
51,
63,
6243,
275,
23734,
6641,
3954,
582,
7214,
1165,
21655,
845,
8262,
2584,
2049,
5522,
5540,
2175,
5122,
3972,
6051,
89,
32,
396,
14,
957,
21891,
2049,
5522,
3282,
18517,
31790,
23407,
19086,
26801,
2049,
5522,
31790,
20201,
582,
905,
2106,
369,
32,
571,
15185,
14,
957,
19057,
7,
2049,
5522,
466,
5122,
9004,
10429,
775,
63,
14848,
948,
1772,
1441,
51,
63,
21488,
3570,
10374,
199,
199,
2864,
63,
6243,
275,
17137,
66,
317,
1190,
582,
5,
83,
4589,
10024,
2723,
582,
5,
83,
4589,
4368,
582,
5,
83,
6834,
450,
334,
272,
15979,
1772,
63,
6243,
12,
644,
33,
10429,
775,
63,
6243,
12,
6461,
51,
63,
6243,
9,
421,
199,
533,
5817,
604,
21823,
7446,
774,
8,
3098,
396,
14,
1746,
304,
819,
347,
511,
3184,
5060,
8,
277,
304,
272,
12846,
14,
1430,
318,
63,
10024,
2723,
63,
31790,
63,
2489,
275,
283,
88,
7,
272,
3305,
275,
283,
1430,
318,
8650,
435,
4474,
14,
21393,
2723,
1262,
20989,
6970,
14,
466,
14,
2325,
342,
272,
5371,
8,
4831,
12,
3305,
12,
283,
87,
14,
1213,
628,
4665,
2538,
1,
9008,
272,
1324,
63,
1745,
275,
5228,
14,
6424,
8,
2864,
63,
6243,
9,
272,
1072,
63,
1745,
275,
5228,
14,
6424,
342,
272,
28279,
63,
9751,
63,
5933,
14,
1065,
63,
3018,
8,
1210,
63,
1745,
12,
1072,
63,
1745,
9,
272,
522,
275,
1072,
63,
1745,
14,
7150,
342,
272,
291,
14,
1815,
360,
10024,
2723,
14,
31675,
7,
315,
522,
9,
421,
199,
318,
2446,
8,
8618,
63,
3020,
304,
523,
31141,
14,
973,
342,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
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,
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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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
SVilgelm/CloudFerry
|
cloudferry/actions/compute/get_info_instances.py
|
1
|
1047
|
# Copyright (c) 2014 Mirantis 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.
from cloudferry.lib.base.action import action
from cloudferry.lib.utils import utils
class GetInfoInstances(action.Action):
def run(self, **kwargs):
search_opts = {'search_opts': kwargs.get('search_opts', {})}
search_opts.update(kwargs.get('search_opts_tenant', {}))
compute_resource = self.cloud.resources[utils.COMPUTE_RESOURCE]
info = compute_resource.read_info(**search_opts)
return {
'info': info
}
|
apache-2.0
|
[
3,
1898,
334,
67,
9,
6927,
603,
723,
4466,
83,
3277,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
844,
2736,
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,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
4319,
2281,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
199,
3,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
3,
199,
3,
4204,
1334,
314,
844,
14,
421,
199,
504,
8002,
2412,
651,
14,
773,
14,
1095,
14,
1287,
492,
1595,
199,
504,
8002,
2412,
651,
14,
773,
14,
1208,
492,
3778,
421,
199,
533,
2372,
2354,
18194,
8,
1287,
14,
3310,
304,
339,
347,
1255,
8,
277,
12,
1011,
958,
304,
267,
2754,
63,
3291,
275,
791,
1733,
63,
3291,
356,
2074,
14,
362,
360,
1733,
63,
3291,
297,
5009,
93,
267,
2754,
63,
3291,
14,
873,
8,
958,
14,
362,
360,
1733,
63,
3291,
63,
4647,
297,
17003,
267,
4526,
63,
1927,
275,
291,
14,
4091,
14,
4435,
59,
1208,
14,
6790,
4586,
63,
14110,
61,
267,
2256,
275,
4526,
63,
1927,
14,
739,
63,
815,
3682,
1733,
63,
3291,
9,
267,
372,
469,
288,
283,
815,
356,
2256,
267,
789,
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
] |
[
1898,
334,
67,
9,
6927,
603,
723,
4466,
83,
3277,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
844,
2736,
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,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
4319,
2281,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
199,
3,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
3,
199,
3,
4204,
1334,
314,
844,
14,
421,
199,
504,
8002,
2412,
651,
14,
773,
14,
1095,
14,
1287,
492,
1595,
199,
504,
8002,
2412,
651,
14,
773,
14,
1208,
492,
3778,
421,
199,
533,
2372,
2354,
18194,
8,
1287,
14,
3310,
304,
339,
347,
1255,
8,
277,
12,
1011,
958,
304,
267,
2754,
63,
3291,
275,
791,
1733,
63,
3291,
356,
2074,
14,
362,
360,
1733,
63,
3291,
297,
5009,
93,
267,
2754,
63,
3291,
14,
873,
8,
958,
14,
362,
360,
1733,
63,
3291,
63,
4647,
297,
17003,
267,
4526,
63,
1927,
275,
291,
14,
4091,
14,
4435,
59,
1208,
14,
6790,
4586,
63,
14110,
61,
267,
2256,
275,
4526,
63,
1927,
14,
739,
63,
815,
3682,
1733,
63,
3291,
9,
267,
372,
469,
288,
283,
815,
356,
2256,
267,
789,
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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
danny200309/anaconda
|
anaconda_lib/autopep/autopep8_lib/lib2to3/pgen2/parse.py
|
569
|
8053
|
# Copyright 2004-2005 Elemental Security, Inc. All Rights Reserved.
# Licensed to PSF under a Contributor Agreement.
"""Parser engine for the grammar tables generated by pgen.
The grammar table must be loaded first.
See Parser/parser.c in the Python distribution for additional info on
how this parsing engine works.
"""
# Local imports
from . import token
class ParseError(Exception):
"""Exception to signal the parser is stuck."""
def __init__(self, msg, type, value, context):
Exception.__init__(self, "%s: type=%r, value=%r, context=%r" %
(msg, type, value, context))
self.msg = msg
self.type = type
self.value = value
self.context = context
class Parser(object):
"""Parser engine.
The proper usage sequence is:
p = Parser(grammar, [converter]) # create instance
p.setup([start]) # prepare for parsing
<for each input token>:
if p.addtoken(...): # parse a token; may raise ParseError
break
root = p.rootnode # root of abstract syntax tree
A Parser instance may be reused by calling setup() repeatedly.
A Parser instance contains state pertaining to the current token
sequence, and should not be used concurrently by different threads
to parse separate token sequences.
See driver.py for how to get input tokens by tokenizing a file or
string.
Parsing is complete when addtoken() returns True; the root of the
abstract syntax tree can then be retrieved from the rootnode
instance variable. When a syntax error occurs, addtoken() raises
the ParseError exception. There is no error recovery; the parser
cannot be used after a syntax error was reported (but it can be
reinitialized by calling setup()).
"""
def __init__(self, grammar, convert=None):
"""Constructor.
The grammar argument is a grammar.Grammar instance; see the
grammar module for more information.
The parser is not ready yet for parsing; you must call the
setup() method to get it started.
The optional convert argument is a function mapping concrete
syntax tree nodes to abstract syntax tree nodes. If not
given, no conversion is done and the syntax tree produced is
the concrete syntax tree. If given, it must be a function of
two arguments, the first being the grammar (a grammar.Grammar
instance), and the second being the concrete syntax tree node
to be converted. The syntax tree is converted from the bottom
up.
A concrete syntax tree node is a (type, value, context, nodes)
tuple, where type is the node type (a token or symbol number),
value is None for symbols and a string for tokens, context is
None or an opaque value used for error reporting (typically a
(lineno, offset) pair), and nodes is a list of children for
symbols, and None for tokens.
An abstract syntax tree node may be anything; this is entirely
up to the converter function.
"""
self.grammar = grammar
self.convert = convert or (lambda grammar, node: node)
def setup(self, start=None):
"""Prepare for parsing.
This *must* be called before starting to parse.
The optional argument is an alternative start symbol; it
defaults to the grammar's start symbol.
You can use a Parser instance to parse any number of programs;
each time you call setup() the parser is reset to an initial
state determined by the (implicit or explicit) start symbol.
"""
if start is None:
start = self.grammar.start
# Each stack entry is a tuple: (dfa, state, node).
# A node is a tuple: (type, value, context, children),
# where children is a list of nodes or None, and context may be None.
newnode = (start, None, None, [])
stackentry = (self.grammar.dfas[start], 0, newnode)
self.stack = [stackentry]
self.rootnode = None
self.used_names = set() # Aliased to self.rootnode.used_names in pop()
def addtoken(self, type, value, context):
"""Add a token; return True iff this is the end of the program."""
# Map from token to label
ilabel = self.classify(type, value, context)
# Loop until the token is shifted; may raise exceptions
while True:
dfa, state, node = self.stack[-1]
states, first = dfa
arcs = states[state]
# Look for a state with this label
for i, newstate in arcs:
t, v = self.grammar.labels[i]
if ilabel == i:
# Look it up in the list of labels
assert t < 256
# Shift a token; we're done with it
self.shift(type, value, newstate, context)
# Pop while we are in an accept-only state
state = newstate
while states[state] == [(0, state)]:
self.pop()
if not self.stack:
# Done parsing!
return True
dfa, state, node = self.stack[-1]
states, first = dfa
# Done with this token
return False
elif t >= 256:
# See if it's a symbol and if we're in its first set
itsdfa = self.grammar.dfas[t]
itsstates, itsfirst = itsdfa
if ilabel in itsfirst:
# Push a symbol
self.push(t, self.grammar.dfas[t], newstate, context)
break # To continue the outer while loop
else:
if (0, state) in arcs:
# An accepting state, pop it and try something else
self.pop()
if not self.stack:
# Done parsing, but another token is input
raise ParseError("too much input",
type, value, context)
else:
# No success finding a transition
raise ParseError("bad input", type, value, context)
def classify(self, type, value, context):
"""Turn a token into a label. (Internal)"""
if type == token.NAME:
# Keep a listing of all used names
self.used_names.add(value)
# Check for reserved words
ilabel = self.grammar.keywords.get(value)
if ilabel is not None:
return ilabel
ilabel = self.grammar.tokens.get(type)
if ilabel is None:
raise ParseError("bad token", type, value, context)
return ilabel
def shift(self, type, value, newstate, context):
"""Shift a token. (Internal)"""
dfa, state, node = self.stack[-1]
newnode = (type, value, context, None)
newnode = self.convert(self.grammar, newnode)
if newnode is not None:
node[-1].append(newnode)
self.stack[-1] = (dfa, newstate, node)
def push(self, type, newdfa, newstate, context):
"""Push a nonterminal. (Internal)"""
dfa, state, node = self.stack[-1]
newnode = (type, None, context, [])
self.stack[-1] = (dfa, newstate, node)
self.stack.append((newdfa, 0, newnode))
def pop(self):
"""Pop a nonterminal. (Internal)"""
popdfa, popstate, popnode = self.stack.pop()
newnode = self.convert(self.grammar, popnode)
if newnode is not None:
if self.stack:
dfa, state, node = self.stack[-1]
node[-1].append(newnode)
else:
self.rootnode = newnode
self.rootnode.used_names = self.used_names
|
gpl-3.0
|
[
3,
1898,
8353,
13,
9397,
6566,
279,
13863,
12,
3277,
14,
2900,
5924,
5702,
14,
199,
3,
3909,
370,
29770,
1334,
282,
17636,
28629,
14,
199,
199,
624,
2842,
6869,
367,
314,
12528,
6716,
4046,
701,
299,
2268,
14,
199,
199,
1918,
12528,
1817,
1471,
506,
6511,
1642,
14,
199,
199,
9295,
10191,
15,
2087,
14,
67,
315,
314,
2018,
4084,
367,
4722,
2256,
641,
199,
1917,
642,
6057,
6869,
5419,
14,
199,
199,
624,
199,
199,
3,
10111,
8925,
199,
504,
1275,
492,
1526,
199,
199,
533,
21743,
8,
1726,
304,
272,
408,
1726,
370,
4673,
314,
1798,
365,
410,
10112,
1041,
339,
347,
636,
826,
721,
277,
12,
1499,
12,
730,
12,
574,
12,
1067,
304,
267,
2186,
855,
826,
721,
277,
12,
2071,
83,
26,
730,
2458,
82,
12,
574,
2458,
82,
12,
1067,
2458,
82,
2,
450,
2574,
334,
1328,
12,
730,
12,
574,
12,
1067,
430,
267,
291,
14,
1328,
275,
1499,
267,
291,
14,
466,
275,
730,
267,
291,
14,
585,
275,
574,
267,
291,
14,
1100,
275,
1067,
199,
199,
533,
10191,
8,
785,
304,
272,
408,
2842,
6869,
14,
339,
710,
5576,
4503,
3414,
365,
26,
339,
299,
275,
10191,
8,
15239,
12,
359,
11256,
566,
221,
327,
1218,
1256,
272,
299,
14,
2758,
779,
928,
566,
8295,
327,
9275,
367,
6057,
272,
665,
509,
1924,
1324,
1526,
20020,
267,
340,
299,
14,
525,
1418,
29195,
304,
3698,
327,
2198,
282,
1526,
27,
1443,
746,
21743,
288,
2059,
272,
1738,
275,
299,
14,
1231,
932,
463,
327,
1738,
402,
9006,
6302,
3123,
339,
437,
10191,
1256,
1443,
506,
24826,
701,
6358,
3272,
342,
27714,
14,
339,
437,
10191,
1256,
3509,
1174,
1126,
24522,
370,
314,
1453,
1526,
272,
3414,
12,
436,
1077,
440,
506,
1202,
406,
19767,
701,
3365,
7183,
272,
370,
2198,
7396,
1526,
8013,
14,
339,
1666,
5253,
14,
647,
367,
4212,
370,
664,
1324,
4645,
701,
1526,
9147,
282,
570,
503,
272,
1059,
14,
339,
28747,
365,
4890,
1380,
1050,
1418,
342,
2529,
715,
27,
314,
1738,
402,
314,
272,
9006,
6302,
3123,
883,
2066,
506,
12396,
687,
314,
1738,
932,
272,
1256,
1750,
14,
221,
3979,
282,
6302,
1125,
11058,
12,
1050,
1418,
342,
6534,
272,
314,
21743,
1919,
14,
221,
6006,
365,
949,
1125,
24201,
27,
314,
1798,
272,
3913,
506,
1202,
2410,
282,
6302,
1125,
1990,
14581,
334,
7911,
652,
883,
506,
272,
295,
12486,
701,
6358,
3272,
8801,
339,
408,
339,
347,
636,
826,
721,
277,
12,
12528,
12,
3957,
29,
403,
304,
267,
408,
11447,
14,
398,
710,
12528,
1423,
365,
282,
12528,
14,
27119,
1256,
27,
1937,
314,
267,
12528,
859,
367,
1655,
2556,
14,
398,
710,
1798,
365,
440,
10144,
5966,
367,
6057,
27,
1265,
1471,
1240,
314,
267,
3272,
342,
1083,
370,
664,
652,
8239,
14,
398,
710,
2716,
3957,
1423,
365,
282,
805,
4412,
13801,
267,
6302,
3123,
3380,
370,
9006,
6302,
3123,
3380,
14,
221,
982,
440,
267,
1627,
12,
949,
8603,
365,
4224,
436,
314,
6302,
3123,
13584,
365,
267,
314,
13801,
6302,
3123,
14,
221,
982,
1627,
12,
652,
1471,
506,
282,
805,
402,
267,
2877,
2368,
12,
314,
1642,
3769,
314,
12528,
334,
65,
12528,
14,
27119,
267,
1256,
395,
436,
314,
3499,
3769,
314,
13801,
6302,
3123,
1031,
267,
370,
506,
6702,
14,
221,
710,
6302,
3123,
365,
6702,
687,
314,
9048,
267,
1536,
14,
398,
437,
13801,
6302,
3123,
1031,
365,
282,
334,
466,
12,
574,
12,
1067,
12,
3380,
9,
267,
2008,
12,
2382,
730,
365,
314,
1031,
730,
334,
65,
1526,
503,
5272,
1329,
395,
267,
574,
365,
488,
367,
6698,
436,
282,
1059,
367,
4645,
12,
1067,
365,
267,
488,
503,
376,
15058,
574,
1202,
367,
1125,
17290,
334,
32251,
282,
267,
334,
3469,
12,
3268,
9,
4092,
395,
436,
3380,
365,
282,
769,
402,
4978,
367,
267,
6698,
12,
436,
488,
367,
4645,
14,
398,
1626,
9006,
6302,
3123,
1031,
1443,
506,
7003,
27,
642,
365,
21926,
267,
1536,
370,
314,
11109,
805,
14,
398,
408,
267,
291,
14,
15239,
275,
12528,
267,
291,
14,
3916,
275,
3957,
503,
334,
2734,
12528,
12,
1031,
26,
1031,
9,
339,
347,
3272,
8,
277,
12,
1343,
29,
403,
304,
267,
408,
22281,
367,
6057,
14,
398,
961,
627,
7790,
10,
506,
2797,
2544,
6617,
370,
2198,
14,
398,
710,
2716,
1423,
365,
376,
13943,
1343,
5272,
27,
652,
267,
4243,
370,
314,
12528,
1159,
1343,
5272,
14,
398,
2047,
883,
675,
282,
10191,
1256,
370,
2198,
1263,
1329,
402,
18572,
27,
267,
1924,
900,
1265,
1240,
3272,
342,
314,
1798,
365,
5305,
370,
376,
2536,
267,
1174,
12037,
701,
314,
334,
11886,
503,
5027,
9,
1343,
5272,
14,
398,
408,
267,
340,
1343,
365,
488,
26,
288,
1343,
275,
291,
14,
15239,
14,
928,
267,
327,
7048,
3464,
2397,
365,
282,
2008,
26,
334,
26520,
12,
1174,
12,
1031,
680,
267,
327,
437,
1031,
365,
282,
2008,
26,
334,
466,
12,
574,
12,
1067,
12,
4978,
395,
267,
327,
2382,
4978,
365,
282,
769,
402,
3380,
503,
488,
12,
436,
1067,
1443,
506,
488,
14,
267,
23584,
275,
334,
928,
12,
488,
12,
488,
12,
3073,
267,
3464,
2373,
275,
334,
277,
14,
15239,
14,
1587,
305,
59,
928,
467,
378,
12,
23584,
9,
267,
291,
14,
2340,
275,
359,
2340,
2373,
61,
267,
291,
14,
1231,
932,
275,
488,
267,
291,
14,
2972,
63,
1247,
275,
663,
342,
327,
15170,
11185,
370,
291,
14,
1231,
932,
14,
2972,
63,
1247,
315,
4560,
342,
339,
347,
1050,
1418,
8,
277,
12,
730,
12,
574,
12,
1067,
304,
267,
408,
1123,
282,
1526,
27,
372,
715,
17963,
642,
365,
314,
1284,
402,
314,
2240,
1041,
267,
327,
9672,
687,
1526,
370,
1768,
267,
284,
1302,
275,
291,
14,
12334,
1399,
8,
466,
12,
574,
12,
1067,
9,
267,
327,
18175,
5133,
314,
1526,
365,
31915,
27,
1443,
746,
4967,
267,
1830,
715,
26,
288,
366,
667,
12,
1174,
12,
1031,
275,
291,
14,
2340,
1988,
17,
61,
288,
6363,
12,
1642,
275,
366,
667,
288,
601,
1259,
275,
6363,
59,
929,
61,
288,
327,
12077,
367,
282,
1174,
543,
642,
1768,
288,
367,
284,
12,
892,
929
] |
[
1898,
8353,
13,
9397,
6566,
279,
13863,
12,
3277,
14,
2900,
5924,
5702,
14,
199,
3,
3909,
370,
29770,
1334,
282,
17636,
28629,
14,
199,
199,
624,
2842,
6869,
367,
314,
12528,
6716,
4046,
701,
299,
2268,
14,
199,
199,
1918,
12528,
1817,
1471,
506,
6511,
1642,
14,
199,
199,
9295,
10191,
15,
2087,
14,
67,
315,
314,
2018,
4084,
367,
4722,
2256,
641,
199,
1917,
642,
6057,
6869,
5419,
14,
199,
199,
624,
199,
199,
3,
10111,
8925,
199,
504,
1275,
492,
1526,
199,
199,
533,
21743,
8,
1726,
304,
272,
408,
1726,
370,
4673,
314,
1798,
365,
410,
10112,
1041,
339,
347,
636,
826,
721,
277,
12,
1499,
12,
730,
12,
574,
12,
1067,
304,
267,
2186,
855,
826,
721,
277,
12,
2071,
83,
26,
730,
2458,
82,
12,
574,
2458,
82,
12,
1067,
2458,
82,
2,
450,
2574,
334,
1328,
12,
730,
12,
574,
12,
1067,
430,
267,
291,
14,
1328,
275,
1499,
267,
291,
14,
466,
275,
730,
267,
291,
14,
585,
275,
574,
267,
291,
14,
1100,
275,
1067,
199,
199,
533,
10191,
8,
785,
304,
272,
408,
2842,
6869,
14,
339,
710,
5576,
4503,
3414,
365,
26,
339,
299,
275,
10191,
8,
15239,
12,
359,
11256,
566,
221,
327,
1218,
1256,
272,
299,
14,
2758,
779,
928,
566,
8295,
327,
9275,
367,
6057,
272,
665,
509,
1924,
1324,
1526,
20020,
267,
340,
299,
14,
525,
1418,
29195,
304,
3698,
327,
2198,
282,
1526,
27,
1443,
746,
21743,
288,
2059,
272,
1738,
275,
299,
14,
1231,
932,
463,
327,
1738,
402,
9006,
6302,
3123,
339,
437,
10191,
1256,
1443,
506,
24826,
701,
6358,
3272,
342,
27714,
14,
339,
437,
10191,
1256,
3509,
1174,
1126,
24522,
370,
314,
1453,
1526,
272,
3414,
12,
436,
1077,
440,
506,
1202,
406,
19767,
701,
3365,
7183,
272,
370,
2198,
7396,
1526,
8013,
14,
339,
1666,
5253,
14,
647,
367,
4212,
370,
664,
1324,
4645,
701,
1526,
9147,
282,
570,
503,
272,
1059,
14,
339,
28747,
365,
4890,
1380,
1050,
1418,
342,
2529,
715,
27,
314,
1738,
402,
314,
272,
9006,
6302,
3123,
883,
2066,
506,
12396,
687,
314,
1738,
932,
272,
1256,
1750,
14,
221,
3979,
282,
6302,
1125,
11058,
12,
1050,
1418,
342,
6534,
272,
314,
21743,
1919,
14,
221,
6006,
365,
949,
1125,
24201,
27,
314,
1798,
272,
3913,
506,
1202,
2410,
282,
6302,
1125,
1990,
14581,
334,
7911,
652,
883,
506,
272,
295,
12486,
701,
6358,
3272,
8801,
339,
408,
339,
347,
636,
826,
721,
277,
12,
12528,
12,
3957,
29,
403,
304,
267,
408,
11447,
14,
398,
710,
12528,
1423,
365,
282,
12528,
14,
27119,
1256,
27,
1937,
314,
267,
12528,
859,
367,
1655,
2556,
14,
398,
710,
1798,
365,
440,
10144,
5966,
367,
6057,
27,
1265,
1471,
1240,
314,
267,
3272,
342,
1083,
370,
664,
652,
8239,
14,
398,
710,
2716,
3957,
1423,
365,
282,
805,
4412,
13801,
267,
6302,
3123,
3380,
370,
9006,
6302,
3123,
3380,
14,
221,
982,
440,
267,
1627,
12,
949,
8603,
365,
4224,
436,
314,
6302,
3123,
13584,
365,
267,
314,
13801,
6302,
3123,
14,
221,
982,
1627,
12,
652,
1471,
506,
282,
805,
402,
267,
2877,
2368,
12,
314,
1642,
3769,
314,
12528,
334,
65,
12528,
14,
27119,
267,
1256,
395,
436,
314,
3499,
3769,
314,
13801,
6302,
3123,
1031,
267,
370,
506,
6702,
14,
221,
710,
6302,
3123,
365,
6702,
687,
314,
9048,
267,
1536,
14,
398,
437,
13801,
6302,
3123,
1031,
365,
282,
334,
466,
12,
574,
12,
1067,
12,
3380,
9,
267,
2008,
12,
2382,
730,
365,
314,
1031,
730,
334,
65,
1526,
503,
5272,
1329,
395,
267,
574,
365,
488,
367,
6698,
436,
282,
1059,
367,
4645,
12,
1067,
365,
267,
488,
503,
376,
15058,
574,
1202,
367,
1125,
17290,
334,
32251,
282,
267,
334,
3469,
12,
3268,
9,
4092,
395,
436,
3380,
365,
282,
769,
402,
4978,
367,
267,
6698,
12,
436,
488,
367,
4645,
14,
398,
1626,
9006,
6302,
3123,
1031,
1443,
506,
7003,
27,
642,
365,
21926,
267,
1536,
370,
314,
11109,
805,
14,
398,
408,
267,
291,
14,
15239,
275,
12528,
267,
291,
14,
3916,
275,
3957,
503,
334,
2734,
12528,
12,
1031,
26,
1031,
9,
339,
347,
3272,
8,
277,
12,
1343,
29,
403,
304,
267,
408,
22281,
367,
6057,
14,
398,
961,
627,
7790,
10,
506,
2797,
2544,
6617,
370,
2198,
14,
398,
710,
2716,
1423,
365,
376,
13943,
1343,
5272,
27,
652,
267,
4243,
370,
314,
12528,
1159,
1343,
5272,
14,
398,
2047,
883,
675,
282,
10191,
1256,
370,
2198,
1263,
1329,
402,
18572,
27,
267,
1924,
900,
1265,
1240,
3272,
342,
314,
1798,
365,
5305,
370,
376,
2536,
267,
1174,
12037,
701,
314,
334,
11886,
503,
5027,
9,
1343,
5272,
14,
398,
408,
267,
340,
1343,
365,
488,
26,
288,
1343,
275,
291,
14,
15239,
14,
928,
267,
327,
7048,
3464,
2397,
365,
282,
2008,
26,
334,
26520,
12,
1174,
12,
1031,
680,
267,
327,
437,
1031,
365,
282,
2008,
26,
334,
466,
12,
574,
12,
1067,
12,
4978,
395,
267,
327,
2382,
4978,
365,
282,
769,
402,
3380,
503,
488,
12,
436,
1067,
1443,
506,
488,
14,
267,
23584,
275,
334,
928,
12,
488,
12,
488,
12,
3073,
267,
3464,
2373,
275,
334,
277,
14,
15239,
14,
1587,
305,
59,
928,
467,
378,
12,
23584,
9,
267,
291,
14,
2340,
275,
359,
2340,
2373,
61,
267,
291,
14,
1231,
932,
275,
488,
267,
291,
14,
2972,
63,
1247,
275,
663,
342,
327,
15170,
11185,
370,
291,
14,
1231,
932,
14,
2972,
63,
1247,
315,
4560,
342,
339,
347,
1050,
1418,
8,
277,
12,
730,
12,
574,
12,
1067,
304,
267,
408,
1123,
282,
1526,
27,
372,
715,
17963,
642,
365,
314,
1284,
402,
314,
2240,
1041,
267,
327,
9672,
687,
1526,
370,
1768,
267,
284,
1302,
275,
291,
14,
12334,
1399,
8,
466,
12,
574,
12,
1067,
9,
267,
327,
18175,
5133,
314,
1526,
365,
31915,
27,
1443,
746,
4967,
267,
1830,
715,
26,
288,
366,
667,
12,
1174,
12,
1031,
275,
291,
14,
2340,
1988,
17,
61,
288,
6363,
12,
1642,
275,
366,
667,
288,
601,
1259,
275,
6363,
59,
929,
61,
288,
327,
12077,
367,
282,
1174,
543,
642,
1768,
288,
367,
284,
12,
892,
929,
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,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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
] |
vegeclic/django-regularcom
|
carts/migrations/0043_auto__del_field_carriertranslation_name__del_field_carriertranslation_.py
|
1
|
27698
|
# -*- coding: utf-8 -*-
from south.utils import datetime_utils as datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
class Migration(SchemaMigration):
def forwards(self, orm):
db.rename_column('carts_carrier_translation', 'name', 'old_name')
db.rename_column('carts_carrier_translation', 'body', 'old_body')
def backwards(self, orm):
db.rename_column('carts_carrier_translation', 'old_name', 'name')
db.rename_column('carts_carrier_translation', 'old_body', 'body')
models = {
'accounts.account': {
'Meta': {'object_name': 'Account'},
'date_created': ('django.db.models.fields.DateTimeField', [], {'blank': 'True', 'auto_now_add': 'True'}),
'date_last_modified': ('django.db.models.fields.DateTimeField', [], {'blank': 'True', 'auto_now': 'True'}),
'email': ('django.db.models.fields.EmailField', [], {'db_index': 'True', 'unique': 'True', 'max_length': '255'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
'is_admin': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'password': ('django.db.models.fields.CharField', [], {'max_length': '128'})
},
'accounts.author': {
'Meta': {'object_name': 'Author'},
'account': ('django.db.models.fields.related.OneToOneField', [], {'unique': 'True', 'to': "orm['accounts.Account']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'main_image': ('django.db.models.fields.related.OneToOneField', [], {'blank': 'True', 'null': 'True', 'related_name': "'+'", 'unique': 'True', 'to': "orm['common.Image']"}),
'name': ('django.db.models.fields.CharField', [], {'blank': 'True', 'max_length': '30'})
},
'carts.carrier': {
'Meta': {'object_name': 'Carrier'},
'apply_suppliers_fee': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
'enabled': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'weight_min': ('django.db.models.fields.FloatField', [], {'default': '0'})
},
'carts.carrierlevel': {
'Meta': {'object_name': 'CarrierLevel', 'unique_together': "(('carrier', 'weight', 'currency'),)"},
'carrier': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['carts.Carrier']"}),
'currency': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'cart_carrier_level_price_currency'", 'to': "orm['common.Currency']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'price': ('django.db.models.fields.FloatField', [], {}),
'weight': ('django.db.models.fields.FloatField', [], {})
},
'carts.carriertranslation': {
'Meta': {'object_name': 'CarrierTranslation', 'db_table': "'carts_carrier_translation'", 'unique_together': "[('language_code', 'master')]"},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'language_code': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '15'}),
'master': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'translations'", 'null': 'True', 'to': "orm['carts.Carrier']"}),
'old_body': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'old_name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '100'})
},
'carts.content': {
'Meta': {'object_name': 'Content', 'unique_together': "(('delivery', 'product'),)"},
'customized': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'delivery': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['carts.Delivery']"}),
'extent': ('django.db.models.fields.PositiveSmallIntegerField', [], {'default': '0'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'product': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['products.Product']"})
},
'carts.contentproduct': {
'Meta': {'object_name': 'ContentProduct', 'unique_together': "(('content', 'product'),)"},
'content': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['carts.Content']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'product': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['suppliers.Product']"}),
'quantity': ('django.db.models.fields.PositiveIntegerField', [], {'default': '1'})
},
'carts.delivery': {
'Meta': {'object_name': 'Delivery'},
'date': ('django.db.models.fields.CharField', [], {'max_length': '7'}),
'date_created': ('django.db.models.fields.DateTimeField', [], {'blank': 'True', 'auto_now_add': 'True'}),
'date_last_modified': ('django.db.models.fields.DateTimeField', [], {'blank': 'True', 'auto_now': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'payed_price': ('django.db.models.fields.FloatField', [], {'blank': 'True', 'null': 'True'}),
'status': ('django.db.models.fields.CharField', [], {'max_length': '1', 'default': "'w'"}),
'subscription': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['carts.Subscription']"})
},
'carts.extent': {
'Meta': {'object_name': 'Extent', 'unique_together': "(('subscription', 'product'),)"},
'customized': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'extent': ('django.db.models.fields.PositiveSmallIntegerField', [], {}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'product': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['products.Product']"}),
'subscription': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['carts.Subscription']"})
},
'carts.extentcontent': {
'Meta': {'object_name': 'ExtentContent'},
'extent': ('django.db.models.fields.related.ForeignKey', [], {'unique': 'True', 'to': "orm['carts.Extent']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
},
'carts.extentcontentproduct': {
'Meta': {'object_name': 'ExtentContentProduct', 'unique_together': "(('content', 'product'),)"},
'content': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['carts.ExtentContent']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'product': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['suppliers.Product']"}),
'quantity': ('django.db.models.fields.PositiveIntegerField', [], {'default': '1'})
},
'carts.price': {
'Meta': {'object_name': 'Price', 'unique_together': "(('size', 'currency'),)"},
'currency': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'cart_size_price_currency'", 'to': "orm['common.Currency']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'price': ('django.db.models.fields.FloatField', [], {}),
'size': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['carts.Size']"})
},
'carts.size': {
'Meta': {'object_name': 'Size'},
'body': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'body_de': ('django.db.models.fields.TextField', [], {'blank': 'True', 'null': 'True'}),
'body_fr': ('django.db.models.fields.TextField', [], {'blank': 'True', 'null': 'True'}),
'enabled': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'main_image': ('django.db.models.fields.related.OneToOneField', [], {'blank': 'True', 'null': 'True', 'related_name': "'+'", 'unique': 'True', 'to': "orm['common.Image']"}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'name_de': ('django.db.models.fields.CharField', [], {'blank': 'True', 'max_length': '100', 'null': 'True'}),
'name_fr': ('django.db.models.fields.CharField', [], {'blank': 'True', 'max_length': '100', 'null': 'True'}),
'weight': ('django.db.models.fields.FloatField', [], {})
},
'carts.subscription': {
'Meta': {'object_name': 'Subscription'},
'carrier': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['carts.Carrier']"}),
'comment': ('django.db.models.fields.TextField', [], {'blank': 'True', 'null': 'True'}),
'criterias': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'cart_subscription_criterias'", 'null': 'True', 'symmetrical': 'False', 'to': "orm['common.Criteria']"}),
'customer': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['customers.Customer']"}),
'date_created': ('django.db.models.fields.DateTimeField', [], {'blank': 'True', 'auto_now_add': 'True'}),
'date_last_modified': ('django.db.models.fields.DateTimeField', [], {'blank': 'True', 'auto_now': 'True'}),
'direct_debit': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
'enabled': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
'end': ('django.db.models.fields.CharField', [], {'max_length': '7'}),
'frequency': ('django.db.models.fields.PositiveIntegerField', [], {'max_length': '2', 'default': '2'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'quantity': ('django.db.models.fields.PositiveIntegerField', [], {'default': '1'}),
'receive_only_once': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'size': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['carts.Size']"}),
'start': ('django.db.models.fields.CharField', [], {'max_length': '7'})
},
'carts.thematic': {
'Meta': {'object_name': 'Thematic'},
'body': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'body_de': ('django.db.models.fields.TextField', [], {'blank': 'True', 'null': 'True'}),
'body_fr': ('django.db.models.fields.TextField', [], {'blank': 'True', 'null': 'True'}),
'carrier': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'null': 'True', 'to': "orm['carts.Carrier']"}),
'criterias': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'thematic_criterias'", 'null': 'True', 'symmetrical': 'False', 'to': "orm['common.Criteria']"}),
'date_created': ('django.db.models.fields.DateTimeField', [], {'blank': 'True', 'auto_now_add': 'True'}),
'date_last_modified': ('django.db.models.fields.DateTimeField', [], {'blank': 'True', 'auto_now': 'True'}),
'enabled': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'end_duration': ('django.db.models.fields.CharField', [], {'blank': 'True', 'max_length': '7', 'null': 'True'}),
'end_period': ('django.db.models.fields.CharField', [], {'blank': 'True', 'max_length': '7', 'null': 'True'}),
'frequency': ('django.db.models.fields.PositiveIntegerField', [], {'blank': 'True', 'max_length': '2', 'null': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'locked_carrier': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'locked_criterias': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'locked_duration': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'locked_frequency': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'locked_products': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'locked_quantity': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'locked_receive_only_once': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'locked_size': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'locked_start': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'main_image': ('django.db.models.fields.related.OneToOneField', [], {'blank': 'True', 'null': 'True', 'related_name': "'+'", 'unique': 'True', 'to': "orm['common.Image']"}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'name_de': ('django.db.models.fields.CharField', [], {'blank': 'True', 'max_length': '100', 'null': 'True'}),
'name_fr': ('django.db.models.fields.CharField', [], {'blank': 'True', 'max_length': '100', 'null': 'True'}),
'quantity': ('django.db.models.fields.PositiveIntegerField', [], {'default': '1'}),
'receive_only_once': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'size': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'null': 'True', 'to': "orm['carts.Size']"}),
'start_duration': ('django.db.models.fields.CharField', [], {'blank': 'True', 'max_length': '7', 'null': 'True'}),
'start_period': ('django.db.models.fields.CharField', [], {'blank': 'True', 'max_length': '10', 'null': 'True'})
},
'carts.thematicextent': {
'Meta': {'object_name': 'ThematicExtent', 'unique_together': "(('thematic', 'product'),)"},
'extent': ('django.db.models.fields.PositiveSmallIntegerField', [], {}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'product': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['products.Product']"}),
'thematic': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['carts.Thematic']"})
},
'common.address': {
'Meta': {'object_name': 'Address'},
'city': ('django.db.models.fields.CharField', [], {'blank': 'True', 'max_length': '100'}),
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'+'", 'to': "orm['contenttypes.ContentType']"}),
'country': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'null': 'True', 'to': "orm['common.Country']"}),
'email': ('django.db.models.fields.EmailField', [], {'blank': 'True', 'max_length': '75'}),
'first_name': ('django.db.models.fields.CharField', [], {'blank': 'True', 'max_length': '30'}),
'gender': ('django.db.models.fields.CharField', [], {'blank': 'True', 'max_length': '1'}),
'home_phone': ('django.db.models.fields.CharField', [], {'blank': 'True', 'max_length': '100'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'last_name': ('django.db.models.fields.CharField', [], {'blank': 'True', 'max_length': '30'}),
'mobile_phone': ('django.db.models.fields.CharField', [], {'blank': 'True', 'max_length': '100'}),
'object_id': ('django.db.models.fields.PositiveIntegerField', [], {}),
'postal_code': ('django.db.models.fields.CharField', [], {'blank': 'True', 'max_length': '100'}),
'street': ('django.db.models.fields.CharField', [], {'blank': 'True', 'max_length': '100'})
},
'common.country': {
'Meta': {'object_name': 'Country'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
},
'common.criteria': {
'Meta': {'object_name': 'Criteria'},
'enabled': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
},
'common.currency': {
'Meta': {'object_name': 'Currency'},
'exchange_rate': ('django.db.models.fields.FloatField', [], {'default': '1'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'unique': 'True', 'max_length': '30'}),
'symbol': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
},
'common.image': {
'Meta': {'object_name': 'Image'},
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'+'", 'to': "orm['contenttypes.ContentType']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'image': ('django.db.models.fields.files.ImageField', [], {'max_length': '200'}),
'object_id': ('django.db.models.fields.PositiveIntegerField', [], {})
},
'contenttypes.contenttype': {
'Meta': {'object_name': 'ContentType', 'db_table': "'django_content_type'", 'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)"},
'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
},
'customers.customer': {
'Meta': {'object_name': 'Customer'},
'account': ('django.db.models.fields.related.OneToOneField', [], {'unique': 'True', 'to': "orm['accounts.Account']"}),
'billing_address': ('django.db.models.fields.related.OneToOneField', [], {'blank': 'True', 'null': 'True', 'related_name': "'+'", 'unique': 'True', 'to': "orm['common.Address']"}),
'date_created': ('django.db.models.fields.DateTimeField', [], {'blank': 'True', 'auto_now_add': 'True'}),
'date_last_modified': ('django.db.models.fields.DateTimeField', [], {'blank': 'True', 'auto_now': 'True'}),
'date_of_birth': ('django.db.models.fields.DateField', [], {'blank': 'True', 'null': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'main_address': ('django.db.models.fields.related.OneToOneField', [], {'blank': 'True', 'null': 'True', 'related_name': "'+'", 'unique': 'True', 'to': "orm['common.Address']"}),
'main_image': ('django.db.models.fields.related.OneToOneField', [], {'blank': 'True', 'null': 'True', 'related_name': "'+'", 'unique': 'True', 'to': "orm['common.Image']"}),
'pro': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'relay_address': ('django.db.models.fields.related.OneToOneField', [], {'blank': 'True', 'null': 'True', 'related_name': "'+'", 'unique': 'True', 'to': "orm['common.Address']"}),
'shipping_address': ('django.db.models.fields.related.OneToOneField', [], {'blank': 'True', 'null': 'True', 'related_name': "'+'", 'unique': 'True', 'to': "orm['common.Address']"})
},
'products.category': {
'Meta': {'object_name': 'Category'},
'authors': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'symmetrical': 'False', 'null': 'True', 'to': "orm['accounts.Author']"}),
'categories': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'categories_rel_+'", 'null': 'True', 'to': "orm['products.Category']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'main_image': ('django.db.models.fields.related.OneToOneField', [], {'blank': 'True', 'null': 'True', 'related_name': "'+'", 'unique': 'True', 'to': "orm['common.Image']"}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'name_de': ('django.db.models.fields.CharField', [], {'blank': 'True', 'max_length': '100', 'null': 'True'}),
'name_fr': ('django.db.models.fields.CharField', [], {'blank': 'True', 'max_length': '100', 'null': 'True'}),
'slug': ('django.db.models.fields.SlugField', [], {'blank': 'True', 'max_length': '50', 'null': 'True'})
},
'products.product': {
'Meta': {'object_name': 'Product'},
'body': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'body_de': ('django.db.models.fields.TextField', [], {'blank': 'True', 'null': 'True'}),
'body_fr': ('django.db.models.fields.TextField', [], {'blank': 'True', 'null': 'True'}),
'categories': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'+'", 'null': 'True', 'symmetrical': 'False', 'to': "orm['products.Category']"}),
'date_created': ('django.db.models.fields.DateTimeField', [], {'blank': 'True', 'auto_now_add': 'True'}),
'date_last_modified': ('django.db.models.fields.DateTimeField', [], {'blank': 'True', 'auto_now': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'main_image': ('django.db.models.fields.related.OneToOneField', [], {'blank': 'True', 'null': 'True', 'related_name': "'+'", 'unique': 'True', 'to': "orm['common.Image']"}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'name_de': ('django.db.models.fields.CharField', [], {'blank': 'True', 'max_length': '100', 'null': 'True'}),
'name_fr': ('django.db.models.fields.CharField', [], {'blank': 'True', 'max_length': '100', 'null': 'True'}),
'products_parent': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'products_children'", 'null': 'True', 'symmetrical': 'False', 'to': "orm['products.Product']"}),
'slug': ('django.db.models.fields.SlugField', [], {'blank': 'True', 'max_length': '50', 'null': 'True'}),
'slug_de': ('django.db.models.fields.SlugField', [], {'blank': 'True', 'max_length': '50', 'null': 'True'}),
'slug_fr': ('django.db.models.fields.SlugField', [], {'blank': 'True', 'max_length': '50', 'null': 'True'}),
'status': ('django.db.models.fields.CharField', [], {'max_length': '1', 'default': "'d'"})
},
'products.taggeditem': {
'Meta': {'object_name': 'TaggedItem'},
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'object_id': ('django.db.models.fields.PositiveIntegerField', [], {}),
'tag': ('django.db.models.fields.SlugField', [], {'max_length': '50'})
},
'suppliers.product': {
'Meta': {'object_name': 'Product'},
'body': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'body_de': ('django.db.models.fields.TextField', [], {'blank': 'True', 'null': 'True'}),
'body_fr': ('django.db.models.fields.TextField', [], {'blank': 'True', 'null': 'True'}),
'criterias': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'product_criterias'", 'null': 'True', 'symmetrical': 'False', 'to': "orm['common.Criteria']"}),
'date_created': ('django.db.models.fields.DateTimeField', [], {'blank': 'True', 'auto_now_add': 'True'}),
'date_last_modified': ('django.db.models.fields.DateTimeField', [], {'blank': 'True', 'auto_now': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'ingredients': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'ingredients_de': ('django.db.models.fields.TextField', [], {'blank': 'True', 'null': 'True'}),
'ingredients_fr': ('django.db.models.fields.TextField', [], {'blank': 'True', 'null': 'True'}),
'main_image': ('django.db.models.fields.related.OneToOneField', [], {'blank': 'True', 'null': 'True', 'related_name': "'+'", 'unique': 'True', 'to': "orm['common.Image']"}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'name_de': ('django.db.models.fields.CharField', [], {'blank': 'True', 'max_length': '100', 'null': 'True'}),
'name_fr': ('django.db.models.fields.CharField', [], {'blank': 'True', 'max_length': '100', 'null': 'True'}),
'product': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'product_product'", 'to': "orm['products.Product']"}),
'sku': ('django.db.models.fields.CharField', [], {'blank': 'True', 'max_length': '100'}),
'slug': ('django.db.models.fields.SlugField', [], {'blank': 'True', 'max_length': '100', 'null': 'True'}),
'slug_de': ('django.db.models.fields.SlugField', [], {'blank': 'True', 'max_length': '100', 'null': 'True'}),
'slug_fr': ('django.db.models.fields.SlugField', [], {'blank': 'True', 'max_length': '100', 'null': 'True'}),
'status': ('django.db.models.fields.CharField', [], {'max_length': '1', 'default': "'d'"}),
'suppliers': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'product_suppliers'", 'null': 'True', 'symmetrical': 'False', 'to': "orm['suppliers.Supplier']"}),
'weight': ('django.db.models.fields.FloatField', [], {'blank': 'True', 'null': 'True'})
},
'suppliers.supplier': {
'Meta': {'object_name': 'Supplier'},
'delivery_delay': ('django.db.models.fields.PositiveIntegerField', [], {'blank': 'True', 'null': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'main_image': ('django.db.models.fields.related.OneToOneField', [], {'blank': 'True', 'null': 'True', 'related_name': "'+'", 'unique': 'True', 'to': "orm['common.Image']"}),
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '100'}),
'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '50'}),
'suppliers': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'suppliers_rel_+'", 'null': 'True', 'to': "orm['suppliers.Supplier']"}),
'threshold_order': ('django.db.models.fields.PositiveIntegerField', [], {'blank': 'True', 'null': 'True'})
}
}
complete_apps = ['carts']
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
12919,
14,
1208,
492,
2197,
63,
1208,
465,
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,
1592,
14,
8165,
63,
2301,
360,
8153,
83,
63,
24499,
63,
6893,
297,
283,
354,
297,
283,
1753,
63,
354,
358,
267,
1592,
14,
8165,
63,
2301,
360,
8153,
83,
63,
24499,
63,
6893,
297,
283,
2030,
297,
283,
1753,
63,
2030,
358,
339,
347,
8552,
8,
277,
12,
9813,
304,
267,
1592,
14,
8165,
63,
2301,
360,
8153,
83,
63,
24499,
63,
6893,
297,
283,
1753,
63,
354,
297,
283,
354,
358,
267,
1592,
14,
8165,
63,
2301,
360,
8153,
83,
63,
24499,
63,
6893,
297,
283,
1753,
63,
2030,
297,
283,
2030,
358,
339,
1709,
275,
469,
267,
283,
8370,
14,
2048,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
6009,
2267,
288,
283,
602,
63,
3966,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
791,
2500,
356,
283,
549,
297,
283,
2495,
63,
2131,
63,
525,
356,
283,
549,
1604,
288,
283,
602,
63,
2019,
63,
5540,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
791,
2500,
356,
283,
549,
297,
283,
2495,
63,
2131,
356,
283,
549,
1604,
288,
283,
2123,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
16577,
297,
990,
791,
697,
63,
1080,
356,
283,
549,
297,
283,
3235,
356,
283,
549,
297,
283,
988,
63,
1267,
356,
283,
2299,
1604,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
374,
63,
2682,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
549,
1604,
288,
283,
374,
63,
2113,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
797,
1604,
288,
283,
2019,
63,
2886,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
791,
885,
356,
283,
2083,
14,
2083,
14,
2131,
1604,
288,
283,
2060,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
3933,
3071,
267,
1660,
267,
283,
8370,
14,
2502,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
5949,
2267,
288,
283,
2048,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
14298,
297,
990,
791,
3235,
356,
283,
549,
297,
283,
475,
356,
298,
1025,
459,
8370,
14,
6009,
6097,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
973,
63,
1569,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
14298,
297,
990,
791,
2500,
356,
283,
549,
297,
283,
2307,
356,
283,
549,
297,
283,
2407,
63,
354,
356,
3546,
11,
4662,
283,
3235,
356,
283,
549,
297,
283,
475,
356,
298,
1025,
459,
2330,
14,
3491,
6097,
288,
283,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
2500,
356,
283,
549,
297,
283,
988,
63,
1267,
356,
283,
1216,
3071,
267,
1660,
267,
283,
8153,
83,
14,
24499,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
16034,
10742,
2267,
288,
283,
4998,
63,
8621,
14035,
63,
11195,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
549,
1604,
288,
283,
3827,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
549,
1604,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
3463,
63,
827,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
13019,
297,
990,
791,
885,
356,
283,
16,
3071,
267,
1660,
267,
283,
8153,
83,
14,
24499,
1896,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
16034,
10742,
4670,
297,
283,
3235,
63,
6314,
356,
9510,
24499,
297,
283,
3463,
297,
283,
4968,
659,
2924,
1386,
288,
283,
24499,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
475,
356,
298,
1025,
459,
8153,
83,
14,
16034,
10742,
6097,
288,
283,
4968,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
2407,
63,
354,
356,
3546,
8153,
63,
24499,
63,
1896,
63,
4777,
63,
4968,
4662,
283,
475,
356,
298,
1025,
459,
2330,
14,
19567,
6097,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
4777,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
13019,
297,
990,
8613,
288,
283,
3463,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
13019,
297,
990,
5009,
267,
1660,
267,
283,
8153,
83,
14,
24499,
6893,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
16034,
10742,
18483,
297,
283,
697,
63,
1224,
356,
3546,
8153,
83,
63,
24499,
63,
6893,
4662,
283,
3235,
63,
6314,
356,
7369,
360,
3671,
63,
600,
297,
283,
4133,
5440,
6018,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
3671,
63,
600,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
697,
63,
1080,
356,
283,
549,
297,
283,
988,
63,
1267,
356,
283,
1046,
1604,
288,
283,
4133,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
2407,
63,
354,
356,
3546,
13982,
4662,
283,
2307,
356,
283,
549,
297,
283,
475,
356,
298,
1025,
459,
8153,
83,
14,
16034,
10742,
6097,
288,
283,
1753,
63,
2030,
356
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
12919,
14,
1208,
492,
2197,
63,
1208,
465,
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,
1592,
14,
8165,
63,
2301,
360,
8153,
83,
63,
24499,
63,
6893,
297,
283,
354,
297,
283,
1753,
63,
354,
358,
267,
1592,
14,
8165,
63,
2301,
360,
8153,
83,
63,
24499,
63,
6893,
297,
283,
2030,
297,
283,
1753,
63,
2030,
358,
339,
347,
8552,
8,
277,
12,
9813,
304,
267,
1592,
14,
8165,
63,
2301,
360,
8153,
83,
63,
24499,
63,
6893,
297,
283,
1753,
63,
354,
297,
283,
354,
358,
267,
1592,
14,
8165,
63,
2301,
360,
8153,
83,
63,
24499,
63,
6893,
297,
283,
1753,
63,
2030,
297,
283,
2030,
358,
339,
1709,
275,
469,
267,
283,
8370,
14,
2048,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
6009,
2267,
288,
283,
602,
63,
3966,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
791,
2500,
356,
283,
549,
297,
283,
2495,
63,
2131,
63,
525,
356,
283,
549,
1604,
288,
283,
602,
63,
2019,
63,
5540,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
791,
2500,
356,
283,
549,
297,
283,
2495,
63,
2131,
356,
283,
549,
1604,
288,
283,
2123,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
16577,
297,
990,
791,
697,
63,
1080,
356,
283,
549,
297,
283,
3235,
356,
283,
549,
297,
283,
988,
63,
1267,
356,
283,
2299,
1604,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
374,
63,
2682,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
549,
1604,
288,
283,
374,
63,
2113,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
797,
1604,
288,
283,
2019,
63,
2886,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
791,
885,
356,
283,
2083,
14,
2083,
14,
2131,
1604,
288,
283,
2060,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
3933,
3071,
267,
1660,
267,
283,
8370,
14,
2502,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
5949,
2267,
288,
283,
2048,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
14298,
297,
990,
791,
3235,
356,
283,
549,
297,
283,
475,
356,
298,
1025,
459,
8370,
14,
6009,
6097,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
973,
63,
1569,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
14298,
297,
990,
791,
2500,
356,
283,
549,
297,
283,
2307,
356,
283,
549,
297,
283,
2407,
63,
354,
356,
3546,
11,
4662,
283,
3235,
356,
283,
549,
297,
283,
475,
356,
298,
1025,
459,
2330,
14,
3491,
6097,
288,
283,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
2500,
356,
283,
549,
297,
283,
988,
63,
1267,
356,
283,
1216,
3071,
267,
1660,
267,
283,
8153,
83,
14,
24499,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
16034,
10742,
2267,
288,
283,
4998,
63,
8621,
14035,
63,
11195,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
549,
1604,
288,
283,
3827,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
549,
1604,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
3463,
63,
827,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
13019,
297,
990,
791,
885,
356,
283,
16,
3071,
267,
1660,
267,
283,
8153,
83,
14,
24499,
1896,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
16034,
10742,
4670,
297,
283,
3235,
63,
6314,
356,
9510,
24499,
297,
283,
3463,
297,
283,
4968,
659,
2924,
1386,
288,
283,
24499,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
475,
356,
298,
1025,
459,
8153,
83,
14,
16034,
10742,
6097,
288,
283,
4968,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
2407,
63,
354,
356,
3546,
8153,
63,
24499,
63,
1896,
63,
4777,
63,
4968,
4662,
283,
475,
356,
298,
1025,
459,
2330,
14,
19567,
6097,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
4777,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
13019,
297,
990,
8613,
288,
283,
3463,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
13019,
297,
990,
5009,
267,
1660,
267,
283,
8153,
83,
14,
24499,
6893,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
16034,
10742,
18483,
297,
283,
697,
63,
1224,
356,
3546,
8153,
83,
63,
24499,
63,
6893,
4662,
283,
3235,
63,
6314,
356,
7369,
360,
3671,
63,
600,
297,
283,
4133,
5440,
6018,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
3671,
63,
600,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
697,
63,
1080,
356,
283,
549,
297,
283,
988,
63,
1267,
356,
283,
1046,
1604,
288,
283,
4133,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
2407,
63,
354,
356,
3546,
13982,
4662,
283,
2307,
356,
283,
549,
297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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
] |
whuaegeanse/mapnik
|
scons/scons-local-2.3.6/SCons/Tool/MSCommon/common.py
|
4
|
9199
|
#
# Copyright (c) 2001 - 2015 The SCons Foundation
#
# 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,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following 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 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 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.
#
__revision__ = "src/engine/SCons/Tool/MSCommon/common.py rel_2.3.5:3347:d31d5a4e74b6 2015/07/31 14:36:10 bdbaddog"
__doc__ = """
Common helper functions for working with the Microsoft tool chain.
"""
import copy
import os
import subprocess
import re
import SCons.Util
logfile = os.environ.get('SCONS_MSCOMMON_DEBUG')
if logfile == '-':
def debug(x):
print x
elif logfile:
try:
import logging
except ImportError:
debug = lambda x: open(logfile, 'a').write(x + '\n')
else:
logging.basicConfig(filename=logfile, level=logging.DEBUG)
debug = logging.debug
else:
debug = lambda x: None
_is_win64 = None
def is_win64():
"""Return true if running on windows 64 bits.
Works whether python itself runs in 64 bits or 32 bits."""
# Unfortunately, python does not provide a useful way to determine
# if the underlying Windows OS is 32-bit or 64-bit. Worse, whether
# the Python itself is 32-bit or 64-bit affects what it returns,
# so nothing in sys.* or os.* help.
# Apparently the best solution is to use env vars that Windows
# sets. If PROCESSOR_ARCHITECTURE is not x86, then the python
# process is running in 64 bit mode (on a 64-bit OS, 64-bit
# hardware, obviously).
# If this python is 32-bit but the OS is 64, Windows will set
# ProgramW6432 and PROCESSOR_ARCHITEW6432 to non-null.
# (Checking for HKLM\Software\Wow6432Node in the registry doesn't
# work, because some 32-bit installers create it.)
global _is_win64
if _is_win64 is None:
# I structured these tests to make it easy to add new ones or
# add exceptions in the future, because this is a bit fragile.
_is_win64 = False
if os.environ.get('PROCESSOR_ARCHITECTURE','x86') != 'x86':
_is_win64 = True
if os.environ.get('PROCESSOR_ARCHITEW6432'):
_is_win64 = True
if os.environ.get('ProgramW6432'):
_is_win64 = True
return _is_win64
def read_reg(value):
return SCons.Util.RegGetValue(SCons.Util.HKEY_LOCAL_MACHINE, value)[0]
def has_reg(value):
"""Return True if the given key exists in HKEY_LOCAL_MACHINE, False
otherwise."""
try:
SCons.Util.RegOpenKeyEx(SCons.Util.HKEY_LOCAL_MACHINE, value)
ret = True
except WindowsError:
ret = False
return ret
# Functions for fetching environment variable settings from batch files.
def normalize_env(env, keys, force=False):
"""Given a dictionary representing a shell environment, add the variables
from os.environ needed for the processing of .bat files; the keys are
controlled by the keys argument.
It also makes sure the environment values are correctly encoded.
If force=True, then all of the key values that exist are copied
into the returned dictionary. If force=false, values are only
copied if the key does not already exist in the copied dictionary.
Note: the environment is copied."""
normenv = {}
if env:
for k in env.keys():
normenv[k] = copy.deepcopy(env[k]).encode('mbcs')
for k in keys:
if k in os.environ and (force or not k in normenv):
normenv[k] = os.environ[k].encode('mbcs')
# This shouldn't be necessary, since the default environment should include system32,
# but keep this here to be safe, since it's needed to find reg.exe which the MSVC
# bat scripts use.
sys32_dir = os.path.join(os.environ.get("SystemRoot", os.environ.get("windir",r"C:\Windows\system32")),"System32")
if sys32_dir not in normenv['PATH']:
normenv['PATH'] = normenv['PATH'] + os.pathsep + sys32_dir
debug("PATH: %s"%normenv['PATH'])
return normenv
def get_output(vcbat, args = None, env = None):
"""Parse the output of given bat file, with given args."""
if env is None:
# Create a blank environment, for use in launching the tools
env = SCons.Environment.Environment(tools=[])
# TODO: This is a hard-coded list of the variables that (may) need
# to be imported from os.environ[] for v[sc]*vars*.bat file
# execution to work. This list should really be either directly
# controlled by vc.py, or else derived from the common_tools_var
# settings in vs.py.
vars = [
'COMSPEC',
# VS100 and VS110: Still set, but modern MSVC setup scripts will
# discard these if registry has values. However Intel compiler setup
# script still requires these as of 2013/2014.
'VS110COMNTOOLS',
'VS100COMNTOOLS',
'VS90COMNTOOLS',
'VS80COMNTOOLS',
'VS71COMNTOOLS',
'VS70COMNTOOLS',
'VS60COMNTOOLS',
]
env['ENV'] = normalize_env(env['ENV'], vars, force=False)
if args:
debug("Calling '%s %s'" % (vcbat, args))
popen = SCons.Action._subproc(env,
'"%s" %s & set' % (vcbat, args),
stdin = 'devnull',
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
else:
debug("Calling '%s'" % vcbat)
popen = SCons.Action._subproc(env,
'"%s" & set' % vcbat,
stdin = 'devnull',
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
# Use the .stdout and .stderr attributes directly because the
# .communicate() method uses the threading module on Windows
# and won't work under Pythons not built with threading.
stdout = popen.stdout.read()
stderr = popen.stderr.read()
# Extra debug logic, uncomment if necessar
# debug('get_output():stdout:%s'%stdout)
# debug('get_output():stderr:%s'%stderr)
if stderr:
# TODO: find something better to do with stderr;
# this at least prevents errors from getting swallowed.
import sys
sys.stderr.write(stderr)
if popen.wait() != 0:
raise IOError(stderr.decode("mbcs"))
output = stdout.decode("mbcs")
return output
def parse_output(output, keep = ("INCLUDE", "LIB", "LIBPATH", "PATH")):
# dkeep is a dict associating key: path_list, where key is one item from
# keep, and pat_list the associated list of paths
dkeep = dict([(i, []) for i in keep])
# rdk will keep the regex to match the .bat file output line starts
rdk = {}
for i in keep:
rdk[i] = re.compile('%s=(.*)' % i, re.I)
def add_env(rmatch, key, dkeep=dkeep):
plist = rmatch.group(1).split(os.pathsep)
for p in plist:
# Do not add empty paths (when a var ends with ;)
if p:
p = p.encode('mbcs')
# XXX: For some reason, VC98 .bat file adds "" around the PATH
# values, and it screws up the environment later, so we strip
# it.
p = p.strip('"')
dkeep[key].append(p)
for line in output.splitlines():
for k,v in rdk.items():
m = v.match(line)
if m:
add_env(m, k)
return dkeep
# TODO(sgk): unused
def output_to_dict(output):
"""Given an output string, parse it to find env variables.
Return a dict where keys are variables names, and values their content"""
envlinem = re.compile(r'^([a-zA-z0-9]+)=([\S\s]*)$')
parsedenv = {}
for line in output.splitlines():
m = envlinem.match(line)
if m:
parsedenv[m.group(1)] = m.group(2)
return parsedenv
# TODO(sgk): unused
def get_new(l1, l2):
"""Given two list l1 and l2, return the items in l2 which are not in l1.
Order is maintained."""
# We don't try to be smart: lists are small, and this is not the bottleneck
# is any case
new = []
for i in l2:
if i not in l1:
new.append(i)
return new
# Local Variables:
# tab-width:4
# indent-tabs-mode:nil
# End:
# vim: set expandtab tabstop=4 shiftwidth=4:
|
lgpl-2.1
|
[
3,
199,
3,
1898,
334,
67,
9,
12521,
446,
6900,
710,
8218,
2752,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
199,
3,
282,
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,
199,
3,
11207,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
199,
3,
11291,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
199,
3,
314,
2569,
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,
199,
3,
3826,
12,
7168,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
199,
3,
2990,
1634,
3169,
12,
3092,
2381,
437,
3115,
3104,
2401,
199,
3,
13229,
14,
1621,
4825,
6461,
7000,
2334,
10610,
1549,
5877,
8164,
6262,
199,
3,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
7061,
1621,
1261,
9612,
199,
3,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
5738,
1634,
1549,
1621,
11287,
199,
3,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
4141,
14,
199,
3,
199,
199,
363,
5792,
363,
275,
298,
2164,
15,
3908,
15,
18521,
15,
5157,
15,
3053,
7844,
15,
2330,
14,
647,
4668,
63,
18,
14,
19,
14,
21,
26,
8425,
23,
26,
68,
2192,
68,
21,
65,
20,
69,
1342,
66,
22,
6900,
15,
1780,
15,
2192,
4329,
26,
1344,
26,
709,
330,
697,
525,
974,
2,
199,
199,
363,
1301,
363,
275,
408,
199,
7844,
5922,
3423,
367,
6449,
543,
314,
15332,
4744,
6036,
14,
199,
624,
199,
199,
646,
1331,
199,
646,
747,
199,
646,
3873,
199,
646,
295,
199,
199,
646,
8218,
14,
9562,
421,
199,
12804,
275,
747,
14,
2314,
14,
362,
360,
51,
1864,
51,
63,
3053,
21637,
63,
5287,
358,
199,
692,
17251,
508,
20905,
272,
347,
3105,
8,
88,
304,
267,
870,
671,
199,
4164,
17251,
26,
272,
862,
26,
267,
492,
2050,
272,
871,
3545,
26,
267,
3105,
275,
2400,
671,
26,
1551,
8,
12804,
12,
283,
65,
1959,
952,
8,
88,
435,
1557,
78,
358,
272,
587,
26,
267,
2050,
14,
19602,
8,
1501,
29,
12804,
12,
2166,
29,
4806,
14,
5287,
9,
267,
3105,
275,
2050,
14,
1757,
199,
2836,
26,
272,
3105,
275,
2400,
671,
26,
488,
421,
199,
63,
374,
63,
2676,
772,
275,
488,
199,
199,
318,
365,
63,
2676,
772,
837,
272,
408,
1767,
2549,
340,
3879,
641,
10061,
5049,
5821,
14,
339,
28099,
3775,
2366,
6337,
7858,
315,
5049,
5821,
503,
4337,
5821,
1041,
272,
327,
31076,
12,
2366,
1630,
440,
5647,
282,
2997,
4340,
370,
6705,
272,
327,
340,
314,
8793,
5417,
4403,
365,
4337,
13,
2075,
503,
5049,
13,
2075,
14,
221,
644,
9050,
12,
3775,
272,
327,
314,
2018,
6337,
365,
4337,
13,
2075,
503,
5049,
13,
2075,
29476,
4052,
652,
2529,
12,
272,
327,
880,
6548,
315,
984,
2795,
503,
747,
2795,
1720,
14,
339,
327,
13450,
1708,
590,
314,
5526,
8744,
365,
370,
675,
2589,
6802,
626,
5417,
272,
327,
5951,
14,
221,
982,
3611,
35,
1608,
726,
63,
7762,
649,
3582,
3942,
365,
440,
671,
1184,
12,
2066,
314,
2366,
272,
327,
2112,
365,
3879,
315,
5049,
4546,
818,
334,
265,
282,
5049,
13,
2075,
4403,
12,
5049,
13,
2075,
272,
327,
14991,
12,
25259,
590,
680,
272,
327,
982,
642,
2366,
365,
4337,
13,
2075,
1325,
314,
4403,
365,
5049,
12,
5417,
911,
663,
272,
327,
18841,
55,
23313,
436,
3611,
35,
1608,
726,
63,
7762,
4427,
55,
23313,
370,
2222,
13,
2307,
14,
272,
327,
334,
14740,
367,
869,
14307,
45,
60,
10337,
60,
55,
583,
23313,
1716,
315,
314,
7086,
3181,
1133,
272,
327,
1736,
12,
2952,
2005,
4337,
13,
2075,
18535,
83,
1218,
652,
4959,
272,
2288,
485,
374,
63,
2676,
772,
272,
340,
485,
374,
63,
2676,
772,
365,
488,
26,
267,
327,
473,
21781,
3520,
2295,
370,
1852,
652,
8837,
370,
1050,
892,
7869,
503,
267,
327,
1050,
4967,
315,
314,
6466,
12,
2952,
642,
365,
282,
4546,
11101,
441,
14,
267,
485,
374,
63,
2676,
772,
275,
756,
267,
340,
747,
14,
2314,
14,
362,
360,
24341,
63,
7762,
649,
3582,
3942,
1673,
88,
1184,
358,
1137,
283,
88,
1184,
356,
288,
485,
374,
63,
2676,
772,
275,
715,
267,
340,
747,
14,
2314,
14,
362,
360,
24341,
63,
7762,
4427,
55,
23313,
735,
288,
485,
374,
63,
2676,
772,
275,
715,
267,
340,
747,
14,
2314,
14,
362,
360,
9184,
55,
23313,
735,
288,
485,
374,
63,
2676,
772,
275,
715,
272,
372,
485,
374,
63,
2676,
772,
421,
199,
318,
1586,
63,
1135,
8,
585,
304,
272,
372,
8218,
14,
9562,
14,
2872,
9334,
8,
18521,
14,
9562,
14,
23802,
63,
7486,
63,
20890,
12,
574,
2788,
16,
61,
199,
199,
318,
965,
63,
1135,
8,
585,
304,
272,
408,
1767,
715,
340,
314,
1627,
790,
3495,
315,
869,
3078,
63,
7486,
63,
20890,
12,
756,
272,
4257,
1041,
272,
862,
26,
267,
8218,
14,
9562,
14,
2872,
28144,
920,
8,
18521,
14,
9562,
14,
23802,
63,
7486,
63,
20890,
12,
574,
9,
267,
2203,
275,
715,
272,
871,
23950,
26,
267,
2203,
275,
756,
272,
372,
2203,
199,
199,
3,
17471,
367,
21239,
3734,
1750,
2202,
687,
3522,
1584,
14,
199,
199,
318,
7666,
63,
1813,
8,
1813,
12,
2883,
12,
3542,
29,
797,
304,
272,
408,
13735,
282,
2600,
6144,
282,
5218,
3734,
12,
1050,
314,
2860,
272,
687,
747,
14,
2314,
4346,
367,
314,
6661,
402,
1275,
13475,
1584,
27,
314,
2883,
787,
272,
22284,
701,
314,
2883,
1423,
14,
339,
2779,
2597,
7704,
3238,
314,
3734,
1338,
787,
6657,
5737,
14,
339,
982,
3542,
29,
549,
12,
2066,
1006,
402,
314,
790,
1338,
626,
2187,
787,
8876,
272,
1901,
314,
2138,
2600,
14,
221
] |
[
199,
3,
1898,
334,
67,
9,
12521,
446,
6900,
710,
8218,
2752,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
199,
3,
282,
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,
199,
3,
11207,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
199,
3,
11291,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
199,
3,
314,
2569,
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,
199,
3,
3826,
12,
7168,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
199,
3,
2990,
1634,
3169,
12,
3092,
2381,
437,
3115,
3104,
2401,
199,
3,
13229,
14,
1621,
4825,
6461,
7000,
2334,
10610,
1549,
5877,
8164,
6262,
199,
3,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
7061,
1621,
1261,
9612,
199,
3,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
5738,
1634,
1549,
1621,
11287,
199,
3,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
4141,
14,
199,
3,
199,
199,
363,
5792,
363,
275,
298,
2164,
15,
3908,
15,
18521,
15,
5157,
15,
3053,
7844,
15,
2330,
14,
647,
4668,
63,
18,
14,
19,
14,
21,
26,
8425,
23,
26,
68,
2192,
68,
21,
65,
20,
69,
1342,
66,
22,
6900,
15,
1780,
15,
2192,
4329,
26,
1344,
26,
709,
330,
697,
525,
974,
2,
199,
199,
363,
1301,
363,
275,
408,
199,
7844,
5922,
3423,
367,
6449,
543,
314,
15332,
4744,
6036,
14,
199,
624,
199,
199,
646,
1331,
199,
646,
747,
199,
646,
3873,
199,
646,
295,
199,
199,
646,
8218,
14,
9562,
421,
199,
12804,
275,
747,
14,
2314,
14,
362,
360,
51,
1864,
51,
63,
3053,
21637,
63,
5287,
358,
199,
692,
17251,
508,
20905,
272,
347,
3105,
8,
88,
304,
267,
870,
671,
199,
4164,
17251,
26,
272,
862,
26,
267,
492,
2050,
272,
871,
3545,
26,
267,
3105,
275,
2400,
671,
26,
1551,
8,
12804,
12,
283,
65,
1959,
952,
8,
88,
435,
1557,
78,
358,
272,
587,
26,
267,
2050,
14,
19602,
8,
1501,
29,
12804,
12,
2166,
29,
4806,
14,
5287,
9,
267,
3105,
275,
2050,
14,
1757,
199,
2836,
26,
272,
3105,
275,
2400,
671,
26,
488,
421,
199,
63,
374,
63,
2676,
772,
275,
488,
199,
199,
318,
365,
63,
2676,
772,
837,
272,
408,
1767,
2549,
340,
3879,
641,
10061,
5049,
5821,
14,
339,
28099,
3775,
2366,
6337,
7858,
315,
5049,
5821,
503,
4337,
5821,
1041,
272,
327,
31076,
12,
2366,
1630,
440,
5647,
282,
2997,
4340,
370,
6705,
272,
327,
340,
314,
8793,
5417,
4403,
365,
4337,
13,
2075,
503,
5049,
13,
2075,
14,
221,
644,
9050,
12,
3775,
272,
327,
314,
2018,
6337,
365,
4337,
13,
2075,
503,
5049,
13,
2075,
29476,
4052,
652,
2529,
12,
272,
327,
880,
6548,
315,
984,
2795,
503,
747,
2795,
1720,
14,
339,
327,
13450,
1708,
590,
314,
5526,
8744,
365,
370,
675,
2589,
6802,
626,
5417,
272,
327,
5951,
14,
221,
982,
3611,
35,
1608,
726,
63,
7762,
649,
3582,
3942,
365,
440,
671,
1184,
12,
2066,
314,
2366,
272,
327,
2112,
365,
3879,
315,
5049,
4546,
818,
334,
265,
282,
5049,
13,
2075,
4403,
12,
5049,
13,
2075,
272,
327,
14991,
12,
25259,
590,
680,
272,
327,
982,
642,
2366,
365,
4337,
13,
2075,
1325,
314,
4403,
365,
5049,
12,
5417,
911,
663,
272,
327,
18841,
55,
23313,
436,
3611,
35,
1608,
726,
63,
7762,
4427,
55,
23313,
370,
2222,
13,
2307,
14,
272,
327,
334,
14740,
367,
869,
14307,
45,
60,
10337,
60,
55,
583,
23313,
1716,
315,
314,
7086,
3181,
1133,
272,
327,
1736,
12,
2952,
2005,
4337,
13,
2075,
18535,
83,
1218,
652,
4959,
272,
2288,
485,
374,
63,
2676,
772,
272,
340,
485,
374,
63,
2676,
772,
365,
488,
26,
267,
327,
473,
21781,
3520,
2295,
370,
1852,
652,
8837,
370,
1050,
892,
7869,
503,
267,
327,
1050,
4967,
315,
314,
6466,
12,
2952,
642,
365,
282,
4546,
11101,
441,
14,
267,
485,
374,
63,
2676,
772,
275,
756,
267,
340,
747,
14,
2314,
14,
362,
360,
24341,
63,
7762,
649,
3582,
3942,
1673,
88,
1184,
358,
1137,
283,
88,
1184,
356,
288,
485,
374,
63,
2676,
772,
275,
715,
267,
340,
747,
14,
2314,
14,
362,
360,
24341,
63,
7762,
4427,
55,
23313,
735,
288,
485,
374,
63,
2676,
772,
275,
715,
267,
340,
747,
14,
2314,
14,
362,
360,
9184,
55,
23313,
735,
288,
485,
374,
63,
2676,
772,
275,
715,
272,
372,
485,
374,
63,
2676,
772,
421,
199,
318,
1586,
63,
1135,
8,
585,
304,
272,
372,
8218,
14,
9562,
14,
2872,
9334,
8,
18521,
14,
9562,
14,
23802,
63,
7486,
63,
20890,
12,
574,
2788,
16,
61,
199,
199,
318,
965,
63,
1135,
8,
585,
304,
272,
408,
1767,
715,
340,
314,
1627,
790,
3495,
315,
869,
3078,
63,
7486,
63,
20890,
12,
756,
272,
4257,
1041,
272,
862,
26,
267,
8218,
14,
9562,
14,
2872,
28144,
920,
8,
18521,
14,
9562,
14,
23802,
63,
7486,
63,
20890,
12,
574,
9,
267,
2203,
275,
715,
272,
871,
23950,
26,
267,
2203,
275,
756,
272,
372,
2203,
199,
199,
3,
17471,
367,
21239,
3734,
1750,
2202,
687,
3522,
1584,
14,
199,
199,
318,
7666,
63,
1813,
8,
1813,
12,
2883,
12,
3542,
29,
797,
304,
272,
408,
13735,
282,
2600,
6144,
282,
5218,
3734,
12,
1050,
314,
2860,
272,
687,
747,
14,
2314,
4346,
367,
314,
6661,
402,
1275,
13475,
1584,
27,
314,
2883,
787,
272,
22284,
701,
314,
2883,
1423,
14,
339,
2779,
2597,
7704,
3238,
314,
3734,
1338,
787,
6657,
5737,
14,
339,
982,
3542,
29,
549,
12,
2066,
1006,
402,
314,
790,
1338,
626,
2187,
787,
8876,
272,
1901,
314,
2138,
2600,
14,
221,
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,
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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
] |
VcamX/pywikibot-core
|
scripts/revertbot.py
|
2
|
5150
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
This script can be used for reverting certain edits.
The following command line parameters are supported:
¶ms;
-username Edits of which user need to be reverted.
-rollback Rollback edits instead of reverting them.
Note that in rollback, no diff would be shown.
"""
#
# (C) Bryan Tong Minh, 2008
# (C) Pywikibot team, 2008-2014
#
# Ported by Geoffrey "GEOFBOT" Mon - User:Sn1per
# for Google Code-In 2013
#
# Distributed under the terms of the MIT license.
#
from __future__ import unicode_literals
__version__ = '$Id$'
#
import re
import pywikibot
from pywikibot import i18n
from pywikibot import pagegenerators
docuReplacements = {
'¶ms;': pagegenerators.parameterHelp
}
class BaseRevertBot(object):
"""Base revert bot.
Subclass this bot and override callback to get it to do something useful.
"""
def __init__(self, site, user=None, comment=None, rollback=False):
self.site = site
self.comment = comment
self.user = user
if not self.user:
self.user = self.site.username()
self.rollback = rollback
def get_contributions(self, max=500, ns=None):
count = 0
iterator = pywikibot.tools.empty_iterator()
never_continue = False
while count != max or never_continue:
try:
item = next(iterator)
except StopIteration:
self.log(u'Fetching new batch of contributions')
data = list(pywikibot.Site().usercontribs(user=self.user, namespaces=ns, total=max))
never_continue = True
iterator = iter(data)
else:
count += 1
yield item
def revert_contribs(self, callback=None):
if callback is None:
callback = self.callback
contribs = self.get_contributions()
for item in contribs:
try:
if callback(item):
result = self.revert(item)
if result:
self.log(u'%s: %s' % (item['title'], result))
else:
self.log(u'Skipped %s' % item['title'])
else:
self.log(u'Skipped %s by callback' % item['title'])
except StopIteration:
return
def callback(self, item):
return 'top' in item
def revert(self, item):
history = pywikibot.Page(self.site, item['title']).fullVersionHistory(
total=2, rollback=self.rollback)
if len(history) > 1:
rev = history[1]
else:
return False
comment = i18n.twtranslate(
pywikibot.Site(), 'revertbot-revert',
{'revid': rev[0], 'author': rev[2], 'timestamp': rev[1]})
if self.comment:
comment += ': ' + self.comment
page = pywikibot.Page(self.site, item['title'])
pywikibot.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<"
% page.title(asLink=True, forceInterwiki=True,
textlink=True))
if not self.rollback:
old = page.text
page.text = rev[3]
pywikibot.showDiff(old, page.text)
page.save(comment)
return comment
try:
pywikibot.data.api.Request(
self.site, parameters={'action': 'rollback', 'title': page,
'user': self.user, 'token': rev[4],
'markbot': True}).submit()
except pywikibot.data.api.APIError as e:
if e.code == 'badtoken':
pywikibot.error("There was an API token error rollbacking the edit")
else:
pywikibot.exception()
return False
return u"The edit(s) made in %s by %s was rollbacked" % (page.title(), self.user)
def log(self, msg):
pywikibot.output(msg)
class myRevertBot(BaseRevertBot):
"""Example revert bot."""
def callback(self, item):
if 'top' in item:
page = pywikibot.Page(self.site, item['title'])
text = page.get(get_redirect=True)
pattern = re.compile(r'\[\[.+?:.+?\..+?\]\]', re.UNICODE)
return pattern.search(text) >= 0
return False
def main(*args):
"""
Process command line arguments and invoke bot.
If args is an empty list, sys.argv is used.
@param args: command line arguments
@type args: list of unicode
"""
user = None
rollback = False
for arg in pywikibot.handle_args(args):
if arg.startswith('-username'):
if len(arg) == 9:
user = pywikibot.input(
u'Please enter username of the person you want to revert:')
else:
user = arg[10:]
elif arg == '-rollback':
rollback = True
bot = myRevertBot(site=pywikibot.Site(), user=user, rollback=rollback)
bot.revert_contribs()
if __name__ == "__main__":
main()
|
mit
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
221,
1882,
199,
624,
199,
2765,
2884,
883,
506,
1202,
367,
29465,
1337,
9842,
7860,
1086,
14,
199,
199,
1918,
2569,
1414,
1004,
2633,
787,
3748,
26,
199,
199,
6,
1162,
27,
199,
199,
13,
2473,
260,
662,
15256,
402,
1314,
922,
1929,
370,
506,
295,
16542,
14,
199,
199,
13,
10437,
260,
820,
14385,
894,
7860,
1086,
3140,
402,
29465,
1337,
3062,
14,
2116,
3390,
626,
315,
16475,
12,
949,
3915,
3955,
506,
9164,
14,
199,
624,
199,
3,
199,
3,
334,
35,
9,
699,
651,
290,
377,
951,
10195,
72,
12,
9079,
199,
3,
334,
35,
9,
1611,
26540,
8099,
12,
9079,
13,
7280,
199,
3,
199,
3,
510,
1376,
701,
5346,
1997,
17885,
298,
4962,
3359,
11372,
2,
10953,
446,
2876,
26,
20821,
17,
529,
199,
3,
367,
4475,
5495,
13,
607,
6171,
199,
3,
199,
3,
17484,
1334,
314,
2895,
402,
314,
10697,
4190,
14,
199,
3,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
363,
1023,
363,
275,
4505,
1304,
12913,
199,
3,
199,
199,
646,
295,
199,
646,
29624,
199,
504,
29624,
492,
284,
1085,
78,
199,
504,
29624,
492,
2034,
20748,
199,
199,
1301,
85,
11328,
1470,
275,
469,
272,
7673,
1162,
6015,
2034,
20748,
14,
5329,
8673,
199,
93,
421,
199,
533,
3523,
497,
1884,
14026,
8,
785,
304,
339,
408,
1563,
23347,
5888,
14,
339,
30184,
642,
5888,
436,
4278,
3233,
370,
664,
652,
370,
886,
6020,
2997,
14,
339,
408,
339,
347,
636,
826,
721,
277,
12,
4770,
12,
922,
29,
403,
12,
3721,
29,
403,
12,
16475,
29,
797,
304,
267,
291,
14,
2124,
275,
4770,
267,
291,
14,
3349,
275,
3721,
267,
291,
14,
751,
275,
922,
267,
340,
440,
291,
14,
751,
26,
288,
291,
14,
751,
275,
291,
14,
2124,
14,
2473,
342,
267,
291,
14,
10437,
275,
16475,
339,
347,
664,
63,
388,
26675,
8,
277,
12,
1390,
29,
5783,
12,
700,
29,
403,
304,
267,
2338,
275,
378,
267,
6122,
275,
29624,
14,
2537,
14,
1667,
63,
5778,
342,
267,
7078,
63,
6958,
275,
756,
267,
1830,
2338,
1137,
1390,
503,
7078,
63,
6958,
26,
288,
862,
26,
355,
1242,
275,
2163,
8,
5778,
9,
288,
871,
10852,
26,
355,
291,
14,
793,
8,
85,
7,
11135,
316,
892,
3522,
402,
406,
26675,
358,
355,
666,
275,
769,
8,
647,
26540,
14,
8972,
1252,
751,
388,
19577,
8,
751,
29,
277,
14,
751,
12,
10747,
29,
561,
12,
3141,
29,
988,
430,
355,
7078,
63,
6958,
275,
715,
355,
6122,
275,
2740,
8,
576,
9,
288,
587,
26,
355,
2338,
847,
413,
355,
1995,
1242,
339,
347,
23347,
63,
388,
19577,
8,
277,
12,
3233,
29,
403,
304,
398,
340,
3233,
365,
488,
26,
288,
3233,
275,
291,
14,
3058,
398,
406,
19577,
275,
291,
14,
362,
63,
388,
26675,
342,
267,
367,
1242,
315,
406,
19577,
26,
288,
862,
26,
355,
340,
3233,
8,
1053,
304,
490,
754,
275,
291,
14,
19092,
8,
1053,
9,
490,
340,
754,
26,
717,
291,
14,
793,
8,
85,
5956,
83,
26,
450,
83,
7,
450,
334,
1053,
459,
1213,
995,
754,
430,
490,
587,
26,
717,
291,
14,
793,
8,
85,
7,
30472,
450,
83,
7,
450,
1242,
459,
1213,
1105,
355,
587,
26,
490,
291,
14,
793,
8,
85,
7,
30472,
450,
83,
701,
3233,
7,
450,
1242,
459,
1213,
1105,
288,
871,
10852,
26,
355,
372,
339,
347,
3233,
8,
277,
12,
1242,
304,
267,
372,
283,
2119,
7,
315,
1242,
339,
347,
23347,
8,
277,
12,
1242,
304,
267,
7994,
275,
29624,
14,
3276,
8,
277,
14,
2124,
12,
1242,
459,
1213,
13227,
2861,
3353,
12114,
8,
288,
3141,
29,
18,
12,
16475,
29,
277,
14,
10437,
9,
267,
340,
822,
8,
5570,
9,
690,
413,
26,
288,
6822,
275,
7994,
59,
17,
61,
267,
587,
26,
288,
372,
756,
267,
3721,
275,
284,
1085,
78,
14,
8122,
5275,
8,
288,
29624,
14,
8972,
1062,
283,
19092,
3018,
13,
19092,
297,
288,
791,
4964,
344,
356,
6822,
59,
16,
467,
283,
2502,
356,
6822,
59,
18,
467,
283,
3954,
356,
6822,
59,
17,
13412,
267,
340,
291,
14,
3349,
26,
288,
3721,
847,
7596,
283,
435,
291,
14,
3349,
267,
2034,
275,
29624,
14,
3276,
8,
277,
14,
2124,
12,
1242,
459,
1213,
1105,
267,
29624,
14,
1199,
8,
85,
3212,
78,
60,
78,
6071,
971,
1644,
91,
4040,
6653,
11045,
22109,
83,
60,
1644,
91,
885,
93,
5213,
28,
2,
586,
450,
2034,
14,
1213,
8,
305,
3834,
29,
549,
12,
3542,
2620,
6797,
29,
549,
12,
4228,
1318,
1073,
29,
549,
430,
267,
340,
440,
291,
14,
10437,
26,
288,
2269,
275,
2034,
14,
505,
288,
2034,
14,
505,
275,
6822,
59,
19,
61,
288,
29624,
14,
2384,
10746,
8,
1753,
12,
2034,
14,
505,
9,
288,
2034,
14,
2117,
8,
3349,
9,
288,
372,
3721,
267,
862,
26,
288,
29624,
14,
576,
14,
1246,
14,
2017,
8,
355,
291,
14,
2124,
12,
2633,
3713,
1287,
356,
283,
10437,
297,
283,
1213,
356,
2034,
12,
4318,
283,
751,
356,
291,
14,
751,
12,
283,
1418,
356,
6822,
59,
20,
467,
4318,
283,
1657,
3018,
356,
715,
21385,
7275,
342,
267,
871,
29624,
14,
576,
14,
1246,
14,
3735,
547,
465,
325,
26,
288,
340,
325,
14,
600,
508,
283,
4087,
1418,
356,
355,
29624,
14,
705,
480,
10924,
1990,
376,
3261,
1526,
1125,
16475,
316,
314,
5283,
531,
288,
587,
26,
355,
29624,
14,
1971,
342,
288,
372,
756,
267,
372,
399,
2,
1918,
5283,
8,
83,
9,
6326,
315,
450,
83,
701,
450,
83,
1990,
16475,
379,
2,
450,
334,
1606,
14,
1213,
1062,
291,
14,
751,
9,
339,
347,
943,
8,
277,
12,
1499,
304,
267,
29624,
14,
1199,
8,
1328,
9,
421,
199,
533,
3002,
497,
1884,
14026,
8,
1563,
497,
1884,
14026,
304,
339,
408,
9846,
23347,
5888,
1041,
339,
347,
3233,
8,
277,
12,
1242,
304,
267,
340,
283,
2119,
7,
315,
1242,
26,
288,
2034,
275,
29624,
14,
3276,
8,
277,
14,
2124,
12,
1242,
459,
1213,
1105,
288,
1318,
275,
2034
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
221,
1882,
199,
624,
199,
2765,
2884,
883,
506,
1202,
367,
29465,
1337,
9842,
7860,
1086,
14,
199,
199,
1918,
2569,
1414,
1004,
2633,
787,
3748,
26,
199,
199,
6,
1162,
27,
199,
199,
13,
2473,
260,
662,
15256,
402,
1314,
922,
1929,
370,
506,
295,
16542,
14,
199,
199,
13,
10437,
260,
820,
14385,
894,
7860,
1086,
3140,
402,
29465,
1337,
3062,
14,
2116,
3390,
626,
315,
16475,
12,
949,
3915,
3955,
506,
9164,
14,
199,
624,
199,
3,
199,
3,
334,
35,
9,
699,
651,
290,
377,
951,
10195,
72,
12,
9079,
199,
3,
334,
35,
9,
1611,
26540,
8099,
12,
9079,
13,
7280,
199,
3,
199,
3,
510,
1376,
701,
5346,
1997,
17885,
298,
4962,
3359,
11372,
2,
10953,
446,
2876,
26,
20821,
17,
529,
199,
3,
367,
4475,
5495,
13,
607,
6171,
199,
3,
199,
3,
17484,
1334,
314,
2895,
402,
314,
10697,
4190,
14,
199,
3,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
363,
1023,
363,
275,
4505,
1304,
12913,
199,
3,
199,
199,
646,
295,
199,
646,
29624,
199,
504,
29624,
492,
284,
1085,
78,
199,
504,
29624,
492,
2034,
20748,
199,
199,
1301,
85,
11328,
1470,
275,
469,
272,
7673,
1162,
6015,
2034,
20748,
14,
5329,
8673,
199,
93,
421,
199,
533,
3523,
497,
1884,
14026,
8,
785,
304,
339,
408,
1563,
23347,
5888,
14,
339,
30184,
642,
5888,
436,
4278,
3233,
370,
664,
652,
370,
886,
6020,
2997,
14,
339,
408,
339,
347,
636,
826,
721,
277,
12,
4770,
12,
922,
29,
403,
12,
3721,
29,
403,
12,
16475,
29,
797,
304,
267,
291,
14,
2124,
275,
4770,
267,
291,
14,
3349,
275,
3721,
267,
291,
14,
751,
275,
922,
267,
340,
440,
291,
14,
751,
26,
288,
291,
14,
751,
275,
291,
14,
2124,
14,
2473,
342,
267,
291,
14,
10437,
275,
16475,
339,
347,
664,
63,
388,
26675,
8,
277,
12,
1390,
29,
5783,
12,
700,
29,
403,
304,
267,
2338,
275,
378,
267,
6122,
275,
29624,
14,
2537,
14,
1667,
63,
5778,
342,
267,
7078,
63,
6958,
275,
756,
267,
1830,
2338,
1137,
1390,
503,
7078,
63,
6958,
26,
288,
862,
26,
355,
1242,
275,
2163,
8,
5778,
9,
288,
871,
10852,
26,
355,
291,
14,
793,
8,
85,
7,
11135,
316,
892,
3522,
402,
406,
26675,
358,
355,
666,
275,
769,
8,
647,
26540,
14,
8972,
1252,
751,
388,
19577,
8,
751,
29,
277,
14,
751,
12,
10747,
29,
561,
12,
3141,
29,
988,
430,
355,
7078,
63,
6958,
275,
715,
355,
6122,
275,
2740,
8,
576,
9,
288,
587,
26,
355,
2338,
847,
413,
355,
1995,
1242,
339,
347,
23347,
63,
388,
19577,
8,
277,
12,
3233,
29,
403,
304,
398,
340,
3233,
365,
488,
26,
288,
3233,
275,
291,
14,
3058,
398,
406,
19577,
275,
291,
14,
362,
63,
388,
26675,
342,
267,
367,
1242,
315,
406,
19577,
26,
288,
862,
26,
355,
340,
3233,
8,
1053,
304,
490,
754,
275,
291,
14,
19092,
8,
1053,
9,
490,
340,
754,
26,
717,
291,
14,
793,
8,
85,
5956,
83,
26,
450,
83,
7,
450,
334,
1053,
459,
1213,
995,
754,
430,
490,
587,
26,
717,
291,
14,
793,
8,
85,
7,
30472,
450,
83,
7,
450,
1242,
459,
1213,
1105,
355,
587,
26,
490,
291,
14,
793,
8,
85,
7,
30472,
450,
83,
701,
3233,
7,
450,
1242,
459,
1213,
1105,
288,
871,
10852,
26,
355,
372,
339,
347,
3233,
8,
277,
12,
1242,
304,
267,
372,
283,
2119,
7,
315,
1242,
339,
347,
23347,
8,
277,
12,
1242,
304,
267,
7994,
275,
29624,
14,
3276,
8,
277,
14,
2124,
12,
1242,
459,
1213,
13227,
2861,
3353,
12114,
8,
288,
3141,
29,
18,
12,
16475,
29,
277,
14,
10437,
9,
267,
340,
822,
8,
5570,
9,
690,
413,
26,
288,
6822,
275,
7994,
59,
17,
61,
267,
587,
26,
288,
372,
756,
267,
3721,
275,
284,
1085,
78,
14,
8122,
5275,
8,
288,
29624,
14,
8972,
1062,
283,
19092,
3018,
13,
19092,
297,
288,
791,
4964,
344,
356,
6822,
59,
16,
467,
283,
2502,
356,
6822,
59,
18,
467,
283,
3954,
356,
6822,
59,
17,
13412,
267,
340,
291,
14,
3349,
26,
288,
3721,
847,
7596,
283,
435,
291,
14,
3349,
267,
2034,
275,
29624,
14,
3276,
8,
277,
14,
2124,
12,
1242,
459,
1213,
1105,
267,
29624,
14,
1199,
8,
85,
3212,
78,
60,
78,
6071,
971,
1644,
91,
4040,
6653,
11045,
22109,
83,
60,
1644,
91,
885,
93,
5213,
28,
2,
586,
450,
2034,
14,
1213,
8,
305,
3834,
29,
549,
12,
3542,
2620,
6797,
29,
549,
12,
4228,
1318,
1073,
29,
549,
430,
267,
340,
440,
291,
14,
10437,
26,
288,
2269,
275,
2034,
14,
505,
288,
2034,
14,
505,
275,
6822,
59,
19,
61,
288,
29624,
14,
2384,
10746,
8,
1753,
12,
2034,
14,
505,
9,
288,
2034,
14,
2117,
8,
3349,
9,
288,
372,
3721,
267,
862,
26,
288,
29624,
14,
576,
14,
1246,
14,
2017,
8,
355,
291,
14,
2124,
12,
2633,
3713,
1287,
356,
283,
10437,
297,
283,
1213,
356,
2034,
12,
4318,
283,
751,
356,
291,
14,
751,
12,
283,
1418,
356,
6822,
59,
20,
467,
4318,
283,
1657,
3018,
356,
715,
21385,
7275,
342,
267,
871,
29624,
14,
576,
14,
1246,
14,
3735,
547,
465,
325,
26,
288,
340,
325,
14,
600,
508,
283,
4087,
1418,
356,
355,
29624,
14,
705,
480,
10924,
1990,
376,
3261,
1526,
1125,
16475,
316,
314,
5283,
531,
288,
587,
26,
355,
29624,
14,
1971,
342,
288,
372,
756,
267,
372,
399,
2,
1918,
5283,
8,
83,
9,
6326,
315,
450,
83,
701,
450,
83,
1990,
16475,
379,
2,
450,
334,
1606,
14,
1213,
1062,
291,
14,
751,
9,
339,
347,
943,
8,
277,
12,
1499,
304,
267,
29624,
14,
1199,
8,
1328,
9,
421,
199,
533,
3002,
497,
1884,
14026,
8,
1563,
497,
1884,
14026,
304,
339,
408,
9846,
23347,
5888,
1041,
339,
347,
3233,
8,
277,
12,
1242,
304,
267,
340,
283,
2119,
7,
315,
1242,
26,
288,
2034,
275,
29624,
14,
3276,
8,
277,
14,
2124,
12,
1242,
459,
1213,
1105,
288,
1318,
275,
2034,
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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
ricardog/raster-project
|
projections/r2py/lm.py
|
1
|
1635
|
from rpy2.robjects import Formula
from rpy2.robjects import pandas2ri
from rpy2.robjects.packages import importr
class LM(object):
'''Class for fitting (simple) linear models using rpy2. When extracting
the coefficients for a model (lmerMod or glmerMod) that uses orthogonal
polynomials (poly in R syntax), it is necessary to fit a linear model
that maps from the original data to the fitted polynomial. The mermod
class uses this class to fir such linear models.
'''
def __init__(self, formula=None, response=None, predictors=None):
self.__stats = importr('stats')
self.formula = formula
self.response = response
self.predictors = predictors
self._coefs = None
@property
def formula(self):
return self._formula
@formula.setter
def formula(self, f):
self._formula = Formula(f)
self.env = self._formula.environment
def fit(self):
'''Fit the linear model and extract the coefficients.
FIXME: This function assumes the model has a single predictor variable (x), but may appear multiple times with different exponents. That is, the equation must be of the form
y ~ x + I(x^2) + I(x^3)
'''
if self.formula is None or self.response is None or self.predictors is None:
raise RuntimeError('set formula, response, and predictor variables')
## FIXME: This is a quick and dirty hack.
self.env['y'] = self.response
self.env['x'] = self.predictors.loc[:, 'x']
fit = self.__stats.lm(self.formula)
self._coefs = pandas2ri.ri2py(fit.rx('coefficients')[0])
@property
def coefs(self):
if self._coefs == None:
self.fit()
return self._coefs
|
apache-2.0
|
[
504,
519,
647,
18,
14,
293,
550,
83,
492,
8204,
7586,
199,
504,
519,
647,
18,
14,
293,
550,
83,
492,
10634,
18,
322,
199,
504,
519,
647,
18,
14,
293,
550,
83,
14,
5154,
492,
492,
82,
199,
199,
533,
491,
45,
8,
785,
304,
523,
1449,
2543,
367,
21774,
334,
4129,
9,
7798,
1709,
1808,
519,
647,
18,
14,
221,
3979,
30137,
199,
1589,
12343,
367,
282,
1402,
334,
76,
2626,
9871,
503,
6482,
2626,
9871,
9,
626,
4440,
29069,
199,
22104,
83,
334,
6023,
315,
820,
6302,
395,
652,
365,
5784,
370,
5542,
282,
7798,
1402,
199,
9099,
9033,
687,
314,
3379,
666,
370,
314,
26093,
11849,
14,
221,
710,
4004,
1494,
199,
533,
4440,
642,
1021,
370,
289,
723,
4066,
7798,
1709,
14,
819,
1449,
523,
347,
636,
826,
721,
277,
12,
15723,
29,
403,
12,
1177,
29,
403,
12,
4557,
13451,
29,
403,
304,
272,
291,
855,
3200,
275,
492,
82,
360,
3200,
358,
272,
291,
14,
16798,
275,
15723,
272,
291,
14,
1310,
275,
1177,
272,
291,
14,
5790,
13451,
275,
4557,
13451,
272,
291,
423,
22892,
275,
488,
819,
768,
1829,
523,
347,
15723,
8,
277,
304,
272,
372,
291,
423,
16798,
819,
768,
16798,
14,
8345,
523,
347,
15723,
8,
277,
12,
289,
304,
272,
291,
423,
16798,
275,
8204,
7586,
8,
70,
9,
272,
291,
14,
1813,
275,
291,
423,
16798,
14,
5418,
819,
347,
5542,
8,
277,
304,
272,
1449,
13776,
314,
7798,
1402,
436,
5536,
314,
12343,
14,
199,
31779,
26,
961,
805,
15194,
314,
1402,
965,
282,
2849,
4557,
630,
1750,
334,
88,
395,
1325,
1443,
7468,
3663,
5431,
543,
3365,
16588,
83,
14,
221,
10314,
365,
12,
314,
18649,
1471,
506,
402,
314,
1824,
339,
612,
6146,
671,
435,
473,
8,
88,
62,
18,
9,
435,
473,
8,
88,
62,
19,
9,
199,
2344,
272,
340,
291,
14,
16798,
365,
488,
503,
291,
14,
1310,
365,
488,
503,
291,
14,
5790,
13451,
365,
488,
26,
489,
746,
6064,
360,
409,
15723,
12,
1177,
12,
436,
4557,
630,
2860,
358,
272,
925,
7600,
26,
961,
365,
282,
12530,
436,
14650,
11176,
14,
272,
291,
14,
1813,
459,
89,
418,
275,
291,
14,
1310,
272,
291,
14,
1813,
459,
88,
418,
275,
291,
14,
5790,
13451,
14,
2102,
3981,
283,
88,
418,
272,
5542,
275,
291,
855,
3200,
14,
14344,
8,
277,
14,
16798,
9,
272,
291,
423,
22892,
275,
10634,
18,
322,
14,
322,
18,
647,
8,
3269,
14,
6872,
360,
30477,
5832,
16,
566,
819,
768,
1829,
523,
347,
29879,
8,
277,
304,
272,
340,
291,
423,
22892,
508,
488,
26,
489,
291,
14,
3269,
342,
272,
372,
291,
423,
22892,
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
] |
[
519,
647,
18,
14,
293,
550,
83,
492,
8204,
7586,
199,
504,
519,
647,
18,
14,
293,
550,
83,
492,
10634,
18,
322,
199,
504,
519,
647,
18,
14,
293,
550,
83,
14,
5154,
492,
492,
82,
199,
199,
533,
491,
45,
8,
785,
304,
523,
1449,
2543,
367,
21774,
334,
4129,
9,
7798,
1709,
1808,
519,
647,
18,
14,
221,
3979,
30137,
199,
1589,
12343,
367,
282,
1402,
334,
76,
2626,
9871,
503,
6482,
2626,
9871,
9,
626,
4440,
29069,
199,
22104,
83,
334,
6023,
315,
820,
6302,
395,
652,
365,
5784,
370,
5542,
282,
7798,
1402,
199,
9099,
9033,
687,
314,
3379,
666,
370,
314,
26093,
11849,
14,
221,
710,
4004,
1494,
199,
533,
4440,
642,
1021,
370,
289,
723,
4066,
7798,
1709,
14,
819,
1449,
523,
347,
636,
826,
721,
277,
12,
15723,
29,
403,
12,
1177,
29,
403,
12,
4557,
13451,
29,
403,
304,
272,
291,
855,
3200,
275,
492,
82,
360,
3200,
358,
272,
291,
14,
16798,
275,
15723,
272,
291,
14,
1310,
275,
1177,
272,
291,
14,
5790,
13451,
275,
4557,
13451,
272,
291,
423,
22892,
275,
488,
819,
768,
1829,
523,
347,
15723,
8,
277,
304,
272,
372,
291,
423,
16798,
819,
768,
16798,
14,
8345,
523,
347,
15723,
8,
277,
12,
289,
304,
272,
291,
423,
16798,
275,
8204,
7586,
8,
70,
9,
272,
291,
14,
1813,
275,
291,
423,
16798,
14,
5418,
819,
347,
5542,
8,
277,
304,
272,
1449,
13776,
314,
7798,
1402,
436,
5536,
314,
12343,
14,
199,
31779,
26,
961,
805,
15194,
314,
1402,
965,
282,
2849,
4557,
630,
1750,
334,
88,
395,
1325,
1443,
7468,
3663,
5431,
543,
3365,
16588,
83,
14,
221,
10314,
365,
12,
314,
18649,
1471,
506,
402,
314,
1824,
339,
612,
6146,
671,
435,
473,
8,
88,
62,
18,
9,
435,
473,
8,
88,
62,
19,
9,
199,
2344,
272,
340,
291,
14,
16798,
365,
488,
503,
291,
14,
1310,
365,
488,
503,
291,
14,
5790,
13451,
365,
488,
26,
489,
746,
6064,
360,
409,
15723,
12,
1177,
12,
436,
4557,
630,
2860,
358,
272,
925,
7600,
26,
961,
365,
282,
12530,
436,
14650,
11176,
14,
272,
291,
14,
1813,
459,
89,
418,
275,
291,
14,
1310,
272,
291,
14,
1813,
459,
88,
418,
275,
291,
14,
5790,
13451,
14,
2102,
3981,
283,
88,
418,
272,
5542,
275,
291,
855,
3200,
14,
14344,
8,
277,
14,
16798,
9,
272,
291,
423,
22892,
275,
10634,
18,
322,
14,
322,
18,
647,
8,
3269,
14,
6872,
360,
30477,
5832,
16,
566,
819,
768,
1829,
523,
347,
29879,
8,
277,
304,
272,
340,
291,
423,
22892,
508,
488,
26,
489,
291,
14,
3269,
342,
272,
372,
291,
423,
22892,
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,
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
] |
syapse/django-storages
|
docs/conf.py
|
6
|
8336
|
# -*- coding: utf-8 -*-
#
# django-storages documentation build configuration file, created by
# sphinx-quickstart on Sun Aug 28 13:44:45 2011.
#
# 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.
import sys, os
# 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.
sys.path.insert(0, os.path.abspath('..'))
import storages
# -- 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.viewcode']
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# The suffix of source filenames.
source_suffix = '.rst'
# The encoding of source files.
#source_encoding = 'utf-8-sig'
# The master toctree document.
master_doc = 'index'
# General information about the project.
project = u'django-storages'
copyright = u'2011-2017, David Larlet, et. al.'
# 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 = storages.__version__
# The full version, including alpha/beta/rc tags.
release = storages.__version__
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#language = None
# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
#today = ''
# Else, today_fmt is used as the format for a strftime call.
#today_fmt = '%B %d, %Y'
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
exclude_patterns = ['_build']
# The reST default role (used for this markup: `text`) to use for all documents.
#default_role = None
# If true, '()' will be appended to :func: etc. cross-reference text.
#add_function_parentheses = True
# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
#add_module_names = True
# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
#show_authors = False
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
# A list of ignored prefixes for module index sorting.
#modindex_common_prefix = []
# -- 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 = 'default'
# 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 = {}
# Add any paths that contain custom themes here, relative to this directory.
#html_theme_path = []
# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
#html_title = None
# A shorter title for the navigation bar. Default is the same as html_title.
#html_short_title = None
# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
#html_logo = None
# The name of an image file (within the static path) to use as favicon of the
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
#html_favicon = None
# 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']
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
#html_last_updated_fmt = '%b %d, %Y'
# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
#html_use_smartypants = True
# Custom sidebar templates, maps document names to template names.
#html_sidebars = {}
# Additional templates that should be rendered to pages, maps page names to
# template names.
#html_additional_pages = {}
# If false, no module index is generated.
#html_domain_indices = True
# If false, no index is generated.
#html_use_index = True
# If true, the index is split into individual pages for each letter.
#html_split_index = False
# If true, links to the reST sources are added to the pages.
#html_show_sourcelink = True
# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
#html_show_sphinx = True
# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
#html_show_copyright = True
# If true, an OpenSearch description file will be output, and all pages will
# contain a <link> tag referring to it. The value of this option must be the
# base URL from which the finished HTML is served.
#html_use_opensearch = ''
# This is the file name suffix for HTML files (e.g. ".xhtml").
#html_file_suffix = None
# Output file base name for HTML help builder.
htmlhelp_basename = 'django-storagesdoc'
# -- Options for LaTeX output --------------------------------------------------
# The paper size ('letter' or 'a4').
#latex_paper_size = 'letter'
# The font size ('10pt', '11pt' or '12pt').
#latex_font_size = '10pt'
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'django-storages.tex', u'django-storages Documentation',
u'David Larlet, et. al.', 'manual'),
]
# The name of an image file (relative to this directory) to place at the top of
# the title page.
#latex_logo = None
# For "manual" documents, if this is true, then toplevel headings are parts,
# not chapters.
#latex_use_parts = False
# If true, show page references after internal links.
#latex_show_pagerefs = False
# If true, show URL addresses after external links.
#latex_show_urls = False
# Additional stuff for the LaTeX preamble.
#latex_preamble = ''
# Documents to append as an appendix to all manuals.
#latex_appendices = []
# If false, no module index is generated.
#latex_domain_indices = True
# -- Options for manual page output --------------------------------------------
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'django-storages', u'django-storages Documentation',
[u'David Larlet, et. al.'], 1)
]
# -- Options for Epub output ---------------------------------------------------
# Bibliographic Dublin Core info.
epub_title = u'django-storages'
epub_author = u'David Larlet, et. al.'
epub_publisher = u'David Larlet, et. al.'
epub_copyright = u'2011-2017, David Larlet, et. al.'
# The language of the text. It defaults to the language option
# or en if the language is not set.
#epub_language = ''
# The scheme of the identifier. Typical schemes are ISBN or URL.
#epub_scheme = ''
# The unique identifier of the text. This can be a ISBN number
# or the project homepage.
#epub_identifier = ''
# A unique identification for the text.
#epub_uid = ''
# HTML files that should be inserted before the pages created by sphinx.
# The format is a list of tuples containing the path and title.
#epub_pre_files = []
# HTML files shat should be inserted after the pages created by sphinx.
# The format is a list of tuples containing the path and title.
#epub_post_files = []
# A list of files that should not be packed into the epub file.
#epub_exclude_files = []
# The depth of the table of contents in toc.ncx.
#epub_tocdepth = 3
# Allow duplicate toc entries.
#epub_tocdup = True
|
bsd-3-clause
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1639,
13,
3494,
83,
3794,
1900,
2897,
570,
12,
2737,
701,
199,
3,
15882,
13,
28957,
641,
25625,
25298,
7294,
4944,
26,
1602,
26,
2322,
7760,
14,
199,
3,
199,
3,
961,
570,
365,
22711,
342,
68,
543,
314,
1453,
2082,
663,
370,
2399,
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,
646,
984,
12,
747,
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,
1274,
14,
515,
14,
3176,
8,
16,
12,
747,
14,
515,
14,
4832,
24893,
1333,
199,
646,
4887,
83,
199,
199,
3,
1553,
1696,
2897,
9527,
9858,
199,
199,
3,
982,
2195,
3794,
4839,
282,
13460,
10229,
1015,
12,
1174,
652,
2348,
14,
199,
3,
10065,
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,
5478,
199,
3,
17262,
543,
10229,
334,
4579,
283,
8008,
14,
832,
24915,
503,
2195,
3537,
7869,
14,
199,
5359,
275,
788,
8008,
14,
832,
14,
28056,
297,
283,
8008,
14,
832,
14,
1345,
600,
418,
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,
402,
1350,
6203,
14,
199,
1365,
63,
4511,
275,
1987,
8332,
7,
199,
199,
3,
710,
2644,
402,
1350,
1584,
14,
199,
3,
1365,
63,
2991,
275,
283,
1624,
13,
24,
13,
4093,
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,
399,
5121,
858,
13,
3494,
83,
7,
199,
7307,
275,
399,
7,
8128,
13,
10680,
12,
20232,
491,
285,
2723,
12,
10844,
14,
741,
3530,
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,
4887,
83,
855,
1023,
363,
199,
3,
710,
2615,
1015,
12,
5893,
5131,
15,
5683,
15,
1195,
3762,
14,
199,
3221,
275,
4887,
83,
855,
1023,
363,
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,
3671,
275,
488,
199,
199,
3,
6006,
787,
2877,
1511,
367,
15810,
1204,
8136,
25004,
1902,
12,
1265,
663,
11168,
370,
2005,
199,
3,
2222,
13,
3910,
574,
12,
2066,
652,
365,
1202,
26,
199,
3,
8136,
275,
2125,
199,
3,
19524,
12,
11168,
63,
5045,
365,
1202,
465,
314,
1475,
367,
282,
14053,
1240,
14,
199,
3,
8136,
63,
5045,
275,
1543,
34,
450,
68,
12,
450,
57,
7,
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,
5473,
63,
7435,
275,
4044,
1506,
418,
199,
199,
3,
710,
20883,
849,
4719,
334,
2972,
367,
642,
9189,
26,
658,
505,
10522,
370,
675,
367,
1006,
8247,
14,
199,
3,
885,
63,
3756,
275,
488,
199,
199,
3,
982,
2549,
12,
26380,
911,
506,
11544,
370,
520,
1532,
26,
5423,
14,
8059,
13,
4443,
1318,
14,
199,
3,
525,
63,
1593,
63,
25510,
275,
715,
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,
3,
525,
63,
578,
63,
1247,
275,
715,
199,
199,
3,
982,
2549,
12,
3420,
2502,
436,
28966,
13502,
911,
506,
9164,
315,
314,
199,
3,
1072,
14,
9322,
787,
5525,
701,
849,
14,
199,
3,
2384,
63,
8149,
275,
756,
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,
437,
769,
402,
5525,
13158,
367,
859,
1478,
13351,
14,
199,
3,
27555,
63,
2330,
63,
1861,
275,
942,
421,
199,
3,
1553,
8394,
367,
4163,
1072,
9527,
2595,
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,
1360,
63,
7915,
275,
283,
885,
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,
1360,
63,
7915,
63,
1419,
275,
1052,
199,
199,
3,
2654,
1263,
3792,
626,
1395,
3537,
17915,
2348,
12,
3847,
370,
642,
2082,
14,
199,
3,
1360,
63,
7915,
63,
515,
275,
942,
199,
199,
3,
710,
536,
367,
642,
663,
402,
10229,
8247,
14,
221,
982,
488,
12,
652,
4243,
370,
199,
3,
3886,
1715,
30,
373,
28,
3221,
30,
3794,
1674,
199,
3,
1360,
63,
1213,
275,
488,
199,
199,
3,
437,
18299,
2538,
367,
314,
19191,
4681,
14,
221,
3758,
365,
314,
2011,
465,
3517,
63,
1213,
14,
199,
3,
1360,
63,
3612,
63,
1213,
275,
488,
199,
199,
3,
710,
536,
402,
376,
1834,
570,
334,
6188,
370,
642,
2082,
9,
370,
4192,
737,
314,
2746,
199,
3,
402,
314,
18437,
14,
199,
3,
1360,
63,
9733,
275,
488,
199,
199,
3,
710,
536,
402,
376,
1834,
570,
334,
12541,
314,
2955,
931,
9,
370,
675,
465,
29139,
402,
314,
199,
3,
9149,
14,
221,
961,
570,
1077,
506,
282,
5417,
7016
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1639,
13,
3494,
83,
3794,
1900,
2897,
570,
12,
2737,
701,
199,
3,
15882,
13,
28957,
641,
25625,
25298,
7294,
4944,
26,
1602,
26,
2322,
7760,
14,
199,
3,
199,
3,
961,
570,
365,
22711,
342,
68,
543,
314,
1453,
2082,
663,
370,
2399,
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,
646,
984,
12,
747,
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,
1274,
14,
515,
14,
3176,
8,
16,
12,
747,
14,
515,
14,
4832,
24893,
1333,
199,
646,
4887,
83,
199,
199,
3,
1553,
1696,
2897,
9527,
9858,
199,
199,
3,
982,
2195,
3794,
4839,
282,
13460,
10229,
1015,
12,
1174,
652,
2348,
14,
199,
3,
10065,
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,
5478,
199,
3,
17262,
543,
10229,
334,
4579,
283,
8008,
14,
832,
24915,
503,
2195,
3537,
7869,
14,
199,
5359,
275,
788,
8008,
14,
832,
14,
28056,
297,
283,
8008,
14,
832,
14,
1345,
600,
418,
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,
402,
1350,
6203,
14,
199,
1365,
63,
4511,
275,
1987,
8332,
7,
199,
199,
3,
710,
2644,
402,
1350,
1584,
14,
199,
3,
1365,
63,
2991,
275,
283,
1624,
13,
24,
13,
4093,
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,
399,
5121,
858,
13,
3494,
83,
7,
199,
7307,
275,
399,
7,
8128,
13,
10680,
12,
20232,
491,
285,
2723,
12,
10844,
14,
741,
3530,
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,
4887,
83,
855,
1023,
363,
199,
3,
710,
2615,
1015,
12,
5893,
5131,
15,
5683,
15,
1195,
3762,
14,
199,
3221,
275,
4887,
83,
855,
1023,
363,
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,
3671,
275,
488,
199,
199,
3,
6006,
787,
2877,
1511,
367,
15810,
1204,
8136,
25004,
1902,
12,
1265,
663,
11168,
370,
2005,
199,
3,
2222,
13,
3910,
574,
12,
2066,
652,
365,
1202,
26,
199,
3,
8136,
275,
2125,
199,
3,
19524,
12,
11168,
63,
5045,
365,
1202,
465,
314,
1475,
367,
282,
14053,
1240,
14,
199,
3,
8136,
63,
5045,
275,
1543,
34,
450,
68,
12,
450,
57,
7,
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,
5473,
63,
7435,
275,
4044,
1506,
418,
199,
199,
3,
710,
20883,
849,
4719,
334,
2972,
367,
642,
9189,
26,
658,
505,
10522,
370,
675,
367,
1006,
8247,
14,
199,
3,
885,
63,
3756,
275,
488,
199,
199,
3,
982,
2549,
12,
26380,
911,
506,
11544,
370,
520,
1532,
26,
5423,
14,
8059,
13,
4443,
1318,
14,
199,
3,
525,
63,
1593,
63,
25510,
275,
715,
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,
3,
525,
63,
578,
63,
1247,
275,
715,
199,
199,
3,
982,
2549,
12,
3420,
2502,
436,
28966,
13502,
911,
506,
9164,
315,
314,
199,
3,
1072,
14,
9322,
787,
5525,
701,
849,
14,
199,
3,
2384,
63,
8149,
275,
756,
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,
437,
769,
402,
5525,
13158,
367,
859,
1478,
13351,
14,
199,
3,
27555,
63,
2330,
63,
1861,
275,
942,
421,
199,
3,
1553,
8394,
367,
4163,
1072,
9527,
2595,
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,
1360,
63,
7915,
275,
283,
885,
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,
1360,
63,
7915,
63,
1419,
275,
1052,
199,
199,
3,
2654,
1263,
3792,
626,
1395,
3537,
17915,
2348,
12,
3847,
370,
642,
2082,
14,
199,
3,
1360,
63,
7915,
63,
515,
275,
942,
199,
199,
3,
710,
536,
367,
642,
663,
402,
10229,
8247,
14,
221,
982,
488,
12,
652,
4243,
370,
199,
3,
3886,
1715,
30,
373,
28,
3221,
30,
3794,
1674,
199,
3,
1360,
63,
1213,
275,
488,
199,
199,
3,
437,
18299,
2538,
367,
314,
19191,
4681,
14,
221,
3758,
365,
314,
2011,
465,
3517,
63,
1213,
14,
199,
3,
1360,
63,
3612,
63,
1213,
275,
488,
199,
199,
3,
710,
536,
402,
376,
1834,
570,
334,
6188,
370,
642,
2082,
9,
370,
4192,
737,
314,
2746,
199,
3,
402,
314,
18437,
14,
199,
3,
1360,
63,
9733,
275,
488,
199,
199,
3,
710,
536,
402,
376,
1834,
570,
334,
12541,
314,
2955,
931,
9,
370,
675,
465,
29139,
402,
314,
199,
3,
9149,
14,
221,
961,
570,
1077,
506,
282,
5417,
7016,
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,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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
] |
Khan/gae_bingo
|
cache.py
|
1
|
15801
|
import logging
import pickle
import random
from google.appengine.ext import db
from google.appengine.ext import deferred
from google.appengine.api import memcache
from google.appengine.datastore import entity_pb
from google.appengine.ext.webapp import RequestHandler
from .models import _GAEBingoExperiment, _GAEBingoAlternative, _GAEBingoIdentityRecord, _GAEBingoSnapshotLog
from identity import identity
# gae_bingo relies on the deferred library,
# and as such it is susceptible to the same path manipulation weaknesses explained here:
# http://stackoverflow.com/questions/2502215/permanenttaskfailure-in-appengine-deferred-library
#
# ...if you need to run one-time configuration or path manipulation code when an instance
# is started, you may need to add that code to this file as this file will become
# a possibly instance-starting entry point. See docs and above Stack Oveflow question.
#
# Example: import config_django
# REQUEST_CACHE is cleared before and after every requests by gae_bingo.middleware.
# NOTE: this request caching will need a bit of a touchup once Python 2.7 is released for GAE and concurrent requests are enabled.
REQUEST_CACHE = {}
def flush_request_cache():
global REQUEST_CACHE
REQUEST_CACHE = {}
def init_request_cache_from_memcache():
global REQUEST_CACHE
if not REQUEST_CACHE.get("loaded_from_memcache"):
REQUEST_CACHE = memcache.get_multi([BingoCache.MEMCACHE_KEY, BingoIdentityCache.key_for_identity(identity())])
REQUEST_CACHE["loaded_from_memcache"] = True
class BingoCache(object):
MEMCACHE_KEY = "_gae_bingo_cache"
@staticmethod
def get():
init_request_cache_from_memcache()
if not REQUEST_CACHE.get(BingoCache.MEMCACHE_KEY):
REQUEST_CACHE[BingoCache.MEMCACHE_KEY] = BingoCache.load_from_datastore()
return REQUEST_CACHE[BingoCache.MEMCACHE_KEY]
def __init__(self):
self.dirty = False
self.experiments = {} # Protobuf version of experiments for extremely fast (de)serialization
self.experiment_models = {} # Deserialized experiment models
self.alternatives = {} # Protobuf version of alternatives for extremely fast (de)serialization
self.alternative_models = {} # Deserialized alternative models
self.experiment_names_by_conversion_name = {} # Mapping of conversion names to experiment names
self.experiment_names_by_canonical_name = {} # Mapping of canonical names to experiment names
def store_if_dirty(self):
# Only write to memcache if a change has been made
if not self.dirty:
return
# Wipe out deserialized models before serialization for speed
self.experiment_models = {}
self.alternative_models = {}
# No longer dirty
self.dirty = False
memcache.set(BingoCache.MEMCACHE_KEY, self)
def persist_to_datastore(self):
# Persist current state of experiment and alternative models to datastore.
# Their sums might be slightly out-of-date during any given persist, but not by much.
for experiment_name in self.experiments:
experiment_model = self.get_experiment(experiment_name)
if experiment_model:
experiment_model.put()
for experiment_name in self.alternatives:
alternative_models = self.get_alternatives(experiment_name)
for alternative_model in alternative_models:
# When persisting to datastore, we want to store the most recent value we've got
alternative_model.load_latest_counts()
alternative_model.put()
def log_cache_snapshot(self):
# Log current data on live experiments to the datastore
log_entries = []
for experiment_name in self.experiments:
experiment_model = self.get_experiment(experiment_name)
if experiment_model and experiment_model.live:
log_entries += self.log_experiment_snapshot(experiment_model)
db.put(log_entries)
def log_experiment_snapshot(self, experiment_model):
log_entries = []
alternative_models = self.get_alternatives(experiment_model.name)
for alternative_model in alternative_models:
# When logging, we want to store the most recent value we've got
alternative_model.load_latest_counts()
log_entry = _GAEBingoSnapshotLog(parent=experiment_model, alternative_number=alternative_model.number, conversions=alternative_model.conversions, participants=alternative_model.participants)
log_entries.append(log_entry)
return log_entries
@staticmethod
def load_from_datastore():
# This shouldn't happen often (should only happen when memcache has been completely evicted),
# but we still want to be as fast as possible.
bingo_cache = BingoCache()
experiment_dict = {}
alternatives_dict = {}
# Kick both of these off w/ run() so they'll prefetch asynchronously
experiments = _GAEBingoExperiment.all().run()
alternatives = _GAEBingoAlternative.all().order("number").run()
for experiment in experiments:
experiment_dict[experiment.name] = experiment
for alternative in alternatives:
if alternative.experiment_name not in alternatives_dict:
alternatives_dict[alternative.experiment_name] = []
alternatives_dict[alternative.experiment_name].append(alternative)
for experiment_name in experiment_dict:
bingo_cache.add_experiment(experiment_dict.get(experiment_name), alternatives_dict.get(experiment_name))
# Immediately store in memcache as soon as possible after loading from datastore to minimize # of datastore loads
bingo_cache.store_if_dirty()
return bingo_cache
def add_experiment(self, experiment, alternatives):
if not experiment or not alternatives:
raise Exception("Cannot add empty experiment or empty alternatives to BingoCache")
self.experiment_models[experiment.name] = experiment
self.experiments[experiment.name] = db.model_to_protobuf(experiment).Encode()
if not experiment.conversion_name in self.experiment_names_by_conversion_name:
self.experiment_names_by_conversion_name[experiment.conversion_name] = []
self.experiment_names_by_conversion_name[experiment.conversion_name].append(experiment.name)
if not experiment.canonical_name in self.experiment_names_by_canonical_name:
self.experiment_names_by_canonical_name[experiment.canonical_name] = []
self.experiment_names_by_canonical_name[experiment.canonical_name].append(experiment.name)
for alternative in alternatives:
self.update_alternative(alternative)
self.dirty = True
def update_experiment(self, experiment):
self.experiment_models[experiment.name] = experiment
self.experiments[experiment.name] = db.model_to_protobuf(experiment).Encode()
self.dirty = True
def update_alternative(self, alternative):
if not alternative.experiment_name in self.alternatives:
self.alternatives[alternative.experiment_name] = {}
self.alternatives[alternative.experiment_name][alternative.number] = db.model_to_protobuf(alternative).Encode()
# Clear out alternative models cache so they'll be re-grabbed w/ next .get_alternatives
if alternative.experiment_name in self.alternative_models:
del self.alternative_models[alternative.experiment_name]
self.dirty = True
def delete_experiment_and_alternatives(self, experiment):
if not experiment:
return
# First delete from datastore
experiment.delete()
for alternative in self.get_alternatives(experiment.name):
alternative.reset_counts()
alternative.delete()
# Remove from current cache
if experiment.name in self.experiments:
del self.experiments[experiment.name]
if experiment.name in self.experiment_models:
del self.experiment_models[experiment.name]
if experiment.name in self.alternatives:
del self.alternatives[experiment.name]
if experiment.name in self.alternative_models:
del self.alternative_models[experiment.name]
if experiment.conversion_name in self.experiment_names_by_conversion_name:
self.experiment_names_by_conversion_name[experiment.conversion_name].remove(experiment.name)
if experiment.canonical_name in self.experiment_names_by_canonical_name:
self.experiment_names_by_canonical_name[experiment.canonical_name].remove(experiment.name)
self.dirty = True
# Immediately store in memcache as soon as possible after deleting from datastore
self.store_if_dirty()
def experiments_and_alternatives_from_canonical_name(self, canonical_name):
experiment_names = self.get_experiment_names_by_canonical_name(canonical_name)
return [self.get_experiment(experiment_name) for experiment_name in experiment_names], \
[self.get_alternatives(experiment_name) for experiment_name in experiment_names]
def get_experiment(self, experiment_name):
if experiment_name not in self.experiment_models:
if experiment_name in self.experiments:
self.experiment_models[experiment_name] = db.model_from_protobuf(entity_pb.EntityProto(self.experiments[experiment_name]))
return self.experiment_models.get(experiment_name)
def get_alternatives(self, experiment_name):
if experiment_name not in self.alternative_models:
if experiment_name in self.alternatives:
self.alternative_models[experiment_name] = []
for alternative_number in self.alternatives[experiment_name]:
self.alternative_models[experiment_name].append(db.model_from_protobuf(entity_pb.EntityProto(self.alternatives[experiment_name][alternative_number])))
return self.alternative_models.get(experiment_name) or []
def get_experiment_names_by_conversion_name(self, conversion_name):
return self.experiment_names_by_conversion_name.get(conversion_name) or []
def get_experiment_names_by_canonical_name(self, canonical_name):
return self.experiment_names_by_canonical_name.get(canonical_name) or []
class BingoIdentityCache(object):
MEMCACHE_KEY = "_gae_bingo_identity_cache:%s"
@staticmethod
def key_for_identity(ident):
return BingoIdentityCache.MEMCACHE_KEY % ident
@staticmethod
def get():
init_request_cache_from_memcache()
key = BingoIdentityCache.key_for_identity(identity())
if not REQUEST_CACHE.get(key):
REQUEST_CACHE[key] = BingoIdentityCache.load_from_datastore()
return REQUEST_CACHE[key]
def store_for_identity_if_dirty(self, ident):
if not self.dirty:
return
# No longer dirty
self.dirty = False
memcache.set(BingoIdentityCache.key_for_identity(ident), self)
# Always fire off a task queue to persist bingo identity cache
# since there's no cron job persisting these objects like BingoCache.
self.persist_to_datastore(ident)
def persist_to_datastore(self, ident):
# Add the memcache value to a random memcache bucket which
# will be persisted to the datastore when it overflows
# or when the periodic cron job is run
bucket = random.randint(0, 50)
key = "_gae_bingo_identity_bucket:%s" % bucket
list_identities = memcache.get(key) or []
list_identities.append(ident)
if len(list_identities) > 50:
# If over 50 identities are waiting for persistent storage,
# go ahead and kick off a deferred task to do so
# in case it'll be a while before the cron job runs.
deferred.defer(persist_gae_bingo_identity_records, list_identities)
# There are race conditions here such that we could miss persistence
# of some identities, but that's not a big deal as long as
# there is no statistical correlation b/w the experiment and those
# being lost.
memcache.set(key, [])
else:
memcache.set(key, list_identities)
@staticmethod
def persist_buckets_to_datastore():
# Persist all memcache buckets to datastore
dict_buckets = memcache.get_multi(["_gae_bingo_identity_bucket:%s" % bucket for bucket in range(0, 50)])
for key in dict_buckets:
if len(dict_buckets[key]) > 0:
deferred.defer(persist_gae_bingo_identity_records, dict_buckets[key])
memcache.set(key, [])
@staticmethod
def load_from_datastore():
bingo_identity_cache = _GAEBingoIdentityRecord.load(identity())
if bingo_identity_cache:
bingo_identity_cache.purge()
bingo_identity_cache.dirty = True
bingo_identity_cache.store_for_identity_if_dirty(identity())
else:
bingo_identity_cache = BingoIdentityCache()
return bingo_identity_cache
def __init__(self):
self.dirty = False
self.participating_tests = [] # List of test names currently participating in
self.converted_tests = {} # Dict of test names:number of times user has successfully converted
def purge(self):
bingo_cache = BingoCache.get()
for participating_test in self.participating_tests:
if not participating_test in bingo_cache.experiments:
self.participating_tests.remove(participating_test)
for converted_test in self.converted_tests.keys():
if not converted_test in bingo_cache.experiments:
del self.converted_tests[converted_test]
def participate_in(self, experiment_name):
self.participating_tests.append(experiment_name)
self.dirty = True
def convert_in(self, experiment_name):
self.converted_tests[experiment_name] = 1
self.dirty = True
def bingo_and_identity_cache():
return BingoCache.get(), BingoIdentityCache.get()
def store_if_dirty():
# Only load from request cache here -- if it hasn't been loaded from memcache previously, it's not dirty.
bingo_cache = REQUEST_CACHE.get(BingoCache.MEMCACHE_KEY)
bingo_identity_cache = REQUEST_CACHE.get(BingoIdentityCache.key_for_identity(identity()))
if bingo_cache:
bingo_cache.store_if_dirty()
if bingo_identity_cache:
bingo_identity_cache.store_for_identity_if_dirty(identity())
def persist_gae_bingo_identity_records(list_identities):
dict_identity_caches = memcache.get_multi([BingoIdentityCache.key_for_identity(ident) for ident in list_identities])
for ident in list_identities:
identity_cache = dict_identity_caches.get(BingoIdentityCache.key_for_identity(ident))
if identity_cache:
bingo_identity = _GAEBingoIdentityRecord(
key_name = _GAEBingoIdentityRecord.key_for_identity(ident),
identity = ident,
pickled = pickle.dumps(identity_cache),
)
bingo_identity.put()
class PersistToDatastore(RequestHandler):
def get(self):
BingoCache.get().persist_to_datastore()
BingoIdentityCache.persist_buckets_to_datastore()
class LogSnapshotToDatastore(RequestHandler):
def get(self):
BingoCache.get().log_cache_snapshot()
|
mit
|
[
646,
2050,
199,
646,
5927,
199,
646,
2196,
199,
199,
504,
6233,
14,
15358,
14,
832,
492,
1592,
199,
504,
6233,
14,
15358,
14,
832,
492,
12309,
199,
504,
6233,
14,
15358,
14,
1246,
492,
21598,
199,
504,
6233,
14,
15358,
14,
11450,
492,
4642,
63,
3317,
199,
504,
6233,
14,
15358,
14,
832,
14,
22632,
492,
4784,
2461,
199,
199,
504,
1275,
992,
492,
485,
9741,
14138,
316,
79,
20781,
12,
485,
9741,
14138,
316,
79,
19978,
1905,
12,
485,
9741,
14138,
316,
79,
10193,
5433,
12,
485,
9741,
14138,
316,
79,
12038,
2445,
199,
504,
8503,
492,
8503,
199,
199,
3,
486,
3624,
63,
10911,
79,
25749,
641,
314,
12309,
3555,
12,
199,
3,
436,
465,
4066,
652,
365,
308,
527,
28448,
21602,
370,
314,
2011,
931,
26212,
9282,
17775,
874,
1437,
23918,
2348,
26,
199,
3,
1455,
921,
23153,
14,
957,
15,
16069,
15,
27874,
7842,
15,
19904,
1765,
5328,
13,
262,
13,
15358,
13,
12116,
13,
4342,
199,
3,
199,
3,
2263,
692,
1265,
1929,
370,
1255,
1373,
13,
521,
2897,
503,
931,
26212,
1233,
1380,
376,
1256,
199,
3,
365,
8239,
12,
1265,
1443,
1929,
370,
1050,
626,
1233,
370,
642,
570,
465,
642,
570,
911,
8649,
199,
3,
282,
12570,
1256,
13,
15769,
2397,
2376,
14,
1666,
9149,
436,
3432,
13894,
593,
432,
1659,
7894,
14,
199,
3,
199,
3,
5679,
26,
492,
1101,
63,
1176,
199,
199,
3,
31325,
63,
8677,
365,
20518,
2544,
436,
2410,
4036,
4145,
701,
486,
3624,
63,
10911,
79,
14,
5754,
14,
199,
3,
6944,
26,
642,
1056,
13627,
911,
1929,
282,
4546,
402,
282,
12943,
384,
5403,
2018,
499,
14,
23,
365,
14286,
367,
598,
12500,
436,
23002,
4145,
787,
5223,
14,
199,
6780,
63,
8677,
275,
1052,
199,
199,
318,
8976,
63,
1069,
63,
1637,
837,
272,
2288,
31325,
63,
8677,
272,
31325,
63,
8677,
275,
1052,
199,
199,
318,
4205,
63,
1069,
63,
1637,
63,
504,
63,
25835,
837,
272,
2288,
31325,
63,
8677,
339,
340,
440,
31325,
63,
8677,
14,
362,
480,
4591,
63,
504,
63,
25835,
2349,
267,
31325,
63,
8677,
275,
21598,
14,
362,
63,
3029,
779,
34,
316,
79,
4437,
14,
10293,
8677,
63,
3078,
12,
699,
316,
79,
10193,
4437,
14,
498,
63,
509,
63,
5582,
8,
5582,
30719,
267,
31325,
63,
8677,
905,
4591,
63,
504,
63,
25835,
937,
275,
715,
199,
199,
533,
699,
316,
79,
4437,
8,
785,
304,
339,
31424,
8677,
63,
3078,
275,
2668,
71,
3624,
63,
10911,
79,
63,
1637,
2,
339,
768,
4639,
272,
347,
664,
837,
267,
4205,
63,
1069,
63,
1637,
63,
504,
63,
25835,
342,
398,
340,
440,
31325,
63,
8677,
14,
362,
8,
34,
316,
79,
4437,
14,
10293,
8677,
63,
3078,
304,
288,
31325,
63,
8677,
59,
34,
316,
79,
4437,
14,
10293,
8677,
63,
3078,
61,
275,
699,
316,
79,
4437,
14,
912,
63,
504,
63,
11450,
342,
398,
372,
31325,
63,
8677,
59,
34,
316,
79,
4437,
14,
10293,
8677,
63,
3078,
61,
339,
347,
636,
826,
721,
277,
304,
267,
291,
14,
8799,
275,
756,
398,
291,
14,
476,
22263,
275,
1052,
327,
2165,
475,
1436,
1015,
402,
444,
22263,
367,
30503,
590,
7377,
334,
271,
9,
12161,
267,
291,
14,
10873,
63,
992,
275,
1052,
327,
1487,
8397,
11805,
1709,
398,
291,
14,
27584,
275,
1052,
327,
2165,
475,
1436,
1015,
402,
8679,
10661,
367,
30503,
590,
7377,
334,
271,
9,
12161,
267,
291,
14,
19389,
63,
992,
275,
1052,
327,
1487,
8397,
13943,
1709,
398,
291,
14,
10873,
63,
1247,
63,
991,
63,
15083,
63,
354,
275,
1052,
327,
12340,
402,
8603,
1561,
370,
11805,
1561,
267,
291,
14,
10873,
63,
1247,
63,
991,
63,
13109,
63,
354,
275,
1052,
327,
12340,
402,
11358,
1561,
370,
11805,
1561,
339,
347,
3877,
63,
692,
63,
8799,
8,
277,
304,
398,
327,
5972,
2218,
370,
21598,
340,
282,
1570,
965,
2757,
6326,
267,
340,
440,
291,
14,
8799,
26,
288,
372,
398,
327,
644,
3662,
734,
13256,
1709,
2544,
16953,
367,
8112,
267,
291,
14,
10873,
63,
992,
275,
1052,
267,
291,
14,
19389,
63,
992,
275,
1052,
398,
327,
3091,
8088,
14650,
267,
291,
14,
8799,
275,
756,
398,
21598,
14,
409,
8,
34,
316,
79,
4437,
14,
10293,
8677,
63,
3078,
12,
291,
9,
339,
347,
22400,
63,
475,
63,
11450,
8,
277,
304,
398,
327,
3492,
11734,
1453,
1174,
402,
11805,
436,
13943,
1709,
370,
12007,
14,
267,
327,
710,
723,
27690,
5594,
506,
18023,
734,
13,
1618,
13,
602,
5309,
1263,
1627,
22400,
12,
1325,
440,
701,
8298,
14,
267,
367,
11805,
63,
354,
315,
291,
14,
476,
22263,
26,
288,
11805,
63,
1238,
275,
291,
14,
362,
63,
10873,
8,
10873,
63,
354,
9,
288,
340,
11805,
63,
1238,
26,
355,
11805,
63,
1238,
14,
524,
342,
398,
367,
11805,
63,
354,
315,
291,
14,
27584,
26,
288,
13943,
63,
992,
275,
291,
14,
362,
63,
27584,
8,
10873,
63,
354,
9,
288,
367,
13943,
63,
1238,
315,
13943,
63,
992,
26,
355,
327,
3979,
22400,
316,
370,
12007,
12,
781,
2934,
370,
3877,
314,
4750,
8058,
574,
781,
9064,
4788,
355,
13943,
63,
1238,
14,
912,
63,
7410,
63,
6851,
342,
355,
13943,
63,
1238,
14,
524,
342,
339,
347,
943,
63,
1637,
63,
4753,
8,
277,
304,
398,
327,
5297,
1453,
666,
641,
12166,
444,
22263,
370,
314,
12007,
267,
943,
63,
3189,
275,
942,
398,
367,
11805,
63,
354,
315,
291,
14,
476,
22263,
26,
288,
11805,
63,
1238,
275,
291,
14,
362,
63,
10873,
8,
10873,
63,
354,
9,
288,
340,
11805,
63,
1238,
436,
11805,
63,
1238,
14,
6442,
26,
355,
943,
63,
3189,
847,
291,
14,
793,
63,
10873,
63,
4753,
8,
10873,
63,
1238,
9,
398,
1592,
14,
524,
8,
793,
63,
3189,
9,
15567,
347,
943,
63,
10873,
63,
4753,
8,
277,
12,
11805,
63,
1238,
304,
398,
943,
63,
3189,
275,
942,
2728,
13943,
63,
992,
275,
291,
14,
362,
63,
27584,
8,
10873,
63,
1238,
14,
354,
9,
267,
367,
13943,
63,
1238,
315,
13943,
63,
992,
26,
288,
327,
3979,
2050,
12,
781,
2934,
370,
3877,
314,
4750,
8058,
574,
781,
9064,
4788
] |
[
2050,
199,
646,
5927,
199,
646,
2196,
199,
199,
504,
6233,
14,
15358,
14,
832,
492,
1592,
199,
504,
6233,
14,
15358,
14,
832,
492,
12309,
199,
504,
6233,
14,
15358,
14,
1246,
492,
21598,
199,
504,
6233,
14,
15358,
14,
11450,
492,
4642,
63,
3317,
199,
504,
6233,
14,
15358,
14,
832,
14,
22632,
492,
4784,
2461,
199,
199,
504,
1275,
992,
492,
485,
9741,
14138,
316,
79,
20781,
12,
485,
9741,
14138,
316,
79,
19978,
1905,
12,
485,
9741,
14138,
316,
79,
10193,
5433,
12,
485,
9741,
14138,
316,
79,
12038,
2445,
199,
504,
8503,
492,
8503,
199,
199,
3,
486,
3624,
63,
10911,
79,
25749,
641,
314,
12309,
3555,
12,
199,
3,
436,
465,
4066,
652,
365,
308,
527,
28448,
21602,
370,
314,
2011,
931,
26212,
9282,
17775,
874,
1437,
23918,
2348,
26,
199,
3,
1455,
921,
23153,
14,
957,
15,
16069,
15,
27874,
7842,
15,
19904,
1765,
5328,
13,
262,
13,
15358,
13,
12116,
13,
4342,
199,
3,
199,
3,
2263,
692,
1265,
1929,
370,
1255,
1373,
13,
521,
2897,
503,
931,
26212,
1233,
1380,
376,
1256,
199,
3,
365,
8239,
12,
1265,
1443,
1929,
370,
1050,
626,
1233,
370,
642,
570,
465,
642,
570,
911,
8649,
199,
3,
282,
12570,
1256,
13,
15769,
2397,
2376,
14,
1666,
9149,
436,
3432,
13894,
593,
432,
1659,
7894,
14,
199,
3,
199,
3,
5679,
26,
492,
1101,
63,
1176,
199,
199,
3,
31325,
63,
8677,
365,
20518,
2544,
436,
2410,
4036,
4145,
701,
486,
3624,
63,
10911,
79,
14,
5754,
14,
199,
3,
6944,
26,
642,
1056,
13627,
911,
1929,
282,
4546,
402,
282,
12943,
384,
5403,
2018,
499,
14,
23,
365,
14286,
367,
598,
12500,
436,
23002,
4145,
787,
5223,
14,
199,
6780,
63,
8677,
275,
1052,
199,
199,
318,
8976,
63,
1069,
63,
1637,
837,
272,
2288,
31325,
63,
8677,
272,
31325,
63,
8677,
275,
1052,
199,
199,
318,
4205,
63,
1069,
63,
1637,
63,
504,
63,
25835,
837,
272,
2288,
31325,
63,
8677,
339,
340,
440,
31325,
63,
8677,
14,
362,
480,
4591,
63,
504,
63,
25835,
2349,
267,
31325,
63,
8677,
275,
21598,
14,
362,
63,
3029,
779,
34,
316,
79,
4437,
14,
10293,
8677,
63,
3078,
12,
699,
316,
79,
10193,
4437,
14,
498,
63,
509,
63,
5582,
8,
5582,
30719,
267,
31325,
63,
8677,
905,
4591,
63,
504,
63,
25835,
937,
275,
715,
199,
199,
533,
699,
316,
79,
4437,
8,
785,
304,
339,
31424,
8677,
63,
3078,
275,
2668,
71,
3624,
63,
10911,
79,
63,
1637,
2,
339,
768,
4639,
272,
347,
664,
837,
267,
4205,
63,
1069,
63,
1637,
63,
504,
63,
25835,
342,
398,
340,
440,
31325,
63,
8677,
14,
362,
8,
34,
316,
79,
4437,
14,
10293,
8677,
63,
3078,
304,
288,
31325,
63,
8677,
59,
34,
316,
79,
4437,
14,
10293,
8677,
63,
3078,
61,
275,
699,
316,
79,
4437,
14,
912,
63,
504,
63,
11450,
342,
398,
372,
31325,
63,
8677,
59,
34,
316,
79,
4437,
14,
10293,
8677,
63,
3078,
61,
339,
347,
636,
826,
721,
277,
304,
267,
291,
14,
8799,
275,
756,
398,
291,
14,
476,
22263,
275,
1052,
327,
2165,
475,
1436,
1015,
402,
444,
22263,
367,
30503,
590,
7377,
334,
271,
9,
12161,
267,
291,
14,
10873,
63,
992,
275,
1052,
327,
1487,
8397,
11805,
1709,
398,
291,
14,
27584,
275,
1052,
327,
2165,
475,
1436,
1015,
402,
8679,
10661,
367,
30503,
590,
7377,
334,
271,
9,
12161,
267,
291,
14,
19389,
63,
992,
275,
1052,
327,
1487,
8397,
13943,
1709,
398,
291,
14,
10873,
63,
1247,
63,
991,
63,
15083,
63,
354,
275,
1052,
327,
12340,
402,
8603,
1561,
370,
11805,
1561,
267,
291,
14,
10873,
63,
1247,
63,
991,
63,
13109,
63,
354,
275,
1052,
327,
12340,
402,
11358,
1561,
370,
11805,
1561,
339,
347,
3877,
63,
692,
63,
8799,
8,
277,
304,
398,
327,
5972,
2218,
370,
21598,
340,
282,
1570,
965,
2757,
6326,
267,
340,
440,
291,
14,
8799,
26,
288,
372,
398,
327,
644,
3662,
734,
13256,
1709,
2544,
16953,
367,
8112,
267,
291,
14,
10873,
63,
992,
275,
1052,
267,
291,
14,
19389,
63,
992,
275,
1052,
398,
327,
3091,
8088,
14650,
267,
291,
14,
8799,
275,
756,
398,
21598,
14,
409,
8,
34,
316,
79,
4437,
14,
10293,
8677,
63,
3078,
12,
291,
9,
339,
347,
22400,
63,
475,
63,
11450,
8,
277,
304,
398,
327,
3492,
11734,
1453,
1174,
402,
11805,
436,
13943,
1709,
370,
12007,
14,
267,
327,
710,
723,
27690,
5594,
506,
18023,
734,
13,
1618,
13,
602,
5309,
1263,
1627,
22400,
12,
1325,
440,
701,
8298,
14,
267,
367,
11805,
63,
354,
315,
291,
14,
476,
22263,
26,
288,
11805,
63,
1238,
275,
291,
14,
362,
63,
10873,
8,
10873,
63,
354,
9,
288,
340,
11805,
63,
1238,
26,
355,
11805,
63,
1238,
14,
524,
342,
398,
367,
11805,
63,
354,
315,
291,
14,
27584,
26,
288,
13943,
63,
992,
275,
291,
14,
362,
63,
27584,
8,
10873,
63,
354,
9,
288,
367,
13943,
63,
1238,
315,
13943,
63,
992,
26,
355,
327,
3979,
22400,
316,
370,
12007,
12,
781,
2934,
370,
3877,
314,
4750,
8058,
574,
781,
9064,
4788,
355,
13943,
63,
1238,
14,
912,
63,
7410,
63,
6851,
342,
355,
13943,
63,
1238,
14,
524,
342,
339,
347,
943,
63,
1637,
63,
4753,
8,
277,
304,
398,
327,
5297,
1453,
666,
641,
12166,
444,
22263,
370,
314,
12007,
267,
943,
63,
3189,
275,
942,
398,
367,
11805,
63,
354,
315,
291,
14,
476,
22263,
26,
288,
11805,
63,
1238,
275,
291,
14,
362,
63,
10873,
8,
10873,
63,
354,
9,
288,
340,
11805,
63,
1238,
436,
11805,
63,
1238,
14,
6442,
26,
355,
943,
63,
3189,
847,
291,
14,
793,
63,
10873,
63,
4753,
8,
10873,
63,
1238,
9,
398,
1592,
14,
524,
8,
793,
63,
3189,
9,
15567,
347,
943,
63,
10873,
63,
4753,
8,
277,
12,
11805,
63,
1238,
304,
398,
943,
63,
3189,
275,
942,
2728,
13943,
63,
992,
275,
291,
14,
362,
63,
27584,
8,
10873,
63,
1238,
14,
354,
9,
267,
367,
13943,
63,
1238,
315,
13943,
63,
992,
26,
288,
327,
3979,
2050,
12,
781,
2934,
370,
3877,
314,
4750,
8058,
574,
781,
9064,
4788,
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,
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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
] |
MSOpenTech/edx-platform
|
lms/djangoapps/shoppingcart/migrations/0004_auto__add_field_orderitem_fulfilled_time.py
|
114
|
8621
|
# -*- 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 field 'OrderItem.fulfilled_time'
db.add_column('shoppingcart_orderitem', 'fulfilled_time',
self.gf('django.db.models.fields.DateTimeField')(null=True),
keep_default=False)
def backwards(self, orm):
# Deleting field 'OrderItem.fulfilled_time'
db.delete_column('shoppingcart_orderitem', 'fulfilled_time')
models = {
'auth.group': {
'Meta': {'object_name': 'Group'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
},
'auth.permission': {
'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
},
'auth.user': {
'Meta': {'object_name': 'User'},
'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
},
'contenttypes.contenttype': {
'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
},
'shoppingcart.certificateitem': {
'Meta': {'object_name': 'CertificateItem', '_ormbases': ['shoppingcart.OrderItem']},
'course_enrollment': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['student.CourseEnrollment']"}),
'course_id': ('django.db.models.fields.CharField', [], {'max_length': '128', 'db_index': 'True'}),
'mode': ('django.db.models.fields.SlugField', [], {'max_length': '50'}),
'orderitem_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['shoppingcart.OrderItem']", 'unique': 'True', 'primary_key': 'True'})
},
'shoppingcart.order': {
'Meta': {'object_name': 'Order'},
'bill_to_cardtype': ('django.db.models.fields.CharField', [], {'max_length': '32', 'blank': 'True'}),
'bill_to_ccnum': ('django.db.models.fields.CharField', [], {'max_length': '8', 'blank': 'True'}),
'bill_to_city': ('django.db.models.fields.CharField', [], {'max_length': '64', 'blank': 'True'}),
'bill_to_country': ('django.db.models.fields.CharField', [], {'max_length': '64', 'blank': 'True'}),
'bill_to_first': ('django.db.models.fields.CharField', [], {'max_length': '64', 'blank': 'True'}),
'bill_to_last': ('django.db.models.fields.CharField', [], {'max_length': '64', 'blank': 'True'}),
'bill_to_postalcode': ('django.db.models.fields.CharField', [], {'max_length': '16', 'blank': 'True'}),
'bill_to_state': ('django.db.models.fields.CharField', [], {'max_length': '8', 'blank': 'True'}),
'bill_to_street1': ('django.db.models.fields.CharField', [], {'max_length': '128', 'blank': 'True'}),
'bill_to_street2': ('django.db.models.fields.CharField', [], {'max_length': '128', 'blank': 'True'}),
'currency': ('django.db.models.fields.CharField', [], {'default': "'usd'", 'max_length': '8'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'processor_reply_dump': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'purchase_time': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
'status': ('django.db.models.fields.CharField', [], {'default': "'cart'", 'max_length': '32'}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"})
},
'shoppingcart.orderitem': {
'Meta': {'object_name': 'OrderItem'},
'currency': ('django.db.models.fields.CharField', [], {'default': "'usd'", 'max_length': '8'}),
'fulfilled_time': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'line_desc': ('django.db.models.fields.CharField', [], {'default': "'Misc. Item'", 'max_length': '1024'}),
'order': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['shoppingcart.Order']"}),
'qty': ('django.db.models.fields.IntegerField', [], {'default': '1'}),
'status': ('django.db.models.fields.CharField', [], {'default': "'cart'", 'max_length': '32'}),
'unit_cost': ('django.db.models.fields.DecimalField', [], {'default': '0.0', 'max_digits': '30', 'decimal_places': '2'}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"})
},
'shoppingcart.paidcourseregistration': {
'Meta': {'object_name': 'PaidCourseRegistration', '_ormbases': ['shoppingcart.OrderItem']},
'course_id': ('django.db.models.fields.CharField', [], {'max_length': '128', 'db_index': 'True'}),
'mode': ('django.db.models.fields.SlugField', [], {'default': "'honor'", 'max_length': '50'}),
'orderitem_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['shoppingcart.OrderItem']", 'unique': 'True', 'primary_key': 'True'})
},
'student.courseenrollment': {
'Meta': {'ordering': "('user', 'course_id')", 'unique_together': "(('user', 'course_id'),)", 'object_name': 'CourseEnrollment'},
'course_id': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'null': 'True', 'db_index': 'True', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
'mode': ('django.db.models.fields.CharField', [], {'default': "'honor'", 'max_length': '100'}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"})
}
}
complete_apps = ['shoppingcart']
|
agpl-3.0
|
[
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,
901,
283,
4738,
2081,
14,
13499,
276,
14535,
63,
521,
7,
267,
1592,
14,
525,
63,
2301,
360,
17788,
63,
269,
9910,
563,
297,
283,
13499,
276,
14535,
63,
521,
297,
1993,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
7533,
2307,
29,
549,
395,
1993,
4215,
63,
885,
29,
797,
9,
2378,
347,
8552,
8,
277,
12,
9813,
304,
267,
327,
15920,
901,
283,
4738,
2081,
14,
13499,
276,
14535,
63,
521,
7,
267,
1592,
14,
1807,
63,
2301,
360,
17788,
63,
269,
9910,
563,
297,
283,
13499,
276,
14535,
63,
521,
358,
2378,
1709,
275,
469,
267,
283,
1178,
14,
923,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
2448,
2267,
288,
283,
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,
3235,
356,
283,
549,
297,
283,
988,
63,
1267,
356,
283,
1257,
1604,
288,
283,
6060,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
475,
356,
298,
1025,
459,
1178,
14,
7980,
6256,
283,
10247,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
3071,
267,
1660,
267,
283,
1178,
14,
5693,
356,
469,
288,
283,
3396,
356,
791,
7128,
356,
16111,
1317,
63,
466,
363,
571,
63,
1302,
297,
283,
1317,
63,
466,
363,
1238,
297,
283,
11879,
18106,
283,
3235,
63,
6314,
356,
9510,
1317,
63,
466,
297,
283,
11879,
9878,
283,
785,
63,
354,
356,
283,
7980,
2267,
288,
283,
11879,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1960,
1604,
288,
283,
1317,
63,
466,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
475,
356,
298,
1025,
459,
10778,
14,
11282,
6097,
288,
283,
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,
1400,
3071,
267,
1660,
267,
283,
1178,
14,
751,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
1899,
2267,
288,
283,
602,
63,
11806,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
791,
885,
356,
283,
2083,
14,
2083,
14,
2131,
1604,
288,
283,
2123,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
16577,
297,
990,
791,
988,
63,
1267,
356,
283,
2194,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2246,
63,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1216,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2634,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
475,
356,
298,
1025,
459,
1178,
14,
2448,
6256,
283,
10247,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
374,
63,
2682,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
549,
1604,
288,
283,
374,
63,
7018,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
797,
1604,
288,
283,
374,
63,
11434,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
797,
1604,
288,
283,
2019,
63,
2886,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
791,
885,
356,
283,
2083,
14,
2083,
14,
2131,
1604,
288,
283,
2019,
63,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1216,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2060,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
3933,
1604,
288,
283,
751,
63,
6060,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
475,
356,
298,
1025,
459,
1178,
14,
7980,
6256,
283,
10247,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2473,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
3235,
356,
283,
549,
297,
283,
988,
63,
1267,
356,
283,
1216,
3071,
267,
1660,
267,
283,
10778,
14,
20735,
356,
469,
288,
283,
3396,
356,
791,
7128,
356,
16111,
354,
21099,
283,
3235,
63,
6314,
356,
9510,
571,
63,
1302,
297,
283,
1238,
9878,
283,
785,
63,
354,
356,
283,
11282,
297,
283,
697,
63,
1224,
356,
3546,
1176,
63,
1317,
63,
466,
15208,
288,
283,
571,
63,
1302,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1960,
1604,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
1238,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1960,
1604,
288,
283,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1960,
3071,
267,
1660,
267,
283,
17788,
14,
6999,
1053,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
11414,
2081,
297,
2513,
31525,
356,
788,
17788,
14,
4738,
2081,
14949,
288,
283,
1972,
63,
12214,
356,
661,
1176,
14,
697,
14,
992,
14,
955
] |
[
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,
901,
283,
4738,
2081,
14,
13499,
276,
14535,
63,
521,
7,
267,
1592,
14,
525,
63,
2301,
360,
17788,
63,
269,
9910,
563,
297,
283,
13499,
276,
14535,
63,
521,
297,
1993,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
7533,
2307,
29,
549,
395,
1993,
4215,
63,
885,
29,
797,
9,
2378,
347,
8552,
8,
277,
12,
9813,
304,
267,
327,
15920,
901,
283,
4738,
2081,
14,
13499,
276,
14535,
63,
521,
7,
267,
1592,
14,
1807,
63,
2301,
360,
17788,
63,
269,
9910,
563,
297,
283,
13499,
276,
14535,
63,
521,
358,
2378,
1709,
275,
469,
267,
283,
1178,
14,
923,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
2448,
2267,
288,
283,
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,
3235,
356,
283,
549,
297,
283,
988,
63,
1267,
356,
283,
1257,
1604,
288,
283,
6060,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
475,
356,
298,
1025,
459,
1178,
14,
7980,
6256,
283,
10247,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
3071,
267,
1660,
267,
283,
1178,
14,
5693,
356,
469,
288,
283,
3396,
356,
791,
7128,
356,
16111,
1317,
63,
466,
363,
571,
63,
1302,
297,
283,
1317,
63,
466,
363,
1238,
297,
283,
11879,
18106,
283,
3235,
63,
6314,
356,
9510,
1317,
63,
466,
297,
283,
11879,
9878,
283,
785,
63,
354,
356,
283,
7980,
2267,
288,
283,
11879,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1960,
1604,
288,
283,
1317,
63,
466,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
475,
356,
298,
1025,
459,
10778,
14,
11282,
6097,
288,
283,
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,
1400,
3071,
267,
1660,
267,
283,
1178,
14,
751,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
1899,
2267,
288,
283,
602,
63,
11806,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
791,
885,
356,
283,
2083,
14,
2083,
14,
2131,
1604,
288,
283,
2123,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
16577,
297,
990,
791,
988,
63,
1267,
356,
283,
2194,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2246,
63,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1216,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2634,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
475,
356,
298,
1025,
459,
1178,
14,
2448,
6256,
283,
10247,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
374,
63,
2682,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
549,
1604,
288,
283,
374,
63,
7018,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
797,
1604,
288,
283,
374,
63,
11434,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
797,
1604,
288,
283,
2019,
63,
2886,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
791,
885,
356,
283,
2083,
14,
2083,
14,
2131,
1604,
288,
283,
2019,
63,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1216,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2060,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
3933,
1604,
288,
283,
751,
63,
6060,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
475,
356,
298,
1025,
459,
1178,
14,
7980,
6256,
283,
10247,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2473,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
3235,
356,
283,
549,
297,
283,
988,
63,
1267,
356,
283,
1216,
3071,
267,
1660,
267,
283,
10778,
14,
20735,
356,
469,
288,
283,
3396,
356,
791,
7128,
356,
16111,
354,
21099,
283,
3235,
63,
6314,
356,
9510,
571,
63,
1302,
297,
283,
1238,
9878,
283,
785,
63,
354,
356,
283,
11282,
297,
283,
697,
63,
1224,
356,
3546,
1176,
63,
1317,
63,
466,
15208,
288,
283,
571,
63,
1302,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1960,
1604,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
1238,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1960,
1604,
288,
283,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1960,
3071,
267,
1660,
267,
283,
17788,
14,
6999,
1053,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
11414,
2081,
297,
2513,
31525,
356,
788,
17788,
14,
4738,
2081,
14949,
288,
283,
1972,
63,
12214,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
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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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
] |
Geoion/AutobahnPython
|
examples/twisted/wamp/app/klein/example2/server.py
|
11
|
2728
|
###############################################################################
#
# The MIT License (MIT)
#
# Copyright (c) Tavendo GmbH
#
# 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, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following 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 MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS 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.
#
###############################################################################
import jinja2
from klein import Klein
from twisted.internet.defer import inlineCallbacks, returnValue
from autobahn.twisted.wamp import Application
# This is our WAMP application
##
wampapp = Application(u'com.example')
@wampapp.register()
def square(x):
print("square() called with {}".format(x))
return x * x
# This is our Web application
##
webapp = Klein()
webapp.visits = 0
webapp.templates = jinja2.Environment(loader=jinja2.FileSystemLoader('templates'))
@webapp.route('/')
def home(request):
webapp.visits += 1
wampapp.session.publish(u'com.example.onvisit', visits=webapp.visits)
page = webapp.templates.get_template('index.html')
return page.render(visits=webapp.visits)
@webapp.route('/square/<int:x>')
@inlineCallbacks
def square(request, x):
result = yield wampapp.session.call(u'com.example.square', x)
page = webapp.templates.get_template('result.html')
content = page.render(x=x, result=result)
returnValue(content)
@webapp.route('/square/submit', methods=['POST'])
def square_submit(request):
x = int(request.args.get('x', [0])[0])
return square(request, x)
if __name__ == "__main__":
import sys
from twisted.python import log
from twisted.web.server import Site
from twisted.internet import reactor
log.startLogging(sys.stdout)
reactor.listenTCP(8080, Site(webapp.resource()))
wampapp.run(u"ws://127.0.0.1:9000", u"realm1", standalone=True)
|
mit
|
[
11490,
199,
3,
199,
3,
710,
10697,
844,
334,
13965,
9,
199,
3,
199,
3,
1898,
334,
67,
9,
377,
1214,
500,
79,
23428,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
1331,
199,
3,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
298,
10337,
1288,
370,
7962,
199,
3,
315,
314,
2290,
1928,
10588,
12,
5893,
1928,
12305,
314,
4481,
199,
3,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
199,
3,
6866,
402,
314,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
2290,
365,
199,
3,
13985,
370,
886,
880,
12,
5420,
370,
314,
2569,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
315,
199,
3,
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,
1549,
199,
3,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
3169,
12,
199,
3,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
7000,
2334,
199,
3,
10610,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
199,
3,
5603,
12,
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,
1621,
199,
3,
2334,
4141,
14,
199,
3,
199,
11490,
199,
199,
646,
10321,
18,
199,
504,
1022,
274,
262,
492,
1804,
274,
262,
199,
199,
504,
7390,
14,
4901,
14,
11610,
492,
8308,
17958,
12,
372,
1110,
199,
504,
2599,
2470,
6164,
14,
12145,
14,
758,
311,
492,
13515,
421,
199,
3,
961,
365,
4154,
644,
7089,
4223,
199,
309,
199,
758,
311,
571,
275,
13515,
8,
85,
7,
957,
14,
2694,
358,
421,
199,
32,
758,
311,
571,
14,
2683,
342,
199,
318,
12386,
8,
88,
304,
272,
870,
480,
9646,
342,
2797,
543,
8352,
908,
8,
88,
430,
272,
372,
671,
627,
671,
421,
199,
3,
961,
365,
4154,
6001,
4223,
199,
309,
199,
22632,
275,
1804,
274,
262,
342,
199,
22632,
14,
433,
30066,
275,
378,
199,
22632,
14,
5876,
275,
10321,
18,
14,
8263,
8,
3422,
29,
12264,
18,
14,
17521,
5455,
360,
5876,
1333,
421,
199,
32,
22632,
14,
4449,
7825,
199,
318,
5629,
8,
1069,
304,
272,
24812,
14,
433,
30066,
847,
413,
272,
336,
5282,
571,
14,
1730,
14,
4763,
8,
85,
7,
957,
14,
2694,
14,
265,
5427,
297,
1321,
30066,
29,
22632,
14,
433,
30066,
9,
272,
2034,
275,
24812,
14,
5876,
14,
362,
63,
1160,
360,
1080,
14,
1360,
358,
272,
372,
2034,
14,
3352,
8,
433,
30066,
29,
22632,
14,
433,
30066,
9,
421,
199,
32,
22632,
14,
4449,
2336,
9646,
8316,
442,
26,
88,
5971,
199,
32,
24813,
199,
318,
12386,
8,
1069,
12,
671,
304,
272,
754,
275,
1995,
336,
5282,
571,
14,
1730,
14,
1250,
8,
85,
7,
957,
14,
2694,
14,
9646,
297,
671,
9,
272,
2034,
275,
24812,
14,
5876,
14,
362,
63,
1160,
360,
1099,
14,
1360,
358,
272,
1564,
275,
2034,
14,
3352,
8,
88,
29,
88,
12,
754,
29,
1099,
9,
272,
372,
1110,
8,
1317,
9,
421,
199,
32,
22632,
14,
4449,
2336,
9646,
15,
7275,
297,
3102,
2968,
4030,
1105,
199,
318,
12386,
63,
7275,
8,
1069,
304,
272,
671,
275,
1109,
8,
1069,
14,
589,
14,
362,
360,
88,
297,
359,
16,
11057,
16,
566,
272,
372,
12386,
8,
1069,
12,
671,
9,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
492,
984,
272,
687,
7390,
14,
1548,
492,
943,
272,
687,
7390,
14,
2520,
14,
1000,
492,
11666,
272,
687,
7390,
14,
4901,
492,
9655,
272,
943,
14,
928,
14054,
8,
1274,
14,
2703,
9,
339,
9655,
14,
5859,
9735,
8,
15844,
12,
11666,
8,
22632,
14,
1927,
4059,
272,
336,
5282,
571,
14,
1065,
8,
85,
2,
3569,
921,
4195,
14,
16,
14,
16,
14,
17,
26,
25,
1493,
401,
399,
2,
7728,
17,
401,
18042,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
199,
3,
710,
10697,
844,
334,
13965,
9,
199,
3,
199,
3,
1898,
334,
67,
9,
377,
1214,
500,
79,
23428,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
1331,
199,
3,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
298,
10337,
1288,
370,
7962,
199,
3,
315,
314,
2290,
1928,
10588,
12,
5893,
1928,
12305,
314,
4481,
199,
3,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
199,
3,
6866,
402,
314,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
2290,
365,
199,
3,
13985,
370,
886,
880,
12,
5420,
370,
314,
2569,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
315,
199,
3,
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,
1549,
199,
3,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
3169,
12,
199,
3,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
7000,
2334,
199,
3,
10610,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
199,
3,
5603,
12,
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,
1621,
199,
3,
2334,
4141,
14,
199,
3,
199,
11490,
199,
199,
646,
10321,
18,
199,
504,
1022,
274,
262,
492,
1804,
274,
262,
199,
199,
504,
7390,
14,
4901,
14,
11610,
492,
8308,
17958,
12,
372,
1110,
199,
504,
2599,
2470,
6164,
14,
12145,
14,
758,
311,
492,
13515,
421,
199,
3,
961,
365,
4154,
644,
7089,
4223,
199,
309,
199,
758,
311,
571,
275,
13515,
8,
85,
7,
957,
14,
2694,
358,
421,
199,
32,
758,
311,
571,
14,
2683,
342,
199,
318,
12386,
8,
88,
304,
272,
870,
480,
9646,
342,
2797,
543,
8352,
908,
8,
88,
430,
272,
372,
671,
627,
671,
421,
199,
3,
961,
365,
4154,
6001,
4223,
199,
309,
199,
22632,
275,
1804,
274,
262,
342,
199,
22632,
14,
433,
30066,
275,
378,
199,
22632,
14,
5876,
275,
10321,
18,
14,
8263,
8,
3422,
29,
12264,
18,
14,
17521,
5455,
360,
5876,
1333,
421,
199,
32,
22632,
14,
4449,
7825,
199,
318,
5629,
8,
1069,
304,
272,
24812,
14,
433,
30066,
847,
413,
272,
336,
5282,
571,
14,
1730,
14,
4763,
8,
85,
7,
957,
14,
2694,
14,
265,
5427,
297,
1321,
30066,
29,
22632,
14,
433,
30066,
9,
272,
2034,
275,
24812,
14,
5876,
14,
362,
63,
1160,
360,
1080,
14,
1360,
358,
272,
372,
2034,
14,
3352,
8,
433,
30066,
29,
22632,
14,
433,
30066,
9,
421,
199,
32,
22632,
14,
4449,
2336,
9646,
8316,
442,
26,
88,
5971,
199,
32,
24813,
199,
318,
12386,
8,
1069,
12,
671,
304,
272,
754,
275,
1995,
336,
5282,
571,
14,
1730,
14,
1250,
8,
85,
7,
957,
14,
2694,
14,
9646,
297,
671,
9,
272,
2034,
275,
24812,
14,
5876,
14,
362,
63,
1160,
360,
1099,
14,
1360,
358,
272,
1564,
275,
2034,
14,
3352,
8,
88,
29,
88,
12,
754,
29,
1099,
9,
272,
372,
1110,
8,
1317,
9,
421,
199,
32,
22632,
14,
4449,
2336,
9646,
15,
7275,
297,
3102,
2968,
4030,
1105,
199,
318,
12386,
63,
7275,
8,
1069,
304,
272,
671,
275,
1109,
8,
1069,
14,
589,
14,
362,
360,
88,
297,
359,
16,
11057,
16,
566,
272,
372,
12386,
8,
1069,
12,
671,
9,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
492,
984,
272,
687,
7390,
14,
1548,
492,
943,
272,
687,
7390,
14,
2520,
14,
1000,
492,
11666,
272,
687,
7390,
14,
4901,
492,
9655,
272,
943,
14,
928,
14054,
8,
1274,
14,
2703,
9,
339,
9655,
14,
5859,
9735,
8,
15844,
12,
11666,
8,
22632,
14,
1927,
4059,
272,
336,
5282,
571,
14,
1065,
8,
85,
2,
3569,
921,
4195,
14,
16,
14,
16,
14,
17,
26,
25,
1493,
401,
399,
2,
7728,
17,
401,
18042,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
diraimondo/osmc
|
package/mediacenter-addon-osmc/src/service.osmc.settings/resources/lib/osmc_slideshow.py
|
7
|
4863
|
# XBMC modules
import xbmc
import xbmcaddon
import xbmcgui
# STANDARD library modules
import os
import sys
import threading
path = xbmcaddon.Addon().getAddonInfo('path')
lib = os.path.join(path, 'resources','lib')
media = os.path.join(path, 'resources','skins','Default','media')
sys.path.append(xbmc.translatePath(lib))
__addon__ = xbmcaddon.Addon()
scriptPath = __addon__.getAddonInfo('path')
WINDOW = xbmcgui.Window(10000)
# LEFT ACTIONS
ACTION_MOVE_LEFT = 1
ACTION_PAGE_DOWN = 6
ACTION_MOUSE_WHEEL_DOWN = 105
ACTION_SCROLL_DOWN = 112
ACTION_CHANNEL_DOWN = 185
# RIGHT ACTIONS
ACTION_MOVE_RIGHT = 2
ACTION_PAGE_UP = 5
ACTION_MOUSE_WHEEL_UP = 104
ACTION_SCROLL_UP = 111
ACTION_CHANNEL_UP = 184
LEFT_ACTIONS = [ACTION_MOVE_LEFT, ACTION_PAGE_DOWN, ACTION_MOUSE_WHEEL_DOWN, ACTION_SCROLL_DOWN, ACTION_CHANNEL_DOWN]
RIGHT_ACTIONS = [ACTION_MOVE_RIGHT, ACTION_PAGE_UP, ACTION_MOUSE_WHEEL_UP, ACTION_SCROLL_UP, ACTION_CHANNEL_UP]
def log(message):
try:
message = str(message)
except UnicodeEncodeError:
message = message.encode('utf-8', 'ignore' )
xbmc.log('osmc_settings: ' + str(message), level=xbmc.LOGDEBUG)
def lang(id):
san = __addon__.getLocalizedString(id).encode( 'utf-8', 'ignore' )
return san
'''
=========================
Slideshow JSON STRUCTURE
=========================
{
"slideshowID": <-- must be unique, will be stored in the settings.xml for the addon
{
"version": {'minimum: x.x.xxx, maximum: y.y.yyy},
"platform": ['pi2', 'vero', 'vero2'],
"expiry_date" : "31/12/2015",
"images" : [URL1, URL2, URL3, URL4] <--these should be named so that the files are in alpahbetical order image1.png, image2.png if you like
},
}
'''
class OSMC_Slideshow(object):
def __init__(self, json_data):
pass
def download_images(self):
pass
def progress_bar(self):
pass
def create_slideshow(self, image_list):
xml = "osmc_slideshow_720.xml" if xbmcgui.Window(10000).getProperty("SkinHeight") == '720' else "osmc_slideshow.xml"
return OSMC_Slideshow_GUI(xml, __path__, 'Default', image_list=image_list)
class ConditionCallBack(threading.Thread):
''' Takes a control -> xbmc.control, a timing (in ms) -> int, and a condition -> str
Waits the set time, then applies the visible condition to the supplied control. '''
def __init__(self, **kwargs):
self.control = kwargs.get('control', None)
self.condition = kwargs.get('condition', '')
self.timing = max(kwargs.get('timing', 0), 3000)
super(ConditionCallBack, self).__init__()
def run(self):
xbmc.sleep(self.timing)
try:
self.control.setVisibleCondition(self.condition)
except:
log('ConditionCallBack failed')
class OSMC_Slideshow_GUI(xbmcgui.WindowXMLDialog):
def __init__(self, strXMLname, strFallbackPath, strDefaultName, **kwargs):
# images is a list of image path strings
self.images = kwargs.get('images', [])
self.image_list = None
self.navi_list = None
self.navi_group = None
log(self.images)
def onInit(self):
self.image_list = self.getControl(1)
self.navi_list = self.getControl(50)
self.navi_group = self.getControl(555)
# set the nagi group to visible, revert to waiting for system idle for 3 second condition after 3 seconds
# self.navi_group.setVisibleCondition('True')
# ccb = ConditionCallBack(control=self.navi_group, condition='!System.IdleTime(2)|Control.HasFocus(555)', timing=2000)
# ccb.start()
# populate the image list as well as the navi list
for image in self.images:
li = xbmcgui.ListItem(label=image, label2='', thumbnailImage =image)
self.image_list.addItem(li)
self.navi_list.addItem(li)
if len(self.images) == 1:
self.setFocusId(999)
def onAction(self, action):
actionID = action.getId()
if (actionID in (10, 92)):
self.close()
elif actionID in LEFT_ACTIONS:
# user is trying to move to the previous image
pos = xbmc.getInfoLabel('Container(1).Position')
if pos == 0:
pass
else:
xbmc.executebuiltin('SetFocus(1,%s)' % pos - 1)
elif actionID in RIGHT_ACTIONS:
# user is trying to move to the next image
pos = xbmc.getInfoLabel('Container(1).Position')
if pos == len(self.images) - 1:
# end of list
self.setFocusId(999)
else:
xbmc.executebuiltin('SetFocus(1,%s)' % pos + 1)
def onClick(self, controlID):
if controlID == 999:
self.close()
elif controlID == 1:
# user has clicked on the image list, cycle to next position, if last position move to exit button
pos = xbmc.getInfoLabel('Container(1).Position')
if pos == len(self.images) -1:
# end of list
self.setFocusId(999)
self.navi_group.setVisibleCondition('True')
else:
xbmc.executebuiltin('SetFocus(1,%s)' % pos + 1)
def onFocus(self, controlID):
pass
|
gpl-2.0
|
[
3,
1323,
28994,
4621,
199,
646,
11709,
199,
646,
11709,
9291,
199,
646,
26418,
199,
199,
3,
4384,
16938,
3555,
4621,
199,
646,
747,
199,
646,
984,
199,
646,
5796,
199,
199,
515,
755,
275,
11709,
9291,
14,
19654,
1252,
362,
19654,
2354,
360,
515,
358,
199,
773,
263,
275,
747,
14,
515,
14,
904,
8,
515,
12,
283,
4435,
1673,
773,
358,
199,
4603,
420,
275,
747,
14,
515,
14,
904,
8,
515,
12,
283,
4435,
1673,
1339,
3617,
1673,
2698,
1673,
4603,
358,
199,
199,
1274,
14,
515,
14,
740,
8,
21382,
14,
5275,
2042,
8,
773,
430,
199,
199,
363,
9291,
363,
221,
275,
11709,
9291,
14,
19654,
342,
199,
1579,
2042,
275,
636,
9291,
4343,
362,
19654,
2354,
360,
515,
358,
199,
15480,
258,
275,
26418,
14,
4301,
8,
9943,
9,
199,
199,
3,
6578,
437,
19560,
199,
10052,
63,
16207,
63,
9894,
22427,
198,
29,
413,
199,
10052,
63,
12898,
63,
8819,
22427,
198,
29,
1227,
199,
10052,
63,
25571,
63,
31588,
2901,
63,
8819,
198,
29,
20462,
199,
10052,
63,
26315,
63,
8819,
22427,
198,
29,
20240,
199,
10052,
63,
14833,
63,
8819,
221,
198,
29,
413,
2426,
421,
199,
3,
7052,
437,
19560,
199,
10052,
63,
16207,
63,
12811,
22427,
198,
29,
499,
199,
10052,
63,
12898,
63,
2160,
221,
1057,
198,
29,
959,
199,
10052,
63,
25571,
63,
31588,
2901,
63,
2160,
221,
198,
29,
21083,
199,
10052,
63,
26315,
63,
2160,
22427,
198,
29,
20128,
199,
10052,
63,
14833,
63,
2160,
22427,
198,
29,
27631,
421,
199,
9894,
63,
25194,
221,
275,
359,
10052,
63,
16207,
63,
9894,
12,
9612,
63,
12898,
63,
8819,
12,
9612,
63,
25571,
63,
31588,
2901,
63,
8819,
12,
9612,
63,
26315,
63,
8819,
12,
9612,
63,
14833,
63,
8819,
61,
199,
12811,
63,
25194,
275,
359,
10052,
63,
16207,
63,
12811,
12,
9612,
63,
12898,
63,
2160,
12,
9612,
63,
25571,
63,
31588,
2901,
63,
2160,
12,
9612,
63,
26315,
63,
2160,
12,
9612,
63,
14833,
63,
2160,
61,
421,
199,
318,
943,
8,
1188,
304,
421,
198,
893,
26,
507,
198,
1188,
275,
620,
8,
1188,
9,
421,
198,
2590,
24094,
26,
507,
198,
1188,
275,
1245,
14,
2143,
360,
1624,
13,
24,
297,
283,
4247,
7,
776,
421,
198,
21382,
14,
793,
360,
736,
5466,
63,
1751,
26,
283,
435,
620,
8,
1188,
395,
2166,
29,
21382,
14,
4947,
5287,
9,
421,
199,
318,
6339,
8,
344,
304,
8299,
198,
18904,
275,
636,
9291,
4343,
362,
29925,
1558,
8,
344,
680,
2143,
8,
283,
1624,
13,
24,
297,
283,
4247,
7,
776,
199,
198,
1107,
28698,
221,
421,
199,
2344,
199,
1280,
15495,
199,
51,
8409,
2384,
4840,
7553,
7996,
3942,
199,
1280,
15495,
199,
199,
91,
2043,
298,
19968,
2384,
998,
582,
665,
306,
1471,
506,
3747,
12,
911,
506,
5489,
315,
314,
2202,
14,
1652,
367,
314,
13553,
10817,
469,
1779,
298,
1023,
582,
791,
10700,
26,
671,
14,
88,
14,
10013,
12,
5696,
26,
612,
14,
89,
14,
30917,
1386,
1779,
298,
3246,
582,
788,
1038,
18,
297,
283,
422,
79,
297,
283,
422,
79,
18,
995,
1779,
298,
16844,
63,
602,
2,
520,
298,
2192,
15,
713,
15,
7806,
401,
1779,
298,
4782,
2,
520,
359,
2632,
17,
12,
2851,
18,
12,
2851,
19,
12,
2851,
20,
61,
665,
306,
29032,
1077,
506,
4310,
880,
626,
314,
1584,
787,
315,
741,
387,
72,
1235,
3294,
1865,
1834,
17,
14,
4524,
12,
1834,
18,
14,
4524,
340,
1265,
2839,
2126,
1660,
199,
93,
199,
2344,
421,
199,
533,
593,
4029,
35,
63,
51,
8409,
2384,
8,
785,
304,
4388,
198,
318,
636,
826,
721,
277,
12,
2022,
63,
576,
304,
2742,
198,
1529,
4388,
198,
318,
5235,
63,
4782,
8,
277,
304,
2742,
198,
1529,
4388,
198,
318,
6696,
63,
1700,
8,
277,
304,
2742,
198,
1529,
4388,
198,
318,
1218,
63,
19968,
2384,
8,
277,
12,
1834,
63,
513,
304,
2742,
198,
1652,
275,
298,
736,
5466,
63,
19968,
2384,
63,
18386,
14,
1652,
2,
340,
26418,
14,
4301,
8,
9943,
680,
28449,
480,
14194,
262,
8436,
531,
508,
283,
18386,
7,
587,
298,
736,
5466,
63,
19968,
2384,
14,
1652,
2,
2742,
198,
1107,
593,
4029,
35,
63,
51,
8409,
2384,
63,
14438,
8,
1652,
12,
636,
515,
3108,
283,
2698,
297,
1834,
63,
513,
29,
1569,
63,
513,
9,
4388,
199,
533,
28401,
2176,
4540,
8,
12562,
14,
4436,
304,
199,
198,
2344,
17415,
282,
3304,
1035,
11709,
14,
2785,
12,
282,
20542,
334,
262,
6605,
9,
1035,
1109,
12,
436,
282,
5558,
1035,
620,
507,
198,
24804,
1405,
314,
663,
900,
12,
2066,
12966,
314,
8917,
5558,
370,
314,
6841,
3304,
14,
1449,
421,
198,
318,
636,
826,
721,
277,
12,
1011,
958,
304,
2742,
198,
277,
14,
2785,
221,
198,
29,
2074,
14,
362,
360,
2785,
297,
488,
9,
507,
198,
277,
14,
5394,
221,
198,
29,
2074,
14,
362,
360,
5394,
297,
4074,
507,
198,
277,
14,
14639,
221,
198,
29,
1390,
8,
958,
14,
362,
360,
14639,
297,
378,
395,
29664,
9,
2742,
198,
4792,
8,
9558,
2176,
4540,
12,
291,
2843,
826,
4533,
4388,
198,
318,
1255,
8,
277,
304,
9068,
198,
21382,
14,
4532,
8,
277,
14,
14639,
9,
2742,
198,
893,
26,
686,
198,
277,
14,
2785,
14,
32232,
9558,
8,
277,
14,
5394,
9,
507,
198,
2590,
26,
686,
198,
793,
360,
9558,
2176,
4540,
3405,
358,
421,
199,
533,
593,
4029,
35,
63,
51,
8409,
2384,
63,
14438,
8,
21382,
5885,
14,
4301,
4317,
5619,
304,
421,
198,
318,
636,
826,
721,
277,
12,
620,
4317,
354,
12,
620,
21860,
2042,
12,
620,
2698,
985,
12,
1011,
958,
304,
2742,
198,
3,
5935,
365,
282,
769,
402,
1834,
931,
3326,
507,
198,
277,
14,
4782,
257,
198,
29,
2074,
14,
362,
360,
4782,
297,
3073,
507,
198,
277,
14,
1569,
63,
513,
275,
488,
507,
198,
277,
14,
15595,
63,
513,
221,
275,
488,
507,
198,
277,
14,
15595,
63,
923,
275,
488,
9068,
198,
793,
8,
277,
14,
4782,
9,
4388,
198,
318,
641,
9346,
8,
277,
304,
2742,
198,
277,
14,
1569,
63,
513,
275,
291,
14,
25117,
8,
17
] |
[
1323,
28994,
4621,
199,
646,
11709,
199,
646,
11709,
9291,
199,
646,
26418,
199,
199,
3,
4384,
16938,
3555,
4621,
199,
646,
747,
199,
646,
984,
199,
646,
5796,
199,
199,
515,
755,
275,
11709,
9291,
14,
19654,
1252,
362,
19654,
2354,
360,
515,
358,
199,
773,
263,
275,
747,
14,
515,
14,
904,
8,
515,
12,
283,
4435,
1673,
773,
358,
199,
4603,
420,
275,
747,
14,
515,
14,
904,
8,
515,
12,
283,
4435,
1673,
1339,
3617,
1673,
2698,
1673,
4603,
358,
199,
199,
1274,
14,
515,
14,
740,
8,
21382,
14,
5275,
2042,
8,
773,
430,
199,
199,
363,
9291,
363,
221,
275,
11709,
9291,
14,
19654,
342,
199,
1579,
2042,
275,
636,
9291,
4343,
362,
19654,
2354,
360,
515,
358,
199,
15480,
258,
275,
26418,
14,
4301,
8,
9943,
9,
199,
199,
3,
6578,
437,
19560,
199,
10052,
63,
16207,
63,
9894,
22427,
198,
29,
413,
199,
10052,
63,
12898,
63,
8819,
22427,
198,
29,
1227,
199,
10052,
63,
25571,
63,
31588,
2901,
63,
8819,
198,
29,
20462,
199,
10052,
63,
26315,
63,
8819,
22427,
198,
29,
20240,
199,
10052,
63,
14833,
63,
8819,
221,
198,
29,
413,
2426,
421,
199,
3,
7052,
437,
19560,
199,
10052,
63,
16207,
63,
12811,
22427,
198,
29,
499,
199,
10052,
63,
12898,
63,
2160,
221,
1057,
198,
29,
959,
199,
10052,
63,
25571,
63,
31588,
2901,
63,
2160,
221,
198,
29,
21083,
199,
10052,
63,
26315,
63,
2160,
22427,
198,
29,
20128,
199,
10052,
63,
14833,
63,
2160,
22427,
198,
29,
27631,
421,
199,
9894,
63,
25194,
221,
275,
359,
10052,
63,
16207,
63,
9894,
12,
9612,
63,
12898,
63,
8819,
12,
9612,
63,
25571,
63,
31588,
2901,
63,
8819,
12,
9612,
63,
26315,
63,
8819,
12,
9612,
63,
14833,
63,
8819,
61,
199,
12811,
63,
25194,
275,
359,
10052,
63,
16207,
63,
12811,
12,
9612,
63,
12898,
63,
2160,
12,
9612,
63,
25571,
63,
31588,
2901,
63,
2160,
12,
9612,
63,
26315,
63,
2160,
12,
9612,
63,
14833,
63,
2160,
61,
421,
199,
318,
943,
8,
1188,
304,
421,
198,
893,
26,
507,
198,
1188,
275,
620,
8,
1188,
9,
421,
198,
2590,
24094,
26,
507,
198,
1188,
275,
1245,
14,
2143,
360,
1624,
13,
24,
297,
283,
4247,
7,
776,
421,
198,
21382,
14,
793,
360,
736,
5466,
63,
1751,
26,
283,
435,
620,
8,
1188,
395,
2166,
29,
21382,
14,
4947,
5287,
9,
421,
199,
318,
6339,
8,
344,
304,
8299,
198,
18904,
275,
636,
9291,
4343,
362,
29925,
1558,
8,
344,
680,
2143,
8,
283,
1624,
13,
24,
297,
283,
4247,
7,
776,
199,
198,
1107,
28698,
221,
421,
199,
2344,
199,
1280,
15495,
199,
51,
8409,
2384,
4840,
7553,
7996,
3942,
199,
1280,
15495,
199,
199,
91,
2043,
298,
19968,
2384,
998,
582,
665,
306,
1471,
506,
3747,
12,
911,
506,
5489,
315,
314,
2202,
14,
1652,
367,
314,
13553,
10817,
469,
1779,
298,
1023,
582,
791,
10700,
26,
671,
14,
88,
14,
10013,
12,
5696,
26,
612,
14,
89,
14,
30917,
1386,
1779,
298,
3246,
582,
788,
1038,
18,
297,
283,
422,
79,
297,
283,
422,
79,
18,
995,
1779,
298,
16844,
63,
602,
2,
520,
298,
2192,
15,
713,
15,
7806,
401,
1779,
298,
4782,
2,
520,
359,
2632,
17,
12,
2851,
18,
12,
2851,
19,
12,
2851,
20,
61,
665,
306,
29032,
1077,
506,
4310,
880,
626,
314,
1584,
787,
315,
741,
387,
72,
1235,
3294,
1865,
1834,
17,
14,
4524,
12,
1834,
18,
14,
4524,
340,
1265,
2839,
2126,
1660,
199,
93,
199,
2344,
421,
199,
533,
593,
4029,
35,
63,
51,
8409,
2384,
8,
785,
304,
4388,
198,
318,
636,
826,
721,
277,
12,
2022,
63,
576,
304,
2742,
198,
1529,
4388,
198,
318,
5235,
63,
4782,
8,
277,
304,
2742,
198,
1529,
4388,
198,
318,
6696,
63,
1700,
8,
277,
304,
2742,
198,
1529,
4388,
198,
318,
1218,
63,
19968,
2384,
8,
277,
12,
1834,
63,
513,
304,
2742,
198,
1652,
275,
298,
736,
5466,
63,
19968,
2384,
63,
18386,
14,
1652,
2,
340,
26418,
14,
4301,
8,
9943,
680,
28449,
480,
14194,
262,
8436,
531,
508,
283,
18386,
7,
587,
298,
736,
5466,
63,
19968,
2384,
14,
1652,
2,
2742,
198,
1107,
593,
4029,
35,
63,
51,
8409,
2384,
63,
14438,
8,
1652,
12,
636,
515,
3108,
283,
2698,
297,
1834,
63,
513,
29,
1569,
63,
513,
9,
4388,
199,
533,
28401,
2176,
4540,
8,
12562,
14,
4436,
304,
199,
198,
2344,
17415,
282,
3304,
1035,
11709,
14,
2785,
12,
282,
20542,
334,
262,
6605,
9,
1035,
1109,
12,
436,
282,
5558,
1035,
620,
507,
198,
24804,
1405,
314,
663,
900,
12,
2066,
12966,
314,
8917,
5558,
370,
314,
6841,
3304,
14,
1449,
421,
198,
318,
636,
826,
721,
277,
12,
1011,
958,
304,
2742,
198,
277,
14,
2785,
221,
198,
29,
2074,
14,
362,
360,
2785,
297,
488,
9,
507,
198,
277,
14,
5394,
221,
198,
29,
2074,
14,
362,
360,
5394,
297,
4074,
507,
198,
277,
14,
14639,
221,
198,
29,
1390,
8,
958,
14,
362,
360,
14639,
297,
378,
395,
29664,
9,
2742,
198,
4792,
8,
9558,
2176,
4540,
12,
291,
2843,
826,
4533,
4388,
198,
318,
1255,
8,
277,
304,
9068,
198,
21382,
14,
4532,
8,
277,
14,
14639,
9,
2742,
198,
893,
26,
686,
198,
277,
14,
2785,
14,
32232,
9558,
8,
277,
14,
5394,
9,
507,
198,
2590,
26,
686,
198,
793,
360,
9558,
2176,
4540,
3405,
358,
421,
199,
533,
593,
4029,
35,
63,
51,
8409,
2384,
63,
14438,
8,
21382,
5885,
14,
4301,
4317,
5619,
304,
421,
198,
318,
636,
826,
721,
277,
12,
620,
4317,
354,
12,
620,
21860,
2042,
12,
620,
2698,
985,
12,
1011,
958,
304,
2742,
198,
3,
5935,
365,
282,
769,
402,
1834,
931,
3326,
507,
198,
277,
14,
4782,
257,
198,
29,
2074,
14,
362,
360,
4782,
297,
3073,
507,
198,
277,
14,
1569,
63,
513,
275,
488,
507,
198,
277,
14,
15595,
63,
513,
221,
275,
488,
507,
198,
277,
14,
15595,
63,
923,
275,
488,
9068,
198,
793,
8,
277,
14,
4782,
9,
4388,
198,
318,
641,
9346,
8,
277,
304,
2742,
198,
277,
14,
1569,
63,
513,
275,
291,
14,
25117,
8,
17,
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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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
] |
marco-lancini/Showcase
|
django/contrib/auth/context_processors.py
|
152
|
2229
|
from django.utils.functional import lazy, memoize, SimpleLazyObject
from django.contrib import messages
# PermWrapper and PermLookupDict proxy the permissions system into objects that
# the template system can understand.
class PermLookupDict(object):
def __init__(self, user, module_name):
self.user, self.module_name = user, module_name
def __repr__(self):
return str(self.user.get_all_permissions())
def __getitem__(self, perm_name):
return self.user.has_perm("%s.%s" % (self.module_name, perm_name))
def __nonzero__(self):
return self.user.has_module_perms(self.module_name)
class PermWrapper(object):
def __init__(self, user):
self.user = user
def __getitem__(self, module_name):
return PermLookupDict(self.user, module_name)
def __iter__(self):
# I am large, I contain multitudes.
raise TypeError("PermWrapper is not iterable.")
def auth(request):
"""
Returns context variables required by apps that use Django's authentication
system.
If there is no 'user' attribute in the request, uses AnonymousUser (from
django.contrib.auth).
"""
# If we access request.user, request.session is accessed, which results in
# 'Vary: Cookie' being sent in every request that uses this context
# processor, which can easily be every request on a site if
# TEMPLATE_CONTEXT_PROCESSORS has this context processor added. This kills
# the ability to cache. So, we carefully ensure these attributes are lazy.
# We don't use django.utils.functional.lazy() for User, because that
# requires knowing the class of the object we want to proxy, which could
# break with custom auth backends. LazyObject is a less complete but more
# flexible solution that is a good enough wrapper for 'User'.
def get_user():
if hasattr(request, 'user'):
return request.user
else:
from django.contrib.auth.models import AnonymousUser
return AnonymousUser()
return {
'user': SimpleLazyObject(get_user),
'messages': messages.get_messages(request),
'perms': lazy(lambda: PermWrapper(get_user()), PermWrapper)(),
}
|
mit
|
[
504,
1639,
14,
1208,
14,
15481,
492,
9617,
12,
11955,
794,
12,
5870,
14269,
1692,
199,
504,
1639,
14,
2828,
492,
3788,
199,
199,
3,
3492,
77,
4590,
436,
3492,
77,
7521,
2141,
4566,
314,
3443,
2656,
1901,
2251,
626,
199,
3,
314,
1978,
2656,
883,
20647,
14,
199,
199,
533,
3492,
77,
7521,
2141,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
922,
12,
859,
63,
354,
304,
267,
291,
14,
751,
12,
291,
14,
578,
63,
354,
275,
922,
12,
859,
63,
354,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
620,
8,
277,
14,
751,
14,
362,
63,
452,
63,
6060,
1012,
339,
347,
636,
6095,
721,
277,
12,
10869,
63,
354,
304,
267,
372,
291,
14,
751,
14,
1989,
63,
8220,
3647,
83,
4111,
83,
2,
450,
334,
277,
14,
578,
63,
354,
12,
10869,
63,
354,
430,
339,
347,
636,
10262,
721,
277,
304,
267,
372,
291,
14,
751,
14,
1989,
63,
578,
63,
12068,
8,
277,
14,
578,
63,
354,
9,
421,
199,
533,
3492,
77,
4590,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
922,
304,
267,
291,
14,
751,
275,
922,
339,
347,
636,
6095,
721,
277,
12,
859,
63,
354,
304,
267,
372,
3492,
77,
7521,
2141,
8,
277,
14,
751,
12,
859,
63,
354,
9,
339,
347,
636,
1661,
721,
277,
304,
267,
327,
473,
8140,
7031,
12,
473,
1395,
3510,
10963,
3424,
14,
267,
746,
3146,
480,
23554,
4590,
365,
440,
6076,
2685,
199,
199,
318,
1790,
8,
1069,
304,
272,
408,
272,
1803,
1067,
2860,
1415,
701,
8686,
626,
675,
5634,
1159,
6299,
272,
2656,
14,
339,
982,
2337,
365,
949,
283,
751,
7,
2225,
315,
314,
1056,
12,
4440,
29952,
334,
504,
272,
1639,
14,
2828,
14,
1178,
680,
272,
408,
272,
327,
982,
781,
2879,
1056,
14,
751,
12,
1056,
14,
1730,
365,
13810,
12,
1314,
2058,
315,
272,
327,
283,
54,
695,
26,
14798,
7,
3769,
4847,
315,
4036,
1056,
626,
4440,
642,
1067,
272,
327,
12495,
12,
1314,
883,
16174,
506,
4036,
1056,
641,
282,
4770,
340,
272,
327,
24877,
63,
9059,
63,
10494,
4149,
965,
642,
1067,
12495,
3483,
14,
221,
961,
1022,
15350,
272,
327,
314,
21255,
370,
2581,
14,
221,
2002,
12,
781,
21191,
8525,
4868,
3520,
3004,
787,
9617,
14,
272,
327,
2136,
2793,
1133,
675,
1639,
14,
1208,
14,
15481,
14,
6395,
342,
367,
2876,
12,
2952,
626,
272,
327,
5074,
5715,
316,
314,
1021,
402,
314,
909,
781,
2934,
370,
4566,
12,
1314,
4293,
272,
327,
2059,
543,
3537,
1790,
14745,
14,
221,
22373,
1692,
365,
282,
6656,
4890,
1325,
1655,
272,
327,
26841,
8744,
626,
365,
282,
6954,
8321,
4975,
367,
283,
1899,
1370,
272,
347,
664,
63,
751,
837,
267,
340,
2688,
8,
1069,
12,
283,
751,
735,
288,
372,
1056,
14,
751,
267,
587,
26,
288,
687,
1639,
14,
2828,
14,
1178,
14,
992,
492,
29952,
288,
372,
29952,
342,
339,
372,
469,
267,
283,
751,
356,
5870,
14269,
1692,
8,
362,
63,
751,
395,
267,
283,
3431,
356,
3788,
14,
362,
63,
3431,
8,
1069,
395,
267,
283,
12068,
356,
221,
9617,
8,
2734,
26,
3492,
77,
4590,
8,
362,
63,
751,
4000,
3492,
77,
4590,
9,
1062,
272,
789,
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
] |
[
1639,
14,
1208,
14,
15481,
492,
9617,
12,
11955,
794,
12,
5870,
14269,
1692,
199,
504,
1639,
14,
2828,
492,
3788,
199,
199,
3,
3492,
77,
4590,
436,
3492,
77,
7521,
2141,
4566,
314,
3443,
2656,
1901,
2251,
626,
199,
3,
314,
1978,
2656,
883,
20647,
14,
199,
199,
533,
3492,
77,
7521,
2141,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
922,
12,
859,
63,
354,
304,
267,
291,
14,
751,
12,
291,
14,
578,
63,
354,
275,
922,
12,
859,
63,
354,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
620,
8,
277,
14,
751,
14,
362,
63,
452,
63,
6060,
1012,
339,
347,
636,
6095,
721,
277,
12,
10869,
63,
354,
304,
267,
372,
291,
14,
751,
14,
1989,
63,
8220,
3647,
83,
4111,
83,
2,
450,
334,
277,
14,
578,
63,
354,
12,
10869,
63,
354,
430,
339,
347,
636,
10262,
721,
277,
304,
267,
372,
291,
14,
751,
14,
1989,
63,
578,
63,
12068,
8,
277,
14,
578,
63,
354,
9,
421,
199,
533,
3492,
77,
4590,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
922,
304,
267,
291,
14,
751,
275,
922,
339,
347,
636,
6095,
721,
277,
12,
859,
63,
354,
304,
267,
372,
3492,
77,
7521,
2141,
8,
277,
14,
751,
12,
859,
63,
354,
9,
339,
347,
636,
1661,
721,
277,
304,
267,
327,
473,
8140,
7031,
12,
473,
1395,
3510,
10963,
3424,
14,
267,
746,
3146,
480,
23554,
4590,
365,
440,
6076,
2685,
199,
199,
318,
1790,
8,
1069,
304,
272,
408,
272,
1803,
1067,
2860,
1415,
701,
8686,
626,
675,
5634,
1159,
6299,
272,
2656,
14,
339,
982,
2337,
365,
949,
283,
751,
7,
2225,
315,
314,
1056,
12,
4440,
29952,
334,
504,
272,
1639,
14,
2828,
14,
1178,
680,
272,
408,
272,
327,
982,
781,
2879,
1056,
14,
751,
12,
1056,
14,
1730,
365,
13810,
12,
1314,
2058,
315,
272,
327,
283,
54,
695,
26,
14798,
7,
3769,
4847,
315,
4036,
1056,
626,
4440,
642,
1067,
272,
327,
12495,
12,
1314,
883,
16174,
506,
4036,
1056,
641,
282,
4770,
340,
272,
327,
24877,
63,
9059,
63,
10494,
4149,
965,
642,
1067,
12495,
3483,
14,
221,
961,
1022,
15350,
272,
327,
314,
21255,
370,
2581,
14,
221,
2002,
12,
781,
21191,
8525,
4868,
3520,
3004,
787,
9617,
14,
272,
327,
2136,
2793,
1133,
675,
1639,
14,
1208,
14,
15481,
14,
6395,
342,
367,
2876,
12,
2952,
626,
272,
327,
5074,
5715,
316,
314,
1021,
402,
314,
909,
781,
2934,
370,
4566,
12,
1314,
4293,
272,
327,
2059,
543,
3537,
1790,
14745,
14,
221,
22373,
1692,
365,
282,
6656,
4890,
1325,
1655,
272,
327,
26841,
8744,
626,
365,
282,
6954,
8321,
4975,
367,
283,
1899,
1370,
272,
347,
664,
63,
751,
837,
267,
340,
2688,
8,
1069,
12,
283,
751,
735,
288,
372,
1056,
14,
751,
267,
587,
26,
288,
687,
1639,
14,
2828,
14,
1178,
14,
992,
492,
29952,
288,
372,
29952,
342,
339,
372,
469,
267,
283,
751,
356,
5870,
14269,
1692,
8,
362,
63,
751,
395,
267,
283,
3431,
356,
3788,
14,
362,
63,
3431,
8,
1069,
395,
267,
283,
12068,
356,
221,
9617,
8,
2734,
26,
3492,
77,
4590,
8,
362,
63,
751,
4000,
3492,
77,
4590,
9,
1062,
272,
789,
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,
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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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
LIKAIMO/MissionPlanner
|
Lib/lib2to3/fixes/fix_map.py
|
61
|
3153
|
# Copyright 2007 Google, Inc. All Rights Reserved.
# Licensed to PSF under a Contributor Agreement.
"""Fixer that changes map(F, ...) into list(map(F, ...)) unless there
exists a 'from future_builtins import map' statement in the top-level
namespace.
As a special case, map(None, X) is changed into list(X). (This is
necessary because the semantics are changed in this case -- the new
map(None, X) is equivalent to [(x,) for x in X].)
We avoid the transformation (except for the special case mentioned
above) if the map() call is directly contained in iter(<>), list(<>),
tuple(<>), sorted(<>), ...join(<>), or for V in <>:.
NOTE: This is still not correct if the original code was depending on
map(F, X, Y, ...) to go on until the longest argument is exhausted,
substituting None for missing values -- like zip(), it now stops as
soon as the shortest argument is exhausted.
"""
# Local imports
from ..pgen2 import token
from .. import fixer_base
from ..fixer_util import Name, Call, ListComp, in_special_context
from ..pygram import python_symbols as syms
class FixMap(fixer_base.ConditionalFix):
BM_compatible = True
PATTERN = """
map_none=power<
'map'
trailer< '(' arglist< 'None' ',' arg=any [','] > ')' >
>
|
map_lambda=power<
'map'
trailer<
'('
arglist<
lambdef< 'lambda'
(fp=NAME | vfpdef< '(' fp=NAME ')'> ) ':' xp=any
>
','
it=any
>
')'
>
>
|
power<
'map' trailer< '(' [arglist=any] ')' >
>
"""
skip_on = 'future_builtins.map'
def transform(self, node, results):
if self.should_skip(node):
return
if node.parent.type == syms.simple_stmt:
self.warning(node, "You should use a for loop here")
new = node.clone()
new.prefix = u""
new = Call(Name(u"list"), [new])
elif "map_lambda" in results:
new = ListComp(results["xp"].clone(),
results["fp"].clone(),
results["it"].clone())
else:
if "map_none" in results:
new = results["arg"].clone()
else:
if "arglist" in results:
args = results["arglist"]
if args.type == syms.arglist and \
args.children[0].type == token.NAME and \
args.children[0].value == "None":
self.warning(node, "cannot convert map(None, ...) "
"with multiple arguments because map() "
"now truncates to the shortest sequence")
return
if in_special_context(node):
return None
new = node.clone()
new.prefix = u""
new = Call(Name(u"list"), [new])
new.prefix = node.prefix
return new
|
gpl-3.0
|
[
3,
1898,
10219,
4475,
12,
3277,
14,
2900,
5924,
5702,
14,
202,
199,
3,
3909,
370,
29770,
1334,
282,
17636,
28629,
14,
2999,
199,
624,
11985,
281,
626,
4493,
2341,
8,
38,
12,
19172,
1901,
769,
8,
1130,
8,
38,
12,
2263,
430,
7444,
2337,
202,
199,
2444,
282,
283,
504,
6466,
63,
10372,
492,
2341,
7,
5164,
315,
314,
2746,
13,
1896,
202,
199,
3251,
14,
2999,
199,
2822,
282,
4539,
1930,
12,
2341,
8,
403,
12,
1323,
9,
365,
2896,
1901,
769,
8,
56,
680,
221,
334,
2765,
365,
202,
199,
17927,
2952,
314,
19002,
787,
2896,
315,
642,
1930,
1553,
314,
892,
202,
199,
1130,
8,
403,
12,
1323,
9,
365,
7353,
370,
3842,
88,
4258,
367,
671,
315,
1323,
1055,
9,
2999,
199,
6004,
5126,
314,
13315,
334,
2590,
367,
314,
4539,
1930,
26239,
202,
199,
16181,
9,
340,
314,
2341,
342,
1240,
365,
5370,
10470,
315,
2740,
8,
16137,
395,
769,
8,
16137,
395,
202,
199,
2960,
8,
16137,
395,
3355,
8,
16137,
395,
2263,
904,
8,
16137,
395,
503,
367,
812,
315,
20941,
14010,
2999,
199,
19855,
26,
961,
365,
5139,
440,
3211,
340,
314,
3379,
1233,
1990,
10298,
641,
202,
199,
1130,
8,
38,
12,
1323,
12,
1488,
12,
19172,
370,
2621,
641,
5133,
314,
21303,
1423,
365,
31103,
12,
202,
199,
14340,
4655,
488,
367,
4124,
1338,
1553,
2839,
3482,
1062,
652,
3063,
20922,
465,
202,
199,
1152,
265,
465,
314,
26564,
1423,
365,
31103,
14,
202,
199,
624,
2999,
199,
3,
10111,
8925,
202,
199,
504,
2508,
80,
2268,
18,
492,
1526,
202,
199,
504,
2508,
492,
24739,
63,
1095,
202,
199,
504,
2508,
25973,
63,
1974,
492,
2812,
12,
6523,
12,
3820,
2404,
12,
315,
63,
6664,
63,
1100,
202,
199,
504,
2508,
647,
1679,
492,
2366,
63,
7450,
465,
25308,
2999,
199,
533,
14811,
2956,
8,
25973,
63,
1095,
14,
21321,
11985,
304,
1128,
699,
45,
63,
6490,
275,
715,
2958,
31467,
7689,
275,
408,
1128,
2341,
63,
3592,
29,
5652,
28,
1039,
283,
1130,
7,
1039,
17357,
28,
16746,
24660,
28,
283,
403,
7,
13647,
1680,
29,
1629,
359,
297,
418,
690,
16107,
690,
1128,
690,
1128,
1204,
1128,
2341,
63,
2734,
29,
5652,
28,
1039,
283,
1130,
7,
1039,
17357,
28,
1675,
16746,
1675,
24660,
28,
2628,
27593,
318,
28,
283,
2734,
7,
202,
586,
334,
3997,
29,
2339,
1204,
373,
3997,
318,
28,
16746,
4090,
29,
2339,
16107,
30,
776,
10871,
21499,
29,
1629,
2628,
690,
2628,
13647,
2628,
652,
29,
1629,
1675,
690,
1675,
16107,
1039,
690,
1128,
690,
1128,
1204,
1128,
7074,
28,
1039,
283,
1130,
7,
17357,
28,
16746,
359,
26995,
29,
1629,
61,
16107,
690,
1128,
690,
1128,
408,
2958,
3372,
63,
265,
275,
283,
2443,
63,
10372,
14,
1130,
7,
2958,
347,
5793,
8,
277,
12,
1031,
12,
2058,
304,
1039,
340,
291,
14,
5626,
63,
2759,
8,
932,
304,
1675,
372,
4341,
340,
1031,
14,
1708,
14,
466,
508,
25308,
14,
4129,
63,
9649,
26,
1675,
291,
14,
3764,
8,
932,
12,
298,
5556,
1077,
675,
282,
367,
4438,
2348,
531,
1675,
892,
275,
1031,
14,
6311,
342,
1675,
892,
14,
1861,
275,
399,
341,
1675,
892,
275,
6523,
8,
985,
8,
85,
2,
513,
1288,
359,
1222,
566,
1039,
916,
298,
1130,
63,
2734,
2,
315,
2058,
26,
1675,
892,
275,
3820,
2404,
8,
2604,
905,
9290,
4140,
6311,
1062,
202,
2574,
2058,
905,
3997,
4140,
6311,
1062,
202,
2574,
2058,
905,
390,
4140,
6311,
1012,
1039,
587,
26,
1675,
340,
298,
1130,
63,
3592,
2,
315,
2058,
26,
2628,
892,
275,
2058,
905,
1273,
4140,
6311,
342,
1675,
587,
26,
2628,
340,
298,
26995,
2,
315,
2058,
26,
4906,
1249,
275,
2058,
905,
26995,
937,
4906,
340,
1249,
14,
466,
508,
25308,
14,
26995,
436,
971,
202,
2432,
1249,
14,
3223,
59,
16,
1055,
466,
508,
1526,
14,
2339,
436,
971,
202,
2432,
1249,
14,
3223,
59,
16,
1055,
585,
508,
298,
403,
582,
8282,
291,
14,
3764,
8,
932,
12,
298,
11250,
3957,
2341,
8,
403,
12,
19172,
298,
202,
3660,
298,
1045,
3663,
2368,
2952,
2341,
342,
298,
202,
3660,
298,
2131,
14547,
83,
370,
314,
26564,
3414,
531,
8282,
372,
2628,
340,
315,
63,
6664,
63,
1100,
8,
932,
304,
4906,
372,
488,
2628,
892,
275,
1031,
14,
6311,
342,
1675,
892,
14,
1861,
275,
399,
341,
1675,
892,
275,
6523,
8,
985,
8,
85,
2,
513,
1288,
359,
1222,
566,
1039,
892,
14,
1861,
275,
1031,
14,
1861,
1039,
372,
892,
1223,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
10219,
4475,
12,
3277,
14,
2900,
5924,
5702,
14,
202,
199,
3,
3909,
370,
29770,
1334,
282,
17636,
28629,
14,
2999,
199,
624,
11985,
281,
626,
4493,
2341,
8,
38,
12,
19172,
1901,
769,
8,
1130,
8,
38,
12,
2263,
430,
7444,
2337,
202,
199,
2444,
282,
283,
504,
6466,
63,
10372,
492,
2341,
7,
5164,
315,
314,
2746,
13,
1896,
202,
199,
3251,
14,
2999,
199,
2822,
282,
4539,
1930,
12,
2341,
8,
403,
12,
1323,
9,
365,
2896,
1901,
769,
8,
56,
680,
221,
334,
2765,
365,
202,
199,
17927,
2952,
314,
19002,
787,
2896,
315,
642,
1930,
1553,
314,
892,
202,
199,
1130,
8,
403,
12,
1323,
9,
365,
7353,
370,
3842,
88,
4258,
367,
671,
315,
1323,
1055,
9,
2999,
199,
6004,
5126,
314,
13315,
334,
2590,
367,
314,
4539,
1930,
26239,
202,
199,
16181,
9,
340,
314,
2341,
342,
1240,
365,
5370,
10470,
315,
2740,
8,
16137,
395,
769,
8,
16137,
395,
202,
199,
2960,
8,
16137,
395,
3355,
8,
16137,
395,
2263,
904,
8,
16137,
395,
503,
367,
812,
315,
20941,
14010,
2999,
199,
19855,
26,
961,
365,
5139,
440,
3211,
340,
314,
3379,
1233,
1990,
10298,
641,
202,
199,
1130,
8,
38,
12,
1323,
12,
1488,
12,
19172,
370,
2621,
641,
5133,
314,
21303,
1423,
365,
31103,
12,
202,
199,
14340,
4655,
488,
367,
4124,
1338,
1553,
2839,
3482,
1062,
652,
3063,
20922,
465,
202,
199,
1152,
265,
465,
314,
26564,
1423,
365,
31103,
14,
202,
199,
624,
2999,
199,
3,
10111,
8925,
202,
199,
504,
2508,
80,
2268,
18,
492,
1526,
202,
199,
504,
2508,
492,
24739,
63,
1095,
202,
199,
504,
2508,
25973,
63,
1974,
492,
2812,
12,
6523,
12,
3820,
2404,
12,
315,
63,
6664,
63,
1100,
202,
199,
504,
2508,
647,
1679,
492,
2366,
63,
7450,
465,
25308,
2999,
199,
533,
14811,
2956,
8,
25973,
63,
1095,
14,
21321,
11985,
304,
1128,
699,
45,
63,
6490,
275,
715,
2958,
31467,
7689,
275,
408,
1128,
2341,
63,
3592,
29,
5652,
28,
1039,
283,
1130,
7,
1039,
17357,
28,
16746,
24660,
28,
283,
403,
7,
13647,
1680,
29,
1629,
359,
297,
418,
690,
16107,
690,
1128,
690,
1128,
1204,
1128,
2341,
63,
2734,
29,
5652,
28,
1039,
283,
1130,
7,
1039,
17357,
28,
1675,
16746,
1675,
24660,
28,
2628,
27593,
318,
28,
283,
2734,
7,
202,
586,
334,
3997,
29,
2339,
1204,
373,
3997,
318,
28,
16746,
4090,
29,
2339,
16107,
30,
776,
10871,
21499,
29,
1629,
2628,
690,
2628,
13647,
2628,
652,
29,
1629,
1675,
690,
1675,
16107,
1039,
690,
1128,
690,
1128,
1204,
1128,
7074,
28,
1039,
283,
1130,
7,
17357,
28,
16746,
359,
26995,
29,
1629,
61,
16107,
690,
1128,
690,
1128,
408,
2958,
3372,
63,
265,
275,
283,
2443,
63,
10372,
14,
1130,
7,
2958,
347,
5793,
8,
277,
12,
1031,
12,
2058,
304,
1039,
340,
291,
14,
5626,
63,
2759,
8,
932,
304,
1675,
372,
4341,
340,
1031,
14,
1708,
14,
466,
508,
25308,
14,
4129,
63,
9649,
26,
1675,
291,
14,
3764,
8,
932,
12,
298,
5556,
1077,
675,
282,
367,
4438,
2348,
531,
1675,
892,
275,
1031,
14,
6311,
342,
1675,
892,
14,
1861,
275,
399,
341,
1675,
892,
275,
6523,
8,
985,
8,
85,
2,
513,
1288,
359,
1222,
566,
1039,
916,
298,
1130,
63,
2734,
2,
315,
2058,
26,
1675,
892,
275,
3820,
2404,
8,
2604,
905,
9290,
4140,
6311,
1062,
202,
2574,
2058,
905,
3997,
4140,
6311,
1062,
202,
2574,
2058,
905,
390,
4140,
6311,
1012,
1039,
587,
26,
1675,
340,
298,
1130,
63,
3592,
2,
315,
2058,
26,
2628,
892,
275,
2058,
905,
1273,
4140,
6311,
342,
1675,
587,
26,
2628,
340,
298,
26995,
2,
315,
2058,
26,
4906,
1249,
275,
2058,
905,
26995,
937,
4906,
340,
1249,
14,
466,
508,
25308,
14,
26995,
436,
971,
202,
2432,
1249,
14,
3223,
59,
16,
1055,
466,
508,
1526,
14,
2339,
436,
971,
202,
2432,
1249,
14,
3223,
59,
16,
1055,
585,
508,
298,
403,
582,
8282,
291,
14,
3764,
8,
932,
12,
298,
11250,
3957,
2341,
8,
403,
12,
19172,
298,
202,
3660,
298,
1045,
3663,
2368,
2952,
2341,
342,
298,
202,
3660,
298,
2131,
14547,
83,
370,
314,
26564,
3414,
531,
8282,
372,
2628,
340,
315,
63,
6664,
63,
1100,
8,
932,
304,
4906,
372,
488,
2628,
892,
275,
1031,
14,
6311,
342,
1675,
892,
14,
1861,
275,
399,
341,
1675,
892,
275,
6523,
8,
985,
8,
85,
2,
513,
1288,
359,
1222,
566,
1039,
892,
14,
1861,
275,
1031,
14,
1861,
1039,
372,
892,
1223,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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
# Copyright 2012 OpenStack Foundation
# 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.
import collections
import os
import sys
import eventlet
eventlet.monkey_patch()
from oslo.config import cfg
from oslo import messaging
from oslo.utils import importutils
from neutron.agent.common import config
from neutron.agent.linux import dhcp
from neutron.agent.linux import external_process
from neutron.agent.linux import interface
from neutron.agent.linux import ovs_lib # noqa
from neutron.agent import rpc as agent_rpc
from neutron.common import config as common_config
from neutron.common import constants
from neutron.common import exceptions
from neutron.common import rpc as n_rpc
from neutron.common import topics
from neutron.common import utils
from neutron import context
from neutron.i18n import _LE, _LI, _LW
from neutron import manager
from neutron.openstack.common import log as logging
from neutron.openstack.common import loopingcall
from neutron.openstack.common import service
from neutron import service as neutron_service
LOG = logging.getLogger(__name__)
class DhcpAgent(manager.Manager):
"""DHCP agent service manager.
Note that the public methods of this class are exposed as the server side
of an rpc interface. The neutron server uses
neutron.api.rpc.agentnotifiers.dhcp_rpc_agent_api.DhcpAgentNotifyApi as the
client side to execute the methods here. For more information about
changing rpc interfaces, see doc/source/devref/rpc_api.rst.
"""
target = messaging.Target(version='1.0')
OPTS = [
cfg.IntOpt('resync_interval', default=5,
help=_("Interval to resync.")),
cfg.StrOpt('dhcp_driver',
default='neutron.agent.linux.dhcp.Dnsmasq',
help=_("The driver used to manage the DHCP server.")),
cfg.BoolOpt('enable_isolated_metadata', default=False,
help=_("Support Metadata requests on isolated networks.")),
cfg.BoolOpt('enable_metadata_network', default=False,
help=_("Allows for serving metadata requests from a "
"dedicated network. Requires "
"enable_isolated_metadata = True")),
cfg.IntOpt('num_sync_threads', default=4,
help=_('Number of threads to use during sync process.')),
cfg.StrOpt('metadata_proxy_socket',
default='$state_path/metadata_proxy',
help=_('Location of Metadata Proxy UNIX domain '
'socket')),
]
def __init__(self, host=None):
super(DhcpAgent, self).__init__(host=host)
self.needs_resync_reasons = collections.defaultdict(list)
self.conf = cfg.CONF
self.cache = NetworkCache()
self.root_helper = config.get_root_helper(self.conf)
self.dhcp_driver_cls = importutils.import_class(self.conf.dhcp_driver)
ctx = context.get_admin_context_without_session()
self.plugin_rpc = DhcpPluginApi(topics.PLUGIN,
ctx, self.conf.use_namespaces)
# create dhcp dir to store dhcp info
dhcp_dir = os.path.dirname("/%s/dhcp/" % self.conf.state_path)
if not os.path.isdir(dhcp_dir):
os.makedirs(dhcp_dir, 0o755)
self.dhcp_version = self.dhcp_driver_cls.check_version()
self._populate_networks_cache()
def _populate_networks_cache(self):
"""Populate the networks cache when the DHCP-agent starts."""
try:
existing_networks = self.dhcp_driver_cls.existing_dhcp_networks(
self.conf,
self.root_helper
)
for net_id in existing_networks:
net = dhcp.NetModel(self.conf.use_namespaces,
{"id": net_id,
"subnets": [],
"ports": []})
self.cache.put(net)
except NotImplementedError:
# just go ahead with an empty networks cache
LOG.debug("The '%s' DHCP-driver does not support retrieving of a "
"list of existing networks",
self.conf.dhcp_driver)
def after_start(self):
self.run()
LOG.info(_LI("DHCP agent started"))
def run(self):
"""Activate the DHCP agent."""
self.sync_state()
self.periodic_resync()
def call_driver(self, action, network, **action_kwargs):
"""Invoke an action on a DHCP driver instance."""
LOG.debug('Calling driver for network: %(net)s action: %(action)s',
{'net': network.id, 'action': action})
try:
# the Driver expects something that is duck typed similar to
# the base models.
driver = self.dhcp_driver_cls(self.conf,
network,
self.root_helper,
self.dhcp_version,
self.plugin_rpc)
getattr(driver, action)(**action_kwargs)
return True
except exceptions.Conflict:
# No need to resync here, the agent will receive the event related
# to a status update for the network
LOG.warning(_LW('Unable to %(action)s dhcp for %(net_id)s: there '
'is a conflict with its current state; please '
'check that the network and/or its subnet(s) '
'still exist.'),
{'net_id': network.id, 'action': action})
except Exception as e:
self.schedule_resync(e, network.id)
if (isinstance(e, messaging.RemoteError)
and e.exc_type == 'NetworkNotFound'
or isinstance(e, exceptions.NetworkNotFound)):
LOG.warning(_LW("Network %s has been deleted."), network.id)
else:
LOG.exception(_LE('Unable to %(action)s dhcp for %(net_id)s.'),
{'net_id': network.id, 'action': action})
def schedule_resync(self, reason, network=None):
"""Schedule a resync for a given network and reason. If no network is
specified, resync all networks.
"""
self.needs_resync_reasons[network].append(reason)
@utils.synchronized('dhcp-agent')
def sync_state(self, networks=None):
"""Sync the local DHCP state with Neutron. If no networks are passed,
or 'None' is one of the networks, sync all of the networks.
"""
only_nets = set([] if (not networks or None in networks) else networks)
LOG.info(_LI('Synchronizing state'))
pool = eventlet.GreenPool(cfg.CONF.num_sync_threads)
known_network_ids = set(self.cache.get_network_ids())
try:
active_networks = self.plugin_rpc.get_active_networks_info()
active_network_ids = set(network.id for network in active_networks)
for deleted_id in known_network_ids - active_network_ids:
try:
self.disable_dhcp_helper(deleted_id)
except Exception as e:
self.schedule_resync(e, deleted_id)
LOG.exception(_LE('Unable to sync network state on '
'deleted network %s'), deleted_id)
for network in active_networks:
if (not only_nets or # specifically resync all
network.id not in known_network_ids or # missing net
network.id in only_nets): # specific network to sync
pool.spawn(self.safe_configure_dhcp_for_network, network)
pool.waitall()
LOG.info(_LI('Synchronizing state complete'))
except Exception as e:
self.schedule_resync(e)
LOG.exception(_LE('Unable to sync network state.'))
@utils.exception_logger()
def _periodic_resync_helper(self):
"""Resync the dhcp state at the configured interval."""
while True:
eventlet.sleep(self.conf.resync_interval)
if self.needs_resync_reasons:
# be careful to avoid a race with additions to list
# from other threads
reasons = self.needs_resync_reasons
self.needs_resync_reasons = collections.defaultdict(list)
for net, r in reasons.items():
if not net:
net = "*"
LOG.debug("resync (%(network)s): %(reason)s",
{"reason": r, "network": net})
self.sync_state(reasons.keys())
def periodic_resync(self):
"""Spawn a thread to periodically resync the dhcp state."""
eventlet.spawn(self._periodic_resync_helper)
def safe_get_network_info(self, network_id):
try:
network = self.plugin_rpc.get_network_info(network_id)
if not network:
LOG.warn(_LW('Network %s has been deleted.'), network_id)
return network
except Exception as e:
self.schedule_resync(e, network_id)
LOG.exception(_LE('Network %s info call failed.'), network_id)
def enable_dhcp_helper(self, network_id):
"""Enable DHCP for a network that meets enabling criteria."""
network = self.safe_get_network_info(network_id)
if network:
self.configure_dhcp_for_network(network)
@utils.exception_logger()
def safe_configure_dhcp_for_network(self, network):
try:
self.configure_dhcp_for_network(network)
except (exceptions.NetworkNotFound, RuntimeError):
LOG.warn(_LW('Network %s may have been deleted and its resources '
'may have already been disposed.'), network.id)
def configure_dhcp_for_network(self, network):
if not network.admin_state_up:
return
enable_metadata = self.dhcp_driver_cls.should_enable_metadata(
self.conf, network)
dhcp_network_enabled = False
for subnet in network.subnets:
if subnet.enable_dhcp:
if self.call_driver('enable', network):
dhcp_network_enabled = True
self.cache.put(network)
break
if enable_metadata and dhcp_network_enabled:
for subnet in network.subnets:
if subnet.ip_version == 4 and subnet.enable_dhcp:
self.enable_isolated_metadata_proxy(network)
break
def disable_dhcp_helper(self, network_id):
"""Disable DHCP for a network known to the agent."""
network = self.cache.get_network_by_id(network_id)
if network:
if (self.conf.use_namespaces and
self.conf.enable_isolated_metadata):
# NOTE(jschwarz): In the case where a network is deleted, all
# the subnets and ports are deleted before this function is
# called, so checking if 'should_enable_metadata' is True
# for any subnet is false logic here.
self.disable_isolated_metadata_proxy(network)
if self.call_driver('disable', network):
self.cache.remove(network)
def refresh_dhcp_helper(self, network_id):
"""Refresh or disable DHCP for a network depending on the current state
of the network.
"""
old_network = self.cache.get_network_by_id(network_id)
if not old_network:
# DHCP current not running for network.
return self.enable_dhcp_helper(network_id)
network = self.safe_get_network_info(network_id)
if not network:
return
old_cidrs = set(s.cidr for s in old_network.subnets if s.enable_dhcp)
new_cidrs = set(s.cidr for s in network.subnets if s.enable_dhcp)
if new_cidrs and old_cidrs == new_cidrs:
self.call_driver('reload_allocations', network)
self.cache.put(network)
elif new_cidrs:
if self.call_driver('restart', network):
self.cache.put(network)
else:
self.disable_dhcp_helper(network.id)
@utils.synchronized('dhcp-agent')
def network_create_end(self, context, payload):
"""Handle the network.create.end notification event."""
network_id = payload['network']['id']
self.enable_dhcp_helper(network_id)
@utils.synchronized('dhcp-agent')
def network_update_end(self, context, payload):
"""Handle the network.update.end notification event."""
network_id = payload['network']['id']
if payload['network']['admin_state_up']:
self.enable_dhcp_helper(network_id)
else:
self.disable_dhcp_helper(network_id)
@utils.synchronized('dhcp-agent')
def network_delete_end(self, context, payload):
"""Handle the network.delete.end notification event."""
self.disable_dhcp_helper(payload['network_id'])
@utils.synchronized('dhcp-agent')
def subnet_update_end(self, context, payload):
"""Handle the subnet.update.end notification event."""
network_id = payload['subnet']['network_id']
self.refresh_dhcp_helper(network_id)
# Use the update handler for the subnet create event.
subnet_create_end = subnet_update_end
@utils.synchronized('dhcp-agent')
def subnet_delete_end(self, context, payload):
"""Handle the subnet.delete.end notification event."""
subnet_id = payload['subnet_id']
network = self.cache.get_network_by_subnet_id(subnet_id)
if network:
self.refresh_dhcp_helper(network.id)
@utils.synchronized('dhcp-agent')
def port_update_end(self, context, payload):
"""Handle the port.update.end notification event."""
updated_port = dhcp.DictModel(payload['port'])
network = self.cache.get_network_by_id(updated_port.network_id)
if network:
self.cache.put_port(updated_port)
self.call_driver('reload_allocations', network)
# Use the update handler for the port create event.
port_create_end = port_update_end
@utils.synchronized('dhcp-agent')
def port_delete_end(self, context, payload):
"""Handle the port.delete.end notification event."""
port = self.cache.get_port_by_id(payload['port_id'])
if port:
network = self.cache.get_network_by_id(port.network_id)
self.cache.remove_port(port)
self.call_driver('reload_allocations', network)
def enable_isolated_metadata_proxy(self, network):
# The proxy might work for either a single network
# or all the networks connected via a router
# to the one passed as a parameter
neutron_lookup_param = '--network_id=%s' % network.id
# When the metadata network is enabled, the proxy might
# be started for the router attached to the network
if self.conf.enable_metadata_network:
router_ports = [port for port in network.ports
if (port.device_owner ==
constants.DEVICE_OWNER_ROUTER_INTF)]
if router_ports:
# Multiple router ports should not be allowed
if len(router_ports) > 1:
LOG.warning(_LW("%(port_num)d router ports found on the "
"metadata access network. Only the port "
"%(port_id)s, for router %(router_id)s "
"will be considered"),
{'port_num': len(router_ports),
'port_id': router_ports[0].id,
'router_id': router_ports[0].device_id})
neutron_lookup_param = ('--router_id=%s' %
router_ports[0].device_id)
def callback(pid_file):
metadata_proxy_socket = cfg.CONF.metadata_proxy_socket
proxy_cmd = ['neutron-ns-metadata-proxy',
'--pid_file=%s' % pid_file,
'--metadata_proxy_socket=%s' % metadata_proxy_socket,
neutron_lookup_param,
'--state_path=%s' % self.conf.state_path,
'--metadata_port=%d' % dhcp.METADATA_PORT]
proxy_cmd.extend(config.get_log_args(
cfg.CONF, 'neutron-ns-metadata-proxy-%s.log' % network.id))
return proxy_cmd
pm = external_process.ProcessManager(
self.conf,
network.id,
self.root_helper,
network.namespace)
pm.enable(callback)
def disable_isolated_metadata_proxy(self, network):
pm = external_process.ProcessManager(
self.conf,
network.id,
self.root_helper,
network.namespace)
pm.disable()
class DhcpPluginApi(object):
"""Agent side of the dhcp rpc API.
This class implements the client side of an rpc interface. The server side
of this interface can be found in
neutron.api.rpc.handlers.dhcp_rpc.DhcpRpcCallback. For more information
about changing rpc interfaces, see doc/source/devref/rpc_api.rst.
API version history:
1.0 - Initial version.
1.1 - Added get_active_networks_info, create_dhcp_port,
and update_dhcp_port methods.
"""
def __init__(self, topic, context, use_namespaces):
self.context = context
self.host = cfg.CONF.host
self.use_namespaces = use_namespaces
target = messaging.Target(
topic=topic,
namespace=constants.RPC_NAMESPACE_DHCP_PLUGIN,
version='1.0')
self.client = n_rpc.get_client(target)
def get_active_networks_info(self):
"""Make a remote process call to retrieve all network info."""
cctxt = self.client.prepare(version='1.1')
networks = cctxt.call(self.context, 'get_active_networks_info',
host=self.host)
return [dhcp.NetModel(self.use_namespaces, n) for n in networks]
def get_network_info(self, network_id):
"""Make a remote process call to retrieve network info."""
cctxt = self.client.prepare()
network = cctxt.call(self.context, 'get_network_info',
network_id=network_id, host=self.host)
if network:
return dhcp.NetModel(self.use_namespaces, network)
def get_dhcp_port(self, network_id, device_id):
"""Make a remote process call to get the dhcp port."""
cctxt = self.client.prepare()
port = cctxt.call(self.context, 'get_dhcp_port',
network_id=network_id, device_id=device_id,
host=self.host)
if port:
return dhcp.DictModel(port)
def create_dhcp_port(self, port):
"""Make a remote process call to create the dhcp port."""
cctxt = self.client.prepare(version='1.1')
port = cctxt.call(self.context, 'create_dhcp_port',
port=port, host=self.host)
if port:
return dhcp.DictModel(port)
def update_dhcp_port(self, port_id, port):
"""Make a remote process call to update the dhcp port."""
cctxt = self.client.prepare(version='1.1')
port = cctxt.call(self.context, 'update_dhcp_port',
port_id=port_id, port=port, host=self.host)
if port:
return dhcp.DictModel(port)
def release_dhcp_port(self, network_id, device_id):
"""Make a remote process call to release the dhcp port."""
cctxt = self.client.prepare()
return cctxt.call(self.context, 'release_dhcp_port',
network_id=network_id, device_id=device_id,
host=self.host)
def release_port_fixed_ip(self, network_id, device_id, subnet_id):
"""Make a remote process call to release a fixed_ip on the port."""
cctxt = self.client.prepare()
return cctxt.call(self.context, 'release_port_fixed_ip',
network_id=network_id, subnet_id=subnet_id,
device_id=device_id, host=self.host)
class NetworkCache(object):
"""Agent cache of the current network state."""
def __init__(self):
self.cache = {}
self.subnet_lookup = {}
self.port_lookup = {}
def get_network_ids(self):
return self.cache.keys()
def get_network_by_id(self, network_id):
return self.cache.get(network_id)
def get_network_by_subnet_id(self, subnet_id):
return self.cache.get(self.subnet_lookup.get(subnet_id))
def get_network_by_port_id(self, port_id):
return self.cache.get(self.port_lookup.get(port_id))
def put(self, network):
if network.id in self.cache:
self.remove(self.cache[network.id])
self.cache[network.id] = network
for subnet in network.subnets:
self.subnet_lookup[subnet.id] = network.id
for port in network.ports:
self.port_lookup[port.id] = network.id
def remove(self, network):
del self.cache[network.id]
for subnet in network.subnets:
del self.subnet_lookup[subnet.id]
for port in network.ports:
del self.port_lookup[port.id]
def put_port(self, port):
network = self.get_network_by_id(port.network_id)
for index in range(len(network.ports)):
if network.ports[index].id == port.id:
network.ports[index] = port
break
else:
network.ports.append(port)
self.port_lookup[port.id] = network.id
def remove_port(self, port):
network = self.get_network_by_port_id(port.id)
for index in range(len(network.ports)):
if network.ports[index] == port:
del network.ports[index]
del self.port_lookup[port.id]
break
def get_port_by_id(self, port_id):
network = self.get_network_by_port_id(port_id)
if network:
for port in network.ports:
if port.id == port_id:
return port
def get_state(self):
net_ids = self.get_network_ids()
num_nets = len(net_ids)
num_subnets = 0
num_ports = 0
for net_id in net_ids:
network = self.get_network_by_id(net_id)
num_subnets += len(network.subnets)
num_ports += len(network.ports)
return {'networks': num_nets,
'subnets': num_subnets,
'ports': num_ports}
class DhcpAgentWithStateReport(DhcpAgent):
def __init__(self, host=None):
super(DhcpAgentWithStateReport, self).__init__(host=host)
self.state_rpc = agent_rpc.PluginReportStateAPI(topics.PLUGIN)
self.agent_state = {
'binary': 'neutron-dhcp-agent',
'host': host,
'topic': topics.DHCP_AGENT,
'configurations': {
'dhcp_driver': cfg.CONF.dhcp_driver,
'use_namespaces': cfg.CONF.use_namespaces,
'dhcp_lease_duration': cfg.CONF.dhcp_lease_duration},
'start_flag': True,
'agent_type': constants.AGENT_TYPE_DHCP}
report_interval = cfg.CONF.AGENT.report_interval
self.use_call = True
if report_interval:
self.heartbeat = loopingcall.FixedIntervalLoopingCall(
self._report_state)
self.heartbeat.start(interval=report_interval)
def _report_state(self):
try:
self.agent_state.get('configurations').update(
self.cache.get_state())
ctx = context.get_admin_context_without_session()
self.state_rpc.report_state(ctx, self.agent_state, self.use_call)
self.use_call = False
except AttributeError:
# This means the server does not support report_state
LOG.warn(_LW("Neutron server does not support state report."
" State report for this agent will be disabled."))
self.heartbeat.stop()
self.run()
return
except Exception:
LOG.exception(_LE("Failed reporting state!"))
return
if self.agent_state.pop('start_flag', None):
self.run()
def agent_updated(self, context, payload):
"""Handle the agent_updated notification event."""
self.schedule_resync(_("Agent updated: %(payload)s") %
{"payload": payload})
LOG.info(_LI("agent_updated by server side %s!"), payload)
def after_start(self):
LOG.info(_LI("DHCP agent started"))
def register_options():
cfg.CONF.register_opts(DhcpAgent.OPTS)
config.register_interface_driver_opts_helper(cfg.CONF)
config.register_use_namespaces_opts_helper(cfg.CONF)
config.register_agent_state_opts_helper(cfg.CONF)
config.register_root_helper(cfg.CONF)
cfg.CONF.register_opts(dhcp.OPTS)
cfg.CONF.register_opts(interface.OPTS)
def main():
register_options()
common_config.init(sys.argv[1:])
config.setup_logging()
server = neutron_service.Service.create(
binary='neutron-dhcp-agent',
topic=topics.DHCP_AGENT,
report_interval=cfg.CONF.AGENT.report_interval,
manager='neutron.agent.dhcp_agent.DhcpAgentWithStateReport')
service.launch(server).wait()
|
apache-2.0
|
[
3,
1898,
6029,
14260,
2752,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
646,
5055,
199,
646,
747,
199,
646,
984,
199,
199,
646,
21819,
199,
1430,
2723,
14,
20372,
63,
2068,
342,
199,
199,
504,
11258,
14,
888,
492,
4810,
199,
504,
11258,
492,
30429,
199,
504,
11258,
14,
1208,
492,
492,
1208,
199,
199,
504,
8224,
14,
4054,
14,
2330,
492,
1101,
199,
504,
8224,
14,
4054,
14,
5135,
492,
19064,
199,
504,
8224,
14,
4054,
14,
5135,
492,
5957,
63,
1412,
199,
504,
8224,
14,
4054,
14,
5135,
492,
3217,
199,
504,
8224,
14,
4054,
14,
5135,
492,
23671,
63,
773,
221,
327,
8151,
199,
504,
8224,
14,
4054,
492,
8985,
465,
6631,
63,
4354,
199,
504,
8224,
14,
2330,
492,
1101,
465,
2863,
63,
888,
199,
504,
8224,
14,
2330,
492,
5262,
199,
504,
8224,
14,
2330,
492,
4967,
199,
504,
8224,
14,
2330,
492,
8985,
465,
302,
63,
4354,
199,
504,
8224,
14,
2330,
492,
17398,
199,
504,
8224,
14,
2330,
492,
3778,
199,
504,
8224,
492,
1067,
199,
504,
8224,
14,
73,
1085,
78,
492,
485,
906,
12,
485,
2673,
12,
485,
20145,
199,
504,
8224,
492,
5256,
199,
504,
8224,
14,
8512,
14,
2330,
492,
943,
465,
2050,
199,
504,
8224,
14,
8512,
14,
2330,
492,
4438,
316,
1250,
199,
504,
8224,
14,
8512,
14,
2330,
492,
2435,
199,
504,
8224,
492,
2435,
465,
8224,
63,
1364,
199,
199,
4947,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
577,
14968,
7788,
8,
2609,
14,
2988,
304,
272,
408,
29977,
6631,
2435,
5256,
14,
339,
3390,
626,
314,
4575,
3102,
402,
642,
1021,
787,
19282,
465,
314,
1654,
5366,
272,
402,
376,
8985,
3217,
14,
221,
710,
8224,
1654,
4440,
272,
8224,
14,
1246,
14,
4354,
14,
4054,
889,
1428,
1192,
14,
10801,
63,
4354,
63,
4054,
63,
1246,
14,
36,
14968,
7788,
8645,
7394,
465,
314,
272,
1890,
5366,
370,
5341,
314,
3102,
2348,
14,
221,
2104,
1655,
2556,
3595,
272,
13729,
8985,
8386,
12,
1937,
1382,
15,
1365,
15,
2374,
1121,
15,
4354,
63,
1246,
14,
8332,
14,
272,
408,
272,
1347,
275,
30429,
14,
4277,
8,
1023,
534,
17,
14,
16,
358,
339,
11662,
51,
275,
359,
267,
4810,
14,
3241,
9985,
360,
470,
1870,
63,
4284,
297,
849,
29,
21,
12,
673,
1720,
9384,
8227,
370,
522,
1870,
2685,
395,
267,
4810,
14,
19340,
360,
10801,
63,
3090,
297,
673,
849,
534,
10271,
14,
4054,
14,
5135,
14,
10801,
14,
27664,
5892,
81,
297,
673,
1720,
9384,
1918,
5253,
1202,
370,
9635,
314,
26821,
1654,
2685,
395,
267,
4810,
14,
10349,
9985,
360,
4296,
63,
21748,
63,
2343,
297,
849,
29,
797,
12,
490,
1720,
9384,
11532,
16160,
4145,
641,
23348,
11759,
2685,
395,
267,
4810,
14,
10349,
9985,
360,
4296,
63,
2343,
63,
1200,
297,
849,
29,
797,
12,
490,
1720,
9384,
19780,
367,
22701,
3341,
4145,
687,
282,
298,
2574,
298,
271,
24489,
2784,
14,
15127,
298,
2574,
298,
4296,
63,
21748,
63,
2343,
275,
715,
8150,
267,
4810,
14,
3241,
9985,
360,
1507,
63,
5186,
63,
6962,
297,
849,
29,
20,
12,
673,
1720,
12397,
3259,
402,
7183,
370,
675,
5309,
7604,
2112,
2659,
395,
267,
4810,
14,
19340,
360,
2343,
63,
3280,
63,
3450,
297,
673,
849,
24269,
929,
63,
515,
15,
2343,
63,
3280,
297,
673,
1720,
12397,
6592,
402,
16160,
12373,
22242,
2881,
283,
2079,
283,
3450,
3855,
272,
1622,
339,
347,
636,
826,
721,
277,
12,
1591,
29,
403,
304,
267,
1613,
8,
36,
14968,
7788,
12,
291,
2843,
826,
721,
1102,
29,
1102,
9,
267,
291,
14,
10065,
63,
470,
1870,
63,
5764,
83,
275,
5055,
14,
21501,
8,
513,
9,
267,
291,
14,
2190,
275,
4810,
14,
3103,
267,
291,
14,
1637,
275,
7220,
4437,
342,
267,
291,
14,
1231,
63,
3676,
275,
1101,
14,
362,
63,
1231,
63,
3676,
8,
277,
14,
2190,
9,
267,
291,
14,
10801,
63,
3090,
63,
1886,
275,
492,
1208,
14,
646,
63,
533,
8,
277,
14,
2190,
14,
10801,
63,
3090,
9,
267,
4027,
275,
1067,
14,
362,
63,
2113,
63,
1100,
63,
7395,
63,
1730,
342,
267,
291,
14,
2718,
63,
4354,
275,
577,
14968,
5061,
7394,
8,
11299,
14,
19108,
12,
3147,
4027,
12,
291,
14,
2190,
14,
1180,
63,
9247,
9,
267,
327,
1218,
19064,
2935,
370,
3877,
19064,
2256,
267,
19064,
63,
694,
275,
747,
14,
515,
14,
3475,
480,
3149,
83,
15,
10801,
6687,
450,
291,
14,
2190,
14,
929,
63,
515,
9,
267,
340,
440,
747,
14,
515,
14,
6027,
8,
10801,
63,
694,
304,
288,
747,
14,
8347,
8,
10801,
63,
694,
12,
378,
79,
12315,
9,
267,
291,
14,
10801,
63,
1023,
275,
291,
14,
10801,
63,
3090,
63,
1886,
14,
1074,
63,
1023,
342,
267,
291,
423,
13817,
63,
7642,
63,
1637,
342,
339,
347,
485,
13817,
63,
7642,
63,
1637,
8,
277,
304,
267,
408,
9606,
5434,
314,
11759,
2581,
1380,
314,
26821,
13,
4054,
9174,
1041,
267,
862,
26,
288,
3411,
63,
7642,
275,
291,
14,
10801,
63,
3090,
63,
1886,
14,
5952,
63,
10801,
63,
7642,
8,
355,
291,
14,
2190,
12,
355,
291,
14,
1231,
63,
3676,
288,
776,
288,
367,
1851,
63,
344,
315,
3411,
63,
7642,
26,
355,
1851,
275,
19064,
14,
2480,
1685,
8,
277,
14,
2190,
14,
1180,
63,
9247
] |
[
1898,
6029,
14260,
2752,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
646,
5055,
199,
646,
747,
199,
646,
984,
199,
199,
646,
21819,
199,
1430,
2723,
14,
20372,
63,
2068,
342,
199,
199,
504,
11258,
14,
888,
492,
4810,
199,
504,
11258,
492,
30429,
199,
504,
11258,
14,
1208,
492,
492,
1208,
199,
199,
504,
8224,
14,
4054,
14,
2330,
492,
1101,
199,
504,
8224,
14,
4054,
14,
5135,
492,
19064,
199,
504,
8224,
14,
4054,
14,
5135,
492,
5957,
63,
1412,
199,
504,
8224,
14,
4054,
14,
5135,
492,
3217,
199,
504,
8224,
14,
4054,
14,
5135,
492,
23671,
63,
773,
221,
327,
8151,
199,
504,
8224,
14,
4054,
492,
8985,
465,
6631,
63,
4354,
199,
504,
8224,
14,
2330,
492,
1101,
465,
2863,
63,
888,
199,
504,
8224,
14,
2330,
492,
5262,
199,
504,
8224,
14,
2330,
492,
4967,
199,
504,
8224,
14,
2330,
492,
8985,
465,
302,
63,
4354,
199,
504,
8224,
14,
2330,
492,
17398,
199,
504,
8224,
14,
2330,
492,
3778,
199,
504,
8224,
492,
1067,
199,
504,
8224,
14,
73,
1085,
78,
492,
485,
906,
12,
485,
2673,
12,
485,
20145,
199,
504,
8224,
492,
5256,
199,
504,
8224,
14,
8512,
14,
2330,
492,
943,
465,
2050,
199,
504,
8224,
14,
8512,
14,
2330,
492,
4438,
316,
1250,
199,
504,
8224,
14,
8512,
14,
2330,
492,
2435,
199,
504,
8224,
492,
2435,
465,
8224,
63,
1364,
199,
199,
4947,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
577,
14968,
7788,
8,
2609,
14,
2988,
304,
272,
408,
29977,
6631,
2435,
5256,
14,
339,
3390,
626,
314,
4575,
3102,
402,
642,
1021,
787,
19282,
465,
314,
1654,
5366,
272,
402,
376,
8985,
3217,
14,
221,
710,
8224,
1654,
4440,
272,
8224,
14,
1246,
14,
4354,
14,
4054,
889,
1428,
1192,
14,
10801,
63,
4354,
63,
4054,
63,
1246,
14,
36,
14968,
7788,
8645,
7394,
465,
314,
272,
1890,
5366,
370,
5341,
314,
3102,
2348,
14,
221,
2104,
1655,
2556,
3595,
272,
13729,
8985,
8386,
12,
1937,
1382,
15,
1365,
15,
2374,
1121,
15,
4354,
63,
1246,
14,
8332,
14,
272,
408,
272,
1347,
275,
30429,
14,
4277,
8,
1023,
534,
17,
14,
16,
358,
339,
11662,
51,
275,
359,
267,
4810,
14,
3241,
9985,
360,
470,
1870,
63,
4284,
297,
849,
29,
21,
12,
673,
1720,
9384,
8227,
370,
522,
1870,
2685,
395,
267,
4810,
14,
19340,
360,
10801,
63,
3090,
297,
673,
849,
534,
10271,
14,
4054,
14,
5135,
14,
10801,
14,
27664,
5892,
81,
297,
673,
1720,
9384,
1918,
5253,
1202,
370,
9635,
314,
26821,
1654,
2685,
395,
267,
4810,
14,
10349,
9985,
360,
4296,
63,
21748,
63,
2343,
297,
849,
29,
797,
12,
490,
1720,
9384,
11532,
16160,
4145,
641,
23348,
11759,
2685,
395,
267,
4810,
14,
10349,
9985,
360,
4296,
63,
2343,
63,
1200,
297,
849,
29,
797,
12,
490,
1720,
9384,
19780,
367,
22701,
3341,
4145,
687,
282,
298,
2574,
298,
271,
24489,
2784,
14,
15127,
298,
2574,
298,
4296,
63,
21748,
63,
2343,
275,
715,
8150,
267,
4810,
14,
3241,
9985,
360,
1507,
63,
5186,
63,
6962,
297,
849,
29,
20,
12,
673,
1720,
12397,
3259,
402,
7183,
370,
675,
5309,
7604,
2112,
2659,
395,
267,
4810,
14,
19340,
360,
2343,
63,
3280,
63,
3450,
297,
673,
849,
24269,
929,
63,
515,
15,
2343,
63,
3280,
297,
673,
1720,
12397,
6592,
402,
16160,
12373,
22242,
2881,
283,
2079,
283,
3450,
3855,
272,
1622,
339,
347,
636,
826,
721,
277,
12,
1591,
29,
403,
304,
267,
1613,
8,
36,
14968,
7788,
12,
291,
2843,
826,
721,
1102,
29,
1102,
9,
267,
291,
14,
10065,
63,
470,
1870,
63,
5764,
83,
275,
5055,
14,
21501,
8,
513,
9,
267,
291,
14,
2190,
275,
4810,
14,
3103,
267,
291,
14,
1637,
275,
7220,
4437,
342,
267,
291,
14,
1231,
63,
3676,
275,
1101,
14,
362,
63,
1231,
63,
3676,
8,
277,
14,
2190,
9,
267,
291,
14,
10801,
63,
3090,
63,
1886,
275,
492,
1208,
14,
646,
63,
533,
8,
277,
14,
2190,
14,
10801,
63,
3090,
9,
267,
4027,
275,
1067,
14,
362,
63,
2113,
63,
1100,
63,
7395,
63,
1730,
342,
267,
291,
14,
2718,
63,
4354,
275,
577,
14968,
5061,
7394,
8,
11299,
14,
19108,
12,
3147,
4027,
12,
291,
14,
2190,
14,
1180,
63,
9247,
9,
267,
327,
1218,
19064,
2935,
370,
3877,
19064,
2256,
267,
19064,
63,
694,
275,
747,
14,
515,
14,
3475,
480,
3149,
83,
15,
10801,
6687,
450,
291,
14,
2190,
14,
929,
63,
515,
9,
267,
340,
440,
747,
14,
515,
14,
6027,
8,
10801,
63,
694,
304,
288,
747,
14,
8347,
8,
10801,
63,
694,
12,
378,
79,
12315,
9,
267,
291,
14,
10801,
63,
1023,
275,
291,
14,
10801,
63,
3090,
63,
1886,
14,
1074,
63,
1023,
342,
267,
291,
423,
13817,
63,
7642,
63,
1637,
342,
339,
347,
485,
13817,
63,
7642,
63,
1637,
8,
277,
304,
267,
408,
9606,
5434,
314,
11759,
2581,
1380,
314,
26821,
13,
4054,
9174,
1041,
267,
862,
26,
288,
3411,
63,
7642,
275,
291,
14,
10801,
63,
3090,
63,
1886,
14,
5952,
63,
10801,
63,
7642,
8,
355,
291,
14,
2190,
12,
355,
291,
14,
1231,
63,
3676,
288,
776,
288,
367,
1851,
63,
344,
315,
3411,
63,
7642,
26,
355,
1851,
275,
19064,
14,
2480,
1685,
8,
277,
14,
2190,
14,
1180,
63,
9247,
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,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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
] |
synasius/django
|
tests/migrations/test_executor.py
|
80
|
26645
|
from django.apps.registry import apps as global_apps
from django.db import connection
from django.db.migrations.exceptions import InvalidMigrationPlan
from django.db.migrations.executor import MigrationExecutor
from django.db.migrations.graph import MigrationGraph
from django.db.migrations.recorder import MigrationRecorder
from django.db.utils import DatabaseError
from django.test import TestCase, modify_settings, override_settings
from .test_base import MigrationTestBase
@modify_settings(INSTALLED_APPS={'append': 'migrations2'})
class ExecutorTests(MigrationTestBase):
"""
Tests the migration executor (full end-to-end running).
Bear in mind that if these are failing you should fix the other
test failures first, as they may be propagating into here.
"""
available_apps = ["migrations", "migrations2", "django.contrib.auth", "django.contrib.contenttypes"]
@override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations"})
def test_run(self):
"""
Tests running a simple set of migrations.
"""
executor = MigrationExecutor(connection)
# Let's look at the plan first and make sure it's up to scratch
plan = executor.migration_plan([("migrations", "0002_second")])
self.assertEqual(
plan,
[
(executor.loader.graph.nodes["migrations", "0001_initial"], False),
(executor.loader.graph.nodes["migrations", "0002_second"], False),
],
)
# Were the tables there before?
self.assertTableNotExists("migrations_author")
self.assertTableNotExists("migrations_book")
# Alright, let's try running it
executor.migrate([("migrations", "0002_second")])
# Are the tables there now?
self.assertTableExists("migrations_author")
self.assertTableExists("migrations_book")
# Rebuild the graph to reflect the new DB state
executor.loader.build_graph()
# Alright, let's undo what we did
plan = executor.migration_plan([("migrations", None)])
self.assertEqual(
plan,
[
(executor.loader.graph.nodes["migrations", "0002_second"], True),
(executor.loader.graph.nodes["migrations", "0001_initial"], True),
],
)
executor.migrate([("migrations", None)])
# Are the tables gone?
self.assertTableNotExists("migrations_author")
self.assertTableNotExists("migrations_book")
@override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations_squashed"})
def test_run_with_squashed(self):
"""
Tests running a squashed migration from zero (should ignore what it replaces)
"""
executor = MigrationExecutor(connection)
# Check our leaf node is the squashed one
leaves = [key for key in executor.loader.graph.leaf_nodes() if key[0] == "migrations"]
self.assertEqual(leaves, [("migrations", "0001_squashed_0002")])
# Check the plan
plan = executor.migration_plan([("migrations", "0001_squashed_0002")])
self.assertEqual(
plan,
[
(executor.loader.graph.nodes["migrations", "0001_squashed_0002"], False),
],
)
# Were the tables there before?
self.assertTableNotExists("migrations_author")
self.assertTableNotExists("migrations_book")
# Alright, let's try running it
executor.migrate([("migrations", "0001_squashed_0002")])
# Are the tables there now?
self.assertTableExists("migrations_author")
self.assertTableExists("migrations_book")
# Rebuild the graph to reflect the new DB state
executor.loader.build_graph()
# Alright, let's undo what we did. Should also just use squashed.
plan = executor.migration_plan([("migrations", None)])
self.assertEqual(
plan,
[
(executor.loader.graph.nodes["migrations", "0001_squashed_0002"], True),
],
)
executor.migrate([("migrations", None)])
# Are the tables gone?
self.assertTableNotExists("migrations_author")
self.assertTableNotExists("migrations_book")
@override_settings(MIGRATION_MODULES={
"migrations": "migrations.test_migrations",
"migrations2": "migrations2.test_migrations_2",
})
def test_empty_plan(self):
"""
Tests that re-planning a full migration of a fully-migrated set doesn't
perform spurious unmigrations and remigrations.
There was previously a bug where the executor just always performed the
backwards plan for applied migrations - which even for the most recent
migration in an app, might include other, dependent apps, and these
were being unmigrated.
"""
# Make the initial plan, check it
executor = MigrationExecutor(connection)
plan = executor.migration_plan([
("migrations", "0002_second"),
("migrations2", "0001_initial"),
])
self.assertEqual(
plan,
[
(executor.loader.graph.nodes["migrations", "0001_initial"], False),
(executor.loader.graph.nodes["migrations", "0002_second"], False),
(executor.loader.graph.nodes["migrations2", "0001_initial"], False),
],
)
# Fake-apply all migrations
executor.migrate([
("migrations", "0002_second"),
("migrations2", "0001_initial")
], fake=True)
# Rebuild the graph to reflect the new DB state
executor.loader.build_graph()
# Now plan a second time and make sure it's empty
plan = executor.migration_plan([
("migrations", "0002_second"),
("migrations2", "0001_initial"),
])
self.assertEqual(plan, [])
# Erase all the fake records
executor.recorder.record_unapplied("migrations2", "0001_initial")
executor.recorder.record_unapplied("migrations", "0002_second")
executor.recorder.record_unapplied("migrations", "0001_initial")
@override_settings(MIGRATION_MODULES={
"migrations": "migrations.test_migrations",
"migrations2": "migrations2.test_migrations_2_no_deps",
})
def test_mixed_plan_not_supported(self):
"""
Although the MigrationExecutor interfaces allows for mixed migration
plans (combined forwards and backwards migrations) this is not
supported.
"""
# Prepare for mixed plan
executor = MigrationExecutor(connection)
plan = executor.migration_plan([("migrations", "0002_second")])
self.assertEqual(
plan,
[
(executor.loader.graph.nodes["migrations", "0001_initial"], False),
(executor.loader.graph.nodes["migrations", "0002_second"], False),
],
)
executor.migrate(None, plan)
# Rebuild the graph to reflect the new DB state
executor.loader.build_graph()
self.assertIn(('migrations', '0001_initial'), executor.loader.applied_migrations)
self.assertIn(('migrations', '0002_second'), executor.loader.applied_migrations)
self.assertNotIn(('migrations2', '0001_initial'), executor.loader.applied_migrations)
# Generate mixed plan
plan = executor.migration_plan([
("migrations", None),
("migrations2", "0001_initial"),
])
msg = (
'Migration plans with both forwards and backwards migrations are '
'not supported. Please split your migration process into separate '
'plans of only forwards OR backwards migrations.'
)
with self.assertRaisesMessage(InvalidMigrationPlan, msg) as cm:
executor.migrate(None, plan)
self.assertEqual(
cm.exception.args[1],
[
(executor.loader.graph.nodes["migrations", "0002_second"], True),
(executor.loader.graph.nodes["migrations", "0001_initial"], True),
(executor.loader.graph.nodes["migrations2", "0001_initial"], False),
],
)
# Rebuild the graph to reflect the new DB state
executor.loader.build_graph()
executor.migrate([
("migrations", None),
("migrations2", None),
])
# Are the tables gone?
self.assertTableNotExists("migrations_author")
self.assertTableNotExists("migrations_book")
self.assertTableNotExists("migrations2_otherauthor")
@override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations"})
def test_soft_apply(self):
"""
Tests detection of initial migrations already having been applied.
"""
state = {"faked": None}
def fake_storer(phase, migration=None, fake=None):
state["faked"] = fake
executor = MigrationExecutor(connection, progress_callback=fake_storer)
# Were the tables there before?
self.assertTableNotExists("migrations_author")
self.assertTableNotExists("migrations_tribble")
# Run it normally
self.assertEqual(
executor.migration_plan([("migrations", "0001_initial")]),
[
(executor.loader.graph.nodes["migrations", "0001_initial"], False),
],
)
executor.migrate([("migrations", "0001_initial")])
# Are the tables there now?
self.assertTableExists("migrations_author")
self.assertTableExists("migrations_tribble")
# We shouldn't have faked that one
self.assertEqual(state["faked"], False)
# Rebuild the graph to reflect the new DB state
executor.loader.build_graph()
# Fake-reverse that
executor.migrate([("migrations", None)], fake=True)
# Are the tables still there?
self.assertTableExists("migrations_author")
self.assertTableExists("migrations_tribble")
# Make sure that was faked
self.assertEqual(state["faked"], True)
# Finally, migrate forwards; this should fake-apply our initial migration
executor.loader.build_graph()
self.assertEqual(
executor.migration_plan([("migrations", "0001_initial")]),
[
(executor.loader.graph.nodes["migrations", "0001_initial"], False),
],
)
# Applying the migration should raise a database level error
# because we haven't given the --fake-initial option
with self.assertRaises(DatabaseError):
executor.migrate([("migrations", "0001_initial")])
# Reset the faked state
state = {"faked": None}
# Allow faking of initial CreateModel operations
executor.migrate([("migrations", "0001_initial")], fake_initial=True)
self.assertEqual(state["faked"], True)
# And migrate back to clean up the database
executor.loader.build_graph()
executor.migrate([("migrations", None)])
self.assertTableNotExists("migrations_author")
self.assertTableNotExists("migrations_tribble")
@override_settings(
MIGRATION_MODULES={
"migrations": "migrations.test_migrations_custom_user",
"django.contrib.auth": "django.contrib.auth.migrations",
},
AUTH_USER_MODEL="migrations.Author",
)
def test_custom_user(self):
"""
Regression test for #22325 - references to a custom user model defined in the
same app are not resolved correctly.
"""
executor = MigrationExecutor(connection)
self.assertTableNotExists("migrations_author")
self.assertTableNotExists("migrations_tribble")
# Migrate forwards
executor.migrate([("migrations", "0001_initial")])
self.assertTableExists("migrations_author")
self.assertTableExists("migrations_tribble")
# Make sure the soft-application detection works (#23093)
# Change table_names to not return auth_user during this as
# it wouldn't be there in a normal run, and ensure migrations.Author
# exists in the global app registry temporarily.
old_table_names = connection.introspection.table_names
connection.introspection.table_names = lambda c: [x for x in old_table_names(c) if x != "auth_user"]
migrations_apps = executor.loader.project_state(("migrations", "0001_initial")).apps
global_apps.get_app_config("migrations").models["author"] = migrations_apps.get_model("migrations", "author")
try:
migration = executor.loader.get_migration("auth", "0001_initial")
self.assertEqual(executor.detect_soft_applied(None, migration)[0], True)
finally:
connection.introspection.table_names = old_table_names
del global_apps.get_app_config("migrations").models["author"]
# And migrate back to clean up the database
executor.loader.build_graph()
executor.migrate([("migrations", None)])
self.assertTableNotExists("migrations_author")
self.assertTableNotExists("migrations_tribble")
@override_settings(
INSTALLED_APPS=[
"migrations.migrations_test_apps.lookuperror_a",
"migrations.migrations_test_apps.lookuperror_b",
"migrations.migrations_test_apps.lookuperror_c"
]
)
def test_unrelated_model_lookups_forwards(self):
"""
#24123 - Tests that all models of apps already applied which are
unrelated to the first app being applied are part of the initial model
state.
"""
try:
executor = MigrationExecutor(connection)
self.assertTableNotExists("lookuperror_a_a1")
self.assertTableNotExists("lookuperror_b_b1")
self.assertTableNotExists("lookuperror_c_c1")
executor.migrate([("lookuperror_b", "0003_b3")])
self.assertTableExists("lookuperror_b_b3")
# Rebuild the graph to reflect the new DB state
executor.loader.build_graph()
# Migrate forwards -- This led to a lookup LookupErrors because
# lookuperror_b.B2 is already applied
executor.migrate([
("lookuperror_a", "0004_a4"),
("lookuperror_c", "0003_c3"),
])
self.assertTableExists("lookuperror_a_a4")
self.assertTableExists("lookuperror_c_c3")
# Rebuild the graph to reflect the new DB state
executor.loader.build_graph()
finally:
# Cleanup
executor.migrate([
("lookuperror_a", None),
("lookuperror_b", None),
("lookuperror_c", None),
])
self.assertTableNotExists("lookuperror_a_a1")
self.assertTableNotExists("lookuperror_b_b1")
self.assertTableNotExists("lookuperror_c_c1")
@override_settings(
INSTALLED_APPS=[
"migrations.migrations_test_apps.lookuperror_a",
"migrations.migrations_test_apps.lookuperror_b",
"migrations.migrations_test_apps.lookuperror_c"
]
)
def test_unrelated_model_lookups_backwards(self):
"""
#24123 - Tests that all models of apps being unapplied which are
unrelated to the first app being unapplied are part of the initial
model state.
"""
try:
executor = MigrationExecutor(connection)
self.assertTableNotExists("lookuperror_a_a1")
self.assertTableNotExists("lookuperror_b_b1")
self.assertTableNotExists("lookuperror_c_c1")
executor.migrate([
("lookuperror_a", "0004_a4"),
("lookuperror_b", "0003_b3"),
("lookuperror_c", "0003_c3"),
])
self.assertTableExists("lookuperror_b_b3")
self.assertTableExists("lookuperror_a_a4")
self.assertTableExists("lookuperror_c_c3")
# Rebuild the graph to reflect the new DB state
executor.loader.build_graph()
# Migrate backwards -- This led to a lookup LookupErrors because
# lookuperror_b.B2 is not in the initial state (unrelated to app c)
executor.migrate([("lookuperror_a", None)])
# Rebuild the graph to reflect the new DB state
executor.loader.build_graph()
finally:
# Cleanup
executor.migrate([
("lookuperror_b", None),
("lookuperror_c", None)
])
self.assertTableNotExists("lookuperror_a_a1")
self.assertTableNotExists("lookuperror_b_b1")
self.assertTableNotExists("lookuperror_c_c1")
@override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations"})
def test_process_callback(self):
"""
#24129 - Tests callback process
"""
call_args_list = []
def callback(*args):
call_args_list.append(args)
executor = MigrationExecutor(connection, progress_callback=callback)
# Were the tables there before?
self.assertTableNotExists("migrations_author")
self.assertTableNotExists("migrations_tribble")
executor.migrate([
("migrations", "0001_initial"),
("migrations", "0002_second"),
])
# Rebuild the graph to reflect the new DB state
executor.loader.build_graph()
executor.migrate([
("migrations", None),
("migrations", None),
])
self.assertTableNotExists("migrations_author")
self.assertTableNotExists("migrations_tribble")
migrations = executor.loader.graph.nodes
expected = [
("render_start", ),
("render_success", ),
("apply_start", migrations['migrations', '0001_initial'], False),
("apply_success", migrations['migrations', '0001_initial'], False),
("apply_start", migrations['migrations', '0002_second'], False),
("apply_success", migrations['migrations', '0002_second'], False),
("render_start", ),
("render_success", ),
("unapply_start", migrations['migrations', '0002_second'], False),
("unapply_success", migrations['migrations', '0002_second'], False),
("unapply_start", migrations['migrations', '0001_initial'], False),
("unapply_success", migrations['migrations', '0001_initial'], False),
]
self.assertEqual(call_args_list, expected)
@override_settings(
INSTALLED_APPS=[
"migrations.migrations_test_apps.alter_fk.author_app",
"migrations.migrations_test_apps.alter_fk.book_app",
]
)
def test_alter_id_type_with_fk(self):
try:
executor = MigrationExecutor(connection)
self.assertTableNotExists("author_app_author")
self.assertTableNotExists("book_app_book")
# Apply initial migrations
executor.migrate([
("author_app", "0001_initial"),
("book_app", "0001_initial"),
])
self.assertTableExists("author_app_author")
self.assertTableExists("book_app_book")
# Rebuild the graph to reflect the new DB state
executor.loader.build_graph()
# Apply PK type alteration
executor.migrate([("author_app", "0002_alter_id")])
# Rebuild the graph to reflect the new DB state
executor.loader.build_graph()
finally:
# We can't simply unapply the migrations here because there is no
# implicit cast from VARCHAR to INT on the database level.
with connection.schema_editor() as editor:
editor.execute(editor.sql_delete_table % {"table": "book_app_book"})
editor.execute(editor.sql_delete_table % {"table": "author_app_author"})
self.assertTableNotExists("author_app_author")
self.assertTableNotExists("book_app_book")
@override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations_squashed"})
def test_apply_all_replaced_marks_replacement_as_applied(self):
"""
Applying all replaced migrations marks replacement as applied (#24628).
"""
recorder = MigrationRecorder(connection)
# Place the database in a state where the replaced migrations are
# partially applied: 0001 is applied, 0002 is not.
recorder.record_applied("migrations", "0001_initial")
executor = MigrationExecutor(connection)
# Use fake because we don't actually have the first migration
# applied, so the second will fail. And there's no need to actually
# create/modify tables here, we're just testing the
# MigrationRecord, which works the same with or without fake.
executor.migrate([("migrations", "0002_second")], fake=True)
# Because we've now applied 0001 and 0002 both, their squashed
# replacement should be marked as applied.
self.assertIn(
("migrations", "0001_squashed_0002"),
recorder.applied_migrations(),
)
@override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations_squashed"})
def test_migrate_marks_replacement_applied_even_if_it_did_nothing(self):
"""
A new squash migration will be marked as applied even if all its
replaced migrations were previously already applied (#24628).
"""
recorder = MigrationRecorder(connection)
# Record all replaced migrations as applied
recorder.record_applied("migrations", "0001_initial")
recorder.record_applied("migrations", "0002_second")
executor = MigrationExecutor(connection)
executor.migrate([("migrations", "0001_squashed_0002")])
# Because 0001 and 0002 are both applied, even though this migrate run
# didn't apply anything new, their squashed replacement should be
# marked as applied.
self.assertIn(
("migrations", "0001_squashed_0002"),
recorder.applied_migrations(),
)
class FakeLoader(object):
def __init__(self, graph, applied):
self.graph = graph
self.applied_migrations = applied
class FakeMigration(object):
"""Really all we need is any object with a debug-useful repr."""
def __init__(self, name):
self.name = name
def __repr__(self):
return 'M<%s>' % self.name
class ExecutorUnitTests(TestCase):
"""(More) isolated unit tests for executor methods."""
def test_minimize_rollbacks(self):
"""
Minimize unnecessary rollbacks in connected apps.
When you say "./manage.py migrate appA 0001", rather than migrating to
just after appA-0001 in the linearized migration plan (which could roll
back migrations in other apps that depend on appA 0001, but don't need
to be rolled back since we're not rolling back appA 0001), we migrate
to just before appA-0002.
"""
a1_impl = FakeMigration('a1')
a1 = ('a', '1')
a2_impl = FakeMigration('a2')
a2 = ('a', '2')
b1_impl = FakeMigration('b1')
b1 = ('b', '1')
graph = MigrationGraph()
graph.add_node(a1, a1_impl)
graph.add_node(a2, a2_impl)
graph.add_node(b1, b1_impl)
graph.add_dependency(None, b1, a1)
graph.add_dependency(None, a2, a1)
executor = MigrationExecutor(None)
executor.loader = FakeLoader(graph, {a1, b1, a2})
plan = executor.migration_plan({a1})
self.assertEqual(plan, [(a2_impl, True)])
def test_minimize_rollbacks_branchy(self):
"""
Minimize rollbacks when target has multiple in-app children.
a: 1 <---- 3 <--\
\ \- 2 <--- 4
\ \
b: \- 1 <--- 2
"""
a1_impl = FakeMigration('a1')
a1 = ('a', '1')
a2_impl = FakeMigration('a2')
a2 = ('a', '2')
a3_impl = FakeMigration('a3')
a3 = ('a', '3')
a4_impl = FakeMigration('a4')
a4 = ('a', '4')
b1_impl = FakeMigration('b1')
b1 = ('b', '1')
b2_impl = FakeMigration('b2')
b2 = ('b', '2')
graph = MigrationGraph()
graph.add_node(a1, a1_impl)
graph.add_node(a2, a2_impl)
graph.add_node(a3, a3_impl)
graph.add_node(a4, a4_impl)
graph.add_node(b1, b1_impl)
graph.add_node(b2, b2_impl)
graph.add_dependency(None, a2, a1)
graph.add_dependency(None, a3, a1)
graph.add_dependency(None, a4, a2)
graph.add_dependency(None, a4, a3)
graph.add_dependency(None, b2, b1)
graph.add_dependency(None, b1, a1)
graph.add_dependency(None, b2, a2)
executor = MigrationExecutor(None)
executor.loader = FakeLoader(graph, {a1, b1, a2, b2, a3, a4})
plan = executor.migration_plan({a1})
should_be_rolled_back = [b2_impl, a4_impl, a2_impl, a3_impl]
exp = [(m, True) for m in should_be_rolled_back]
self.assertEqual(plan, exp)
def test_backwards_nothing_to_do(self):
"""
If the current state satisfies the given target, do nothing.
a: 1 <--- 2
b: \- 1
c: \- 1
If a1 is applied already and a2 is not, and we're asked to migrate to
a1, don't apply or unapply b1 or c1, regardless of their current state.
"""
a1_impl = FakeMigration('a1')
a1 = ('a', '1')
a2_impl = FakeMigration('a2')
a2 = ('a', '2')
b1_impl = FakeMigration('b1')
b1 = ('b', '1')
c1_impl = FakeMigration('c1')
c1 = ('c', '1')
graph = MigrationGraph()
graph.add_node(a1, a1_impl)
graph.add_node(a2, a2_impl)
graph.add_node(b1, b1_impl)
graph.add_node(c1, c1_impl)
graph.add_dependency(None, a2, a1)
graph.add_dependency(None, b1, a1)
graph.add_dependency(None, c1, a1)
executor = MigrationExecutor(None)
executor.loader = FakeLoader(graph, {a1, b1})
plan = executor.migration_plan({a1})
self.assertEqual(plan, [])
|
bsd-3-clause
|
[
504,
1639,
14,
5181,
14,
5189,
492,
8686,
465,
2288,
63,
5181,
199,
504,
1639,
14,
697,
492,
1950,
199,
504,
1639,
14,
697,
14,
7685,
14,
3924,
492,
6378,
9816,
13375,
199,
504,
1639,
14,
697,
14,
7685,
14,
13471,
492,
12090,
16752,
199,
504,
1639,
14,
697,
14,
7685,
14,
2180,
492,
12090,
4578,
199,
504,
1639,
14,
697,
14,
7685,
14,
27733,
492,
12090,
497,
16940,
199,
504,
1639,
14,
697,
14,
1208,
492,
27728,
199,
504,
1639,
14,
396,
492,
7640,
12,
2811,
63,
1751,
12,
4278,
63,
1751,
199,
199,
504,
1275,
396,
63,
1095,
492,
12090,
14440,
421,
199,
32,
8951,
63,
1751,
8,
15942,
63,
14219,
3713,
740,
356,
283,
7685,
18,
3071,
199,
533,
9434,
4139,
2925,
8,
9816,
14440,
304,
272,
408,
272,
6496,
314,
8367,
13270,
334,
2861,
1284,
13,
475,
13,
500,
3879,
680,
339,
699,
2210,
315,
25169,
626,
340,
3520,
787,
18648,
1265,
1077,
5325,
314,
1163,
272,
511,
9081,
1642,
12,
465,
2985,
1443,
506,
20796,
1958,
1901,
2348,
14,
272,
408,
339,
2808,
63,
5181,
275,
2097,
7685,
401,
298,
7685,
18,
401,
298,
1176,
14,
2828,
14,
1178,
401,
298,
1176,
14,
2828,
14,
10778,
937,
339,
768,
4415,
63,
1751,
8,
22487,
23743,
63,
21194,
8871,
7685,
582,
298,
7685,
14,
396,
63,
7685,
5984,
272,
347,
511,
63,
1065,
8,
277,
304,
267,
408,
267,
6496,
3879,
282,
3486,
663,
402,
6180,
14,
267,
408,
267,
13270,
275,
12090,
16752,
8,
2105,
9,
267,
327,
12230,
1159,
3648,
737,
314,
8683,
1642,
436,
1852,
3238,
652,
1159,
1536,
370,
28975,
267,
8683,
275,
13270,
14,
8998,
63,
5140,
27187,
7685,
401,
298,
9425,
63,
4375,
13403,
267,
291,
14,
629,
8,
288,
8683,
12,
288,
359,
355,
334,
13471,
14,
3422,
14,
2180,
14,
2415,
905,
7685,
401,
298,
4183,
63,
2747,
2255,
756,
395,
355,
334,
13471,
14,
3422,
14,
2180,
14,
2415,
905,
7685,
401,
298,
9425,
63,
4375,
2255,
756,
395,
288,
2156,
267,
776,
267,
327,
2136,
264,
314,
6716,
2337,
2544,
31,
267,
291,
14,
23550,
25095,
480,
7685,
63,
2502,
531,
267,
291,
14,
23550,
25095,
480,
7685,
63,
2706,
531,
267,
327,
4580,
1019,
12,
4691,
1159,
862,
3879,
652,
267,
13270,
14,
8462,
27187,
7685,
401,
298,
9425,
63,
4375,
13403,
267,
327,
23889,
314,
6716,
2337,
3063,
31,
267,
291,
14,
23550,
7965,
480,
7685,
63,
2502,
531,
267,
291,
14,
23550,
7965,
480,
7685,
63,
2706,
531,
267,
327,
799,
1506,
314,
3343,
370,
16806,
314,
892,
6249,
1174,
267,
13270,
14,
3422,
14,
1506,
63,
2180,
342,
267,
327,
4580,
1019,
12,
4691,
1159,
18172,
4052,
781,
8103,
267,
8683,
275,
13270,
14,
8998,
63,
5140,
27187,
7685,
401,
488,
3948,
267,
291,
14,
629,
8,
288,
8683,
12,
288,
359,
355,
334,
13471,
14,
3422,
14,
2180,
14,
2415,
905,
7685,
401,
298,
9425,
63,
4375,
2255,
715,
395,
355,
334,
13471,
14,
3422,
14,
2180,
14,
2415,
905,
7685,
401,
298,
4183,
63,
2747,
2255,
715,
395,
288,
2156,
267,
776,
267,
13270,
14,
8462,
27187,
7685,
401,
488,
3948,
267,
327,
23889,
314,
6716,
21737,
31,
267,
291,
14,
23550,
25095,
480,
7685,
63,
2502,
531,
267,
291,
14,
23550,
25095,
480,
7685,
63,
2706,
531,
339,
768,
4415,
63,
1751,
8,
22487,
23743,
63,
21194,
8871,
7685,
582,
298,
7685,
14,
396,
63,
7685,
63,
8471,
21189,
5984,
272,
347,
511,
63,
1065,
63,
1045,
63,
8471,
21189,
8,
277,
304,
267,
408,
267,
6496,
3879,
282,
12345,
21189,
8367,
687,
4697,
334,
5626,
3686,
4052,
652,
19058,
9,
267,
408,
267,
13270,
275,
12090,
16752,
8,
2105,
9,
267,
327,
2670,
4154,
11747,
1031,
365,
314,
12345,
21189,
1373,
267,
16733,
275,
359,
498,
367,
790,
315,
13270,
14,
3422,
14,
2180,
14,
8914,
63,
2415,
342,
340,
790,
59,
16,
61,
508,
298,
7685,
937,
267,
291,
14,
629,
8,
16554,
12,
10003,
7685,
401,
298,
4183,
63,
8471,
21189,
63,
9425,
13403,
267,
327,
2670,
314,
8683,
267,
8683,
275,
13270,
14,
8998,
63,
5140,
27187,
7685,
401,
298,
4183,
63,
8471,
21189,
63,
9425,
13403,
267,
291,
14,
629,
8,
288,
8683,
12,
288,
359,
355,
334,
13471,
14,
3422,
14,
2180,
14,
2415,
905,
7685,
401,
298,
4183,
63,
8471,
21189,
63,
9425,
2255,
756,
395,
288,
2156,
267,
776,
267,
327,
2136,
264,
314,
6716,
2337,
2544,
31,
267,
291,
14,
23550,
25095,
480,
7685,
63,
2502,
531,
267,
291,
14,
23550,
25095,
480,
7685,
63,
2706,
531,
267,
327,
4580,
1019,
12,
4691,
1159,
862,
3879,
652,
267,
13270,
14,
8462,
27187,
7685,
401,
298,
4183,
63,
8471,
21189,
63,
9425,
13403,
267,
327,
23889,
314,
6716,
2337,
3063,
31,
267,
291,
14,
23550,
7965,
480,
7685,
63,
2502,
531,
267,
291,
14,
23550,
7965,
480,
7685,
63,
2706,
531,
267,
327,
799,
1506,
314,
3343,
370,
16806,
314,
892,
6249,
1174,
267,
13270,
14,
3422,
14,
1506,
63,
2180,
342,
267,
327,
4580,
1019,
12,
4691,
1159,
18172,
4052,
781,
8103,
14,
7719,
2597,
2951,
675,
12345,
21189,
14,
267,
8683,
275,
13270,
14,
8998,
63,
5140,
27187,
7685,
401,
488,
3948,
267,
291,
14,
629,
8,
288,
8683,
12,
288,
359,
355,
334,
13471,
14,
3422,
14,
2180,
14,
2415,
905,
7685,
401,
298,
4183,
63,
8471,
21189,
63,
9425,
2255,
715,
395,
288,
2156,
267,
776,
267,
13270,
14,
8462,
27187,
7685,
401,
488,
3948,
267,
327,
23889,
314,
6716,
21737,
31,
267,
291,
14,
23550,
25095,
480,
7685,
63,
2502,
531,
267,
291,
14,
23550,
25095,
480,
7685,
63,
2706,
531,
339,
768,
4415,
63,
1751,
8,
22487,
23743,
63,
21194,
3126,
267,
298,
7685,
582,
298,
7685,
14,
396,
63,
7685,
401,
267,
298,
7685,
18,
582,
298,
7685,
18,
14,
396,
63,
7685,
63,
18,
401,
272,
3828,
272,
347,
511,
63,
1667,
63,
5140,
8,
277,
304,
267,
408,
267,
6496,
626,
295,
13,
1168,
11495,
282,
2615,
8367,
402,
282,
9999,
13,
31544,
663,
3181,
1133,
267,
5147,
2249,
2302,
1785,
625,
7685,
436,
295,
7685,
14,
398,
6006,
1990,
10889,
282,
6519,
2382,
314,
13270
] |
[
1639,
14,
5181,
14,
5189,
492,
8686,
465,
2288,
63,
5181,
199,
504,
1639,
14,
697,
492,
1950,
199,
504,
1639,
14,
697,
14,
7685,
14,
3924,
492,
6378,
9816,
13375,
199,
504,
1639,
14,
697,
14,
7685,
14,
13471,
492,
12090,
16752,
199,
504,
1639,
14,
697,
14,
7685,
14,
2180,
492,
12090,
4578,
199,
504,
1639,
14,
697,
14,
7685,
14,
27733,
492,
12090,
497,
16940,
199,
504,
1639,
14,
697,
14,
1208,
492,
27728,
199,
504,
1639,
14,
396,
492,
7640,
12,
2811,
63,
1751,
12,
4278,
63,
1751,
199,
199,
504,
1275,
396,
63,
1095,
492,
12090,
14440,
421,
199,
32,
8951,
63,
1751,
8,
15942,
63,
14219,
3713,
740,
356,
283,
7685,
18,
3071,
199,
533,
9434,
4139,
2925,
8,
9816,
14440,
304,
272,
408,
272,
6496,
314,
8367,
13270,
334,
2861,
1284,
13,
475,
13,
500,
3879,
680,
339,
699,
2210,
315,
25169,
626,
340,
3520,
787,
18648,
1265,
1077,
5325,
314,
1163,
272,
511,
9081,
1642,
12,
465,
2985,
1443,
506,
20796,
1958,
1901,
2348,
14,
272,
408,
339,
2808,
63,
5181,
275,
2097,
7685,
401,
298,
7685,
18,
401,
298,
1176,
14,
2828,
14,
1178,
401,
298,
1176,
14,
2828,
14,
10778,
937,
339,
768,
4415,
63,
1751,
8,
22487,
23743,
63,
21194,
8871,
7685,
582,
298,
7685,
14,
396,
63,
7685,
5984,
272,
347,
511,
63,
1065,
8,
277,
304,
267,
408,
267,
6496,
3879,
282,
3486,
663,
402,
6180,
14,
267,
408,
267,
13270,
275,
12090,
16752,
8,
2105,
9,
267,
327,
12230,
1159,
3648,
737,
314,
8683,
1642,
436,
1852,
3238,
652,
1159,
1536,
370,
28975,
267,
8683,
275,
13270,
14,
8998,
63,
5140,
27187,
7685,
401,
298,
9425,
63,
4375,
13403,
267,
291,
14,
629,
8,
288,
8683,
12,
288,
359,
355,
334,
13471,
14,
3422,
14,
2180,
14,
2415,
905,
7685,
401,
298,
4183,
63,
2747,
2255,
756,
395,
355,
334,
13471,
14,
3422,
14,
2180,
14,
2415,
905,
7685,
401,
298,
9425,
63,
4375,
2255,
756,
395,
288,
2156,
267,
776,
267,
327,
2136,
264,
314,
6716,
2337,
2544,
31,
267,
291,
14,
23550,
25095,
480,
7685,
63,
2502,
531,
267,
291,
14,
23550,
25095,
480,
7685,
63,
2706,
531,
267,
327,
4580,
1019,
12,
4691,
1159,
862,
3879,
652,
267,
13270,
14,
8462,
27187,
7685,
401,
298,
9425,
63,
4375,
13403,
267,
327,
23889,
314,
6716,
2337,
3063,
31,
267,
291,
14,
23550,
7965,
480,
7685,
63,
2502,
531,
267,
291,
14,
23550,
7965,
480,
7685,
63,
2706,
531,
267,
327,
799,
1506,
314,
3343,
370,
16806,
314,
892,
6249,
1174,
267,
13270,
14,
3422,
14,
1506,
63,
2180,
342,
267,
327,
4580,
1019,
12,
4691,
1159,
18172,
4052,
781,
8103,
267,
8683,
275,
13270,
14,
8998,
63,
5140,
27187,
7685,
401,
488,
3948,
267,
291,
14,
629,
8,
288,
8683,
12,
288,
359,
355,
334,
13471,
14,
3422,
14,
2180,
14,
2415,
905,
7685,
401,
298,
9425,
63,
4375,
2255,
715,
395,
355,
334,
13471,
14,
3422,
14,
2180,
14,
2415,
905,
7685,
401,
298,
4183,
63,
2747,
2255,
715,
395,
288,
2156,
267,
776,
267,
13270,
14,
8462,
27187,
7685,
401,
488,
3948,
267,
327,
23889,
314,
6716,
21737,
31,
267,
291,
14,
23550,
25095,
480,
7685,
63,
2502,
531,
267,
291,
14,
23550,
25095,
480,
7685,
63,
2706,
531,
339,
768,
4415,
63,
1751,
8,
22487,
23743,
63,
21194,
8871,
7685,
582,
298,
7685,
14,
396,
63,
7685,
63,
8471,
21189,
5984,
272,
347,
511,
63,
1065,
63,
1045,
63,
8471,
21189,
8,
277,
304,
267,
408,
267,
6496,
3879,
282,
12345,
21189,
8367,
687,
4697,
334,
5626,
3686,
4052,
652,
19058,
9,
267,
408,
267,
13270,
275,
12090,
16752,
8,
2105,
9,
267,
327,
2670,
4154,
11747,
1031,
365,
314,
12345,
21189,
1373,
267,
16733,
275,
359,
498,
367,
790,
315,
13270,
14,
3422,
14,
2180,
14,
8914,
63,
2415,
342,
340,
790,
59,
16,
61,
508,
298,
7685,
937,
267,
291,
14,
629,
8,
16554,
12,
10003,
7685,
401,
298,
4183,
63,
8471,
21189,
63,
9425,
13403,
267,
327,
2670,
314,
8683,
267,
8683,
275,
13270,
14,
8998,
63,
5140,
27187,
7685,
401,
298,
4183,
63,
8471,
21189,
63,
9425,
13403,
267,
291,
14,
629,
8,
288,
8683,
12,
288,
359,
355,
334,
13471,
14,
3422,
14,
2180,
14,
2415,
905,
7685,
401,
298,
4183,
63,
8471,
21189,
63,
9425,
2255,
756,
395,
288,
2156,
267,
776,
267,
327,
2136,
264,
314,
6716,
2337,
2544,
31,
267,
291,
14,
23550,
25095,
480,
7685,
63,
2502,
531,
267,
291,
14,
23550,
25095,
480,
7685,
63,
2706,
531,
267,
327,
4580,
1019,
12,
4691,
1159,
862,
3879,
652,
267,
13270,
14,
8462,
27187,
7685,
401,
298,
4183,
63,
8471,
21189,
63,
9425,
13403,
267,
327,
23889,
314,
6716,
2337,
3063,
31,
267,
291,
14,
23550,
7965,
480,
7685,
63,
2502,
531,
267,
291,
14,
23550,
7965,
480,
7685,
63,
2706,
531,
267,
327,
799,
1506,
314,
3343,
370,
16806,
314,
892,
6249,
1174,
267,
13270,
14,
3422,
14,
1506,
63,
2180,
342,
267,
327,
4580,
1019,
12,
4691,
1159,
18172,
4052,
781,
8103,
14,
7719,
2597,
2951,
675,
12345,
21189,
14,
267,
8683,
275,
13270,
14,
8998,
63,
5140,
27187,
7685,
401,
488,
3948,
267,
291,
14,
629,
8,
288,
8683,
12,
288,
359,
355,
334,
13471,
14,
3422,
14,
2180,
14,
2415,
905,
7685,
401,
298,
4183,
63,
8471,
21189,
63,
9425,
2255,
715,
395,
288,
2156,
267,
776,
267,
13270,
14,
8462,
27187,
7685,
401,
488,
3948,
267,
327,
23889,
314,
6716,
21737,
31,
267,
291,
14,
23550,
25095,
480,
7685,
63,
2502,
531,
267,
291,
14,
23550,
25095,
480,
7685,
63,
2706,
531,
339,
768,
4415,
63,
1751,
8,
22487,
23743,
63,
21194,
3126,
267,
298,
7685,
582,
298,
7685,
14,
396,
63,
7685,
401,
267,
298,
7685,
18,
582,
298,
7685,
18,
14,
396,
63,
7685,
63,
18,
401,
272,
3828,
272,
347,
511,
63,
1667,
63,
5140,
8,
277,
304,
267,
408,
267,
6496,
626,
295,
13,
1168,
11495,
282,
2615,
8367,
402,
282,
9999,
13,
31544,
663,
3181,
1133,
267,
5147,
2249,
2302,
1785,
625,
7685,
436,
295,
7685,
14,
398,
6006,
1990,
10889,
282,
6519,
2382,
314,
13270,
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,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TimeField
from utils import LocalFlavorTestCase
class GenericLocalFlavorTests(LocalFlavorTestCase):
def test_GenericDateField(self):
error_invalid = [u'Enter a valid date.']
valid = {
datetime.date(2006, 10, 25): datetime.date(2006, 10, 25),
datetime.datetime(2006, 10, 25, 14, 30): datetime.date(2006, 10, 25),
datetime.datetime(2006, 10, 25, 14, 30, 59): datetime.date(2006, 10, 25),
datetime.datetime(2006, 10, 25, 14, 30, 59, 200): datetime.date(2006, 10, 25),
'2006-10-25': datetime.date(2006, 10, 25),
'25/10/2006': datetime.date(2006, 10, 25),
'25/10/06': datetime.date(2006, 10, 25),
'Oct 25 2006': datetime.date(2006, 10, 25),
'October 25 2006': datetime.date(2006, 10, 25),
'October 25, 2006': datetime.date(2006, 10, 25),
'25 October 2006': datetime.date(2006, 10, 25),
'25 October, 2006': datetime.date(2006, 10, 25),
}
invalid = {
'2006-4-31': error_invalid,
'200a-10-25': error_invalid,
'10/25/06': error_invalid,
}
self.assertFieldOutput(DateField, valid, invalid, empty_value=None)
# DateField with optional input_formats parameter
valid = {
datetime.date(2006, 10, 25): datetime.date(2006, 10, 25),
datetime.datetime(2006, 10, 25, 14, 30): datetime.date(2006, 10, 25),
'2006 10 25': datetime.date(2006, 10, 25),
}
invalid = {
'2006-10-25': error_invalid,
'25/10/2006': error_invalid,
'25/10/06': error_invalid,
}
kwargs = {'input_formats':['%Y %m %d'],}
self.assertFieldOutput(DateField,
valid, invalid, field_kwargs=kwargs, empty_value=None
)
def test_GenericDateTimeField(self):
error_invalid = [u'Enter a valid date/time.']
valid = {
datetime.date(2006, 10, 25): datetime.datetime(2006, 10, 25, 0, 0),
datetime.datetime(2006, 10, 25, 14, 30): datetime.datetime(2006, 10, 25, 14, 30),
datetime.datetime(2006, 10, 25, 14, 30, 59): datetime.datetime(2006, 10, 25, 14, 30, 59),
datetime.datetime(2006, 10, 25, 14, 30, 59, 200): datetime.datetime(2006, 10, 25, 14, 30, 59, 200),
'2006-10-25 14:30:45': datetime.datetime(2006, 10, 25, 14, 30, 45),
'2006-10-25 14:30:00': datetime.datetime(2006, 10, 25, 14, 30),
'2006-10-25 14:30': datetime.datetime(2006, 10, 25, 14, 30),
'2006-10-25': datetime.datetime(2006, 10, 25, 0, 0),
'25/10/2006 14:30:45': datetime.datetime(2006, 10, 25, 14, 30, 45),
'25/10/2006 14:30:00': datetime.datetime(2006, 10, 25, 14, 30),
'25/10/2006 14:30': datetime.datetime(2006, 10, 25, 14, 30),
'25/10/2006': datetime.datetime(2006, 10, 25, 0, 0),
'25/10/06 14:30:45': datetime.datetime(2006, 10, 25, 14, 30, 45),
'25/10/06 14:30:00': datetime.datetime(2006, 10, 25, 14, 30),
'25/10/06 14:30': datetime.datetime(2006, 10, 25, 14, 30),
'25/10/06': datetime.datetime(2006, 10, 25, 0, 0),
}
invalid = {
'hello': error_invalid,
'2006-10-25 4:30 p.m.': error_invalid,
}
self.assertFieldOutput(DateTimeField, valid, invalid, empty_value=None)
# DateTimeField with optional input_formats paramter
valid = {
datetime.date(2006, 10, 25): datetime.datetime(2006, 10, 25, 0, 0),
datetime.datetime(2006, 10, 25, 14, 30): datetime.datetime(2006, 10, 25, 14, 30),
datetime.datetime(2006, 10, 25, 14, 30, 59): datetime.datetime(2006, 10, 25, 14, 30, 59),
datetime.datetime(2006, 10, 25, 14, 30, 59, 200): datetime.datetime(2006, 10, 25, 14, 30, 59, 200),
'2006 10 25 2:30 PM': datetime.datetime(2006, 10, 25, 14, 30),
}
invalid = {
'2006-10-25 14:30:45': error_invalid,
}
kwargs = {'input_formats':['%Y %m %d %I:%M %p'],}
self.assertFieldOutput(DateTimeField,
valid, invalid, field_kwargs=kwargs, empty_value=None
)
|
bsd-3-clause
|
[
646,
2197,
199,
199,
504,
1639,
14,
2828,
14,
320,
696,
276,
4271,
14,
6767,
14,
3351,
492,
30997,
12,
31637,
199,
199,
504,
3778,
492,
10111,
16739,
1746,
421,
199,
533,
8307,
5339,
16739,
2925,
8,
5339,
16739,
1746,
304,
272,
347,
511,
63,
9417,
14071,
8,
277,
304,
267,
1125,
63,
3197,
275,
359,
85,
7,
8468,
282,
1686,
1434,
14,
418,
267,
1686,
275,
469,
288,
2197,
14,
602,
8,
7968,
12,
1616,
12,
5661,
304,
2197,
14,
602,
8,
7968,
12,
1616,
12,
5661,
395,
288,
2197,
14,
2083,
8,
7968,
12,
1616,
12,
5661,
12,
4329,
12,
4233,
304,
2197,
14,
602,
8,
7968,
12,
1616,
12,
5661,
395,
288,
2197,
14,
2083,
8,
7968,
12,
1616,
12,
5661,
12,
4329,
12,
4233,
12,
8155,
304,
2197,
14,
602,
8,
7968,
12,
1616,
12,
5661,
395,
288,
2197,
14,
2083,
8,
7968,
12,
1616,
12,
5661,
12,
4329,
12,
4233,
12,
8155,
12,
1926,
304,
2197,
14,
602,
8,
7968,
12,
1616,
12,
5661,
395,
288,
283,
7968,
13,
709,
13,
821,
356,
2197,
14,
602,
8,
7968,
12,
1616,
12,
5661,
395,
288,
283,
821,
15,
709,
15,
7968,
356,
2197,
14,
602,
8,
7968,
12,
1616,
12,
5661,
395,
288,
283,
821,
15,
709,
15,
1690,
356,
2197,
14,
602,
8,
7968,
12,
1616,
12,
5661,
395,
288,
283,
17584,
5661,
8315,
356,
2197,
14,
602,
8,
7968,
12,
1616,
12,
5661,
395,
288,
283,
17584,
22459,
5661,
8315,
356,
2197,
14,
602,
8,
7968,
12,
1616,
12,
5661,
395,
288,
283,
17584,
22459,
5661,
12,
8315,
356,
2197,
14,
602,
8,
7968,
12,
1616,
12,
5661,
395,
288,
283,
821,
18365,
22459,
8315,
356,
2197,
14,
602,
8,
7968,
12,
1616,
12,
5661,
395,
288,
283,
821,
18365,
22459,
12,
8315,
356,
2197,
14,
602,
8,
7968,
12,
1616,
12,
5661,
395,
267,
789,
267,
3866,
275,
469,
288,
283,
7968,
13,
20,
13,
2192,
356,
1125,
63,
3197,
12,
288,
283,
1840,
65,
13,
709,
13,
821,
356,
1125,
63,
3197,
12,
288,
283,
709,
15,
821,
15,
1690,
356,
1125,
63,
3197,
12,
267,
789,
267,
291,
14,
479,
792,
2959,
8,
14071,
12,
1686,
12,
3866,
12,
2701,
63,
585,
29,
403,
9,
398,
327,
30997,
543,
2716,
1324,
63,
6321,
2725,
267,
1686,
275,
469,
288,
2197,
14,
602,
8,
7968,
12,
1616,
12,
5661,
304,
2197,
14,
602,
8,
7968,
12,
1616,
12,
5661,
395,
288,
2197,
14,
2083,
8,
7968,
12,
1616,
12,
5661,
12,
4329,
12,
4233,
304,
2197,
14,
602,
8,
7968,
12,
1616,
12,
5661,
395,
288,
283,
7968,
1616,
5661,
356,
2197,
14,
602,
8,
7968,
12,
1616,
12,
5661,
395,
267,
789,
267,
3866,
275,
469,
288,
283,
7968,
13,
709,
13,
821,
356,
1125,
63,
3197,
12,
288,
283,
821,
15,
709,
15,
7968,
356,
1125,
63,
3197,
12,
288,
283,
821,
15,
709,
15,
1690,
356,
1125,
63,
3197,
12,
267,
789,
267,
2074,
275,
791,
1210,
63,
6321,
356,
13890,
57,
450,
77,
450,
68,
995,
93,
267,
291,
14,
479,
792,
2959,
8,
14071,
12,
288,
1686,
12,
3866,
12,
901,
63,
958,
29,
958,
12,
2701,
63,
585,
29,
403,
267,
776,
339,
347,
511,
63,
9417,
4626,
8,
277,
304,
267,
1125,
63,
3197,
275,
359,
85,
7,
8468,
282,
1686,
1434,
15,
521,
14,
418,
267,
1686,
275,
469,
288,
2197,
14,
602,
8,
7968,
12,
1616,
12,
5661,
304,
2197,
14,
2083,
8,
7968,
12,
1616,
12,
5661,
12,
378,
12,
378,
395,
288,
2197,
14,
2083,
8,
7968,
12,
1616,
12,
5661,
12,
4329,
12,
4233,
304,
2197,
14,
2083,
8,
7968,
12,
1616,
12,
5661,
12,
4329,
12,
4233,
395,
288,
2197,
14,
2083,
8,
7968,
12,
1616,
12,
5661,
12,
4329,
12,
4233,
12,
8155,
304,
2197,
14,
2083,
8,
7968,
12,
1616,
12,
5661,
12,
4329,
12,
4233,
12,
8155,
395,
288,
2197,
14,
2083,
8,
7968,
12,
1616,
12,
5661,
12,
4329,
12,
4233,
12,
8155,
12,
1926,
304,
2197,
14,
2083,
8,
7968,
12,
1616,
12,
5661,
12,
4329,
12,
4233,
12,
8155,
12,
1926,
395,
288,
283,
7968,
13,
709,
13,
821,
4329,
26,
1216,
26,
2322,
356,
2197,
14,
2083,
8,
7968,
12,
1616,
12,
5661,
12,
4329,
12,
4233,
12,
10416,
395,
288,
283,
7968,
13,
709,
13,
821,
4329,
26,
1216,
26,
383,
356,
2197,
14,
2083,
8,
7968,
12,
1616,
12,
5661,
12,
4329,
12,
4233,
395,
288,
283,
7968,
13,
709,
13,
821,
4329,
26,
1216,
356,
2197,
14,
2083,
8,
7968,
12,
1616,
12,
5661,
12,
4329,
12,
4233,
395,
288,
283,
7968,
13,
709,
13,
821,
356,
2197,
14,
2083,
8,
7968,
12,
1616,
12,
5661,
12,
378,
12,
378,
395,
288,
283,
821,
15,
709,
15,
7968,
4329,
26,
1216,
26,
2322,
356,
2197,
14,
2083,
8,
7968,
12,
1616,
12,
5661,
12,
4329,
12,
4233,
12,
10416,
395,
288,
283,
821,
15,
709,
15,
7968,
4329,
26,
1216,
26,
383,
356,
2197,
14,
2083,
8,
7968,
12,
1616,
12,
5661,
12,
4329,
12,
4233,
395,
288,
283,
821,
15,
709,
15,
7968,
4329,
26,
1216,
356,
2197,
14,
2083,
8,
7968,
12,
1616,
12,
5661,
12,
4329,
12,
4233,
395,
288,
283,
821,
15,
709,
15,
7968,
356,
2197,
14,
2083,
8,
7968,
12,
1616,
12,
5661,
12,
378,
12,
378,
395,
288,
283,
821,
15,
709,
15,
1690,
4329,
26,
1216,
26,
2322,
356,
2197,
14,
2083,
8,
7968,
12,
1616,
12,
5661,
12,
4329,
12,
4233,
12,
10416,
395,
288,
283,
821,
15,
709,
15,
1690,
4329,
26,
1216,
26,
383,
356,
2197,
14,
2083,
8,
7968,
12,
1616,
12,
5661,
12,
4329,
12,
4233,
395,
288,
283,
821,
15,
709,
15,
1690,
4329,
26,
1216,
356,
2197,
14,
2083,
8,
7968,
12,
1616,
12,
5661,
12,
4329,
12,
4233,
395,
288,
283,
821,
15,
709,
15,
1690,
356,
2197,
14,
2083,
8,
7968,
12,
1616,
12,
5661,
12,
378,
12,
378,
395,
267,
789,
267,
3866,
275,
469,
288,
283,
5006,
356,
1125,
63,
3197,
12,
288,
283,
7968,
13,
709,
13,
821,
841,
26,
1216,
299,
14
] |
[
2197,
199,
199,
504,
1639,
14,
2828,
14,
320,
696,
276,
4271,
14,
6767,
14,
3351,
492,
30997,
12,
31637,
199,
199,
504,
3778,
492,
10111,
16739,
1746,
421,
199,
533,
8307,
5339,
16739,
2925,
8,
5339,
16739,
1746,
304,
272,
347,
511,
63,
9417,
14071,
8,
277,
304,
267,
1125,
63,
3197,
275,
359,
85,
7,
8468,
282,
1686,
1434,
14,
418,
267,
1686,
275,
469,
288,
2197,
14,
602,
8,
7968,
12,
1616,
12,
5661,
304,
2197,
14,
602,
8,
7968,
12,
1616,
12,
5661,
395,
288,
2197,
14,
2083,
8,
7968,
12,
1616,
12,
5661,
12,
4329,
12,
4233,
304,
2197,
14,
602,
8,
7968,
12,
1616,
12,
5661,
395,
288,
2197,
14,
2083,
8,
7968,
12,
1616,
12,
5661,
12,
4329,
12,
4233,
12,
8155,
304,
2197,
14,
602,
8,
7968,
12,
1616,
12,
5661,
395,
288,
2197,
14,
2083,
8,
7968,
12,
1616,
12,
5661,
12,
4329,
12,
4233,
12,
8155,
12,
1926,
304,
2197,
14,
602,
8,
7968,
12,
1616,
12,
5661,
395,
288,
283,
7968,
13,
709,
13,
821,
356,
2197,
14,
602,
8,
7968,
12,
1616,
12,
5661,
395,
288,
283,
821,
15,
709,
15,
7968,
356,
2197,
14,
602,
8,
7968,
12,
1616,
12,
5661,
395,
288,
283,
821,
15,
709,
15,
1690,
356,
2197,
14,
602,
8,
7968,
12,
1616,
12,
5661,
395,
288,
283,
17584,
5661,
8315,
356,
2197,
14,
602,
8,
7968,
12,
1616,
12,
5661,
395,
288,
283,
17584,
22459,
5661,
8315,
356,
2197,
14,
602,
8,
7968,
12,
1616,
12,
5661,
395,
288,
283,
17584,
22459,
5661,
12,
8315,
356,
2197,
14,
602,
8,
7968,
12,
1616,
12,
5661,
395,
288,
283,
821,
18365,
22459,
8315,
356,
2197,
14,
602,
8,
7968,
12,
1616,
12,
5661,
395,
288,
283,
821,
18365,
22459,
12,
8315,
356,
2197,
14,
602,
8,
7968,
12,
1616,
12,
5661,
395,
267,
789,
267,
3866,
275,
469,
288,
283,
7968,
13,
20,
13,
2192,
356,
1125,
63,
3197,
12,
288,
283,
1840,
65,
13,
709,
13,
821,
356,
1125,
63,
3197,
12,
288,
283,
709,
15,
821,
15,
1690,
356,
1125,
63,
3197,
12,
267,
789,
267,
291,
14,
479,
792,
2959,
8,
14071,
12,
1686,
12,
3866,
12,
2701,
63,
585,
29,
403,
9,
398,
327,
30997,
543,
2716,
1324,
63,
6321,
2725,
267,
1686,
275,
469,
288,
2197,
14,
602,
8,
7968,
12,
1616,
12,
5661,
304,
2197,
14,
602,
8,
7968,
12,
1616,
12,
5661,
395,
288,
2197,
14,
2083,
8,
7968,
12,
1616,
12,
5661,
12,
4329,
12,
4233,
304,
2197,
14,
602,
8,
7968,
12,
1616,
12,
5661,
395,
288,
283,
7968,
1616,
5661,
356,
2197,
14,
602,
8,
7968,
12,
1616,
12,
5661,
395,
267,
789,
267,
3866,
275,
469,
288,
283,
7968,
13,
709,
13,
821,
356,
1125,
63,
3197,
12,
288,
283,
821,
15,
709,
15,
7968,
356,
1125,
63,
3197,
12,
288,
283,
821,
15,
709,
15,
1690,
356,
1125,
63,
3197,
12,
267,
789,
267,
2074,
275,
791,
1210,
63,
6321,
356,
13890,
57,
450,
77,
450,
68,
995,
93,
267,
291,
14,
479,
792,
2959,
8,
14071,
12,
288,
1686,
12,
3866,
12,
901,
63,
958,
29,
958,
12,
2701,
63,
585,
29,
403,
267,
776,
339,
347,
511,
63,
9417,
4626,
8,
277,
304,
267,
1125,
63,
3197,
275,
359,
85,
7,
8468,
282,
1686,
1434,
15,
521,
14,
418,
267,
1686,
275,
469,
288,
2197,
14,
602,
8,
7968,
12,
1616,
12,
5661,
304,
2197,
14,
2083,
8,
7968,
12,
1616,
12,
5661,
12,
378,
12,
378,
395,
288,
2197,
14,
2083,
8,
7968,
12,
1616,
12,
5661,
12,
4329,
12,
4233,
304,
2197,
14,
2083,
8,
7968,
12,
1616,
12,
5661,
12,
4329,
12,
4233,
395,
288,
2197,
14,
2083,
8,
7968,
12,
1616,
12,
5661,
12,
4329,
12,
4233,
12,
8155,
304,
2197,
14,
2083,
8,
7968,
12,
1616,
12,
5661,
12,
4329,
12,
4233,
12,
8155,
395,
288,
2197,
14,
2083,
8,
7968,
12,
1616,
12,
5661,
12,
4329,
12,
4233,
12,
8155,
12,
1926,
304,
2197,
14,
2083,
8,
7968,
12,
1616,
12,
5661,
12,
4329,
12,
4233,
12,
8155,
12,
1926,
395,
288,
283,
7968,
13,
709,
13,
821,
4329,
26,
1216,
26,
2322,
356,
2197,
14,
2083,
8,
7968,
12,
1616,
12,
5661,
12,
4329,
12,
4233,
12,
10416,
395,
288,
283,
7968,
13,
709,
13,
821,
4329,
26,
1216,
26,
383,
356,
2197,
14,
2083,
8,
7968,
12,
1616,
12,
5661,
12,
4329,
12,
4233,
395,
288,
283,
7968,
13,
709,
13,
821,
4329,
26,
1216,
356,
2197,
14,
2083,
8,
7968,
12,
1616,
12,
5661,
12,
4329,
12,
4233,
395,
288,
283,
7968,
13,
709,
13,
821,
356,
2197,
14,
2083,
8,
7968,
12,
1616,
12,
5661,
12,
378,
12,
378,
395,
288,
283,
821,
15,
709,
15,
7968,
4329,
26,
1216,
26,
2322,
356,
2197,
14,
2083,
8,
7968,
12,
1616,
12,
5661,
12,
4329,
12,
4233,
12,
10416,
395,
288,
283,
821,
15,
709,
15,
7968,
4329,
26,
1216,
26,
383,
356,
2197,
14,
2083,
8,
7968,
12,
1616,
12,
5661,
12,
4329,
12,
4233,
395,
288,
283,
821,
15,
709,
15,
7968,
4329,
26,
1216,
356,
2197,
14,
2083,
8,
7968,
12,
1616,
12,
5661,
12,
4329,
12,
4233,
395,
288,
283,
821,
15,
709,
15,
7968,
356,
2197,
14,
2083,
8,
7968,
12,
1616,
12,
5661,
12,
378,
12,
378,
395,
288,
283,
821,
15,
709,
15,
1690,
4329,
26,
1216,
26,
2322,
356,
2197,
14,
2083,
8,
7968,
12,
1616,
12,
5661,
12,
4329,
12,
4233,
12,
10416,
395,
288,
283,
821,
15,
709,
15,
1690,
4329,
26,
1216,
26,
383,
356,
2197,
14,
2083,
8,
7968,
12,
1616,
12,
5661,
12,
4329,
12,
4233,
395,
288,
283,
821,
15,
709,
15,
1690,
4329,
26,
1216,
356,
2197,
14,
2083,
8,
7968,
12,
1616,
12,
5661,
12,
4329,
12,
4233,
395,
288,
283,
821,
15,
709,
15,
1690,
356,
2197,
14,
2083,
8,
7968,
12,
1616,
12,
5661,
12,
378,
12,
378,
395,
267,
789,
267,
3866,
275,
469,
288,
283,
5006,
356,
1125,
63,
3197,
12,
288,
283,
7968,
13,
709,
13,
821,
841,
26,
1216,
299,
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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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
] |
doug-fish/horizon
|
openstack_dashboard/test/settings.py
|
7
|
6317
|
# 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 os
from horizon.test.settings import * # noqa
from horizon.utils import secret_key
from openstack_dashboard import exceptions
from openstack_dashboard.static_settings import get_staticfiles_dirs # noqa
STATICFILES_DIRS = get_staticfiles_dirs()
TEST_DIR = os.path.dirname(os.path.abspath(__file__))
ROOT_PATH = os.path.abspath(os.path.join(TEST_DIR, ".."))
STATIC_ROOT = os.path.abspath(os.path.join(ROOT_PATH, '..', 'static'))
SECRET_KEY = secret_key.generate_or_read_from_file(
os.path.join(TEST_DIR, '.secret_key_store'))
ROOT_URLCONF = 'openstack_dashboard.test.urls'
TEMPLATE_DIRS = (
os.path.join(TEST_DIR, 'templates'),
)
TEMPLATE_CONTEXT_PROCESSORS += (
'openstack_dashboard.context_processors.openstack',
)
COMPRESS_OFFLINE = False
INSTALLED_APPS = (
'django.contrib.contenttypes',
'django.contrib.auth',
'django.contrib.sessions',
'django.contrib.staticfiles',
'django.contrib.messages',
'django.contrib.humanize',
'django_nose',
'openstack_auth',
'compressor',
'horizon',
'openstack_dashboard',
)
AUTHENTICATION_BACKENDS = ('openstack_auth.backend.KeystoneBackend',)
SITE_BRANDING = 'OpenStack'
HORIZON_CONFIG = {
"password_validator": {
"regex": '^.{8,18}$',
"help_text": "Password must be between 8 and 18 characters."
},
'user_home': None,
'help_url': "http://docs.openstack.org",
'exceptions': {'recoverable': exceptions.RECOVERABLE,
'not_found': exceptions.NOT_FOUND,
'unauthorized': exceptions.UNAUTHORIZED},
'angular_modules': [],
'js_files': [],
}
# Load the pluggable dashboard settings
import openstack_dashboard.enabled
import openstack_dashboard.local.enabled
from openstack_dashboard.utils import settings
INSTALLED_APPS = list(INSTALLED_APPS) # Make sure it's mutable
settings.update_dashboards(
[
openstack_dashboard.enabled,
openstack_dashboard.local.enabled,
],
HORIZON_CONFIG,
INSTALLED_APPS,
)
INSTALLED_APPS[0:0] = []
# Set to True to allow users to upload images to glance via Horizon server.
# When enabled, a file form field will appear on the create image form.
# See documentation for deployment considerations.
HORIZON_IMAGES_ALLOW_UPLOAD = True
AVAILABLE_REGIONS = [
('http://localhost:5000/v2.0', 'local'),
('http://remote:5000/v2.0', 'remote'),
]
OPENSTACK_API_VERSIONS = {
"identity": 3
}
OPENSTACK_KEYSTONE_URL = "http://localhost:5000/v2.0"
OPENSTACK_KEYSTONE_DEFAULT_ROLE = "_member_"
OPENSTACK_KEYSTONE_MULTIDOMAIN_SUPPORT = True
OPENSTACK_KEYSTONE_DEFAULT_DOMAIN = 'test_domain'
OPENSTACK_KEYSTONE_BACKEND = {
'name': 'native',
'can_edit_user': True,
'can_edit_group': True,
'can_edit_project': True,
'can_edit_domain': True,
'can_edit_role': True
}
OPENSTACK_CINDER_FEATURES = {
'enable_backup': True,
}
OPENSTACK_NEUTRON_NETWORK = {
'enable_router': True,
'enable_quotas': False, # Enabled in specific tests only
# Parameters below (enable_lb, enable_firewall, enable_vpn)
# control if these panels are displayed or not,
# i.e. they only affect the navigation menu.
# These panels are registered even if enable_XXX is False,
# so we don't need to set them to True in most unit tests
# to avoid stubbing neutron extension check calls.
'enable_lb': False,
'enable_firewall': False,
'enable_vpn': False,
'profile_support': None,
'enable_distributed_router': False,
# 'profile_support': 'cisco'
}
OPENSTACK_HYPERVISOR_FEATURES = {
'can_set_mount_point': False,
'can_set_password': True,
}
OPENSTACK_IMAGE_BACKEND = {
'image_formats': [
('', 'Select format'),
('aki', 'AKI - Amazon Kernel Image'),
('ami', 'AMI - Amazon Machine Image'),
('ari', 'ARI - Amazon Ramdisk Image'),
('iso', 'ISO - Optical Disk Image'),
('qcow2', 'QCOW2 - QEMU Emulator'),
('raw', 'Raw'),
('vdi', 'VDI'),
('vhd', 'VHD'),
('vmdk', 'VMDK')
]
}
LOGGING['loggers'].update(
{
'openstack_dashboard': {
'handlers': ['test'],
'propagate': False,
},
'openstack_auth': {
'handlers': ['test'],
'propagate': False,
},
'novaclient': {
'handlers': ['test'],
'propagate': False,
},
'keystoneclient': {
'handlers': ['test'],
'propagate': False,
},
'glanceclient': {
'handlers': ['test'],
'propagate': False,
},
'neutronclient': {
'handlers': ['test'],
'propagate': False,
},
'iso8601': {
'handlers': ['null'],
'propagate': False,
},
}
)
SECURITY_GROUP_RULES = {
'all_tcp': {
'name': 'ALL TCP',
'ip_protocol': 'tcp',
'from_port': '1',
'to_port': '65535',
},
'http': {
'name': 'HTTP',
'ip_protocol': 'tcp',
'from_port': '80',
'to_port': '80',
},
}
NOSE_ARGS = ['--nocapture',
'--nologcapture',
'--cover-package=openstack_dashboard',
'--cover-inclusive',
'--all-modules']
POLICY_FILES_PATH = os.path.join(ROOT_PATH, "conf")
POLICY_FILES = {
'identity': 'keystone_policy.json',
'compute': 'nova_policy.json'
}
# The openstack_auth.user.Token object isn't JSON-serializable ATM
SESSION_SERIALIZER = 'django.contrib.sessions.serializers.PickleSerializer'
REST_API_SETTING_1 = 'foo'
REST_API_SETTING_2 = 'bar'
REST_API_SECURITY = 'SECURITY'
REST_API_REQUIRED_SETTINGS = ['REST_API_SETTING_1']
REST_API_ADDITIONAL_SETTINGS = ['REST_API_SETTING_2']
|
apache-2.0
|
[
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,
747,
199,
199,
504,
21726,
14,
396,
14,
1751,
492,
627,
221,
327,
8151,
199,
504,
21726,
14,
1208,
492,
7565,
63,
498,
199,
504,
13869,
63,
9743,
492,
4967,
199,
504,
13869,
63,
9743,
14,
1986,
63,
1751,
492,
664,
63,
18373,
63,
3220,
221,
327,
8151,
199,
199,
10449,
9472,
63,
14455,
275,
664,
63,
18373,
63,
3220,
342,
199,
199,
2864,
63,
3022,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
8964,
199,
5441,
63,
3243,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
904,
8,
2864,
63,
3022,
12,
21777,
2237,
199,
10449,
63,
5441,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
904,
8,
5441,
63,
3243,
12,
19155,
283,
1986,
1333,
199,
199,
12961,
63,
3078,
275,
7565,
63,
498,
14,
4208,
63,
269,
63,
739,
63,
504,
63,
493,
8,
272,
747,
14,
515,
14,
904,
8,
2864,
63,
3022,
12,
1987,
4731,
63,
498,
63,
1617,
1333,
199,
5441,
63,
18125,
275,
283,
8512,
63,
9743,
14,
396,
14,
3603,
7,
199,
7433,
63,
14455,
275,
334,
272,
747,
14,
515,
14,
904,
8,
2864,
63,
3022,
12,
283,
5876,
659,
199,
9,
199,
199,
7433,
63,
9059,
63,
10494,
4149,
847,
334,
272,
283,
8512,
63,
9743,
14,
1100,
63,
10547,
14,
8512,
297,
199,
9,
199,
199,
22827,
1608,
63,
7517,
6174,
275,
756,
199,
199,
15942,
63,
14219,
275,
334,
272,
283,
1176,
14,
2828,
14,
10778,
297,
272,
283,
1176,
14,
2828,
14,
1178,
297,
272,
283,
1176,
14,
2828,
14,
11676,
297,
272,
283,
1176,
14,
2828,
14,
18373,
297,
272,
283,
1176,
14,
2828,
14,
3431,
297,
272,
283,
1176,
14,
2828,
14,
14864,
794,
297,
272,
283,
1176,
63,
21085,
297,
272,
283,
8512,
63,
1178,
297,
272,
283,
27879,
297,
272,
283,
16561,
297,
272,
283,
8512,
63,
9743,
297,
199,
9,
199,
199,
29599,
63,
28988,
275,
661,
8512,
63,
1178,
14,
4620,
14,
1197,
8361,
8447,
9538,
199,
199,
7917,
63,
7184,
3649,
1206,
275,
283,
26208,
7,
199,
199,
40,
7123,
615,
63,
5569,
275,
469,
272,
298,
2060,
63,
11034,
582,
469,
267,
298,
3821,
582,
14452,
23379,
24,
12,
1085,
19204,
267,
298,
3437,
63,
505,
582,
298,
6139,
1471,
506,
3382,
1695,
436,
6155,
4110,
2122,
272,
1660,
272,
283,
751,
63,
4219,
356,
488,
12,
272,
283,
3437,
63,
633,
356,
298,
1014,
921,
4757,
14,
8512,
14,
1308,
401,
272,
283,
3924,
356,
791,
23131,
461,
356,
4967,
14,
907,
19052,
2617,
12,
673,
283,
1397,
63,
4214,
356,
4967,
14,
4609,
63,
13945,
12,
673,
283,
324,
11497,
356,
4967,
14,
1734,
25303,
1149,
1386,
272,
283,
11572,
63,
3112,
356,
990,
272,
283,
3596,
63,
1725,
356,
990,
199,
93,
199,
199,
3,
7190,
314,
14202,
16725,
17216,
2202,
199,
646,
13869,
63,
9743,
14,
3827,
199,
646,
13869,
63,
9743,
14,
1832,
14,
3827,
199,
504,
13869,
63,
9743,
14,
1208,
492,
2202,
199,
199,
15942,
63,
14219,
275,
769,
8,
15942,
63,
14219,
9,
221,
327,
4155,
3238,
652,
1159,
17194,
199,
1751,
14,
873,
63,
30424,
8,
272,
359,
267,
13869,
63,
9743,
14,
3827,
12,
267,
13869,
63,
9743,
14,
1832,
14,
3827,
12,
272,
2156,
272,
869,
7123,
615,
63,
5569,
12,
272,
31061,
63,
14219,
12,
199,
9,
199,
15942,
63,
14219,
59,
16,
26,
16,
61,
275,
942,
199,
199,
3,
2494,
370,
715,
370,
2040,
4390,
370,
5802,
5935,
370,
21785,
4799,
869,
11925,
1654,
14,
199,
3,
3979,
5223,
12,
282,
570,
1824,
901,
911,
7468,
641,
314,
1218,
1834,
1824,
14,
199,
3,
1666,
3794,
367,
14295,
8219,
3801,
14,
199,
40,
7123,
615,
63,
1469,
5383,
63,
12231,
63,
16418,
275,
715,
199,
199,
17377,
63,
5616,
2823,
275,
359,
272,
661,
1014,
921,
5967,
26,
13128,
15,
86,
18,
14,
16,
297,
283,
1832,
659,
272,
661,
1014,
921,
3846,
26,
13128,
15,
86,
18,
14,
16,
297,
283,
3846,
659,
199,
61,
199,
199,
9935,
17014,
63,
3735,
63,
26358,
275,
469,
272,
298,
5582,
582,
650,
199,
93,
199,
199,
9935,
17014,
63,
3078,
840,
4817,
63,
2632,
275,
298,
1014,
921,
5967,
26,
13128,
15,
86,
18,
14,
16,
2,
199,
9935,
17014,
63,
3078,
840,
4817,
63,
3472,
63,
15468,
275,
2668,
1114,
12172,
199,
199,
9935,
17014,
63,
3078,
840,
4817,
63,
8203,
998,
47,
5848,
63,
10640,
275,
715,
199,
9935,
17014,
63,
3078,
840,
4817,
63,
3472,
63,
7378,
275,
283,
396,
63,
2261,
7,
199,
199,
9935,
17014,
63,
3078,
840,
4817,
63,
18145,
275,
469,
272,
283,
354,
356,
283,
6106,
297,
272,
283,
2425,
63,
3773,
63,
751,
356,
715,
12,
272,
283,
2425,
63,
3773,
63,
923,
356,
715,
12,
272,
283,
2425,
63,
3773,
63,
1715,
356,
715,
12,
272,
283,
2425,
63,
3773,
63,
2261,
356,
715,
12,
272,
283,
2425,
63,
3773,
63,
3756,
356,
715,
199,
93,
199,
199,
9935,
17014,
63,
35,
3192,
540,
63,
13313,
275,
469,
272,
283,
4296,
63,
5751,
356,
715,
12,
199,
93,
199,
199,
9935,
17014,
63,
6388,
934,
12758,
63,
14560,
275,
469,
272,
283,
4296,
63,
4995,
356,
715,
12,
272,
283,
4296,
63,
17056,
356,
756,
12,
221,
327,
3447,
1909,
315,
2488,
2295,
1454,
272,
327,
3897
] |
[
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,
747,
199,
199,
504,
21726,
14,
396,
14,
1751,
492,
627,
221,
327,
8151,
199,
504,
21726,
14,
1208,
492,
7565,
63,
498,
199,
504,
13869,
63,
9743,
492,
4967,
199,
504,
13869,
63,
9743,
14,
1986,
63,
1751,
492,
664,
63,
18373,
63,
3220,
221,
327,
8151,
199,
199,
10449,
9472,
63,
14455,
275,
664,
63,
18373,
63,
3220,
342,
199,
199,
2864,
63,
3022,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
8964,
199,
5441,
63,
3243,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
904,
8,
2864,
63,
3022,
12,
21777,
2237,
199,
10449,
63,
5441,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
904,
8,
5441,
63,
3243,
12,
19155,
283,
1986,
1333,
199,
199,
12961,
63,
3078,
275,
7565,
63,
498,
14,
4208,
63,
269,
63,
739,
63,
504,
63,
493,
8,
272,
747,
14,
515,
14,
904,
8,
2864,
63,
3022,
12,
1987,
4731,
63,
498,
63,
1617,
1333,
199,
5441,
63,
18125,
275,
283,
8512,
63,
9743,
14,
396,
14,
3603,
7,
199,
7433,
63,
14455,
275,
334,
272,
747,
14,
515,
14,
904,
8,
2864,
63,
3022,
12,
283,
5876,
659,
199,
9,
199,
199,
7433,
63,
9059,
63,
10494,
4149,
847,
334,
272,
283,
8512,
63,
9743,
14,
1100,
63,
10547,
14,
8512,
297,
199,
9,
199,
199,
22827,
1608,
63,
7517,
6174,
275,
756,
199,
199,
15942,
63,
14219,
275,
334,
272,
283,
1176,
14,
2828,
14,
10778,
297,
272,
283,
1176,
14,
2828,
14,
1178,
297,
272,
283,
1176,
14,
2828,
14,
11676,
297,
272,
283,
1176,
14,
2828,
14,
18373,
297,
272,
283,
1176,
14,
2828,
14,
3431,
297,
272,
283,
1176,
14,
2828,
14,
14864,
794,
297,
272,
283,
1176,
63,
21085,
297,
272,
283,
8512,
63,
1178,
297,
272,
283,
27879,
297,
272,
283,
16561,
297,
272,
283,
8512,
63,
9743,
297,
199,
9,
199,
199,
29599,
63,
28988,
275,
661,
8512,
63,
1178,
14,
4620,
14,
1197,
8361,
8447,
9538,
199,
199,
7917,
63,
7184,
3649,
1206,
275,
283,
26208,
7,
199,
199,
40,
7123,
615,
63,
5569,
275,
469,
272,
298,
2060,
63,
11034,
582,
469,
267,
298,
3821,
582,
14452,
23379,
24,
12,
1085,
19204,
267,
298,
3437,
63,
505,
582,
298,
6139,
1471,
506,
3382,
1695,
436,
6155,
4110,
2122,
272,
1660,
272,
283,
751,
63,
4219,
356,
488,
12,
272,
283,
3437,
63,
633,
356,
298,
1014,
921,
4757,
14,
8512,
14,
1308,
401,
272,
283,
3924,
356,
791,
23131,
461,
356,
4967,
14,
907,
19052,
2617,
12,
673,
283,
1397,
63,
4214,
356,
4967,
14,
4609,
63,
13945,
12,
673,
283,
324,
11497,
356,
4967,
14,
1734,
25303,
1149,
1386,
272,
283,
11572,
63,
3112,
356,
990,
272,
283,
3596,
63,
1725,
356,
990,
199,
93,
199,
199,
3,
7190,
314,
14202,
16725,
17216,
2202,
199,
646,
13869,
63,
9743,
14,
3827,
199,
646,
13869,
63,
9743,
14,
1832,
14,
3827,
199,
504,
13869,
63,
9743,
14,
1208,
492,
2202,
199,
199,
15942,
63,
14219,
275,
769,
8,
15942,
63,
14219,
9,
221,
327,
4155,
3238,
652,
1159,
17194,
199,
1751,
14,
873,
63,
30424,
8,
272,
359,
267,
13869,
63,
9743,
14,
3827,
12,
267,
13869,
63,
9743,
14,
1832,
14,
3827,
12,
272,
2156,
272,
869,
7123,
615,
63,
5569,
12,
272,
31061,
63,
14219,
12,
199,
9,
199,
15942,
63,
14219,
59,
16,
26,
16,
61,
275,
942,
199,
199,
3,
2494,
370,
715,
370,
2040,
4390,
370,
5802,
5935,
370,
21785,
4799,
869,
11925,
1654,
14,
199,
3,
3979,
5223,
12,
282,
570,
1824,
901,
911,
7468,
641,
314,
1218,
1834,
1824,
14,
199,
3,
1666,
3794,
367,
14295,
8219,
3801,
14,
199,
40,
7123,
615,
63,
1469,
5383,
63,
12231,
63,
16418,
275,
715,
199,
199,
17377,
63,
5616,
2823,
275,
359,
272,
661,
1014,
921,
5967,
26,
13128,
15,
86,
18,
14,
16,
297,
283,
1832,
659,
272,
661,
1014,
921,
3846,
26,
13128,
15,
86,
18,
14,
16,
297,
283,
3846,
659,
199,
61,
199,
199,
9935,
17014,
63,
3735,
63,
26358,
275,
469,
272,
298,
5582,
582,
650,
199,
93,
199,
199,
9935,
17014,
63,
3078,
840,
4817,
63,
2632,
275,
298,
1014,
921,
5967,
26,
13128,
15,
86,
18,
14,
16,
2,
199,
9935,
17014,
63,
3078,
840,
4817,
63,
3472,
63,
15468,
275,
2668,
1114,
12172,
199,
199,
9935,
17014,
63,
3078,
840,
4817,
63,
8203,
998,
47,
5848,
63,
10640,
275,
715,
199,
9935,
17014,
63,
3078,
840,
4817,
63,
3472,
63,
7378,
275,
283,
396,
63,
2261,
7,
199,
199,
9935,
17014,
63,
3078,
840,
4817,
63,
18145,
275,
469,
272,
283,
354,
356,
283,
6106,
297,
272,
283,
2425,
63,
3773,
63,
751,
356,
715,
12,
272,
283,
2425,
63,
3773,
63,
923,
356,
715,
12,
272,
283,
2425,
63,
3773,
63,
1715,
356,
715,
12,
272,
283,
2425,
63,
3773,
63,
2261,
356,
715,
12,
272,
283,
2425,
63,
3773,
63,
3756,
356,
715,
199,
93,
199,
199,
9935,
17014,
63,
35,
3192,
540,
63,
13313,
275,
469,
272,
283,
4296,
63,
5751,
356,
715,
12,
199,
93,
199,
199,
9935,
17014,
63,
6388,
934,
12758,
63,
14560,
275,
469,
272,
283,
4296,
63,
4995,
356,
715,
12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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
] |
1200wd/1200wd_addons
|
stock_forecasted/models/sale.py
|
1
|
1283
|
# -*- coding: utf-8 -*-
##############################################################################
#
# Stock Forecasted
# 1200 Web Development
# http://1200wd.com/
# Copyright (C) 2016 January
#
# 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 openerp import models, fields, api, _
class SaleOrderLine(models.Model):
_inherit = 'sale.order.line'
# Add index to sale order line on product_id and create_date
product_id = fields.Many2one('product.product', 'Product', select=1)
create_date = fields.Date('Created on', select=1)
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
28406,
21684,
9765,
471,
199,
3,
259,
413,
1840,
6001,
15290,
199,
3,
259,
1455,
921,
23781,
2989,
14,
957,
15,
199,
3,
259,
1898,
334,
35,
9,
7800,
17474,
20527,
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,
5166,
492,
1709,
12,
1504,
12,
2986,
12,
485,
199,
199,
533,
428,
1895,
4738,
3049,
8,
992,
14,
1685,
304,
272,
485,
6486,
275,
283,
8515,
14,
1648,
14,
604,
7,
339,
327,
2654,
1478,
370,
13590,
1865,
1004,
641,
3336,
63,
344,
436,
1218,
63,
602,
272,
3336,
63,
344,
275,
1504,
14,
4089,
18,
368,
360,
2558,
14,
2558,
297,
283,
5884,
297,
3504,
29,
17,
9,
272,
1218,
63,
602,
275,
1504,
14,
2506,
360,
10502,
641,
297,
3504,
29,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
28406,
21684,
9765,
471,
199,
3,
259,
413,
1840,
6001,
15290,
199,
3,
259,
1455,
921,
23781,
2989,
14,
957,
15,
199,
3,
259,
1898,
334,
35,
9,
7800,
17474,
20527,
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,
5166,
492,
1709,
12,
1504,
12,
2986,
12,
485,
199,
199,
533,
428,
1895,
4738,
3049,
8,
992,
14,
1685,
304,
272,
485,
6486,
275,
283,
8515,
14,
1648,
14,
604,
7,
339,
327,
2654,
1478,
370,
13590,
1865,
1004,
641,
3336,
63,
344,
436,
1218,
63,
602,
272,
3336,
63,
344,
275,
1504,
14,
4089,
18,
368,
360,
2558,
14,
2558,
297,
283,
5884,
297,
3504,
29,
17,
9,
272,
1218,
63,
602,
275,
1504,
14,
2506,
360,
10502,
641,
297,
3504,
29,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
sfumato77/Kernel-4.8_Android-x86_BayTrail
|
tools/perf/scripts/python/compaction-times.py
|
958
|
7950
|
# report time spent in compaction
# Licensed under the terms of the GNU GPL License version 2
# testing:
# 'echo 1 > /proc/sys/vm/compact_memory' to force compaction of all zones
import os
import sys
import re
import signal
signal.signal(signal.SIGPIPE, signal.SIG_DFL)
usage = "usage: perf script report compaction-times.py -- [-h] [-u] [-p|-pv] [-t | [-m] [-fs] [-ms]] [pid|pid-range|comm-regex]\n"
class popt:
DISP_DFL = 0
DISP_PROC = 1
DISP_PROC_VERBOSE=2
class topt:
DISP_TIME = 0
DISP_MIG = 1
DISP_ISOLFREE = 2
DISP_ISOLMIG = 4
DISP_ALL = 7
class comm_filter:
def __init__(self, re):
self.re = re
def filter(self, pid, comm):
m = self.re.search(comm)
return m == None or m.group() == ""
class pid_filter:
def __init__(self, low, high):
self.low = (0 if low == "" else int(low))
self.high = (0 if high == "" else int(high))
def filter(self, pid, comm):
return not (pid >= self.low and (self.high == 0 or pid <= self.high))
def set_type(t):
global opt_disp
opt_disp = (t if opt_disp == topt.DISP_ALL else opt_disp|t)
def ns(sec, nsec):
return (sec * 1000000000) + nsec
def time(ns):
return "%dns" % ns if opt_ns else "%dus" % (round(ns, -3) / 1000)
class pair:
def __init__(self, aval, bval, alabel = None, blabel = None):
self.alabel = alabel
self.blabel = blabel
self.aval = aval
self.bval = bval
def __add__(self, rhs):
self.aval += rhs.aval
self.bval += rhs.bval
return self
def __str__(self):
return "%s=%d %s=%d" % (self.alabel, self.aval, self.blabel, self.bval)
class cnode:
def __init__(self, ns):
self.ns = ns
self.migrated = pair(0, 0, "moved", "failed")
self.fscan = pair(0,0, "scanned", "isolated")
self.mscan = pair(0,0, "scanned", "isolated")
def __add__(self, rhs):
self.ns += rhs.ns
self.migrated += rhs.migrated
self.fscan += rhs.fscan
self.mscan += rhs.mscan
return self
def __str__(self):
prev = 0
s = "%s " % time(self.ns)
if (opt_disp & topt.DISP_MIG):
s += "migration: %s" % self.migrated
prev = 1
if (opt_disp & topt.DISP_ISOLFREE):
s += "%sfree_scanner: %s" % (" " if prev else "", self.fscan)
prev = 1
if (opt_disp & topt.DISP_ISOLMIG):
s += "%smigration_scanner: %s" % (" " if prev else "", self.mscan)
return s
def complete(self, secs, nsecs):
self.ns = ns(secs, nsecs) - self.ns
def increment(self, migrated, fscan, mscan):
if (migrated != None):
self.migrated += migrated
if (fscan != None):
self.fscan += fscan
if (mscan != None):
self.mscan += mscan
class chead:
heads = {}
val = cnode(0);
fobj = None
@classmethod
def add_filter(cls, filter):
cls.fobj = filter
@classmethod
def create_pending(cls, pid, comm, start_secs, start_nsecs):
filtered = 0
try:
head = cls.heads[pid]
filtered = head.is_filtered()
except KeyError:
if cls.fobj != None:
filtered = cls.fobj.filter(pid, comm)
head = cls.heads[pid] = chead(comm, pid, filtered)
if not filtered:
head.mark_pending(start_secs, start_nsecs)
@classmethod
def increment_pending(cls, pid, migrated, fscan, mscan):
head = cls.heads[pid]
if not head.is_filtered():
if head.is_pending():
head.do_increment(migrated, fscan, mscan)
else:
sys.stderr.write("missing start compaction event for pid %d\n" % pid)
@classmethod
def complete_pending(cls, pid, secs, nsecs):
head = cls.heads[pid]
if not head.is_filtered():
if head.is_pending():
head.make_complete(secs, nsecs)
else:
sys.stderr.write("missing start compaction event for pid %d\n" % pid)
@classmethod
def gen(cls):
if opt_proc != popt.DISP_DFL:
for i in cls.heads:
yield cls.heads[i]
@classmethod
def str(cls):
return cls.val
def __init__(self, comm, pid, filtered):
self.comm = comm
self.pid = pid
self.val = cnode(0)
self.pending = None
self.filtered = filtered
self.list = []
def __add__(self, rhs):
self.ns += rhs.ns
self.val += rhs.val
return self
def mark_pending(self, secs, nsecs):
self.pending = cnode(ns(secs, nsecs))
def do_increment(self, migrated, fscan, mscan):
self.pending.increment(migrated, fscan, mscan)
def make_complete(self, secs, nsecs):
self.pending.complete(secs, nsecs)
chead.val += self.pending
if opt_proc != popt.DISP_DFL:
self.val += self.pending
if opt_proc == popt.DISP_PROC_VERBOSE:
self.list.append(self.pending)
self.pending = None
def enumerate(self):
if opt_proc == popt.DISP_PROC_VERBOSE and not self.is_filtered():
for i, pelem in enumerate(self.list):
sys.stdout.write("%d[%s].%d: %s\n" % (self.pid, self.comm, i+1, pelem))
def is_pending(self):
return self.pending != None
def is_filtered(self):
return self.filtered
def display(self):
if not self.is_filtered():
sys.stdout.write("%d[%s]: %s\n" % (self.pid, self.comm, self.val))
def trace_end():
sys.stdout.write("total: %s\n" % chead.str())
for i in chead.gen():
i.display(),
i.enumerate()
def compaction__mm_compaction_migratepages(event_name, context, common_cpu,
common_secs, common_nsecs, common_pid, common_comm,
common_callchain, nr_migrated, nr_failed):
chead.increment_pending(common_pid,
pair(nr_migrated, nr_failed), None, None)
def compaction__mm_compaction_isolate_freepages(event_name, context, common_cpu,
common_secs, common_nsecs, common_pid, common_comm,
common_callchain, start_pfn, end_pfn, nr_scanned, nr_taken):
chead.increment_pending(common_pid,
None, pair(nr_scanned, nr_taken), None)
def compaction__mm_compaction_isolate_migratepages(event_name, context, common_cpu,
common_secs, common_nsecs, common_pid, common_comm,
common_callchain, start_pfn, end_pfn, nr_scanned, nr_taken):
chead.increment_pending(common_pid,
None, None, pair(nr_scanned, nr_taken))
def compaction__mm_compaction_end(event_name, context, common_cpu,
common_secs, common_nsecs, common_pid, common_comm,
common_callchain, zone_start, migrate_start, free_start, zone_end,
sync, status):
chead.complete_pending(common_pid, common_secs, common_nsecs)
def compaction__mm_compaction_begin(event_name, context, common_cpu,
common_secs, common_nsecs, common_pid, common_comm,
common_callchain, zone_start, migrate_start, free_start, zone_end,
sync):
chead.create_pending(common_pid, common_comm, common_secs, common_nsecs)
def pr_help():
global usage
sys.stdout.write(usage)
sys.stdout.write("\n")
sys.stdout.write("-h display this help\n")
sys.stdout.write("-p display by process\n")
sys.stdout.write("-pv display by process (verbose)\n")
sys.stdout.write("-t display stall times only\n")
sys.stdout.write("-m display stats for migration\n")
sys.stdout.write("-fs display stats for free scanner\n")
sys.stdout.write("-ms display stats for migration scanner\n")
sys.stdout.write("-u display results in microseconds (default nanoseconds)\n")
comm_re = None
pid_re = None
pid_regex = "^(\d*)-(\d*)$|^(\d*)$"
opt_proc = popt.DISP_DFL
opt_disp = topt.DISP_ALL
opt_ns = True
argc = len(sys.argv) - 1
if argc >= 1:
pid_re = re.compile(pid_regex)
for i, opt in enumerate(sys.argv[1:]):
if opt[0] == "-":
if opt == "-h":
pr_help()
exit(0);
elif opt == "-p":
opt_proc = popt.DISP_PROC
elif opt == "-pv":
opt_proc = popt.DISP_PROC_VERBOSE
elif opt == '-u':
opt_ns = False
elif opt == "-t":
set_type(topt.DISP_TIME)
elif opt == "-m":
set_type(topt.DISP_MIG)
elif opt == "-fs":
set_type(topt.DISP_ISOLFREE)
elif opt == "-ms":
set_type(topt.DISP_ISOLMIG)
else:
sys.exit(usage)
elif i == argc - 1:
m = pid_re.search(opt)
if m != None and m.group() != "":
if m.group(3) != None:
f = pid_filter(m.group(3), m.group(3))
else:
f = pid_filter(m.group(1), m.group(2))
else:
try:
comm_re=re.compile(opt)
except:
sys.stderr.write("invalid regex '%s'" % opt)
sys.exit(usage)
f = comm_filter(comm_re)
chead.add_filter(f)
|
gpl-2.0
|
[
3,
3622,
900,
2249,
484,
315,
1013,
1287,
199,
3,
3909,
1334,
314,
2895,
402,
314,
1664,
14629,
844,
1015,
499,
199,
199,
3,
5343,
26,
199,
3,
283,
7878,
413,
690,
1182,
4687,
15,
1274,
15,
2611,
15,
23046,
63,
4844,
7,
370,
3542,
1013,
1287,
402,
1006,
18666,
199,
199,
646,
747,
199,
646,
984,
199,
646,
295,
199,
199,
646,
4673,
199,
4653,
14,
4653,
8,
4653,
14,
7864,
6089,
12,
4673,
14,
7864,
63,
36,
3143,
9,
199,
199,
3807,
275,
298,
3807,
26,
8582,
2884,
3622,
1013,
1287,
13,
4508,
14,
647,
1553,
5243,
72,
61,
5243,
85,
61,
5243,
80,
28447,
1381,
61,
5243,
84,
1204,
5243,
77,
61,
5243,
2319,
61,
5243,
706,
2677,
359,
3150,
92,
3150,
13,
1842,
92,
1404,
13,
3821,
7272,
78,
2,
199,
199,
533,
299,
2992,
26,
199,
198,
6178,
48,
63,
36,
3143,
275,
378,
199,
198,
6178,
48,
63,
6072,
275,
413,
199,
198,
6178,
48,
63,
6072,
63,
16075,
29,
18,
199,
199,
533,
370,
541,
26,
199,
198,
6178,
48,
63,
4961,
275,
378,
199,
198,
6178,
48,
63,
22487,
275,
413,
199,
198,
6178,
48,
63,
1311,
2228,
28170,
275,
499,
199,
198,
6178,
48,
63,
1311,
2228,
22487,
275,
841,
199,
198,
6178,
48,
63,
1761,
275,
1520,
199,
199,
533,
1923,
63,
1541,
26,
199,
198,
318,
636,
826,
721,
277,
12,
295,
304,
507,
198,
277,
14,
264,
275,
295,
421,
198,
318,
2457,
8,
277,
12,
4422,
12,
1923,
304,
507,
198,
77,
275,
291,
14,
264,
14,
1733,
8,
1404,
9,
507,
198,
1107,
333,
508,
488,
503,
333,
14,
923,
342,
508,
3087,
199,
199,
533,
4422,
63,
1541,
26,
199,
198,
318,
636,
826,
721,
277,
12,
6465,
12,
4721,
304,
507,
198,
277,
14,
674,
275,
334,
16,
340,
6465,
508,
3087,
587,
1109,
8,
674,
430,
507,
198,
277,
14,
6260,
275,
334,
16,
340,
4721,
508,
3087,
587,
1109,
8,
6260,
430,
421,
198,
318,
2457,
8,
277,
12,
4422,
12,
1923,
304,
507,
198,
1107,
440,
334,
3150,
2356,
291,
14,
674,
436,
334,
277,
14,
6260,
508,
378,
503,
4422,
2695,
291,
14,
6260,
430,
199,
199,
318,
663,
63,
466,
8,
84,
304,
199,
198,
2966,
2450,
63,
13654,
199,
198,
2992,
63,
13654,
275,
334,
84,
340,
2450,
63,
13654,
508,
370,
541,
14,
6178,
48,
63,
1761,
587,
2450,
63,
13654,
92,
84,
9,
199,
199,
318,
700,
8,
3321,
12,
14256,
304,
199,
198,
1107,
334,
3321,
627,
413,
25464,
9,
435,
14256,
199,
199,
318,
900,
8,
561,
304,
199,
198,
1107,
2071,
5797,
2,
450,
700,
340,
2450,
63,
561,
587,
2071,
68,
527,
2,
450,
334,
2363,
8,
561,
12,
446,
19,
9,
1182,
5198,
9,
199,
199,
533,
4092,
26,
199,
198,
318,
636,
826,
721,
277,
12,
282,
637,
12,
330,
637,
12,
741,
902,
275,
488,
12,
330,
1302,
275,
488,
304,
507,
198,
277,
14,
279,
902,
275,
741,
902,
507,
198,
277,
14,
66,
1302,
275,
330,
1302,
507,
198,
277,
14,
65,
637,
275,
282,
637,
507,
198,
277,
14,
66,
637,
275,
330,
637,
421,
198,
318,
636,
525,
721,
277,
12,
9085,
304,
507,
198,
277,
14,
65,
637,
847,
9085,
14,
65,
637,
507,
198,
277,
14,
66,
637,
847,
9085,
14,
66,
637,
507,
198,
1107,
291,
421,
198,
318,
636,
495,
721,
277,
304,
507,
198,
1107,
2071,
83,
2458,
68,
450,
83,
2458,
68,
2,
450,
334,
277,
14,
279,
902,
12,
291,
14,
65,
637,
12,
291,
14,
66,
1302,
12,
291,
14,
66,
637,
9,
199,
199,
533,
286,
932,
26,
199,
198,
318,
636,
826,
721,
277,
12,
700,
304,
507,
198,
277,
14,
561,
275,
700,
507,
198,
277,
14,
31544,
275,
4092,
8,
16,
12,
378,
12,
298,
3539,
401,
298,
4892,
531,
507,
198,
277,
14,
70,
6282,
275,
4092,
8,
16,
12,
16,
12,
298,
551,
9386,
401,
298,
21748,
531,
507,
198,
277,
14,
77,
6282,
275,
4092,
8,
16,
12,
16,
12,
298,
551,
9386,
401,
298,
21748,
531,
421,
198,
318,
636,
525,
721,
277,
12,
9085,
304,
507,
198,
277,
14,
561,
847,
9085,
14,
561,
507,
198,
277,
14,
31544,
847,
9085,
14,
31544,
507,
198,
277,
14,
70,
6282,
847,
9085,
14,
70,
6282,
507,
198,
277,
14,
77,
6282,
847,
9085,
14,
77,
6282,
507,
198,
1107,
291,
421,
198,
318,
636,
495,
721,
277,
304,
507,
198,
5701,
275,
378,
507,
198,
83,
275,
2071,
83,
298,
450,
900,
8,
277,
14,
561,
9,
507,
198,
692,
334,
2992,
63,
13654,
1253,
370,
541,
14,
6178,
48,
63,
22487,
304,
686,
198,
83,
847,
298,
8998,
26,
450,
83,
2,
450,
291,
14,
31544,
686,
198,
5701,
275,
413,
507,
198,
692,
334,
2992,
63,
13654,
1253,
370,
541,
14,
6178,
48,
63,
1311,
2228,
28170,
304,
686,
198,
83,
847,
2071,
83,
4624,
63,
16378,
26,
450,
83,
2,
450,
1689,
298,
340,
5071,
587,
4873,
291,
14,
70,
6282,
9,
686,
198,
5701,
275,
413,
507,
198,
692,
334,
2992,
63,
13654,
1253,
370,
541,
14,
6178,
48,
63,
1311,
2228,
22487,
304,
686,
198,
83,
847,
2071,
3300,
7077,
63,
16378,
26,
450,
83,
2,
450,
1689,
298,
340,
5071,
587,
4873,
291,
14,
77,
6282,
9,
507,
198,
1107,
308,
421,
198,
318,
4890,
8,
277,
12,
20091,
12,
13781,
304,
507,
198,
277,
14,
561,
275,
700,
8,
4855,
12,
13781,
9,
446,
291,
14,
561,
421,
198,
318,
11609,
8,
277,
12,
28322,
12,
289,
6282,
12,
333,
6282,
304,
507,
198,
692,
334,
31544,
1137,
488,
304,
686,
198,
277,
14,
31544,
847,
28322,
507,
198,
692,
334,
70,
6282,
1137,
488,
304,
686,
198,
277,
14,
70,
6282,
847,
289,
6282,
507,
198,
692,
334,
77,
6282,
1137,
488,
304,
686,
198,
277,
14,
77,
6282,
847,
333,
6282,
421,
199,
533,
286,
2993,
26,
199,
198,
17033,
275,
1052,
199,
198,
637,
275,
286,
932,
8,
16,
2736,
199,
198,
32755,
275,
488,
421,
198,
32,
3744,
199,
198,
318,
1050
] |
[
3622,
900,
2249,
484,
315,
1013,
1287,
199,
3,
3909,
1334,
314,
2895,
402,
314,
1664,
14629,
844,
1015,
499,
199,
199,
3,
5343,
26,
199,
3,
283,
7878,
413,
690,
1182,
4687,
15,
1274,
15,
2611,
15,
23046,
63,
4844,
7,
370,
3542,
1013,
1287,
402,
1006,
18666,
199,
199,
646,
747,
199,
646,
984,
199,
646,
295,
199,
199,
646,
4673,
199,
4653,
14,
4653,
8,
4653,
14,
7864,
6089,
12,
4673,
14,
7864,
63,
36,
3143,
9,
199,
199,
3807,
275,
298,
3807,
26,
8582,
2884,
3622,
1013,
1287,
13,
4508,
14,
647,
1553,
5243,
72,
61,
5243,
85,
61,
5243,
80,
28447,
1381,
61,
5243,
84,
1204,
5243,
77,
61,
5243,
2319,
61,
5243,
706,
2677,
359,
3150,
92,
3150,
13,
1842,
92,
1404,
13,
3821,
7272,
78,
2,
199,
199,
533,
299,
2992,
26,
199,
198,
6178,
48,
63,
36,
3143,
275,
378,
199,
198,
6178,
48,
63,
6072,
275,
413,
199,
198,
6178,
48,
63,
6072,
63,
16075,
29,
18,
199,
199,
533,
370,
541,
26,
199,
198,
6178,
48,
63,
4961,
275,
378,
199,
198,
6178,
48,
63,
22487,
275,
413,
199,
198,
6178,
48,
63,
1311,
2228,
28170,
275,
499,
199,
198,
6178,
48,
63,
1311,
2228,
22487,
275,
841,
199,
198,
6178,
48,
63,
1761,
275,
1520,
199,
199,
533,
1923,
63,
1541,
26,
199,
198,
318,
636,
826,
721,
277,
12,
295,
304,
507,
198,
277,
14,
264,
275,
295,
421,
198,
318,
2457,
8,
277,
12,
4422,
12,
1923,
304,
507,
198,
77,
275,
291,
14,
264,
14,
1733,
8,
1404,
9,
507,
198,
1107,
333,
508,
488,
503,
333,
14,
923,
342,
508,
3087,
199,
199,
533,
4422,
63,
1541,
26,
199,
198,
318,
636,
826,
721,
277,
12,
6465,
12,
4721,
304,
507,
198,
277,
14,
674,
275,
334,
16,
340,
6465,
508,
3087,
587,
1109,
8,
674,
430,
507,
198,
277,
14,
6260,
275,
334,
16,
340,
4721,
508,
3087,
587,
1109,
8,
6260,
430,
421,
198,
318,
2457,
8,
277,
12,
4422,
12,
1923,
304,
507,
198,
1107,
440,
334,
3150,
2356,
291,
14,
674,
436,
334,
277,
14,
6260,
508,
378,
503,
4422,
2695,
291,
14,
6260,
430,
199,
199,
318,
663,
63,
466,
8,
84,
304,
199,
198,
2966,
2450,
63,
13654,
199,
198,
2992,
63,
13654,
275,
334,
84,
340,
2450,
63,
13654,
508,
370,
541,
14,
6178,
48,
63,
1761,
587,
2450,
63,
13654,
92,
84,
9,
199,
199,
318,
700,
8,
3321,
12,
14256,
304,
199,
198,
1107,
334,
3321,
627,
413,
25464,
9,
435,
14256,
199,
199,
318,
900,
8,
561,
304,
199,
198,
1107,
2071,
5797,
2,
450,
700,
340,
2450,
63,
561,
587,
2071,
68,
527,
2,
450,
334,
2363,
8,
561,
12,
446,
19,
9,
1182,
5198,
9,
199,
199,
533,
4092,
26,
199,
198,
318,
636,
826,
721,
277,
12,
282,
637,
12,
330,
637,
12,
741,
902,
275,
488,
12,
330,
1302,
275,
488,
304,
507,
198,
277,
14,
279,
902,
275,
741,
902,
507,
198,
277,
14,
66,
1302,
275,
330,
1302,
507,
198,
277,
14,
65,
637,
275,
282,
637,
507,
198,
277,
14,
66,
637,
275,
330,
637,
421,
198,
318,
636,
525,
721,
277,
12,
9085,
304,
507,
198,
277,
14,
65,
637,
847,
9085,
14,
65,
637,
507,
198,
277,
14,
66,
637,
847,
9085,
14,
66,
637,
507,
198,
1107,
291,
421,
198,
318,
636,
495,
721,
277,
304,
507,
198,
1107,
2071,
83,
2458,
68,
450,
83,
2458,
68,
2,
450,
334,
277,
14,
279,
902,
12,
291,
14,
65,
637,
12,
291,
14,
66,
1302,
12,
291,
14,
66,
637,
9,
199,
199,
533,
286,
932,
26,
199,
198,
318,
636,
826,
721,
277,
12,
700,
304,
507,
198,
277,
14,
561,
275,
700,
507,
198,
277,
14,
31544,
275,
4092,
8,
16,
12,
378,
12,
298,
3539,
401,
298,
4892,
531,
507,
198,
277,
14,
70,
6282,
275,
4092,
8,
16,
12,
16,
12,
298,
551,
9386,
401,
298,
21748,
531,
507,
198,
277,
14,
77,
6282,
275,
4092,
8,
16,
12,
16,
12,
298,
551,
9386,
401,
298,
21748,
531,
421,
198,
318,
636,
525,
721,
277,
12,
9085,
304,
507,
198,
277,
14,
561,
847,
9085,
14,
561,
507,
198,
277,
14,
31544,
847,
9085,
14,
31544,
507,
198,
277,
14,
70,
6282,
847,
9085,
14,
70,
6282,
507,
198,
277,
14,
77,
6282,
847,
9085,
14,
77,
6282,
507,
198,
1107,
291,
421,
198,
318,
636,
495,
721,
277,
304,
507,
198,
5701,
275,
378,
507,
198,
83,
275,
2071,
83,
298,
450,
900,
8,
277,
14,
561,
9,
507,
198,
692,
334,
2992,
63,
13654,
1253,
370,
541,
14,
6178,
48,
63,
22487,
304,
686,
198,
83,
847,
298,
8998,
26,
450,
83,
2,
450,
291,
14,
31544,
686,
198,
5701,
275,
413,
507,
198,
692,
334,
2992,
63,
13654,
1253,
370,
541,
14,
6178,
48,
63,
1311,
2228,
28170,
304,
686,
198,
83,
847,
2071,
83,
4624,
63,
16378,
26,
450,
83,
2,
450,
1689,
298,
340,
5071,
587,
4873,
291,
14,
70,
6282,
9,
686,
198,
5701,
275,
413,
507,
198,
692,
334,
2992,
63,
13654,
1253,
370,
541,
14,
6178,
48,
63,
1311,
2228,
22487,
304,
686,
198,
83,
847,
2071,
3300,
7077,
63,
16378,
26,
450,
83,
2,
450,
1689,
298,
340,
5071,
587,
4873,
291,
14,
77,
6282,
9,
507,
198,
1107,
308,
421,
198,
318,
4890,
8,
277,
12,
20091,
12,
13781,
304,
507,
198,
277,
14,
561,
275,
700,
8,
4855,
12,
13781,
9,
446,
291,
14,
561,
421,
198,
318,
11609,
8,
277,
12,
28322,
12,
289,
6282,
12,
333,
6282,
304,
507,
198,
692,
334,
31544,
1137,
488,
304,
686,
198,
277,
14,
31544,
847,
28322,
507,
198,
692,
334,
70,
6282,
1137,
488,
304,
686,
198,
277,
14,
70,
6282,
847,
289,
6282,
507,
198,
692,
334,
77,
6282,
1137,
488,
304,
686,
198,
277,
14,
77,
6282,
847,
333,
6282,
421,
199,
533,
286,
2993,
26,
199,
198,
17033,
275,
1052,
199,
198,
637,
275,
286,
932,
8,
16,
2736,
199,
198,
32755,
275,
488,
421,
198,
32,
3744,
199,
198,
318,
1050,
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,
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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
] |
hoho/dosido
|
nodejs/deps/npm/node_modules/node-gyp/gyp/pylib/gyp/input_test.py
|
1841
|
3207
|
#!/usr/bin/env python
# Copyright 2013 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.
"""Unit tests for the input.py file."""
import gyp.input
import unittest
import sys
class TestFindCycles(unittest.TestCase):
def setUp(self):
self.nodes = {}
for x in ('a', 'b', 'c', 'd', 'e'):
self.nodes[x] = gyp.input.DependencyGraphNode(x)
def _create_dependency(self, dependent, dependency):
dependent.dependencies.append(dependency)
dependency.dependents.append(dependent)
def test_no_cycle_empty_graph(self):
for label, node in self.nodes.iteritems():
self.assertEquals([], node.FindCycles())
def test_no_cycle_line(self):
self._create_dependency(self.nodes['a'], self.nodes['b'])
self._create_dependency(self.nodes['b'], self.nodes['c'])
self._create_dependency(self.nodes['c'], self.nodes['d'])
for label, node in self.nodes.iteritems():
self.assertEquals([], node.FindCycles())
def test_no_cycle_dag(self):
self._create_dependency(self.nodes['a'], self.nodes['b'])
self._create_dependency(self.nodes['a'], self.nodes['c'])
self._create_dependency(self.nodes['b'], self.nodes['c'])
for label, node in self.nodes.iteritems():
self.assertEquals([], node.FindCycles())
def test_cycle_self_reference(self):
self._create_dependency(self.nodes['a'], self.nodes['a'])
self.assertEquals([[self.nodes['a'], self.nodes['a']]],
self.nodes['a'].FindCycles())
def test_cycle_two_nodes(self):
self._create_dependency(self.nodes['a'], self.nodes['b'])
self._create_dependency(self.nodes['b'], self.nodes['a'])
self.assertEquals([[self.nodes['a'], self.nodes['b'], self.nodes['a']]],
self.nodes['a'].FindCycles())
self.assertEquals([[self.nodes['b'], self.nodes['a'], self.nodes['b']]],
self.nodes['b'].FindCycles())
def test_two_cycles(self):
self._create_dependency(self.nodes['a'], self.nodes['b'])
self._create_dependency(self.nodes['b'], self.nodes['a'])
self._create_dependency(self.nodes['b'], self.nodes['c'])
self._create_dependency(self.nodes['c'], self.nodes['b'])
cycles = self.nodes['a'].FindCycles()
self.assertTrue(
[self.nodes['a'], self.nodes['b'], self.nodes['a']] in cycles)
self.assertTrue(
[self.nodes['b'], self.nodes['c'], self.nodes['b']] in cycles)
self.assertEquals(2, len(cycles))
def test_big_cycle(self):
self._create_dependency(self.nodes['a'], self.nodes['b'])
self._create_dependency(self.nodes['b'], self.nodes['c'])
self._create_dependency(self.nodes['c'], self.nodes['d'])
self._create_dependency(self.nodes['d'], self.nodes['e'])
self._create_dependency(self.nodes['e'], self.nodes['a'])
self.assertEquals([[self.nodes['a'],
self.nodes['b'],
self.nodes['c'],
self.nodes['d'],
self.nodes['e'],
self.nodes['a']]],
self.nodes['a'].FindCycles())
if __name__ == '__main__':
unittest.main()
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
1898,
6171,
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,
5072,
2295,
367,
314,
1324,
14,
647,
570,
1041,
199,
199,
646,
4902,
14,
1210,
199,
646,
2882,
199,
646,
984,
421,
199,
533,
1379,
6591,
28016,
8,
2796,
14,
1746,
304,
523,
347,
3613,
8,
277,
304,
272,
291,
14,
2415,
275,
1052,
272,
367,
671,
315,
661,
65,
297,
283,
66,
297,
283,
67,
297,
283,
68,
297,
283,
69,
735,
489,
291,
14,
2415,
59,
88,
61,
275,
4902,
14,
1210,
14,
14403,
4578,
1716,
8,
88,
9,
819,
347,
485,
981,
63,
8575,
8,
277,
12,
11410,
12,
5936,
304,
272,
11410,
14,
5714,
14,
740,
8,
8575,
9,
272,
5936,
14,
32333,
14,
740,
8,
7106,
9,
819,
347,
511,
63,
889,
63,
7612,
63,
1667,
63,
2180,
8,
277,
304,
272,
367,
1768,
12,
1031,
315,
291,
14,
2415,
14,
4611,
837,
489,
291,
14,
2947,
8798,
1031,
14,
6591,
28016,
1012,
819,
347,
511,
63,
889,
63,
7612,
63,
604,
8,
277,
304,
272,
291,
423,
981,
63,
8575,
8,
277,
14,
2415,
459,
65,
995,
291,
14,
2415,
459,
66,
1105,
272,
291,
423,
981,
63,
8575,
8,
277,
14,
2415,
459,
66,
995,
291,
14,
2415,
459,
67,
1105,
272,
291,
423,
981,
63,
8575,
8,
277,
14,
2415,
459,
67,
995,
291,
14,
2415,
459,
68,
1105,
339,
367,
1768,
12,
1031,
315,
291,
14,
2415,
14,
4611,
837,
489,
291,
14,
2947,
8798,
1031,
14,
6591,
28016,
1012,
819,
347,
511,
63,
889,
63,
7612,
63,
7406,
8,
277,
304,
272,
291,
423,
981,
63,
8575,
8,
277,
14,
2415,
459,
65,
995,
291,
14,
2415,
459,
66,
1105,
272,
291,
423,
981,
63,
8575,
8,
277,
14,
2415,
459,
65,
995,
291,
14,
2415,
459,
67,
1105,
272,
291,
423,
981,
63,
8575,
8,
277,
14,
2415,
459,
66,
995,
291,
14,
2415,
459,
67,
1105,
339,
367,
1768,
12,
1031,
315,
291,
14,
2415,
14,
4611,
837,
489,
291,
14,
2947,
8798,
1031,
14,
6591,
28016,
1012,
819,
347,
511,
63,
7612,
63,
277,
63,
4443,
8,
277,
304,
272,
291,
423,
981,
63,
8575,
8,
277,
14,
2415,
459,
65,
995,
291,
14,
2415,
459,
65,
1105,
339,
291,
14,
2947,
4038,
277,
14,
2415,
459,
65,
995,
291,
14,
2415,
459,
65,
4397,
1993,
291,
14,
2415,
459,
65,
2278,
6591,
28016,
1012,
819,
347,
511,
63,
7612,
63,
5601,
63,
2415,
8,
277,
304,
272,
291,
423,
981,
63,
8575,
8,
277,
14,
2415,
459,
65,
995,
291,
14,
2415,
459,
66,
1105,
272,
291,
423,
981,
63,
8575,
8,
277,
14,
2415,
459,
66,
995,
291,
14,
2415,
459,
65,
1105,
339,
291,
14,
2947,
4038,
277,
14,
2415,
459,
65,
995,
291,
14,
2415,
459,
66,
995,
291,
14,
2415,
459,
65,
4397,
1993,
291,
14,
2415,
459,
65,
2278,
6591,
28016,
1012,
272,
291,
14,
2947,
4038,
277,
14,
2415,
459,
66,
995,
291,
14,
2415,
459,
65,
995,
291,
14,
2415,
459,
66,
4397,
1993,
291,
14,
2415,
459,
66,
2278,
6591,
28016,
1012,
819,
347,
511,
63,
5601,
63,
23356,
8,
277,
304,
272,
291,
423,
981,
63,
8575,
8,
277,
14,
2415,
459,
65,
995,
291,
14,
2415,
459,
66,
1105,
272,
291,
423,
981,
63,
8575,
8,
277,
14,
2415,
459,
66,
995,
291,
14,
2415,
459,
65,
1105,
339,
291,
423,
981,
63,
8575,
8,
277,
14,
2415,
459,
66,
995,
291,
14,
2415,
459,
67,
1105,
272,
291,
423,
981,
63,
8575,
8,
277,
14,
2415,
459,
67,
995,
291,
14,
2415,
459,
66,
1105,
339,
19001,
275,
291,
14,
2415,
459,
65,
2278,
6591,
28016,
342,
272,
291,
14,
1815,
8,
2126,
359,
277,
14,
2415,
459,
65,
995,
291,
14,
2415,
459,
66,
995,
291,
14,
2415,
459,
65,
6538,
315,
19001,
9,
272,
291,
14,
1815,
8,
2126,
359,
277,
14,
2415,
459,
66,
995,
291,
14,
2415,
459,
67,
995,
291,
14,
2415,
459,
66,
6538,
315,
19001,
9,
272,
291,
14,
2947,
8,
18,
12,
822,
8,
23356,
430,
819,
347,
511,
63,
5076,
63,
7612,
8,
277,
304,
272,
291,
423,
981,
63,
8575,
8,
277,
14,
2415,
459,
65,
995,
291,
14,
2415,
459,
66,
1105,
272,
291,
423,
981,
63,
8575,
8,
277,
14,
2415,
459,
66,
995,
291,
14,
2415,
459,
67,
1105,
272,
291,
423,
981,
63,
8575,
8,
277,
14,
2415,
459,
67,
995,
291,
14,
2415,
459,
68,
1105,
272,
291,
423,
981,
63,
8575,
8,
277,
14,
2415,
459,
68,
995,
291,
14,
2415,
459,
69,
1105,
272,
291,
423,
981,
63,
8575,
8,
277,
14,
2415,
459,
69,
995,
291,
14,
2415,
459,
65,
1105,
339,
291,
14,
2947,
4038,
277,
14,
2415,
459,
65,
995,
717,
291,
14,
2415,
459,
66,
995,
717,
291,
14,
2415,
459,
67,
995,
717,
291,
14,
2415,
459,
68,
995,
717,
291,
14,
2415,
459,
69,
995,
717,
291,
14,
2415,
459,
65,
4397,
1993,
291,
14,
2415,
459,
65,
2278,
6591,
28016,
1012,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
2882,
14,
973,
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
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
1898,
6171,
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,
5072,
2295,
367,
314,
1324,
14,
647,
570,
1041,
199,
199,
646,
4902,
14,
1210,
199,
646,
2882,
199,
646,
984,
421,
199,
533,
1379,
6591,
28016,
8,
2796,
14,
1746,
304,
523,
347,
3613,
8,
277,
304,
272,
291,
14,
2415,
275,
1052,
272,
367,
671,
315,
661,
65,
297,
283,
66,
297,
283,
67,
297,
283,
68,
297,
283,
69,
735,
489,
291,
14,
2415,
59,
88,
61,
275,
4902,
14,
1210,
14,
14403,
4578,
1716,
8,
88,
9,
819,
347,
485,
981,
63,
8575,
8,
277,
12,
11410,
12,
5936,
304,
272,
11410,
14,
5714,
14,
740,
8,
8575,
9,
272,
5936,
14,
32333,
14,
740,
8,
7106,
9,
819,
347,
511,
63,
889,
63,
7612,
63,
1667,
63,
2180,
8,
277,
304,
272,
367,
1768,
12,
1031,
315,
291,
14,
2415,
14,
4611,
837,
489,
291,
14,
2947,
8798,
1031,
14,
6591,
28016,
1012,
819,
347,
511,
63,
889,
63,
7612,
63,
604,
8,
277,
304,
272,
291,
423,
981,
63,
8575,
8,
277,
14,
2415,
459,
65,
995,
291,
14,
2415,
459,
66,
1105,
272,
291,
423,
981,
63,
8575,
8,
277,
14,
2415,
459,
66,
995,
291,
14,
2415,
459,
67,
1105,
272,
291,
423,
981,
63,
8575,
8,
277,
14,
2415,
459,
67,
995,
291,
14,
2415,
459,
68,
1105,
339,
367,
1768,
12,
1031,
315,
291,
14,
2415,
14,
4611,
837,
489,
291,
14,
2947,
8798,
1031,
14,
6591,
28016,
1012,
819,
347,
511,
63,
889,
63,
7612,
63,
7406,
8,
277,
304,
272,
291,
423,
981,
63,
8575,
8,
277,
14,
2415,
459,
65,
995,
291,
14,
2415,
459,
66,
1105,
272,
291,
423,
981,
63,
8575,
8,
277,
14,
2415,
459,
65,
995,
291,
14,
2415,
459,
67,
1105,
272,
291,
423,
981,
63,
8575,
8,
277,
14,
2415,
459,
66,
995,
291,
14,
2415,
459,
67,
1105,
339,
367,
1768,
12,
1031,
315,
291,
14,
2415,
14,
4611,
837,
489,
291,
14,
2947,
8798,
1031,
14,
6591,
28016,
1012,
819,
347,
511,
63,
7612,
63,
277,
63,
4443,
8,
277,
304,
272,
291,
423,
981,
63,
8575,
8,
277,
14,
2415,
459,
65,
995,
291,
14,
2415,
459,
65,
1105,
339,
291,
14,
2947,
4038,
277,
14,
2415,
459,
65,
995,
291,
14,
2415,
459,
65,
4397,
1993,
291,
14,
2415,
459,
65,
2278,
6591,
28016,
1012,
819,
347,
511,
63,
7612,
63,
5601,
63,
2415,
8,
277,
304,
272,
291,
423,
981,
63,
8575,
8,
277,
14,
2415,
459,
65,
995,
291,
14,
2415,
459,
66,
1105,
272,
291,
423,
981,
63,
8575,
8,
277,
14,
2415,
459,
66,
995,
291,
14,
2415,
459,
65,
1105,
339,
291,
14,
2947,
4038,
277,
14,
2415,
459,
65,
995,
291,
14,
2415,
459,
66,
995,
291,
14,
2415,
459,
65,
4397,
1993,
291,
14,
2415,
459,
65,
2278,
6591,
28016,
1012,
272,
291,
14,
2947,
4038,
277,
14,
2415,
459,
66,
995,
291,
14,
2415,
459,
65,
995,
291,
14,
2415,
459,
66,
4397,
1993,
291,
14,
2415,
459,
66,
2278,
6591,
28016,
1012,
819,
347,
511,
63,
5601,
63,
23356,
8,
277,
304,
272,
291,
423,
981,
63,
8575,
8,
277,
14,
2415,
459,
65,
995,
291,
14,
2415,
459,
66,
1105,
272,
291,
423,
981,
63,
8575,
8,
277,
14,
2415,
459,
66,
995,
291,
14,
2415,
459,
65,
1105,
339,
291,
423,
981,
63,
8575,
8,
277,
14,
2415,
459,
66,
995,
291,
14,
2415,
459,
67,
1105,
272,
291,
423,
981,
63,
8575,
8,
277,
14,
2415,
459,
67,
995,
291,
14,
2415,
459,
66,
1105,
339,
19001,
275,
291,
14,
2415,
459,
65,
2278,
6591,
28016,
342,
272,
291,
14,
1815,
8,
2126,
359,
277,
14,
2415,
459,
65,
995,
291,
14,
2415,
459,
66,
995,
291,
14,
2415,
459,
65,
6538,
315,
19001,
9,
272,
291,
14,
1815,
8,
2126,
359,
277,
14,
2415,
459,
66,
995,
291,
14,
2415,
459,
67,
995,
291,
14,
2415,
459,
66,
6538,
315,
19001,
9,
272,
291,
14,
2947,
8,
18,
12,
822,
8,
23356,
430,
819,
347,
511,
63,
5076,
63,
7612,
8,
277,
304,
272,
291,
423,
981,
63,
8575,
8,
277,
14,
2415,
459,
65,
995,
291,
14,
2415,
459,
66,
1105,
272,
291,
423,
981,
63,
8575,
8,
277,
14,
2415,
459,
66,
995,
291,
14,
2415,
459,
67,
1105,
272,
291,
423,
981,
63,
8575,
8,
277,
14,
2415,
459,
67,
995,
291,
14,
2415,
459,
68,
1105,
272,
291,
423,
981,
63,
8575,
8,
277,
14,
2415,
459,
68,
995,
291,
14,
2415,
459,
69,
1105,
272,
291,
423,
981,
63,
8575,
8,
277,
14,
2415,
459,
69,
995,
291,
14,
2415,
459,
65,
1105,
339,
291,
14,
2947,
4038,
277,
14,
2415,
459,
65,
995,
717,
291,
14,
2415,
459,
66,
995,
717,
291,
14,
2415,
459,
67,
995,
717,
291,
14,
2415,
459,
68,
995,
717,
291,
14,
2415,
459,
69,
995,
717,
291,
14,
2415,
459,
65,
4397,
1993,
291,
14,
2415,
459,
65,
2278,
6591,
28016,
1012,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
2882,
14,
973,
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,
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,
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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
] |
delta2323/chainer
|
tests/chainer_tests/functions_tests/loss_tests/test_sigmoid_cross_entropy.py
|
3
|
7799
|
import math
import unittest
import mock
import numpy
import six
import chainer
from chainer import cuda
from chainer import functions
from chainer import gradient_check
from chainer import testing
from chainer.testing import attr
from chainer.testing import condition
@testing.parameterize(
{'shape': (8, 7), 'normalize': True},
{'shape': (8, 7), 'normalize': False},
{'shape': (8, 7), 'normalize': True, 'ignore_all': True},
# too large shape causes int32 -> float64 issue
{'shape': (65536, 1), 'normalize': False},
)
class TestSigmoidCrossEntropy(unittest.TestCase):
def setUp(self):
self.x = numpy.random.uniform(-1, 1, self.shape).astype(numpy.float32)
if getattr(self, 'ignore_all', False):
self.t = -numpy.ones(self.shape).astype(numpy.int32)
else:
self.t = numpy.random.randint(-1, 2,
self.shape).astype(numpy.int32)
self.gy = numpy.random.random(self.shape).astype(numpy.float32)
def check_forward(self, x_data, t_data, use_cudnn='always'):
x_val = chainer.Variable(x_data)
t_val = chainer.Variable(t_data)
with chainer.using_config('use_cudnn', use_cudnn):
loss = functions.sigmoid_cross_entropy(x_val, t_val,
self.normalize)
self.assertEqual(loss.data.shape, ())
self.assertEqual(loss.data.dtype, numpy.float32)
loss_value = float(cuda.to_cpu(loss.data))
# Compute expected value
loss_expect = 0
non_ignore_count = 0
for i in six.moves.range(self.x.shape[0]):
for j in six.moves.range(self.x.shape[1]):
xd, td = self.x[i, j], self.t[i, j]
if td == -1:
continue
loss_expect -= xd * (td - (xd >= 0)) \
- math.log(1 + math.exp(-numpy.abs(xd)))
non_ignore_count += 1
if non_ignore_count == 0:
loss_expect = 0
elif self.normalize:
loss_expect /= non_ignore_count
else:
loss_expect /= self.t.shape[0]
self.assertAlmostEqual(loss_expect, loss_value, places=5)
def check_forward_no_reduction(self, x_data, t_data):
x_val = chainer.Variable(x_data)
t_val = chainer.Variable(t_data)
loss = functions.sigmoid_cross_entropy(
x_val, t_val, self.normalize, reduce='no')
self.assertEqual(loss.data.shape, self.x.shape)
self.assertEqual(loss.data.dtype, numpy.float32)
loss_value = cuda.to_cpu(loss.data)
# Compute expected value
if not getattr(self, 'ignore_all', False):
for i in six.moves.range(self.x.shape[0]):
for j in six.moves.range(self.x.shape[1]):
xd, td = self.x[i, j], self.t[i, j]
if td == -1:
loss_expect = 0
else:
loss_expect = -(
xd * (td - (xd >= 0)) -
math.log(1 + math.exp(-numpy.abs(xd))))
self.assertAlmostEqual(
loss_expect, loss_value[i, j], places=5)
@condition.retry(3)
def test_forward_cpu(self):
with chainer.using_config('use_cudnn', 'always'):
self.check_forward(self.x, self.t)
@condition.retry(3)
def test_forward_no_reduction_cpu(self):
with chainer.using_config('use_cudnn', 'always'):
self.check_forward_no_reduction(self.x, self.t)
@attr.gpu
@condition.retry(3)
def test_forward_gpu(self):
with chainer.using_config('use_cudnn', 'always'):
self.check_forward(cuda.to_gpu(self.x), cuda.to_gpu(self.t))
@attr.gpu
@condition.retry(3)
def test_forward_no_reduction_gpu(self):
with chainer.using_config('use_cudnn', 'always'):
self.check_forward_no_reduction(
cuda.to_gpu(self.x), cuda.to_gpu(self.t))
@attr.gpu
@condition.retry(3)
def test_forward_gpu_no_cudnn(self):
with chainer.using_config('use_cudnn', 'never'):
self.check_forward(cuda.to_gpu(self.x), cuda.to_gpu(self.t))
@attr.gpu
@condition.retry(3)
def test_forward_no_reduction_gpu_no_cudnn(self):
with chainer.using_config('use_cudnn', 'never'):
self.check_forward_no_reduction(
cuda.to_gpu(self.x), cuda.to_gpu(self.t))
def check_backward(self, x_data, t_data, y_grad):
# Skip too large case. That requires a long time.
if self.shape[0] == 65536:
return
gradient_check.check_backward(
functions.SigmoidCrossEntropy(),
(x_data, t_data), None, eps=1e-2)
def check_backward_no_reduction(
self, x_data, t_data, y_grad):
# Skip too large case. That requires a long time.
if self.shape[0] == 65536:
return
gradient_check.check_backward(
functions.SigmoidCrossEntropy(reduce='no'),
(x_data, t_data), y_grad, eps=1e-2)
@condition.retry(3)
def test_backward_cpu(self):
with chainer.using_config('use_cudnn', 'never'):
self.check_backward(self.x, self.t, self.gy)
@condition.retry(3)
def test_backward_no_reduction_cpu(self):
with chainer.using_config('use_cudnn', 'never'):
self.check_backward_no_reduction(self.x, self.t, self.gy)
@attr.gpu
@condition.retry(3)
def test_backward_gpu(self):
with chainer.using_config('use_cudnn', 'always'):
self.check_backward(
cuda.to_gpu(self.x), cuda.to_gpu(self.t), cuda.to_gpu(self.gy))
@attr.gpu
@condition.retry(3)
def test_backward_no_reduction_gpu(self):
with chainer.using_config('use_cudnn', 'always'):
self.check_backward_no_reduction(
cuda.to_gpu(self.x), cuda.to_gpu(self.t), cuda.to_gpu(self.gy))
@attr.gpu
@condition.retry(3)
def test_backward_gpu_no_cudnn(self):
with chainer.using_config('use_cudnn', 'never'):
self.check_backward(
cuda.to_gpu(self.x), cuda.to_gpu(self.t),
cuda.to_gpu(self.gy))
@attr.gpu
@condition.retry(3)
def test_backward_no_reduction_gpu_no_cudnn(self):
with chainer.using_config('use_cudnn', 'never'):
self.check_backward_no_reduction(
cuda.to_gpu(self.x), cuda.to_gpu(self.t),
cuda.to_gpu(self.gy))
@testing.parameterize(
{'use_cudnn': 'always'},
{'use_cudnn': 'auto'},
{'use_cudnn': 'never'},
)
@attr.cudnn
class TestSigmoidCrossEntropyCudnnCall(unittest.TestCase):
def setUp(self):
self.x = cuda.cupy.random.uniform(-1, 1, (4, 3)).astype(numpy.float32)
self.t = cuda.cupy.random.randint(0, 3, (4, 3)).astype(numpy.int32)
with chainer.using_config('use_cudnn', self.use_cudnn):
self.expect = chainer.should_use_cudnn('==always')
def forward(self):
x = chainer.Variable(self.x)
t = chainer.Variable(self.t)
return functions.sigmoid_cross_entropy(x, t)
def test_call_cudnn_backward(self):
with chainer.using_config('use_cudnn', self.use_cudnn):
y = self.forward()
if cuda.cudnn.cudnn.getVersion() >= 4000:
patch = 'cupy.cudnn.cudnn.activationForward_v4'
else:
patch = 'cupy.cudnn.cudnn.activationForward_v3'
with mock.patch(patch) as func:
y.backward()
self.assertEqual(func.called, self.expect)
# Note that SoftmaxCrossEntropy does not use cudnn on backward
testing.run_module(__name__, __file__)
|
mit
|
[
646,
3473,
199,
646,
2882,
199,
199,
646,
1683,
199,
646,
2680,
199,
646,
3816,
199,
199,
646,
20333,
199,
504,
20333,
492,
23123,
199,
504,
20333,
492,
3423,
199,
504,
20333,
492,
6709,
63,
1074,
199,
504,
20333,
492,
5343,
199,
504,
20333,
14,
4776,
492,
1921,
199,
504,
20333,
14,
4776,
492,
5558,
421,
199,
32,
4776,
14,
8121,
6236,
806,
8,
272,
791,
1392,
356,
334,
24,
12,
1520,
395,
283,
7721,
356,
715,
1386,
272,
791,
1392,
356,
334,
24,
12,
1520,
395,
283,
7721,
356,
756,
1386,
272,
791,
1392,
356,
334,
24,
12,
1520,
395,
283,
7721,
356,
715,
12,
283,
4247,
63,
452,
356,
715,
1386,
272,
327,
4634,
7031,
2215,
14486,
1109,
708,
1035,
2069,
772,
4976,
272,
791,
1392,
356,
334,
10027,
1344,
12,
413,
395,
283,
7721,
356,
756,
1386,
199,
9,
199,
533,
1379,
11575,
14356,
14072,
31224,
8,
2796,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
88,
275,
2680,
14,
2355,
14,
8830,
2801,
17,
12,
413,
12,
291,
14,
1392,
680,
6041,
8,
4714,
14,
1609,
708,
9,
267,
340,
2519,
8,
277,
12,
283,
4247,
63,
452,
297,
756,
304,
288,
291,
14,
84,
275,
446,
4714,
14,
4548,
8,
277,
14,
1392,
680,
6041,
8,
4714,
14,
442,
708,
9,
267,
587,
26,
288,
291,
14,
84,
275,
2680,
14,
2355,
14,
8393,
2801,
17,
12,
499,
12,
5101,
291,
14,
1392,
680,
6041,
8,
4714,
14,
442,
708,
9,
267,
291,
14,
4312,
275,
2680,
14,
2355,
14,
2355,
8,
277,
14,
1392,
680,
6041,
8,
4714,
14,
1609,
708,
9,
339,
347,
1104,
63,
6688,
8,
277,
12,
671,
63,
576,
12,
307,
63,
576,
12,
675,
63,
27934,
534,
9223,
735,
267,
671,
63,
637,
275,
20333,
14,
2773,
8,
88,
63,
576,
9,
267,
307,
63,
637,
275,
20333,
14,
2773,
8,
84,
63,
576,
9,
267,
543,
20333,
14,
4941,
63,
888,
360,
1180,
63,
27934,
297,
675,
63,
27934,
304,
288,
5621,
275,
3423,
14,
20035,
63,
7925,
63,
10435,
8,
88,
63,
637,
12,
307,
63,
637,
12,
8962,
291,
14,
7721,
9,
267,
291,
14,
629,
8,
4358,
14,
576,
14,
1392,
12,
14515,
267,
291,
14,
629,
8,
4358,
14,
576,
14,
2271,
12,
2680,
14,
1609,
708,
9,
267,
5621,
63,
585,
275,
2069,
8,
16309,
14,
475,
63,
3541,
8,
4358,
14,
576,
430,
398,
327,
8354,
1420,
574,
267,
5621,
63,
4921,
275,
378,
267,
2222,
63,
4247,
63,
835,
275,
378,
267,
367,
284,
315,
3816,
14,
4912,
14,
1842,
8,
277,
14,
88,
14,
1392,
59,
16,
4682,
288,
367,
1335,
315,
3816,
14,
4912,
14,
1842,
8,
277,
14,
88,
14,
1392,
59,
17,
4682,
355,
671,
68,
12,
12749,
275,
291,
14,
88,
59,
73,
12,
1335,
467,
291,
14,
84,
59,
73,
12,
1335,
61,
355,
340,
12749,
508,
446,
17,
26,
490,
1980,
355,
5621,
63,
4921,
4862,
671,
68,
627,
334,
2076,
446,
334,
2207,
2356,
378,
430,
971,
490,
446,
3473,
14,
793,
8,
17,
435,
3473,
14,
1474,
2801,
4714,
14,
2101,
8,
2207,
1724,
355,
2222,
63,
4247,
63,
835,
847,
413,
267,
340,
2222,
63,
4247,
63,
835,
508,
378,
26,
288,
5621,
63,
4921,
275,
378,
267,
916,
291,
14,
7721,
26,
288,
5621,
63,
4921,
12257,
2222,
63,
4247,
63,
835,
267,
587,
26,
288,
5621,
63,
4921,
12257,
291,
14,
84,
14,
1392,
59,
16,
61,
267,
291,
14,
7904,
8,
4358,
63,
4921,
12,
5621,
63,
585,
12,
9825,
29,
21,
9,
339,
347,
1104,
63,
6688,
63,
889,
63,
22508,
8,
277,
12,
671,
63,
576,
12,
307,
63,
576,
304,
267,
671,
63,
637,
275,
20333,
14,
2773,
8,
88,
63,
576,
9,
267,
307,
63,
637,
275,
20333,
14,
2773,
8,
84,
63,
576,
9,
267,
5621,
275,
3423,
14,
20035,
63,
7925,
63,
10435,
8,
288,
671,
63,
637,
12,
307,
63,
637,
12,
291,
14,
7721,
12,
7114,
534,
889,
358,
267,
291,
14,
629,
8,
4358,
14,
576,
14,
1392,
12,
291,
14,
88,
14,
1392,
9,
267,
291,
14,
629,
8,
4358,
14,
576,
14,
2271,
12,
2680,
14,
1609,
708,
9,
267,
5621,
63,
585,
275,
23123,
14,
475,
63,
3541,
8,
4358,
14,
576,
9,
398,
327,
8354,
1420,
574,
267,
340,
440,
2519,
8,
277,
12,
283,
4247,
63,
452,
297,
756,
304,
288,
367,
284,
315,
3816,
14,
4912,
14,
1842,
8,
277,
14,
88,
14,
1392,
59,
16,
4682,
355,
367,
1335,
315,
3816,
14,
4912,
14,
1842,
8,
277,
14,
88,
14,
1392,
59,
17,
4682,
490,
671,
68,
12,
12749,
275,
291,
14,
88,
59,
73,
12,
1335,
467,
291,
14,
84,
59,
73,
12,
1335,
61,
490,
340,
12749,
508,
446,
17,
26,
717,
5621,
63,
4921,
275,
378,
490,
587,
26,
717,
5621,
63,
4921,
275,
24953,
1169,
671,
68,
627,
334,
2076,
446,
334,
2207,
2356,
378,
430,
446,
1169,
3473,
14,
793,
8,
17,
435,
3473,
14,
1474,
2801,
4714,
14,
2101,
8,
2207,
7845,
490,
291,
14,
7904,
8,
717,
5621,
63,
4921,
12,
5621,
63,
585,
59,
73,
12,
1335,
467,
9825,
29,
21,
9,
339,
768,
5394,
14,
7154,
8,
19,
9,
272,
347,
511,
63,
6688,
63,
3541,
8,
277,
304,
267,
543,
20333,
14,
4941,
63,
888,
360,
1180,
63,
27934,
297,
283,
9223,
735,
288,
291,
14,
1074,
63,
6688,
8,
277,
14,
88,
12,
291,
14,
84,
9,
339,
768,
5394,
14,
7154,
8,
19,
9,
272,
347,
511,
63,
6688,
63,
889,
63,
22508,
63,
3541,
8,
277,
304,
267,
543,
20333,
14,
4941,
63,
888,
360,
1180,
63,
27934,
297,
283,
9223,
735,
288,
291,
14,
1074,
63,
6688,
63,
889,
63,
22508,
8,
277,
14,
88,
12,
291,
14,
84,
9,
339,
768,
962,
14,
6477,
272,
768,
5394,
14,
7154,
8,
19,
9,
272,
347,
511,
63,
6688,
63,
6477,
8,
277,
304,
267,
543,
20333,
14,
4941,
63,
888,
360,
1180,
63,
27934,
297,
283,
9223,
735,
288,
291,
14,
1074,
63,
6688,
8,
16309,
14,
475
] |
[
3473,
199,
646,
2882,
199,
199,
646,
1683,
199,
646,
2680,
199,
646,
3816,
199,
199,
646,
20333,
199,
504,
20333,
492,
23123,
199,
504,
20333,
492,
3423,
199,
504,
20333,
492,
6709,
63,
1074,
199,
504,
20333,
492,
5343,
199,
504,
20333,
14,
4776,
492,
1921,
199,
504,
20333,
14,
4776,
492,
5558,
421,
199,
32,
4776,
14,
8121,
6236,
806,
8,
272,
791,
1392,
356,
334,
24,
12,
1520,
395,
283,
7721,
356,
715,
1386,
272,
791,
1392,
356,
334,
24,
12,
1520,
395,
283,
7721,
356,
756,
1386,
272,
791,
1392,
356,
334,
24,
12,
1520,
395,
283,
7721,
356,
715,
12,
283,
4247,
63,
452,
356,
715,
1386,
272,
327,
4634,
7031,
2215,
14486,
1109,
708,
1035,
2069,
772,
4976,
272,
791,
1392,
356,
334,
10027,
1344,
12,
413,
395,
283,
7721,
356,
756,
1386,
199,
9,
199,
533,
1379,
11575,
14356,
14072,
31224,
8,
2796,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
88,
275,
2680,
14,
2355,
14,
8830,
2801,
17,
12,
413,
12,
291,
14,
1392,
680,
6041,
8,
4714,
14,
1609,
708,
9,
267,
340,
2519,
8,
277,
12,
283,
4247,
63,
452,
297,
756,
304,
288,
291,
14,
84,
275,
446,
4714,
14,
4548,
8,
277,
14,
1392,
680,
6041,
8,
4714,
14,
442,
708,
9,
267,
587,
26,
288,
291,
14,
84,
275,
2680,
14,
2355,
14,
8393,
2801,
17,
12,
499,
12,
5101,
291,
14,
1392,
680,
6041,
8,
4714,
14,
442,
708,
9,
267,
291,
14,
4312,
275,
2680,
14,
2355,
14,
2355,
8,
277,
14,
1392,
680,
6041,
8,
4714,
14,
1609,
708,
9,
339,
347,
1104,
63,
6688,
8,
277,
12,
671,
63,
576,
12,
307,
63,
576,
12,
675,
63,
27934,
534,
9223,
735,
267,
671,
63,
637,
275,
20333,
14,
2773,
8,
88,
63,
576,
9,
267,
307,
63,
637,
275,
20333,
14,
2773,
8,
84,
63,
576,
9,
267,
543,
20333,
14,
4941,
63,
888,
360,
1180,
63,
27934,
297,
675,
63,
27934,
304,
288,
5621,
275,
3423,
14,
20035,
63,
7925,
63,
10435,
8,
88,
63,
637,
12,
307,
63,
637,
12,
8962,
291,
14,
7721,
9,
267,
291,
14,
629,
8,
4358,
14,
576,
14,
1392,
12,
14515,
267,
291,
14,
629,
8,
4358,
14,
576,
14,
2271,
12,
2680,
14,
1609,
708,
9,
267,
5621,
63,
585,
275,
2069,
8,
16309,
14,
475,
63,
3541,
8,
4358,
14,
576,
430,
398,
327,
8354,
1420,
574,
267,
5621,
63,
4921,
275,
378,
267,
2222,
63,
4247,
63,
835,
275,
378,
267,
367,
284,
315,
3816,
14,
4912,
14,
1842,
8,
277,
14,
88,
14,
1392,
59,
16,
4682,
288,
367,
1335,
315,
3816,
14,
4912,
14,
1842,
8,
277,
14,
88,
14,
1392,
59,
17,
4682,
355,
671,
68,
12,
12749,
275,
291,
14,
88,
59,
73,
12,
1335,
467,
291,
14,
84,
59,
73,
12,
1335,
61,
355,
340,
12749,
508,
446,
17,
26,
490,
1980,
355,
5621,
63,
4921,
4862,
671,
68,
627,
334,
2076,
446,
334,
2207,
2356,
378,
430,
971,
490,
446,
3473,
14,
793,
8,
17,
435,
3473,
14,
1474,
2801,
4714,
14,
2101,
8,
2207,
1724,
355,
2222,
63,
4247,
63,
835,
847,
413,
267,
340,
2222,
63,
4247,
63,
835,
508,
378,
26,
288,
5621,
63,
4921,
275,
378,
267,
916,
291,
14,
7721,
26,
288,
5621,
63,
4921,
12257,
2222,
63,
4247,
63,
835,
267,
587,
26,
288,
5621,
63,
4921,
12257,
291,
14,
84,
14,
1392,
59,
16,
61,
267,
291,
14,
7904,
8,
4358,
63,
4921,
12,
5621,
63,
585,
12,
9825,
29,
21,
9,
339,
347,
1104,
63,
6688,
63,
889,
63,
22508,
8,
277,
12,
671,
63,
576,
12,
307,
63,
576,
304,
267,
671,
63,
637,
275,
20333,
14,
2773,
8,
88,
63,
576,
9,
267,
307,
63,
637,
275,
20333,
14,
2773,
8,
84,
63,
576,
9,
267,
5621,
275,
3423,
14,
20035,
63,
7925,
63,
10435,
8,
288,
671,
63,
637,
12,
307,
63,
637,
12,
291,
14,
7721,
12,
7114,
534,
889,
358,
267,
291,
14,
629,
8,
4358,
14,
576,
14,
1392,
12,
291,
14,
88,
14,
1392,
9,
267,
291,
14,
629,
8,
4358,
14,
576,
14,
2271,
12,
2680,
14,
1609,
708,
9,
267,
5621,
63,
585,
275,
23123,
14,
475,
63,
3541,
8,
4358,
14,
576,
9,
398,
327,
8354,
1420,
574,
267,
340,
440,
2519,
8,
277,
12,
283,
4247,
63,
452,
297,
756,
304,
288,
367,
284,
315,
3816,
14,
4912,
14,
1842,
8,
277,
14,
88,
14,
1392,
59,
16,
4682,
355,
367,
1335,
315,
3816,
14,
4912,
14,
1842,
8,
277,
14,
88,
14,
1392,
59,
17,
4682,
490,
671,
68,
12,
12749,
275,
291,
14,
88,
59,
73,
12,
1335,
467,
291,
14,
84,
59,
73,
12,
1335,
61,
490,
340,
12749,
508,
446,
17,
26,
717,
5621,
63,
4921,
275,
378,
490,
587,
26,
717,
5621,
63,
4921,
275,
24953,
1169,
671,
68,
627,
334,
2076,
446,
334,
2207,
2356,
378,
430,
446,
1169,
3473,
14,
793,
8,
17,
435,
3473,
14,
1474,
2801,
4714,
14,
2101,
8,
2207,
7845,
490,
291,
14,
7904,
8,
717,
5621,
63,
4921,
12,
5621,
63,
585,
59,
73,
12,
1335,
467,
9825,
29,
21,
9,
339,
768,
5394,
14,
7154,
8,
19,
9,
272,
347,
511,
63,
6688,
63,
3541,
8,
277,
304,
267,
543,
20333,
14,
4941,
63,
888,
360,
1180,
63,
27934,
297,
283,
9223,
735,
288,
291,
14,
1074,
63,
6688,
8,
277,
14,
88,
12,
291,
14,
84,
9,
339,
768,
5394,
14,
7154,
8,
19,
9,
272,
347,
511,
63,
6688,
63,
889,
63,
22508,
63,
3541,
8,
277,
304,
267,
543,
20333,
14,
4941,
63,
888,
360,
1180,
63,
27934,
297,
283,
9223,
735,
288,
291,
14,
1074,
63,
6688,
63,
889,
63,
22508,
8,
277,
14,
88,
12,
291,
14,
84,
9,
339,
768,
962,
14,
6477,
272,
768,
5394,
14,
7154,
8,
19,
9,
272,
347,
511,
63,
6688,
63,
6477,
8,
277,
304,
267,
543,
20333,
14,
4941,
63,
888,
360,
1180,
63,
27934,
297,
283,
9223,
735,
288,
291,
14,
1074,
63,
6688,
8,
16309,
14,
475,
0
] |
[
1,
1,
1,
1,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s
|
lfs/portlet/migrations/0001_initial.py
|
5
|
5932
|
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
]
operations = [
migrations.CreateModel(
name='AverageRatingPortlet',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('title', models.CharField(max_length=100, verbose_name='Title', blank=True)),
],
),
migrations.CreateModel(
name='CartPortlet',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('title', models.CharField(max_length=100, verbose_name='Title', blank=True)),
],
),
migrations.CreateModel(
name='CategoriesPortlet',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('title', models.CharField(max_length=100, verbose_name='Title', blank=True)),
('start_level', models.PositiveSmallIntegerField(default=1)),
('expand_level', models.PositiveSmallIntegerField(default=1)),
],
),
migrations.CreateModel(
name='DeliveryTimePortlet',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('title', models.CharField(max_length=100, verbose_name='Title', blank=True)),
],
),
migrations.CreateModel(
name='FeaturedPortlet',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('title', models.CharField(max_length=100, verbose_name='Title', blank=True)),
('limit', models.IntegerField(default=5, verbose_name='Limit')),
('current_category', models.BooleanField(default=False, verbose_name='Use current category')),
('slideshow', models.BooleanField(default=False, verbose_name='Slideshow')),
],
),
migrations.CreateModel(
name='FilterPortlet',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('title', models.CharField(max_length=100, verbose_name='Title', blank=True)),
('show_product_filters', models.BooleanField(default=True, verbose_name='Show product filters')),
('show_price_filters', models.BooleanField(default=True, verbose_name='Show price filters')),
('show_manufacturer_filters', models.BooleanField(default=False, verbose_name='Show manufacturer filters')),
],
),
migrations.CreateModel(
name='ForsalePortlet',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('title', models.CharField(max_length=100, verbose_name='Title', blank=True)),
('limit', models.IntegerField(default=5, verbose_name='Limit')),
('current_category', models.BooleanField(default=False, verbose_name='Use current category')),
('slideshow', models.BooleanField(default=False, verbose_name='Slideshow')),
],
),
migrations.CreateModel(
name='LatestPortlet',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('title', models.CharField(max_length=100, verbose_name='Title', blank=True)),
('limit', models.IntegerField(default=5, verbose_name='Limit')),
('current_category', models.BooleanField(default=False, verbose_name='Use current category')),
('slideshow', models.BooleanField(default=False, verbose_name='Slideshow')),
],
),
migrations.CreateModel(
name='PagesPortlet',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('title', models.CharField(max_length=100, verbose_name='Title', blank=True)),
],
),
migrations.CreateModel(
name='RecentProductsPortlet',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('title', models.CharField(max_length=100, verbose_name='Title', blank=True)),
],
),
migrations.CreateModel(
name='RelatedProductsPortlet',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('title', models.CharField(max_length=100, verbose_name='Title', blank=True)),
],
),
migrations.CreateModel(
name='TextPortlet',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('title', models.CharField(max_length=100, verbose_name='Title', blank=True)),
('text', models.TextField(verbose_name='Text', blank=True)),
],
),
migrations.CreateModel(
name='TopsellerPortlet',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('title', models.CharField(max_length=100, verbose_name='Title', blank=True)),
('limit', models.IntegerField(default=5)),
],
),
]
|
bsd-3-clause
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
697,
492,
1709,
12,
6180,
421,
199,
533,
12090,
8,
7685,
14,
9816,
304,
339,
5124,
275,
359,
272,
1622,
339,
5331,
275,
359,
267,
6180,
14,
14907,
8,
288,
536,
534,
17400,
32533,
4313,
2723,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
1213,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
12,
3376,
63,
354,
534,
6888,
297,
4596,
29,
549,
1826,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
31667,
4313,
2723,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
1213,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
12,
3376,
63,
354,
534,
6888,
297,
4596,
29,
549,
1826,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
28731,
4313,
2723,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
1213,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
12,
3376,
63,
354,
534,
6888,
297,
4596,
29,
549,
1826,
355,
661,
928,
63,
1896,
297,
1709,
14,
25197,
8,
885,
29,
17,
1826,
355,
661,
4441,
63,
1896,
297,
1709,
14,
25197,
8,
885,
29,
17,
1826,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
24640,
1366,
4313,
2723,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
1213,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
12,
3376,
63,
354,
534,
6888,
297,
4596,
29,
549,
1826,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
24927,
3297,
4313,
2723,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
1213,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
12,
3376,
63,
354,
534,
6888,
297,
4596,
29,
549,
1826,
355,
661,
3097,
297,
1709,
14,
3901,
8,
885,
29,
21,
12,
3376,
63,
354,
534,
8407,
3855,
355,
661,
1818,
63,
3710,
297,
1709,
14,
5036,
8,
885,
29,
797,
12,
3376,
63,
354,
534,
6119,
1453,
4637,
3855,
355,
661,
19968,
2384,
297,
1709,
14,
5036,
8,
885,
29,
797,
12,
3376,
63,
354,
534,
51,
8409,
2384,
3855,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
4131,
4313,
2723,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
1213,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
12,
3376,
63,
354,
534,
6888,
297,
4596,
29,
549,
1826,
355,
661,
2384,
63,
2558,
63,
4273,
297,
1709,
14,
5036,
8,
885,
29,
549,
12,
3376,
63,
354,
534,
6824,
3336,
4766,
3855,
355,
661,
2384,
63,
4777,
63,
4273,
297,
1709,
14,
5036,
8,
885,
29,
549,
12,
3376,
63,
354,
534,
6824,
8033,
4766,
3855,
355,
661,
2384,
63,
32214,
63,
4273,
297,
1709,
14,
5036,
8,
885,
29,
797,
12,
3376,
63,
354,
534,
6824,
2169,
21087,
4766,
3855,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
38,
1384,
1895,
4313,
2723,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
1213,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
12,
3376,
63,
354,
534,
6888,
297,
4596,
29,
549,
1826,
355,
661,
3097,
297,
1709,
14,
3901,
8,
885,
29,
21,
12,
3376,
63,
354,
534,
8407,
3855,
355,
661,
1818,
63,
3710,
297,
1709,
14,
5036,
8,
885,
29,
797,
12,
3376,
63,
354,
534,
6119,
1453,
4637,
3855,
355,
661,
19968,
2384,
297,
1709,
14,
5036,
8,
885,
29,
797,
12,
3376,
63,
354,
534,
51,
8409,
2384,
3855,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
31438,
4313,
2723,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
1213,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
12,
3376,
63,
354,
534,
6888,
297,
4596,
29,
549,
1826,
355,
661,
3097,
297,
1709,
14,
3901,
8,
885,
29,
21,
12,
3376,
63,
354,
534,
8407,
3855,
355,
661,
1818,
63,
3710,
297,
1709,
14,
5036,
8,
885,
29,
797,
12,
3376,
63,
354,
534,
6119,
1453,
4637,
3855,
355,
661,
19968,
2384,
297,
1709,
14,
5036,
8,
885,
29,
797,
12,
3376,
63,
354,
534,
51,
8409,
2384,
3855,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
17773,
4313,
2723,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
1213,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
12,
3376,
63,
354,
534,
6888,
297,
4596,
29,
549,
1826,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
29574,
29631,
4313,
2723,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
697,
492,
1709,
12,
6180,
421,
199,
533,
12090,
8,
7685,
14,
9816,
304,
339,
5124,
275,
359,
272,
1622,
339,
5331,
275,
359,
267,
6180,
14,
14907,
8,
288,
536,
534,
17400,
32533,
4313,
2723,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
1213,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
12,
3376,
63,
354,
534,
6888,
297,
4596,
29,
549,
1826,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
31667,
4313,
2723,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
1213,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
12,
3376,
63,
354,
534,
6888,
297,
4596,
29,
549,
1826,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
28731,
4313,
2723,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
1213,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
12,
3376,
63,
354,
534,
6888,
297,
4596,
29,
549,
1826,
355,
661,
928,
63,
1896,
297,
1709,
14,
25197,
8,
885,
29,
17,
1826,
355,
661,
4441,
63,
1896,
297,
1709,
14,
25197,
8,
885,
29,
17,
1826,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
24640,
1366,
4313,
2723,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
1213,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
12,
3376,
63,
354,
534,
6888,
297,
4596,
29,
549,
1826,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
24927,
3297,
4313,
2723,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
1213,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
12,
3376,
63,
354,
534,
6888,
297,
4596,
29,
549,
1826,
355,
661,
3097,
297,
1709,
14,
3901,
8,
885,
29,
21,
12,
3376,
63,
354,
534,
8407,
3855,
355,
661,
1818,
63,
3710,
297,
1709,
14,
5036,
8,
885,
29,
797,
12,
3376,
63,
354,
534,
6119,
1453,
4637,
3855,
355,
661,
19968,
2384,
297,
1709,
14,
5036,
8,
885,
29,
797,
12,
3376,
63,
354,
534,
51,
8409,
2384,
3855,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
4131,
4313,
2723,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
1213,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
12,
3376,
63,
354,
534,
6888,
297,
4596,
29,
549,
1826,
355,
661,
2384,
63,
2558,
63,
4273,
297,
1709,
14,
5036,
8,
885,
29,
549,
12,
3376,
63,
354,
534,
6824,
3336,
4766,
3855,
355,
661,
2384,
63,
4777,
63,
4273,
297,
1709,
14,
5036,
8,
885,
29,
549,
12,
3376,
63,
354,
534,
6824,
8033,
4766,
3855,
355,
661,
2384,
63,
32214,
63,
4273,
297,
1709,
14,
5036,
8,
885,
29,
797,
12,
3376,
63,
354,
534,
6824,
2169,
21087,
4766,
3855,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
38,
1384,
1895,
4313,
2723,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
1213,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
12,
3376,
63,
354,
534,
6888,
297,
4596,
29,
549,
1826,
355,
661,
3097,
297,
1709,
14,
3901,
8,
885,
29,
21,
12,
3376,
63,
354,
534,
8407,
3855,
355,
661,
1818,
63,
3710,
297,
1709,
14,
5036,
8,
885,
29,
797,
12,
3376,
63,
354,
534,
6119,
1453,
4637,
3855,
355,
661,
19968,
2384,
297,
1709,
14,
5036,
8,
885,
29,
797,
12,
3376,
63,
354,
534,
51,
8409,
2384,
3855,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
31438,
4313,
2723,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
1213,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
12,
3376,
63,
354,
534,
6888,
297,
4596,
29,
549,
1826,
355,
661,
3097,
297,
1709,
14,
3901,
8,
885,
29,
21,
12,
3376,
63,
354,
534,
8407,
3855,
355,
661,
1818,
63,
3710,
297,
1709,
14,
5036,
8,
885,
29,
797,
12,
3376,
63,
354,
534,
6119,
1453,
4637,
3855,
355,
661,
19968,
2384,
297,
1709,
14,
5036,
8,
885,
29,
797,
12,
3376,
63,
354,
534,
51,
8409,
2384,
3855,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
17773,
4313,
2723,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
1213,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
12,
3376,
63,
354,
534,
6888,
297,
4596,
29,
549,
1826,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
29574,
29631,
4313,
2723,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
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,
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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
] |
mmnelemane/nova
|
nova/api/openstack/compute/legacy_v2/contrib/scheduler_hints.py
|
97
|
2066
|
# Copyright 2011 OpenStack Foundation
#
# 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 webob.exc
from nova.api.openstack import extensions
from nova.api.openstack import wsgi
from nova.i18n import _
class SchedulerHintsController(wsgi.Controller):
@staticmethod
def _extract_scheduler_hints(body):
hints = {}
attr = '%s:scheduler_hints' % Scheduler_hints.alias
try:
if 'os:scheduler_hints' in body:
# NOTE(vish): This is for legacy support
hints.update(body['os:scheduler_hints'])
elif attr in body:
hints.update(body[attr])
# Fail if non-dict provided
except ValueError:
msg = _("Malformed scheduler_hints attribute")
raise webob.exc.HTTPBadRequest(explanation=msg)
return hints
@wsgi.extends
def create(self, req, body):
hints = self._extract_scheduler_hints(body)
if 'server' in body:
body['server']['scheduler_hints'] = hints
yield
class Scheduler_hints(extensions.ExtensionDescriptor):
"""Pass arbitrary key/value pairs to the scheduler."""
name = "SchedulerHints"
alias = "OS-SCH-HNT"
namespace = ("http://docs.openstack.org/compute/ext/"
"scheduler-hints/api/v2")
updated = "2011-07-19T00:00:00Z"
def get_controller_extensions(self):
controller = SchedulerHintsController()
ext = extensions.ControllerExtension(self, 'servers', controller)
return [ext]
|
apache-2.0
|
[
3,
1898,
7760,
14260,
2752,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
646,
14568,
14,
2804,
199,
199,
504,
5913,
14,
1246,
14,
8512,
492,
5478,
199,
504,
5913,
14,
1246,
14,
8512,
492,
12464,
199,
504,
5913,
14,
73,
1085,
78,
492,
485,
421,
199,
533,
32051,
40,
13141,
7506,
8,
6508,
14,
7506,
304,
339,
768,
4639,
272,
347,
485,
5005,
63,
8874,
63,
12354,
8,
2030,
304,
267,
18069,
275,
1052,
398,
1921,
275,
1543,
83,
26,
8874,
63,
12354,
7,
450,
32051,
63,
12354,
14,
3620,
267,
862,
26,
288,
340,
283,
736,
26,
8874,
63,
12354,
7,
315,
2396,
26,
355,
327,
6944,
8,
86,
2453,
304,
961,
365,
367,
12139,
2291,
355,
18069,
14,
873,
8,
2030,
459,
736,
26,
8874,
63,
12354,
1105,
288,
916,
1921,
315,
2396,
26,
355,
18069,
14,
873,
8,
2030,
59,
962,
566,
267,
327,
12176,
340,
2222,
13,
807,
2741,
267,
871,
1722,
26,
288,
1499,
275,
3824,
29513,
11899,
63,
12354,
2225,
531,
288,
746,
14568,
14,
2804,
14,
21070,
8,
15228,
29,
1328,
9,
398,
372,
18069,
339,
768,
6508,
14,
11036,
272,
347,
1218,
8,
277,
12,
2648,
12,
2396,
304,
267,
18069,
275,
291,
423,
5005,
63,
8874,
63,
12354,
8,
2030,
9,
398,
340,
283,
1000,
7,
315,
2396,
26,
288,
2396,
459,
1000,
2545,
8874,
63,
12354,
418,
275,
18069,
267,
1995,
421,
199,
533,
32051,
63,
12354,
8,
5359,
14,
6382,
4311,
304,
272,
408,
4986,
9697,
790,
15,
585,
6342,
370,
314,
11899,
1041,
339,
536,
275,
298,
11251,
40,
13141,
2,
272,
5162,
275,
298,
3100,
13,
13900,
13,
40,
12460,
2,
272,
3231,
275,
1689,
1014,
921,
4757,
14,
8512,
14,
1308,
15,
3357,
15,
832,
6687,
326,
298,
8874,
13,
12354,
15,
1246,
15,
86,
18,
531,
272,
4588,
275,
298,
8128,
13,
1780,
13,
1167,
52,
383,
26,
383,
26,
383,
58,
2,
339,
347,
664,
63,
5538,
63,
5359,
8,
277,
304,
267,
7614,
275,
32051,
40,
13141,
7506,
342,
267,
1599,
275,
5478,
14,
7506,
6382,
8,
277,
12,
283,
5871,
297,
7614,
9,
267,
372,
359,
832,
61,
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
] |
[
1898,
7760,
14260,
2752,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
646,
14568,
14,
2804,
199,
199,
504,
5913,
14,
1246,
14,
8512,
492,
5478,
199,
504,
5913,
14,
1246,
14,
8512,
492,
12464,
199,
504,
5913,
14,
73,
1085,
78,
492,
485,
421,
199,
533,
32051,
40,
13141,
7506,
8,
6508,
14,
7506,
304,
339,
768,
4639,
272,
347,
485,
5005,
63,
8874,
63,
12354,
8,
2030,
304,
267,
18069,
275,
1052,
398,
1921,
275,
1543,
83,
26,
8874,
63,
12354,
7,
450,
32051,
63,
12354,
14,
3620,
267,
862,
26,
288,
340,
283,
736,
26,
8874,
63,
12354,
7,
315,
2396,
26,
355,
327,
6944,
8,
86,
2453,
304,
961,
365,
367,
12139,
2291,
355,
18069,
14,
873,
8,
2030,
459,
736,
26,
8874,
63,
12354,
1105,
288,
916,
1921,
315,
2396,
26,
355,
18069,
14,
873,
8,
2030,
59,
962,
566,
267,
327,
12176,
340,
2222,
13,
807,
2741,
267,
871,
1722,
26,
288,
1499,
275,
3824,
29513,
11899,
63,
12354,
2225,
531,
288,
746,
14568,
14,
2804,
14,
21070,
8,
15228,
29,
1328,
9,
398,
372,
18069,
339,
768,
6508,
14,
11036,
272,
347,
1218,
8,
277,
12,
2648,
12,
2396,
304,
267,
18069,
275,
291,
423,
5005,
63,
8874,
63,
12354,
8,
2030,
9,
398,
340,
283,
1000,
7,
315,
2396,
26,
288,
2396,
459,
1000,
2545,
8874,
63,
12354,
418,
275,
18069,
267,
1995,
421,
199,
533,
32051,
63,
12354,
8,
5359,
14,
6382,
4311,
304,
272,
408,
4986,
9697,
790,
15,
585,
6342,
370,
314,
11899,
1041,
339,
536,
275,
298,
11251,
40,
13141,
2,
272,
5162,
275,
298,
3100,
13,
13900,
13,
40,
12460,
2,
272,
3231,
275,
1689,
1014,
921,
4757,
14,
8512,
14,
1308,
15,
3357,
15,
832,
6687,
326,
298,
8874,
13,
12354,
15,
1246,
15,
86,
18,
531,
272,
4588,
275,
298,
8128,
13,
1780,
13,
1167,
52,
383,
26,
383,
26,
383,
58,
2,
339,
347,
664,
63,
5538,
63,
5359,
8,
277,
304,
267,
7614,
275,
32051,
40,
13141,
7506,
342,
267,
1599,
275,
5478,
14,
7506,
6382,
8,
277,
12,
283,
5871,
297,
7614,
9,
267,
372,
359,
832,
61,
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,
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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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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
CPFL/gxen
|
tools/libxl/gentest.py
|
2
|
9390
|
#!/usr/bin/python
import os
import sys
import re
import random
import idl
def randomize_char(c):
if random.random() < 0.5:
return str.lower(c)
else:
return str.upper(c)
def randomize_case(s):
r = [randomize_char(c) for c in s]
return "".join(r)
def randomize_enum(e):
return random.choice([v.name for v in e.values])
handcoded = ["libxl_bitmap", "libxl_key_value_list",
"libxl_cpuid_policy_list", "libxl_string_list"]
def gen_rand_init(ty, v, indent = " ", parent = None):
s = ""
if isinstance(ty, idl.Enumeration):
s += "%s = %s;\n" % (ty.pass_arg(v, parent is None), randomize_enum(ty))
elif isinstance(ty, idl.Array):
if parent is None:
raise Exception("Array type must have a parent")
s += "%s = rand()%%8;\n" % (parent + ty.lenvar.name)
s += "%s = calloc(%s, sizeof(*%s));\n" % \
(v, parent + ty.lenvar.name, v)
s += "{\n"
s += " int i;\n"
s += " for (i=0; i<%s; i++)\n" % (parent + ty.lenvar.name)
s += gen_rand_init(ty.elem_type, v+"[i]",
indent + " ", parent)
s += "}\n"
elif isinstance(ty, idl.KeyedUnion):
if parent is None:
raise Exception("KeyedUnion type must have a parent")
s += "switch (%s) {\n" % (parent + ty.keyvar.name)
for f in ty.fields:
(nparent,fexpr) = ty.member(v, f, parent is None)
s += "case %s:\n" % f.enumname
s += gen_rand_init(f.type, fexpr, indent + " ", nparent)
s += " break;\n"
s += "}\n"
elif isinstance(ty, idl.Struct) \
and (parent is None or ty.json_fn is None):
for f in [f for f in ty.fields if not f.const]:
(nparent,fexpr) = ty.member(v, f, parent is None)
s += gen_rand_init(f.type, fexpr, "", nparent)
elif hasattr(ty, "rand_init") and ty.rand_init is not None:
s += "%s(%s);\n" % (ty.rand_init,
ty.pass_arg(v, isref=parent is None,
passby=idl.PASS_BY_REFERENCE))
elif ty.typename in ["libxl_uuid", "libxl_mac", "libxl_hwcap"]:
s += "rand_bytes((uint8_t *)%s, sizeof(*%s));\n" % (v,v)
elif ty.typename in ["libxl_domid"] or isinstance(ty, idl.Number):
s += "%s = rand() %% (sizeof(%s)*8);\n" % \
(ty.pass_arg(v, parent is None),
ty.pass_arg(v, parent is None))
elif ty.typename in ["bool"]:
s += "%s = rand() %% 2;\n" % v
elif ty.typename in ["libxl_defbool"]:
s += "libxl_defbool_set(%s, !!rand() %% 1);\n" % v
elif ty.typename in ["char *"]:
s += "%s = rand_str();\n" % v
elif ty.private:
pass
elif ty.typename in handcoded:
raise Exception("Gen for handcoded %s" % ty.typename)
else:
raise Exception("Cannot randomly init %s" % ty.typename)
if s != "":
s = indent + s
return s.replace("\n", "\n%s" % indent).rstrip(indent)
if __name__ == '__main__':
if len(sys.argv) < 3:
print >>sys.stderr, "Usage: gentest.py <idl> <implementation>"
sys.exit(1)
random.seed(os.getenv('LIBXL_TESTIDL_SEED'))
(builtins,types) = idl.parse(sys.argv[1])
impl = sys.argv[2]
f = open(impl, "w")
f.write("""
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "libxl.h"
#include "libxl_utils.h"
static char *rand_str(void)
{
int i, sz = rand() % 32;
char *s = malloc(sz+1);
for (i=0; i<sz; i++)
s[i] = 'a' + (rand() % 26);
s[i] = '\\0';
return s;
}
static void rand_bytes(uint8_t *p, size_t sz)
{
int i;
for (i=0; i<sz; i++)
p[i] = rand() % 256;
}
static void libxl_bitmap_rand_init(libxl_bitmap *bitmap)
{
int i;
bitmap->size = rand() % 16;
bitmap->map = calloc(bitmap->size, sizeof(*bitmap->map));
libxl_for_each_bit(i, *bitmap) {
if (rand() % 2)
libxl_bitmap_set(bitmap, i);
else
libxl_bitmap_reset(bitmap, i);
}
}
static void libxl_key_value_list_rand_init(libxl_key_value_list *pkvl)
{
int i, nr_kvp = rand() % 16;
libxl_key_value_list kvl = calloc(nr_kvp+1, 2*sizeof(char *));
for (i = 0; i<2*nr_kvp; i += 2) {
kvl[i] = rand_str();
if (rand() % 8)
kvl[i+1] = rand_str();
else
kvl[i+1] = NULL;
}
kvl[i] = NULL;
kvl[i+1] = NULL;
*pkvl = kvl;
}
static void libxl_cpuid_policy_list_rand_init(libxl_cpuid_policy_list *pp)
{
int i, nr_policies = rand() % 16;
struct {
const char *n;
int w;
} options[] = {
/* A random selection from libxl_cpuid_parse_config */
{"maxleaf", 32},
{"family", 8},
{"model", 8},
{"stepping", 4},
{"localapicid", 8},
{"proccount", 8},
{"clflush", 8},
{"brandid", 8},
{"f16c", 1},
{"avx", 1},
{"osxsave", 1},
{"xsave", 1},
{"aes", 1},
{"popcnt", 1},
{"movbe", 1},
{"x2apic", 1},
{"sse4.2", 1},
{"sse4.1", 1},
{"dca", 1},
{"pdcm", 1},
{"procpkg", 6},
};
const int nr_options = sizeof(options)/sizeof(options[0]);
char buf[64];
libxl_cpuid_policy_list p = NULL;
for (i = 0; i < nr_policies; i++) {
int opt = rand() % nr_options;
int val = rand() % (1<<options[opt].w);
snprintf(buf, 64, \"%s=%#x\", options[opt].n, val);
libxl_cpuid_parse_config(&p, buf);
}
*pp = p;
}
static void libxl_string_list_rand_init(libxl_string_list *p)
{
int i, nr = rand() % 16;
libxl_string_list l = calloc(nr+1, sizeof(char *));
for (i = 0; i<nr; i++) {
l[i] = rand_str();
}
l[i] = NULL;
*p = l;
}
""")
for ty in builtins + types:
if isinstance(ty, idl.Number): continue
if ty.typename not in handcoded:
f.write("static void %s_rand_init(%s);\n" % \
(ty.typename,
ty.make_arg("p", passby=idl.PASS_BY_REFERENCE)))
f.write("static void %s_rand_init(%s)\n" % \
(ty.typename,
ty.make_arg("p", passby=idl.PASS_BY_REFERENCE)))
f.write("{\n")
f.write(gen_rand_init(ty, "p"))
f.write("}\n")
f.write("\n")
ty.rand_init = "%s_rand_init" % ty.typename
f.write("""
int main(int argc, char **argv)
{
""")
for ty in types:
f.write(" %s %s_val;\n" % (ty.typename, ty.typename))
f.write("""
int rc;
char *s;
xentoollog_logger_stdiostream *logger;
libxl_ctx *ctx;
logger = xtl_createlogger_stdiostream(stderr, XTL_DETAIL, 0);
if (!logger) exit(1);
if (libxl_ctx_alloc(&ctx, LIBXL_VERSION, 0, (xentoollog_logger*)logger)) {
fprintf(stderr, "cannot init xl context\\n");
exit(1);
}
""")
f.write(" printf(\"Testing TYPE_to_json()\\n\");\n")
f.write(" printf(\"----------------------\\n\");\n")
f.write(" printf(\"\\n\");\n")
for ty in [t for t in types if t.json_fn is not None]:
arg = ty.typename + "_val"
f.write(" %s_rand_init(%s);\n" % (ty.typename, \
ty.pass_arg(arg, isref=False, passby=idl.PASS_BY_REFERENCE)))
f.write(" s = %s_to_json(ctx, %s);\n" % \
(ty.typename, ty.pass_arg(arg, isref=False)))
f.write(" printf(\"%%s: %%s\\n\", \"%s\", s);\n" % ty.typename)
f.write(" if (s == NULL) abort();\n")
f.write(" free(s);\n")
if ty.dispose_fn is not None:
f.write(" %s(&%s_val);\n" % (ty.dispose_fn, ty.typename))
f.write("\n")
f.write(" printf(\"Testing Enumerations\\n\");\n")
f.write(" printf(\"--------------------\\n\");\n")
f.write(" printf(\"\\n\");\n")
for ty in [t for t in types if isinstance(t,idl.Enumeration)]:
f.write(" printf(\"%s -- to string:\\n\");\n" % (ty.typename))
for v in ty.values:
f.write(" printf(\"\\t%s = %%d = \\\"%%s\\\"\\n\", " \
"%s, %s_to_string(%s));\n" % \
(v.valuename, v.name, ty.typename, v.name))
f.write("\n")
f.write(" printf(\"%s -- to JSON:\\n\");\n" % (ty.typename))
for v in ty.values:
f.write(" printf(\"\\t%s = %%d = %%s\", " \
"%s, %s_to_json(ctx, %s));\n" %\
(v.valuename, v.name, ty.typename, v.name))
f.write("\n")
f.write(" printf(\"%s -- from string:\\n\");\n" % (ty.typename))
for v in [v.valuename for v in ty.values] + ["AN INVALID VALUE"]:
n = randomize_case(v)
f.write(" %s_val = -1;\n" % (ty.typename))
f.write(" rc = %s_from_string(\"%s\", &%s_val);\n" %\
(ty.typename, n, ty.typename))
f.write(" printf(\"\\t%s = \\\"%%s\\\" = %%d (rc %%d)\\n\", " \
"\"%s\", %s_val, rc);\n" %\
(v, n, ty.typename))
f.write("\n")
f.write("""
libxl_ctx_free(ctx);
xtl_logger_destroy((xentoollog_logger*)logger);
return 0;
}
""")
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
199,
646,
747,
199,
646,
984,
199,
646,
295,
199,
646,
2196,
199,
199,
646,
20365,
199,
199,
318,
2196,
794,
63,
1560,
8,
67,
304,
272,
340,
2196,
14,
2355,
342,
665,
378,
14,
21,
26,
267,
372,
620,
14,
2325,
8,
67,
9,
272,
587,
26,
267,
372,
620,
14,
4142,
8,
67,
9,
199,
199,
318,
2196,
794,
63,
2546,
8,
83,
304,
272,
519,
275,
359,
28610,
63,
1560,
8,
67,
9,
367,
286,
315,
308,
61,
272,
372,
10587,
904,
8,
82,
9,
199,
199,
318,
2196,
794,
63,
4869,
8,
69,
304,
272,
372,
2196,
14,
5095,
779,
86,
14,
354,
367,
373,
315,
325,
14,
1459,
566,
199,
199,
6868,
15282,
275,
2097,
773,
15455,
63,
20299,
401,
298,
773,
15455,
63,
498,
63,
585,
63,
513,
401,
1467,
298,
773,
15455,
63,
1850,
1535,
63,
3185,
63,
513,
401,
298,
773,
15455,
63,
875,
63,
513,
937,
199,
199,
318,
3805,
63,
3759,
63,
826,
8,
369,
12,
373,
12,
4363,
275,
298,
259,
3872,
1676,
275,
488,
304,
272,
308,
275,
3087,
272,
340,
1228,
8,
369,
12,
20365,
14,
13425,
304,
267,
308,
847,
2071,
83,
275,
450,
83,
3779,
78,
2,
450,
334,
369,
14,
1529,
63,
1273,
8,
86,
12,
1676,
365,
488,
395,
2196,
794,
63,
4869,
8,
369,
430,
272,
916,
1228,
8,
369,
12,
20365,
14,
3836,
304,
267,
340,
1676,
365,
488,
26,
288,
746,
2186,
480,
3836,
730,
1471,
1172,
282,
1676,
531,
267,
308,
847,
2071,
83,
275,
10261,
342,
8530,
24,
3779,
78,
2,
450,
334,
1708,
435,
10284,
14,
552,
1391,
14,
354,
9,
267,
308,
847,
2071,
83,
275,
3213,
2102,
4042,
83,
12,
13855,
2031,
5,
83,
430,
3779,
78,
2,
450,
971,
288,
334,
86,
12,
1676,
435,
10284,
14,
552,
1391,
14,
354,
12,
373,
9,
267,
308,
847,
9965,
78,
2,
267,
308,
847,
298,
259,
1109,
284,
3779,
78,
2,
267,
308,
847,
298,
259,
367,
334,
73,
29,
16,
27,
284,
21110,
83,
27,
284,
4176,
2862,
78,
2,
450,
334,
1708,
435,
10284,
14,
552,
1391,
14,
354,
9,
267,
308,
847,
3805,
63,
3759,
63,
826,
8,
369,
14,
6086,
63,
466,
12,
373,
5207,
59,
73,
11472,
2574,
4363,
435,
298,
263,
3872,
1676,
9,
267,
308,
847,
10620,
78,
2,
272,
916,
1228,
8,
369,
12,
20365,
14,
1197,
379,
15540,
304,
267,
340,
1676,
365,
488,
26,
288,
746,
2186,
480,
1197,
379,
15540,
730,
1471,
1172,
282,
1676,
531,
267,
308,
847,
298,
5656,
4366,
83,
9,
9459,
78,
2,
450,
334,
1708,
435,
10284,
14,
498,
1391,
14,
354,
9,
267,
367,
289,
315,
10284,
14,
955,
26,
288,
334,
78,
1708,
12,
70,
3684,
9,
275,
10284,
14,
1114,
8,
86,
12,
289,
12,
1676,
365,
488,
9,
288,
308,
847,
298,
2546,
450,
83,
3427,
78,
2,
450,
289,
14,
4869,
354,
288,
308,
847,
3805,
63,
3759,
63,
826,
8,
70,
14,
466,
12,
289,
3684,
12,
4363,
435,
298,
259,
3872,
302,
1708,
9,
288,
308,
847,
298,
259,
2059,
3779,
78,
2,
267,
308,
847,
10620,
78,
2,
272,
916,
1228,
8,
369,
12,
20365,
14,
4836,
9,
971,
1362,
436,
334,
1708,
365,
488,
503,
10284,
14,
1001,
63,
2324,
365,
488,
304,
267,
367,
289,
315,
359,
70,
367,
289,
315,
10284,
14,
955,
340,
440,
289,
14,
1297,
2189,
288,
334,
78,
1708,
12,
70,
3684,
9,
275,
10284,
14,
1114,
8,
86,
12,
289,
12,
1676,
365,
488,
9,
288,
308,
847,
3805,
63,
3759,
63,
826,
8,
70,
14,
466,
12,
289,
3684,
12,
4873,
302,
1708,
9,
272,
916,
2688,
8,
369,
12,
298,
3759,
63,
826,
531,
436,
10284,
14,
3759,
63,
826,
365,
440,
488,
26,
267,
308,
847,
2071,
83,
4042,
83,
6152,
78,
2,
450,
334,
369,
14,
3759,
63,
826,
12,
1169,
10284,
14,
1529,
63,
1273,
8,
86,
12,
365,
1121,
29,
1708,
365,
488,
12,
3147,
986,
991,
29,
13398,
14,
6909,
63,
8285,
63,
31177,
430,
272,
916,
10284,
14,
18596,
315,
2097,
773,
15455,
63,
2580,
401,
298,
773,
15455,
63,
3088,
401,
298,
773,
15455,
63,
8090,
2874,
6229,
267,
308,
847,
298,
3759,
63,
2394,
1332,
1635,
24,
63,
84,
627,
19656,
83,
12,
13855,
2031,
5,
83,
430,
3779,
78,
2,
450,
334,
86,
12,
86,
9,
272,
916,
10284,
14,
18596,
315,
2097,
773,
15455,
63,
4556,
344,
937,
503,
1228,
8,
369,
12,
20365,
14,
3259,
304,
267,
308,
847,
2071,
83,
275,
10261,
342,
11539,
334,
12590,
4042,
83,
3342,
24,
6152,
78,
2,
450,
971,
1467,
334,
369,
14,
1529,
63,
1273,
8,
86,
12,
1676,
365,
488,
395,
1598,
10284,
14,
1529,
63,
1273,
8,
86,
12,
1676,
365,
488,
430,
272,
916,
10284,
14,
18596,
315,
2097,
2245,
6229,
267,
308,
847,
2071,
83,
275,
10261,
342,
11539,
499,
3779,
78,
2,
450,
373,
272,
916,
10284,
14,
18596,
315,
2097,
773,
15455,
63,
318,
2245,
6229,
267,
308,
847,
298,
773,
15455,
63,
318,
2245,
63,
409,
4042,
83,
12,
221,
3480,
3759,
342,
11539,
413,
6152,
78,
2,
450,
373,
272,
916,
10284,
14,
18596,
315,
2097,
1560,
627,
6229,
267,
308,
847,
2071,
83,
275,
10261,
63,
495,
342,
3779,
78,
2,
450,
373,
272,
916,
10284,
14,
4239,
26,
267,
986,
272,
916,
10284,
14,
18596,
315,
4926,
15282,
26,
267,
746,
2186,
480,
8168,
367,
4926,
15282,
450,
83,
2,
450,
10284,
14,
18596,
9,
272,
587,
26,
267,
746,
2186,
480,
6612,
19311,
4205,
450,
83,
2,
450,
10284,
14,
18596,
9,
339,
340,
308,
1137,
10812,
267,
308,
275,
4363,
435,
308,
272,
372,
308,
14,
1814,
4582,
78,
401,
1867,
78,
5,
83,
2,
450,
4363,
680,
6735,
8,
3724,
9,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
340,
822,
8,
1274,
14,
3020,
9,
665,
650,
26,
267,
870,
4331,
1274,
14,
3083,
12,
298,
7692,
26,
3805,
396,
14,
647,
665,
13398,
30,
665,
12236,
4335,
267,
984,
14,
2224
] |
[
2647,
15,
1393,
15,
1548,
199,
199,
646,
747,
199,
646,
984,
199,
646,
295,
199,
646,
2196,
199,
199,
646,
20365,
199,
199,
318,
2196,
794,
63,
1560,
8,
67,
304,
272,
340,
2196,
14,
2355,
342,
665,
378,
14,
21,
26,
267,
372,
620,
14,
2325,
8,
67,
9,
272,
587,
26,
267,
372,
620,
14,
4142,
8,
67,
9,
199,
199,
318,
2196,
794,
63,
2546,
8,
83,
304,
272,
519,
275,
359,
28610,
63,
1560,
8,
67,
9,
367,
286,
315,
308,
61,
272,
372,
10587,
904,
8,
82,
9,
199,
199,
318,
2196,
794,
63,
4869,
8,
69,
304,
272,
372,
2196,
14,
5095,
779,
86,
14,
354,
367,
373,
315,
325,
14,
1459,
566,
199,
199,
6868,
15282,
275,
2097,
773,
15455,
63,
20299,
401,
298,
773,
15455,
63,
498,
63,
585,
63,
513,
401,
1467,
298,
773,
15455,
63,
1850,
1535,
63,
3185,
63,
513,
401,
298,
773,
15455,
63,
875,
63,
513,
937,
199,
199,
318,
3805,
63,
3759,
63,
826,
8,
369,
12,
373,
12,
4363,
275,
298,
259,
3872,
1676,
275,
488,
304,
272,
308,
275,
3087,
272,
340,
1228,
8,
369,
12,
20365,
14,
13425,
304,
267,
308,
847,
2071,
83,
275,
450,
83,
3779,
78,
2,
450,
334,
369,
14,
1529,
63,
1273,
8,
86,
12,
1676,
365,
488,
395,
2196,
794,
63,
4869,
8,
369,
430,
272,
916,
1228,
8,
369,
12,
20365,
14,
3836,
304,
267,
340,
1676,
365,
488,
26,
288,
746,
2186,
480,
3836,
730,
1471,
1172,
282,
1676,
531,
267,
308,
847,
2071,
83,
275,
10261,
342,
8530,
24,
3779,
78,
2,
450,
334,
1708,
435,
10284,
14,
552,
1391,
14,
354,
9,
267,
308,
847,
2071,
83,
275,
3213,
2102,
4042,
83,
12,
13855,
2031,
5,
83,
430,
3779,
78,
2,
450,
971,
288,
334,
86,
12,
1676,
435,
10284,
14,
552,
1391,
14,
354,
12,
373,
9,
267,
308,
847,
9965,
78,
2,
267,
308,
847,
298,
259,
1109,
284,
3779,
78,
2,
267,
308,
847,
298,
259,
367,
334,
73,
29,
16,
27,
284,
21110,
83,
27,
284,
4176,
2862,
78,
2,
450,
334,
1708,
435,
10284,
14,
552,
1391,
14,
354,
9,
267,
308,
847,
3805,
63,
3759,
63,
826,
8,
369,
14,
6086,
63,
466,
12,
373,
5207,
59,
73,
11472,
2574,
4363,
435,
298,
263,
3872,
1676,
9,
267,
308,
847,
10620,
78,
2,
272,
916,
1228,
8,
369,
12,
20365,
14,
1197,
379,
15540,
304,
267,
340,
1676,
365,
488,
26,
288,
746,
2186,
480,
1197,
379,
15540,
730,
1471,
1172,
282,
1676,
531,
267,
308,
847,
298,
5656,
4366,
83,
9,
9459,
78,
2,
450,
334,
1708,
435,
10284,
14,
498,
1391,
14,
354,
9,
267,
367,
289,
315,
10284,
14,
955,
26,
288,
334,
78,
1708,
12,
70,
3684,
9,
275,
10284,
14,
1114,
8,
86,
12,
289,
12,
1676,
365,
488,
9,
288,
308,
847,
298,
2546,
450,
83,
3427,
78,
2,
450,
289,
14,
4869,
354,
288,
308,
847,
3805,
63,
3759,
63,
826,
8,
70,
14,
466,
12,
289,
3684,
12,
4363,
435,
298,
259,
3872,
302,
1708,
9,
288,
308,
847,
298,
259,
2059,
3779,
78,
2,
267,
308,
847,
10620,
78,
2,
272,
916,
1228,
8,
369,
12,
20365,
14,
4836,
9,
971,
1362,
436,
334,
1708,
365,
488,
503,
10284,
14,
1001,
63,
2324,
365,
488,
304,
267,
367,
289,
315,
359,
70,
367,
289,
315,
10284,
14,
955,
340,
440,
289,
14,
1297,
2189,
288,
334,
78,
1708,
12,
70,
3684,
9,
275,
10284,
14,
1114,
8,
86,
12,
289,
12,
1676,
365,
488,
9,
288,
308,
847,
3805,
63,
3759,
63,
826,
8,
70,
14,
466,
12,
289,
3684,
12,
4873,
302,
1708,
9,
272,
916,
2688,
8,
369,
12,
298,
3759,
63,
826,
531,
436,
10284,
14,
3759,
63,
826,
365,
440,
488,
26,
267,
308,
847,
2071,
83,
4042,
83,
6152,
78,
2,
450,
334,
369,
14,
3759,
63,
826,
12,
1169,
10284,
14,
1529,
63,
1273,
8,
86,
12,
365,
1121,
29,
1708,
365,
488,
12,
3147,
986,
991,
29,
13398,
14,
6909,
63,
8285,
63,
31177,
430,
272,
916,
10284,
14,
18596,
315,
2097,
773,
15455,
63,
2580,
401,
298,
773,
15455,
63,
3088,
401,
298,
773,
15455,
63,
8090,
2874,
6229,
267,
308,
847,
298,
3759,
63,
2394,
1332,
1635,
24,
63,
84,
627,
19656,
83,
12,
13855,
2031,
5,
83,
430,
3779,
78,
2,
450,
334,
86,
12,
86,
9,
272,
916,
10284,
14,
18596,
315,
2097,
773,
15455,
63,
4556,
344,
937,
503,
1228,
8,
369,
12,
20365,
14,
3259,
304,
267,
308,
847,
2071,
83,
275,
10261,
342,
11539,
334,
12590,
4042,
83,
3342,
24,
6152,
78,
2,
450,
971,
1467,
334,
369,
14,
1529,
63,
1273,
8,
86,
12,
1676,
365,
488,
395,
1598,
10284,
14,
1529,
63,
1273,
8,
86,
12,
1676,
365,
488,
430,
272,
916,
10284,
14,
18596,
315,
2097,
2245,
6229,
267,
308,
847,
2071,
83,
275,
10261,
342,
11539,
499,
3779,
78,
2,
450,
373,
272,
916,
10284,
14,
18596,
315,
2097,
773,
15455,
63,
318,
2245,
6229,
267,
308,
847,
298,
773,
15455,
63,
318,
2245,
63,
409,
4042,
83,
12,
221,
3480,
3759,
342,
11539,
413,
6152,
78,
2,
450,
373,
272,
916,
10284,
14,
18596,
315,
2097,
1560,
627,
6229,
267,
308,
847,
2071,
83,
275,
10261,
63,
495,
342,
3779,
78,
2,
450,
373,
272,
916,
10284,
14,
4239,
26,
267,
986,
272,
916,
10284,
14,
18596,
315,
4926,
15282,
26,
267,
746,
2186,
480,
8168,
367,
4926,
15282,
450,
83,
2,
450,
10284,
14,
18596,
9,
272,
587,
26,
267,
746,
2186,
480,
6612,
19311,
4205,
450,
83,
2,
450,
10284,
14,
18596,
9,
339,
340,
308,
1137,
10812,
267,
308,
275,
4363,
435,
308,
272,
372,
308,
14,
1814,
4582,
78,
401,
1867,
78,
5,
83,
2,
450,
4363,
680,
6735,
8,
3724,
9,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
340,
822,
8,
1274,
14,
3020,
9,
665,
650,
26,
267,
870,
4331,
1274,
14,
3083,
12,
298,
7692,
26,
3805,
396,
14,
647,
665,
13398,
30,
665,
12236,
4335,
267,
984,
14,
2224,
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
] |
shroman/ignite
|
modules/platforms/python/tests/test_sql.py
|
7
|
4551
|
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You 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 pyignite.api import (
sql_fields, sql_fields_cursor_get_page,
cache_get_or_create, sql, sql_cursor_get_page,
cache_get_configuration,
)
from pyignite.datatypes.prop_codes import *
from pyignite.utils import entity_id, unwrap_binary
initial_data = [
('John', 'Doe', 5),
('Jane', 'Roe', 4),
('Joe', 'Bloggs', 4),
('Richard', 'Public', 3),
('Negidius', 'Numerius', 3),
]
create_query = '''CREATE TABLE Student (
id INT(11) PRIMARY KEY,
first_name CHAR(24),
last_name CHAR(32),
grade INT(11))'''
insert_query = '''INSERT INTO Student(id, first_name, last_name, grade)
VALUES (?, ?, ?, ?)'''
select_query = 'SELECT id, first_name, last_name, grade FROM Student'
drop_query = 'DROP TABLE Student IF EXISTS'
page_size = 4
def test_sql(client):
# cleanup
client.sql(drop_query)
result = sql_fields(
client,
'PUBLIC',
create_query,
page_size,
include_field_names=True
)
assert result.status == 0, result.message
for i, data_line in enumerate(initial_data, start=1):
fname, lname, grade = data_line
result = sql_fields(
client,
'PUBLIC',
insert_query,
page_size,
query_args=[i, fname, lname, grade],
include_field_names=True
)
assert result.status == 0, result.message
result = cache_get_configuration(client, 'SQL_PUBLIC_STUDENT')
assert result.status == 0, result.message
binary_type_name = result.value[PROP_QUERY_ENTITIES][0]['value_type_name']
result = sql(
client,
'SQL_PUBLIC_STUDENT',
binary_type_name,
'TRUE',
page_size
)
assert result.status == 0, result.message
assert len(result.value['data']) == page_size
assert result.value['more'] is True
for wrapped_object in result.value['data'].values():
data = unwrap_binary(client, wrapped_object)
assert data.type_id == entity_id(binary_type_name)
cursor = result.value['cursor']
while result.value['more']:
result = sql_cursor_get_page(client, cursor)
assert result.status == 0, result.message
for wrapped_object in result.value['data'].values():
data = unwrap_binary(client, wrapped_object)
assert data.type_id == entity_id(binary_type_name)
# repeat cleanup
result = sql_fields(client, 'PUBLIC', drop_query, page_size)
assert result.status == 0
def test_sql_fields(client):
# cleanup
client.sql(drop_query)
result = sql_fields(
client,
'PUBLIC',
create_query,
page_size,
include_field_names=True
)
assert result.status == 0, result.message
for i, data_line in enumerate(initial_data, start=1):
fname, lname, grade = data_line
result = sql_fields(
client,
'PUBLIC',
insert_query,
page_size,
query_args=[i, fname, lname, grade],
include_field_names=True
)
assert result.status == 0, result.message
result = sql_fields(
client,
'PUBLIC',
select_query,
page_size,
include_field_names=True
)
assert result.status == 0
assert len(result.value['data']) == page_size
assert result.value['more'] is True
cursor = result.value['cursor']
result = sql_fields_cursor_get_page(client, cursor, field_count=4)
assert result.status == 0
assert len(result.value['data']) == len(initial_data) - page_size
assert result.value['more'] is False
# repeat cleanup
result = sql_fields(client, 'PUBLIC', drop_query, page_size)
assert result.status == 0
|
apache-2.0
|
[
3,
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
503,
1655,
199,
3,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
1854,
543,
199,
3,
642,
1736,
367,
4722,
2556,
12602,
4248,
12715,
14,
199,
3,
710,
14857,
12378,
642,
570,
370,
2047,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
199,
3,
334,
1589,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
199,
3,
314,
844,
14,
221,
2047,
1443,
3332,
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,
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,
1134,
1030,
1175,
14,
1246,
492,
334,
272,
3875,
63,
955,
12,
3875,
63,
955,
63,
3937,
63,
362,
63,
1606,
12,
272,
2581,
63,
362,
63,
269,
63,
981,
12,
3875,
12,
3875,
63,
3937,
63,
362,
63,
1606,
12,
272,
2581,
63,
362,
63,
4758,
12,
199,
9,
199,
504,
1134,
1030,
1175,
14,
14184,
83,
14,
4469,
63,
6021,
492,
627,
199,
504,
1134,
1030,
1175,
14,
1208,
492,
4642,
63,
344,
12,
625,
3823,
63,
3008,
199,
199,
2747,
63,
576,
275,
359,
267,
661,
12923,
297,
283,
2585,
69,
297,
959,
395,
267,
661,
42,
5865,
297,
283,
3863,
69,
297,
841,
395,
267,
661,
5691,
69,
297,
283,
26081,
458,
297,
841,
395,
267,
661,
50,
1158,
1005,
297,
283,
9885,
297,
650,
395,
267,
661,
4698,
6153,
5231,
297,
283,
46,
940,
322,
527,
297,
650,
395,
272,
1622,
199,
199,
981,
63,
1131,
275,
1449,
8366,
9934,
17246,
334,
272,
1305,
16429,
8,
845,
9,
19770,
9301,
12,
272,
1642,
63,
354,
8518,
8,
1194,
395,
272,
2061,
63,
354,
8518,
8,
708,
395,
272,
16183,
16429,
8,
845,
430,
2344,
199,
199,
3176,
63,
1131,
275,
1449,
10258,
12872,
17246,
8,
344,
12,
1642,
63,
354,
12,
2061,
63,
354,
12,
16183,
9,
199,
15514,
7558,
12,
21259,
21259,
5805,
9,
2344,
199,
199,
2416,
63,
1131,
275,
283,
4859,
1305,
12,
1642,
63,
354,
12,
2061,
63,
354,
12,
16183,
4442,
17246,
7,
199,
199,
4824,
63,
1131,
275,
283,
14764,
9934,
17246,
8036,
23875,
7,
199,
199,
1606,
63,
890,
275,
841,
421,
199,
318,
511,
63,
3009,
8,
1258,
304,
339,
327,
9058,
272,
1890,
14,
3009,
8,
4824,
63,
1131,
9,
339,
754,
275,
3875,
63,
955,
8,
267,
1890,
12,
267,
283,
19476,
297,
267,
1218,
63,
1131,
12,
267,
2034,
63,
890,
12,
267,
2387,
63,
698,
63,
1247,
29,
549,
272,
776,
272,
702,
754,
14,
1205,
508,
378,
12,
754,
14,
1188,
339,
367,
284,
12,
666,
63,
604,
315,
3874,
8,
2747,
63,
576,
12,
1343,
29,
17,
304,
267,
6748,
12,
634,
354,
12,
16183,
275,
666,
63,
604,
267,
754,
275,
3875,
63,
955,
8,
288,
1890,
12,
288,
283,
19476,
297,
288,
5518,
63,
1131,
12,
288,
2034,
63,
890,
12,
288,
1827,
63,
589,
1524,
73,
12,
6748,
12,
634,
354,
12,
16183,
467,
288,
2387,
63,
698,
63,
1247,
29,
549,
267,
776,
267,
702,
754,
14,
1205,
508,
378,
12,
754,
14,
1188,
339,
754,
275,
2581,
63,
362,
63,
4758,
8,
1258,
12,
283,
4657,
63,
19476,
63,
840,
29317,
358,
272,
702,
754,
14,
1205,
508,
378,
12,
754,
14,
1188,
339,
3366,
63,
466,
63,
354,
275,
754,
14,
585,
59,
19926,
63,
11938,
63,
1309,
19144,
1527,
16,
2733,
585,
63,
466,
63,
354,
418,
272,
754,
275,
3875,
8,
267,
1890,
12,
267,
283,
4657,
63,
19476,
63,
840,
29317,
297,
267,
3366,
63,
466,
63,
354,
12,
267,
283,
15064,
297,
267,
2034,
63,
890,
272,
776,
272,
702,
754,
14,
1205,
508,
378,
12,
754,
14,
1188,
272,
702,
822,
8,
1099,
14,
585,
459,
576,
1105,
508,
2034,
63,
890,
272,
702,
754,
14,
585,
459,
6878,
418,
365,
715,
339,
367,
8072,
63,
785,
315,
754,
14,
585,
459,
576,
2278,
1459,
837,
267,
666,
275,
625,
3823,
63,
3008,
8,
1258,
12,
8072,
63,
785,
9,
267,
702,
666,
14,
466,
63,
344,
508,
4642,
63,
344,
8,
3008,
63,
466,
63,
354,
9,
339,
3920,
275,
754,
14,
585,
459,
3937,
418,
339,
1830,
754,
14,
585,
459,
6878,
2565,
267,
754,
275,
3875,
63,
3937,
63,
362,
63,
1606,
8,
1258,
12,
3920,
9,
267,
702,
754,
14,
1205,
508,
378,
12,
754,
14,
1188,
398,
367,
8072,
63,
785,
315,
754,
14,
585,
459,
576,
2278,
1459,
837,
288,
666,
275,
625,
3823,
63,
3008,
8,
1258,
12,
8072,
63,
785,
9,
288,
702,
666,
14,
466,
63,
344,
508,
4642,
63,
344,
8,
3008,
63,
466,
63,
354,
9,
339,
327,
11982,
9058,
272,
754,
275,
3875,
63,
955,
8,
1258,
12,
283,
19476,
297,
5978,
63,
1131,
12,
2034,
63,
890,
9,
272,
702,
754,
14,
1205,
508,
378,
421,
199,
318,
511,
63,
3009,
63,
955,
8,
1258,
304,
339,
327,
9058,
272,
1890,
14,
3009,
8,
4824,
63,
1131,
9,
339,
754,
275,
3875,
63,
955,
8,
267,
1890,
12,
267,
283,
19476,
297,
267,
1218,
63,
1131,
12,
267,
2034,
63,
890,
12,
267,
2387,
63,
698,
63,
1247,
29,
549,
272,
776,
272,
702,
754,
14,
1205,
508,
378,
12,
754,
14,
1188,
339,
367,
284,
12,
666,
63,
604,
315,
3874,
8,
2747,
63,
576,
12,
1343,
29,
17,
304,
267,
6748,
12,
634,
354,
12,
16183,
275,
666,
63,
604,
267,
754,
275,
3875,
63,
955,
8,
288,
1890,
12,
288,
283,
19476,
297,
288,
5518,
63,
1131,
12,
288,
2034,
63,
890,
12,
288,
1827,
63,
589,
1524,
73,
12,
6748,
12,
634,
354,
12,
16183,
467,
288,
2387,
63,
698
] |
[
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
503,
1655,
199,
3,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
1854,
543,
199,
3,
642,
1736,
367,
4722,
2556,
12602,
4248,
12715,
14,
199,
3,
710,
14857,
12378,
642,
570,
370,
2047,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
199,
3,
334,
1589,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
199,
3,
314,
844,
14,
221,
2047,
1443,
3332,
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,
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,
1134,
1030,
1175,
14,
1246,
492,
334,
272,
3875,
63,
955,
12,
3875,
63,
955,
63,
3937,
63,
362,
63,
1606,
12,
272,
2581,
63,
362,
63,
269,
63,
981,
12,
3875,
12,
3875,
63,
3937,
63,
362,
63,
1606,
12,
272,
2581,
63,
362,
63,
4758,
12,
199,
9,
199,
504,
1134,
1030,
1175,
14,
14184,
83,
14,
4469,
63,
6021,
492,
627,
199,
504,
1134,
1030,
1175,
14,
1208,
492,
4642,
63,
344,
12,
625,
3823,
63,
3008,
199,
199,
2747,
63,
576,
275,
359,
267,
661,
12923,
297,
283,
2585,
69,
297,
959,
395,
267,
661,
42,
5865,
297,
283,
3863,
69,
297,
841,
395,
267,
661,
5691,
69,
297,
283,
26081,
458,
297,
841,
395,
267,
661,
50,
1158,
1005,
297,
283,
9885,
297,
650,
395,
267,
661,
4698,
6153,
5231,
297,
283,
46,
940,
322,
527,
297,
650,
395,
272,
1622,
199,
199,
981,
63,
1131,
275,
1449,
8366,
9934,
17246,
334,
272,
1305,
16429,
8,
845,
9,
19770,
9301,
12,
272,
1642,
63,
354,
8518,
8,
1194,
395,
272,
2061,
63,
354,
8518,
8,
708,
395,
272,
16183,
16429,
8,
845,
430,
2344,
199,
199,
3176,
63,
1131,
275,
1449,
10258,
12872,
17246,
8,
344,
12,
1642,
63,
354,
12,
2061,
63,
354,
12,
16183,
9,
199,
15514,
7558,
12,
21259,
21259,
5805,
9,
2344,
199,
199,
2416,
63,
1131,
275,
283,
4859,
1305,
12,
1642,
63,
354,
12,
2061,
63,
354,
12,
16183,
4442,
17246,
7,
199,
199,
4824,
63,
1131,
275,
283,
14764,
9934,
17246,
8036,
23875,
7,
199,
199,
1606,
63,
890,
275,
841,
421,
199,
318,
511,
63,
3009,
8,
1258,
304,
339,
327,
9058,
272,
1890,
14,
3009,
8,
4824,
63,
1131,
9,
339,
754,
275,
3875,
63,
955,
8,
267,
1890,
12,
267,
283,
19476,
297,
267,
1218,
63,
1131,
12,
267,
2034,
63,
890,
12,
267,
2387,
63,
698,
63,
1247,
29,
549,
272,
776,
272,
702,
754,
14,
1205,
508,
378,
12,
754,
14,
1188,
339,
367,
284,
12,
666,
63,
604,
315,
3874,
8,
2747,
63,
576,
12,
1343,
29,
17,
304,
267,
6748,
12,
634,
354,
12,
16183,
275,
666,
63,
604,
267,
754,
275,
3875,
63,
955,
8,
288,
1890,
12,
288,
283,
19476,
297,
288,
5518,
63,
1131,
12,
288,
2034,
63,
890,
12,
288,
1827,
63,
589,
1524,
73,
12,
6748,
12,
634,
354,
12,
16183,
467,
288,
2387,
63,
698,
63,
1247,
29,
549,
267,
776,
267,
702,
754,
14,
1205,
508,
378,
12,
754,
14,
1188,
339,
754,
275,
2581,
63,
362,
63,
4758,
8,
1258,
12,
283,
4657,
63,
19476,
63,
840,
29317,
358,
272,
702,
754,
14,
1205,
508,
378,
12,
754,
14,
1188,
339,
3366,
63,
466,
63,
354,
275,
754,
14,
585,
59,
19926,
63,
11938,
63,
1309,
19144,
1527,
16,
2733,
585,
63,
466,
63,
354,
418,
272,
754,
275,
3875,
8,
267,
1890,
12,
267,
283,
4657,
63,
19476,
63,
840,
29317,
297,
267,
3366,
63,
466,
63,
354,
12,
267,
283,
15064,
297,
267,
2034,
63,
890,
272,
776,
272,
702,
754,
14,
1205,
508,
378,
12,
754,
14,
1188,
272,
702,
822,
8,
1099,
14,
585,
459,
576,
1105,
508,
2034,
63,
890,
272,
702,
754,
14,
585,
459,
6878,
418,
365,
715,
339,
367,
8072,
63,
785,
315,
754,
14,
585,
459,
576,
2278,
1459,
837,
267,
666,
275,
625,
3823,
63,
3008,
8,
1258,
12,
8072,
63,
785,
9,
267,
702,
666,
14,
466,
63,
344,
508,
4642,
63,
344,
8,
3008,
63,
466,
63,
354,
9,
339,
3920,
275,
754,
14,
585,
459,
3937,
418,
339,
1830,
754,
14,
585,
459,
6878,
2565,
267,
754,
275,
3875,
63,
3937,
63,
362,
63,
1606,
8,
1258,
12,
3920,
9,
267,
702,
754,
14,
1205,
508,
378,
12,
754,
14,
1188,
398,
367,
8072,
63,
785,
315,
754,
14,
585,
459,
576,
2278,
1459,
837,
288,
666,
275,
625,
3823,
63,
3008,
8,
1258,
12,
8072,
63,
785,
9,
288,
702,
666,
14,
466,
63,
344,
508,
4642,
63,
344,
8,
3008,
63,
466,
63,
354,
9,
339,
327,
11982,
9058,
272,
754,
275,
3875,
63,
955,
8,
1258,
12,
283,
19476,
297,
5978,
63,
1131,
12,
2034,
63,
890,
9,
272,
702,
754,
14,
1205,
508,
378,
421,
199,
318,
511,
63,
3009,
63,
955,
8,
1258,
304,
339,
327,
9058,
272,
1890,
14,
3009,
8,
4824,
63,
1131,
9,
339,
754,
275,
3875,
63,
955,
8,
267,
1890,
12,
267,
283,
19476,
297,
267,
1218,
63,
1131,
12,
267,
2034,
63,
890,
12,
267,
2387,
63,
698,
63,
1247,
29,
549,
272,
776,
272,
702,
754,
14,
1205,
508,
378,
12,
754,
14,
1188,
339,
367,
284,
12,
666,
63,
604,
315,
3874,
8,
2747,
63,
576,
12,
1343,
29,
17,
304,
267,
6748,
12,
634,
354,
12,
16183,
275,
666,
63,
604,
267,
754,
275,
3875,
63,
955,
8,
288,
1890,
12,
288,
283,
19476,
297,
288,
5518,
63,
1131,
12,
288,
2034,
63,
890,
12,
288,
1827,
63,
589,
1524,
73,
12,
6748,
12,
634,
354,
12,
16183,
467,
288,
2387,
63,
698,
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,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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
] |
wkentaro/termsaver
|
termsaverlib/common.py
|
1
|
4621
|
###############################################################################
#
# file: common.py
#
# Purpose: holds common helper functions used by termsaver code.
#
# Note: This file is part of Termsaver application, and should not be used
# or executed separately.
#
###############################################################################
#
# Copyright 2012 Termsaver
#
# 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.
#
###############################################################################
"""
Holds common functionality used by termsaver screens.
"""
#
# Python build-in modules
#
import os
import sys
import traceback
import HTMLParser
import subprocess
import re
def is_windows():
"""
Returns True if the environment is Microsoft Windows.
"""
return sys.platform == "win32"
def prettify_exception(ex):
"""
Outputs the exception with its stack trace within separator lines.
"""
print """
===================================
Exception: (%s) %s
%s
===================================
""" % (ex.__class__.__name__, ex.message, traceback.format_exc())
def get_app_dir():
"""
Retrieves the termsaver main directory based on current operating system.
For Windows machines, this should be something like:
<root>\Documents and Settings\<user>\Application Data\termsaver
For Unix machines, it will be:
/home/<user>/.termsaver/
"""
if is_windows():
path = os.path.join(os.environ['APPDATA'], "termsaver")
else:
path = os.path.join(os.environ['HOME'], ".termsaver")
# create if applicable
if not os.path.exists(path):
# permission errors here will just propagate error
os.mkdir(path)
return path
def get_temp_dir():
"""
Retrieves the temporary based on current operating system.
For Windows machines, this should be something like:
<root>\Documents and Settings\<user>\Local Settings\Temp
For Unix machines, it will be:
/tmp/
"""
if is_windows():
path = os.environ['TMP']
else:
path = "/tmp"
return path
def unescape_string(escaped_text):
"""
Unescape strings. This is useful for cases when data that needs to be
displayed on screen is escaped for HTML or database stuff.
Additional replacing is taken here, such as some HTML tags:
* <br>, replaced to \n
"""
unescaped = escaped_text
try:
unescaped = HTMLParser.HTMLParser().unescape(escaped_text)
# replace most common HTML data
unescaped = unescaped.replace('<br>', '\n')
unescaped = unescaped.replace('<br/>', '\n')
unescaped = unescaped.replace('<br />', '\n')
unescaped = unescaped.decode('string_escape')
except:
#
# If there were errors here, just ignore them and try to give back
# the string the best it could do
#
pass
return unescaped
def get_day_suffix(day):
"""
Returns the suffix of the day, such as in 1st, 2nd, ...
"""
if day in (1, 11, 21, 31):
return 'st'
elif day in (2, 12, 22):
return 'nd'
elif day in (3, 13, 23):
return 'rd'
else:
return 'th'
def execute_shell(cmd, ignore_errors=False):
"""
Simple routine to execute shell commands.
If `ignore_errors` is false (default) errors here will be thrown, and
must be treated individually, to ensure proper message to end-user.
The `cmd` argument must be an array, formatted for subprocess.Popen.
If you are not sure on how to do that, just use: shlex.split(string).
"""
try:
p = subprocess.Popen(cmd, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, close_fds=True)
out, __ = p.communicate()
except Exception, e:
if not ignore_errors:
raise e
return out.rstrip()
def strip_html(text):
"""
Simple regex that cleans a string of any HTML tags (for terminal output,
there isn't much sense to have them printed anyway).
"""
return re.sub('<[^<]+?>', '', text)
|
apache-2.0
|
[
11490,
199,
3,
199,
3,
570,
26,
258,
2863,
14,
647,
199,
3,
199,
3,
23177,
4070,
26,
221,
15164,
2863,
5922,
3423,
1202,
701,
2895,
28396,
1233,
14,
199,
3,
199,
3,
3390,
26,
258,
961,
570,
365,
1777,
402,
13861,
706,
28396,
4223,
12,
436,
1077,
440,
506,
1202,
199,
3,
3698,
503,
7934,
18159,
14,
199,
3,
199,
11490,
199,
3,
199,
3,
1898,
6029,
13861,
706,
28396,
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,
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,
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,
3,
199,
11490,
199,
624,
199,
40,
8250,
2863,
9330,
1202,
701,
2895,
28396,
6426,
83,
14,
199,
624,
199,
199,
3,
199,
3,
2018,
1900,
13,
262,
4621,
199,
3,
199,
646,
747,
199,
646,
984,
199,
646,
5190,
199,
646,
24581,
199,
646,
3873,
199,
646,
295,
421,
199,
318,
365,
63,
8258,
837,
272,
408,
272,
1803,
715,
340,
314,
3734,
365,
15332,
5417,
14,
272,
408,
272,
372,
984,
14,
3246,
508,
298,
2676,
708,
2,
421,
199,
318,
876,
84,
3338,
63,
1971,
8,
476,
304,
272,
408,
272,
29206,
314,
1919,
543,
2399,
3464,
3307,
4453,
9432,
2385,
14,
272,
408,
272,
870,
408,
199,
2486,
5918,
199,
1726,
26,
4366,
83,
9,
450,
83,
199,
5,
83,
199,
2486,
5918,
199,
624,
450,
334,
476,
855,
533,
4914,
354,
3108,
444,
14,
1188,
12,
5190,
14,
908,
63,
2804,
1012,
421,
199,
318,
664,
63,
571,
63,
694,
837,
272,
408,
272,
27940,
314,
2895,
28396,
2446,
2082,
4079,
641,
1453,
17406,
2656,
14,
339,
2104,
5417,
20601,
12,
642,
1077,
506,
6020,
2839,
26,
398,
665,
1231,
3072,
26872,
436,
13303,
60,
28,
751,
3072,
5039,
3918,
60,
9187,
28396,
339,
2104,
13074,
20601,
12,
652,
911,
506,
26,
398,
1182,
4219,
8316,
751,
30,
8083,
9187,
28396,
15,
272,
408,
272,
340,
365,
63,
8258,
837,
267,
931,
275,
747,
14,
515,
14,
904,
8,
736,
14,
2314,
459,
28057,
995,
298,
9187,
28396,
531,
272,
587,
26,
267,
931,
275,
747,
14,
515,
14,
904,
8,
736,
14,
2314,
459,
9524,
995,
3680,
9187,
28396,
531,
339,
327,
1218,
340,
3964,
272,
340,
440,
747,
14,
515,
14,
2444,
8,
515,
304,
267,
327,
4983,
2552,
2348,
911,
2951,
19843,
1125,
267,
747,
14,
8215,
8,
515,
9,
339,
372,
931,
421,
199,
318,
664,
63,
808,
63,
694,
837,
272,
408,
272,
27940,
314,
7937,
4079,
641,
1453,
17406,
2656,
14,
339,
2104,
5417,
20601,
12,
642,
1077,
506,
6020,
2839,
26,
398,
665,
1231,
3072,
26872,
436,
13303,
60,
28,
751,
3072,
5339,
13303,
60,
6530,
339,
2104,
13074,
20601,
12,
652,
911,
506,
26,
398,
1182,
2791,
15,
339,
408,
272,
340,
365,
63,
8258,
837,
267,
931,
275,
747,
14,
2314,
459,
17983,
418,
272,
587,
26,
267,
931,
275,
3286,
2791,
2,
339,
372,
931,
421,
199,
318,
22221,
63,
875,
8,
13572,
63,
505,
304,
272,
408,
272,
1910,
3765,
3326,
14,
961,
365,
2997,
367,
5560,
1380,
666,
626,
4839,
370,
506,
272,
9080,
641,
6426,
365,
11077,
367,
4163,
503,
3050,
8292,
14,
339,
10961,
15810,
365,
9394,
2348,
12,
4066,
465,
2005,
4163,
3762,
26,
398,
627,
665,
3289,
6244,
8717,
370,
971,
78,
272,
408,
272,
625,
13572,
275,
11077,
63,
505,
272,
862,
26,
267,
625,
13572,
275,
24581,
14,
27375,
1252,
22726,
8,
13572,
63,
505,
9,
267,
327,
3350,
4750,
2863,
4163,
666,
267,
625,
13572,
275,
625,
13572,
14,
1814,
4827,
3289,
4206,
1557,
78,
358,
267,
625,
13572,
275,
625,
13572,
14,
1814,
4827,
3289,
3133,
297,
1557,
78,
358,
267,
625,
13572,
275,
625,
13572,
14,
1814,
4827,
3289,
1182,
4206,
1557,
78,
358,
267,
625,
13572,
275,
625,
13572,
14,
2708,
360,
875,
63,
3765,
358,
272,
871,
26,
267,
327,
267,
327,
982,
2337,
4898,
2552,
2348,
12,
2951,
3686,
3062,
436,
862,
370,
8120,
1771,
267,
327,
314,
1059,
314,
5526,
652,
4293,
886,
267,
327,
267,
986,
272,
372,
625,
13572,
421,
199,
318,
664,
63,
2977,
63,
4511,
8,
2977,
304,
272,
408,
272,
1803,
314,
4739,
402,
314,
5382,
12,
4066,
465,
315,
413,
270,
12,
499,
977,
12,
2263,
272,
408,
272,
340,
5382,
315,
334,
17,
12,
4119,
12,
7829,
12,
7105,
304,
267,
372,
283,
270,
7,
272,
916,
5382,
315,
334,
18,
12,
3144,
12,
6928,
304,
267,
372,
283,
977,
7,
272,
916,
5382,
315,
334,
19,
12,
4944,
12,
6546,
304,
267,
372,
283,
6883,
7,
272,
587,
26,
267,
372,
283,
273,
7,
421,
199,
318,
5341,
63,
5641,
8,
1760,
12,
3686,
63,
2550,
29,
797,
304,
272,
408,
272,
5870,
12981,
370,
5341,
5218,
3718,
14,
272,
982,
658,
4247,
63,
2550,
64,
365,
3055,
334,
885,
9,
2552,
2348,
911,
506,
14031,
12,
436,
272,
1471,
506,
10184,
7814,
3163,
12,
370,
4868,
5576,
1245,
370,
1284,
13,
751,
14,
339,
710,
658,
1760,
64,
1423,
1471,
506,
376,
1625,
12,
7871,
367,
3873,
14,
7942,
14,
272,
982,
1265,
787,
440,
3238,
641,
4212,
370,
886,
626,
12,
2951,
675,
26,
221,
16701,
14,
1294,
8,
875,
680,
272,
408,
272,
862,
26,
267,
299,
275,
3873,
14,
7942,
8,
1760,
12,
9009,
29,
5781,
14,
6089,
12,
355,
3839,
29,
5781,
14,
6089,
12,
4002,
63,
14240,
29,
549,
9,
267,
734,
12,
636,
275,
299,
14,
10664,
342,
272,
871,
2186,
12,
325,
26,
267,
340
] |
[
199,
3,
199,
3,
570,
26,
258,
2863,
14,
647,
199,
3,
199,
3,
23177,
4070,
26,
221,
15164,
2863,
5922,
3423,
1202,
701,
2895,
28396,
1233,
14,
199,
3,
199,
3,
3390,
26,
258,
961,
570,
365,
1777,
402,
13861,
706,
28396,
4223,
12,
436,
1077,
440,
506,
1202,
199,
3,
3698,
503,
7934,
18159,
14,
199,
3,
199,
11490,
199,
3,
199,
3,
1898,
6029,
13861,
706,
28396,
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,
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,
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,
3,
199,
11490,
199,
624,
199,
40,
8250,
2863,
9330,
1202,
701,
2895,
28396,
6426,
83,
14,
199,
624,
199,
199,
3,
199,
3,
2018,
1900,
13,
262,
4621,
199,
3,
199,
646,
747,
199,
646,
984,
199,
646,
5190,
199,
646,
24581,
199,
646,
3873,
199,
646,
295,
421,
199,
318,
365,
63,
8258,
837,
272,
408,
272,
1803,
715,
340,
314,
3734,
365,
15332,
5417,
14,
272,
408,
272,
372,
984,
14,
3246,
508,
298,
2676,
708,
2,
421,
199,
318,
876,
84,
3338,
63,
1971,
8,
476,
304,
272,
408,
272,
29206,
314,
1919,
543,
2399,
3464,
3307,
4453,
9432,
2385,
14,
272,
408,
272,
870,
408,
199,
2486,
5918,
199,
1726,
26,
4366,
83,
9,
450,
83,
199,
5,
83,
199,
2486,
5918,
199,
624,
450,
334,
476,
855,
533,
4914,
354,
3108,
444,
14,
1188,
12,
5190,
14,
908,
63,
2804,
1012,
421,
199,
318,
664,
63,
571,
63,
694,
837,
272,
408,
272,
27940,
314,
2895,
28396,
2446,
2082,
4079,
641,
1453,
17406,
2656,
14,
339,
2104,
5417,
20601,
12,
642,
1077,
506,
6020,
2839,
26,
398,
665,
1231,
3072,
26872,
436,
13303,
60,
28,
751,
3072,
5039,
3918,
60,
9187,
28396,
339,
2104,
13074,
20601,
12,
652,
911,
506,
26,
398,
1182,
4219,
8316,
751,
30,
8083,
9187,
28396,
15,
272,
408,
272,
340,
365,
63,
8258,
837,
267,
931,
275,
747,
14,
515,
14,
904,
8,
736,
14,
2314,
459,
28057,
995,
298,
9187,
28396,
531,
272,
587,
26,
267,
931,
275,
747,
14,
515,
14,
904,
8,
736,
14,
2314,
459,
9524,
995,
3680,
9187,
28396,
531,
339,
327,
1218,
340,
3964,
272,
340,
440,
747,
14,
515,
14,
2444,
8,
515,
304,
267,
327,
4983,
2552,
2348,
911,
2951,
19843,
1125,
267,
747,
14,
8215,
8,
515,
9,
339,
372,
931,
421,
199,
318,
664,
63,
808,
63,
694,
837,
272,
408,
272,
27940,
314,
7937,
4079,
641,
1453,
17406,
2656,
14,
339,
2104,
5417,
20601,
12,
642,
1077,
506,
6020,
2839,
26,
398,
665,
1231,
3072,
26872,
436,
13303,
60,
28,
751,
3072,
5339,
13303,
60,
6530,
339,
2104,
13074,
20601,
12,
652,
911,
506,
26,
398,
1182,
2791,
15,
339,
408,
272,
340,
365,
63,
8258,
837,
267,
931,
275,
747,
14,
2314,
459,
17983,
418,
272,
587,
26,
267,
931,
275,
3286,
2791,
2,
339,
372,
931,
421,
199,
318,
22221,
63,
875,
8,
13572,
63,
505,
304,
272,
408,
272,
1910,
3765,
3326,
14,
961,
365,
2997,
367,
5560,
1380,
666,
626,
4839,
370,
506,
272,
9080,
641,
6426,
365,
11077,
367,
4163,
503,
3050,
8292,
14,
339,
10961,
15810,
365,
9394,
2348,
12,
4066,
465,
2005,
4163,
3762,
26,
398,
627,
665,
3289,
6244,
8717,
370,
971,
78,
272,
408,
272,
625,
13572,
275,
11077,
63,
505,
272,
862,
26,
267,
625,
13572,
275,
24581,
14,
27375,
1252,
22726,
8,
13572,
63,
505,
9,
267,
327,
3350,
4750,
2863,
4163,
666,
267,
625,
13572,
275,
625,
13572,
14,
1814,
4827,
3289,
4206,
1557,
78,
358,
267,
625,
13572,
275,
625,
13572,
14,
1814,
4827,
3289,
3133,
297,
1557,
78,
358,
267,
625,
13572,
275,
625,
13572,
14,
1814,
4827,
3289,
1182,
4206,
1557,
78,
358,
267,
625,
13572,
275,
625,
13572,
14,
2708,
360,
875,
63,
3765,
358,
272,
871,
26,
267,
327,
267,
327,
982,
2337,
4898,
2552,
2348,
12,
2951,
3686,
3062,
436,
862,
370,
8120,
1771,
267,
327,
314,
1059,
314,
5526,
652,
4293,
886,
267,
327,
267,
986,
272,
372,
625,
13572,
421,
199,
318,
664,
63,
2977,
63,
4511,
8,
2977,
304,
272,
408,
272,
1803,
314,
4739,
402,
314,
5382,
12,
4066,
465,
315,
413,
270,
12,
499,
977,
12,
2263,
272,
408,
272,
340,
5382,
315,
334,
17,
12,
4119,
12,
7829,
12,
7105,
304,
267,
372,
283,
270,
7,
272,
916,
5382,
315,
334,
18,
12,
3144,
12,
6928,
304,
267,
372,
283,
977,
7,
272,
916,
5382,
315,
334,
19,
12,
4944,
12,
6546,
304,
267,
372,
283,
6883,
7,
272,
587,
26,
267,
372,
283,
273,
7,
421,
199,
318,
5341,
63,
5641,
8,
1760,
12,
3686,
63,
2550,
29,
797,
304,
272,
408,
272,
5870,
12981,
370,
5341,
5218,
3718,
14,
272,
982,
658,
4247,
63,
2550,
64,
365,
3055,
334,
885,
9,
2552,
2348,
911,
506,
14031,
12,
436,
272,
1471,
506,
10184,
7814,
3163,
12,
370,
4868,
5576,
1245,
370,
1284,
13,
751,
14,
339,
710,
658,
1760,
64,
1423,
1471,
506,
376,
1625,
12,
7871,
367,
3873,
14,
7942,
14,
272,
982,
1265,
787,
440,
3238,
641,
4212,
370,
886,
626,
12,
2951,
675,
26,
221,
16701,
14,
1294,
8,
875,
680,
272,
408,
272,
862,
26,
267,
299,
275,
3873,
14,
7942,
8,
1760,
12,
9009,
29,
5781,
14,
6089,
12,
355,
3839,
29,
5781,
14,
6089,
12,
4002,
63,
14240,
29,
549,
9,
267,
734,
12,
636,
275,
299,
14,
10664,
342,
272,
871,
2186,
12,
325,
26,
267,
340,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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ors/py/fckcommands.py
|
48
|
6335
|
#!/usr/bin/env python
"""
FCKeditor - The text editor for Internet - http://www.fckeditor.net
Copyright (C) 2003-2010 Frederico Caldeira Knabben
== BEGIN LICENSE ==
Licensed under the terms of any of the following licenses at your
choice:
- GNU General Public License Version 2 or later (the "GPL")
http://www.gnu.org/licenses/gpl.html
- GNU Lesser General Public License Version 2.1 or later (the "LGPL")
http://www.gnu.org/licenses/lgpl.html
- Mozilla Public License Version 1.1 or later (the "MPL")
http://www.mozilla.org/MPL/MPL-1.1.html
== END LICENSE ==
Connector for Python (CGI and WSGI).
"""
import os
try: # Windows needs stdio set for binary mode for file upload to work.
import msvcrt
msvcrt.setmode (0, os.O_BINARY) # stdin = 0
msvcrt.setmode (1, os.O_BINARY) # stdout = 1
except ImportError:
pass
from fckutil import *
from fckoutput import *
import config as Config
class GetFoldersCommandMixin (object):
def getFolders(self, resourceType, currentFolder):
"""
Purpose: command to recieve a list of folders
"""
# Map the virtual path to our local server
serverPath = mapServerFolder(self.userFilesFolder,currentFolder)
s = """<Folders>""" # Open the folders node
for someObject in os.listdir(serverPath):
someObjectPath = mapServerFolder(serverPath, someObject)
if os.path.isdir(someObjectPath):
s += """<Folder name="%s" />""" % (
convertToXmlAttribute(someObject)
)
s += """</Folders>""" # Close the folders node
return s
class GetFoldersAndFilesCommandMixin (object):
def getFoldersAndFiles(self, resourceType, currentFolder):
"""
Purpose: command to recieve a list of folders and files
"""
# Map the virtual path to our local server
serverPath = mapServerFolder(self.userFilesFolder,currentFolder)
# Open the folders / files node
folders = """<Folders>"""
files = """<Files>"""
for someObject in os.listdir(serverPath):
someObjectPath = mapServerFolder(serverPath, someObject)
if os.path.isdir(someObjectPath):
folders += """<Folder name="%s" />""" % (
convertToXmlAttribute(someObject)
)
elif os.path.isfile(someObjectPath):
size = os.path.getsize(someObjectPath)
if size > 0:
size = round(size/1024)
if size < 1:
size = 1
files += """<File name="%s" size="%d" />""" % (
convertToXmlAttribute(someObject),
size
)
# Close the folders / files node
folders += """</Folders>"""
files += """</Files>"""
return folders + files
class CreateFolderCommandMixin (object):
def createFolder(self, resourceType, currentFolder):
"""
Purpose: command to create a new folder
"""
errorNo = 0; errorMsg ='';
if self.request.has_key("NewFolderName"):
newFolder = self.request.get("NewFolderName", None)
newFolder = sanitizeFolderName (newFolder)
try:
newFolderPath = mapServerFolder(self.userFilesFolder, combinePaths(currentFolder, newFolder))
self.createServerFolder(newFolderPath)
except Exception, e:
errorMsg = str(e).decode('iso-8859-1').encode('utf-8') # warning with encodigns!!!
if hasattr(e,'errno'):
if e.errno==17: #file already exists
errorNo=0
elif e.errno==13: # permission denied
errorNo = 103
elif e.errno==36 or e.errno==2 or e.errno==22: # filename too long / no such file / invalid name
errorNo = 102
else:
errorNo = 110
else:
errorNo = 102
return self.sendErrorNode ( errorNo, errorMsg )
def createServerFolder(self, folderPath):
"Purpose: physically creates a folder on the server"
# No need to check if the parent exists, just create all hierachy
try:
permissions = Config.ChmodOnFolderCreate
if not permissions:
os.makedirs(folderPath)
except AttributeError: #ChmodOnFolderCreate undefined
permissions = 0755
if permissions:
oldumask = os.umask(0)
os.makedirs(folderPath,mode=0755)
os.umask( oldumask )
class UploadFileCommandMixin (object):
def uploadFile(self, resourceType, currentFolder):
"""
Purpose: command to upload files to server (same as FileUpload)
"""
errorNo = 0
if self.request.has_key("NewFile"):
# newFile has all the contents we need
newFile = self.request.get("NewFile", "")
# Get the file name
newFileName = newFile.filename
newFileName = sanitizeFileName( newFileName )
newFileNameOnly = removeExtension(newFileName)
newFileExtension = getExtension(newFileName).lower()
allowedExtensions = Config.AllowedExtensions[resourceType]
deniedExtensions = Config.DeniedExtensions[resourceType]
if (allowedExtensions):
# Check for allowed
isAllowed = False
if (newFileExtension in allowedExtensions):
isAllowed = True
elif (deniedExtensions):
# Check for denied
isAllowed = True
if (newFileExtension in deniedExtensions):
isAllowed = False
else:
# No extension limitations
isAllowed = True
if (isAllowed):
# Upload to operating system
# Map the virtual path to the local server path
currentFolderPath = mapServerFolder(self.userFilesFolder, currentFolder)
i = 0
while (True):
newFilePath = os.path.join (currentFolderPath,newFileName)
if os.path.exists(newFilePath):
i += 1
newFileName = "%s(%d).%s" % (
newFileNameOnly, i, newFileExtension
)
errorNo= 201 # file renamed
else:
# Read file contents and write to the desired path (similar to php's move_uploaded_file)
fout = file(newFilePath, 'wb')
while (True):
chunk = newFile.file.read(100000)
if not chunk: break
fout.write (chunk)
fout.close()
if os.path.exists ( newFilePath ):
doChmod = False
try:
doChmod = Config.ChmodOnUpload
permissions = Config.ChmodOnUpload
except AttributeError: #ChmodOnUpload undefined
doChmod = True
permissions = 0755
if ( doChmod ):
oldumask = os.umask(0)
os.chmod( newFilePath, permissions )
os.umask( oldumask )
newFileUrl = combinePaths(self.webUserFilesFolder, currentFolder) + newFileName
return self.sendUploadResults( errorNo , newFileUrl, newFileName )
else:
return self.sendUploadResults( errorNo = 202, customMsg = "" )
else:
return self.sendUploadResults( errorNo = 202, customMsg = "No File" )
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
624,
199,
4161,
1136,
27050,
446,
710,
1318,
8823,
367,
22026,
446,
1455,
921,
1544,
14,
70,
346,
7515,
14,
846,
199,
7384,
334,
35,
9,
13004,
13,
6542,
481,
264,
9910,
331,
8256,
271,
20936,
1804,
78,
12198,
287,
199,
199,
389,
16427,
5113,
508,
199,
199,
31661,
1334,
314,
2895,
402,
1263,
402,
314,
2569,
12378,
737,
2195,
199,
5095,
26,
199,
199,
13,
1664,
1696,
1684,
844,
3394,
499,
503,
2945,
334,
1589,
298,
12006,
531,
199,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
14,
1360,
199,
199,
13,
1664,
6401,
1696,
1684,
844,
3394,
499,
14,
17,
503,
2945,
334,
1589,
298,
44,
12006,
531,
199,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
9783,
1168,
14,
1360,
199,
199,
13,
17728,
1684,
844,
3394,
413,
14,
17,
503,
2945,
334,
1589,
298,
3950,
531,
199,
1014,
921,
1544,
14,
12102,
14,
1308,
15,
3950,
15,
3950,
13,
17,
14,
17,
14,
1360,
199,
199,
389,
7729,
5113,
508,
199,
199,
20476,
367,
2018,
334,
21337,
436,
9279,
680,
199,
199,
624,
199,
199,
646,
747,
199,
893,
26,
327,
5417,
4839,
410,
3006,
663,
367,
3366,
818,
367,
570,
5802,
370,
1736,
14,
199,
198,
646,
31756,
199,
198,
706,
86,
16617,
14,
409,
632,
334,
16,
12,
747,
14,
47,
63,
13246,
9,
327,
9009,
221,
275,
378,
199,
198,
706,
86,
16617,
14,
409,
632,
334,
17,
12,
747,
14,
47,
63,
13246,
9,
327,
3839,
275,
413,
199,
2590,
3545,
26,
199,
198,
1529,
199,
199,
504,
289,
346,
1974,
492,
627,
199,
504,
289,
346,
1199,
492,
627,
199,
646,
1101,
465,
4094,
199,
199,
533,
2372,
7850,
83,
3110,
4256,
334,
785,
304,
199,
198,
318,
664,
7850,
83,
8,
277,
12,
2073,
804,
12,
1453,
7850,
304,
507,
198,
624,
507,
198,
14959,
4070,
26,
1414,
370,
295,
559,
4754,
282,
769,
402,
16533,
507,
198,
624,
507,
198,
3,
9672,
314,
5791,
931,
370,
4154,
2257,
1654,
507,
198,
1000,
2042,
275,
2341,
3120,
7850,
8,
277,
14,
751,
5535,
7850,
12,
1818,
7850,
9,
507,
198,
83,
275,
8894,
7850,
83,
11193,
198,
327,
3232,
314,
16533,
1031,
507,
198,
509,
2005,
1692,
315,
747,
14,
7374,
8,
1000,
2042,
304,
686,
198,
3972,
1692,
2042,
275,
2341,
3120,
7850,
8,
1000,
2042,
12,
2005,
1692,
9,
686,
198,
692,
747,
14,
515,
14,
6027,
8,
3972,
1692,
2042,
304,
1585,
198,
83,
847,
8894,
7850,
536,
5961,
83,
2,
7082,
624,
450,
334,
4671,
198,
21880,
8672,
1646,
8,
3972,
1692,
9,
4671,
198,
9,
507,
198,
83,
847,
408,
1108,
7850,
83,
11193,
327,
15524,
314,
16533,
1031,
507,
198,
1107,
308,
199,
199,
533,
2372,
7850,
83,
3325,
5535,
3110,
4256,
334,
785,
304,
199,
198,
318,
664,
7850,
83,
3325,
5535,
8,
277,
12,
2073,
804,
12,
1453,
7850,
304,
507,
198,
624,
507,
198,
14959,
4070,
26,
1414,
370,
295,
559,
4754,
282,
769,
402,
16533,
436,
1584,
507,
198,
624,
507,
198,
3,
9672,
314,
5791,
931,
370,
4154,
2257,
1654,
507,
198,
1000,
2042,
275,
2341,
3120,
7850,
8,
277,
14,
751,
5535,
7850,
12,
1818,
7850,
9,
507,
198,
3,
3232,
314,
16533,
1182,
1584,
1031,
507,
198,
15171,
275,
8894,
7850,
83,
11193,
507,
198,
1725,
275,
8894,
5535,
11193,
507,
198,
509,
2005,
1692,
315,
747,
14,
7374,
8,
1000,
2042,
304,
686,
198,
3972,
1692,
2042,
275,
2341,
3120,
7850,
8,
1000,
2042,
12,
2005,
1692,
9,
686,
198,
692,
747,
14,
515,
14,
6027,
8,
3972,
1692,
2042,
304,
1585,
198,
15171,
847,
8894,
7850,
536,
5961,
83,
2,
7082,
624,
450,
334,
4671,
198,
21880,
8672,
1646,
8,
3972,
1692,
9,
4671,
198,
9,
686,
198,
4164,
747,
14,
515,
14,
6292,
8,
3972,
1692,
2042,
304,
1585,
198,
890,
275,
747,
14,
515,
14,
20733,
8,
3972,
1692,
2042,
9,
1585,
198,
692,
1568,
690,
378,
26,
1871,
198,
890,
275,
6168,
8,
890,
15,
7727,
9,
1871,
198,
692,
1568,
665,
413,
26,
4671,
198,
890,
275,
413,
1585,
198,
1725,
847,
8894,
1173,
536,
5961,
83,
2,
1568,
5961,
68,
2,
7082,
624,
450,
334,
4671,
198,
21880,
8672,
1646,
8,
3972,
1692,
395,
4671,
198,
890,
4671,
198,
9,
507,
198,
3,
15524,
314,
16533,
1182,
1584,
1031,
507,
198,
15171,
847,
408,
1108,
7850,
83,
11193,
507,
198,
1725,
847,
408,
1108,
5535,
11193,
507,
198,
1107,
16533,
435,
1584,
199,
199,
533,
2790,
7850,
3110,
4256,
334,
785,
304,
199,
198,
318,
1218,
7850,
8,
277,
12,
2073,
804,
12,
1453,
7850,
304,
507,
198,
624,
507,
198,
14959,
4070,
26,
1414,
370,
1218,
282,
892,
4922,
507,
198,
624,
507,
198,
705,
1944,
275,
378,
27,
1125,
6173,
275,
891,
27,
507,
198,
692,
291,
14,
1069,
14,
1989,
63,
498,
480,
4665,
7850,
985,
2349,
686,
198,
1222,
7850,
275,
291,
14,
1069,
14,
362,
480,
4665,
7850,
985,
401,
488,
9,
686,
198,
1222,
7850,
275,
21077,
7850,
985,
334,
1222,
7850,
9,
686,
198,
893,
26,
1585,
198,
1222,
7850,
2042,
275,
2341,
3120,
7850,
8,
277,
14,
751,
5535,
7850,
12,
13323,
11804,
8,
1818,
7850,
12,
892,
7850,
430,
1585,
198,
277,
14,
981,
3120,
7850,
8,
1222,
7850,
2042,
9,
686,
198,
2590,
2186,
12,
325,
26,
1585,
198,
705,
6173,
275,
620,
8,
69,
680,
2708,
360,
4595,
13,
4830,
13,
17,
1959,
2143,
360,
1624,
13,
24,
358,
327,
5721,
543,
655,
331,
18367,
561,
21512,
1585,
198,
692,
2688,
8,
69,
2584,
7931,
735,
1871,
198,
692,
325,
14,
7931,
389,
1196,
26,
327,
493,
2575,
3495,
4671,
198,
705,
1944,
29,
16,
1871,
198,
4164,
325,
14,
7931,
389,
969,
26,
327,
4983,
23355,
4671,
198,
705,
1944,
275,
22363,
1871,
198,
4164,
325,
14,
7931,
389,
1344,
503,
325,
14,
7931,
389,
18,
503,
325,
14,
7931,
389,
1081,
26,
327,
1788,
4634,
1846,
1182,
949,
4066,
570,
1182,
3866,
536,
4671,
198,
705,
1944,
275,
12996,
1585,
198,
2836,
26,
1871,
198,
705,
1944
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
624,
199,
4161,
1136,
27050,
446,
710,
1318,
8823,
367,
22026,
446,
1455,
921,
1544,
14,
70,
346,
7515,
14,
846,
199,
7384,
334,
35,
9,
13004,
13,
6542,
481,
264,
9910,
331,
8256,
271,
20936,
1804,
78,
12198,
287,
199,
199,
389,
16427,
5113,
508,
199,
199,
31661,
1334,
314,
2895,
402,
1263,
402,
314,
2569,
12378,
737,
2195,
199,
5095,
26,
199,
199,
13,
1664,
1696,
1684,
844,
3394,
499,
503,
2945,
334,
1589,
298,
12006,
531,
199,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
14,
1360,
199,
199,
13,
1664,
6401,
1696,
1684,
844,
3394,
499,
14,
17,
503,
2945,
334,
1589,
298,
44,
12006,
531,
199,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
9783,
1168,
14,
1360,
199,
199,
13,
17728,
1684,
844,
3394,
413,
14,
17,
503,
2945,
334,
1589,
298,
3950,
531,
199,
1014,
921,
1544,
14,
12102,
14,
1308,
15,
3950,
15,
3950,
13,
17,
14,
17,
14,
1360,
199,
199,
389,
7729,
5113,
508,
199,
199,
20476,
367,
2018,
334,
21337,
436,
9279,
680,
199,
199,
624,
199,
199,
646,
747,
199,
893,
26,
327,
5417,
4839,
410,
3006,
663,
367,
3366,
818,
367,
570,
5802,
370,
1736,
14,
199,
198,
646,
31756,
199,
198,
706,
86,
16617,
14,
409,
632,
334,
16,
12,
747,
14,
47,
63,
13246,
9,
327,
9009,
221,
275,
378,
199,
198,
706,
86,
16617,
14,
409,
632,
334,
17,
12,
747,
14,
47,
63,
13246,
9,
327,
3839,
275,
413,
199,
2590,
3545,
26,
199,
198,
1529,
199,
199,
504,
289,
346,
1974,
492,
627,
199,
504,
289,
346,
1199,
492,
627,
199,
646,
1101,
465,
4094,
199,
199,
533,
2372,
7850,
83,
3110,
4256,
334,
785,
304,
199,
198,
318,
664,
7850,
83,
8,
277,
12,
2073,
804,
12,
1453,
7850,
304,
507,
198,
624,
507,
198,
14959,
4070,
26,
1414,
370,
295,
559,
4754,
282,
769,
402,
16533,
507,
198,
624,
507,
198,
3,
9672,
314,
5791,
931,
370,
4154,
2257,
1654,
507,
198,
1000,
2042,
275,
2341,
3120,
7850,
8,
277,
14,
751,
5535,
7850,
12,
1818,
7850,
9,
507,
198,
83,
275,
8894,
7850,
83,
11193,
198,
327,
3232,
314,
16533,
1031,
507,
198,
509,
2005,
1692,
315,
747,
14,
7374,
8,
1000,
2042,
304,
686,
198,
3972,
1692,
2042,
275,
2341,
3120,
7850,
8,
1000,
2042,
12,
2005,
1692,
9,
686,
198,
692,
747,
14,
515,
14,
6027,
8,
3972,
1692,
2042,
304,
1585,
198,
83,
847,
8894,
7850,
536,
5961,
83,
2,
7082,
624,
450,
334,
4671,
198,
21880,
8672,
1646,
8,
3972,
1692,
9,
4671,
198,
9,
507,
198,
83,
847,
408,
1108,
7850,
83,
11193,
327,
15524,
314,
16533,
1031,
507,
198,
1107,
308,
199,
199,
533,
2372,
7850,
83,
3325,
5535,
3110,
4256,
334,
785,
304,
199,
198,
318,
664,
7850,
83,
3325,
5535,
8,
277,
12,
2073,
804,
12,
1453,
7850,
304,
507,
198,
624,
507,
198,
14959,
4070,
26,
1414,
370,
295,
559,
4754,
282,
769,
402,
16533,
436,
1584,
507,
198,
624,
507,
198,
3,
9672,
314,
5791,
931,
370,
4154,
2257,
1654,
507,
198,
1000,
2042,
275,
2341,
3120,
7850,
8,
277,
14,
751,
5535,
7850,
12,
1818,
7850,
9,
507,
198,
3,
3232,
314,
16533,
1182,
1584,
1031,
507,
198,
15171,
275,
8894,
7850,
83,
11193,
507,
198,
1725,
275,
8894,
5535,
11193,
507,
198,
509,
2005,
1692,
315,
747,
14,
7374,
8,
1000,
2042,
304,
686,
198,
3972,
1692,
2042,
275,
2341,
3120,
7850,
8,
1000,
2042,
12,
2005,
1692,
9,
686,
198,
692,
747,
14,
515,
14,
6027,
8,
3972,
1692,
2042,
304,
1585,
198,
15171,
847,
8894,
7850,
536,
5961,
83,
2,
7082,
624,
450,
334,
4671,
198,
21880,
8672,
1646,
8,
3972,
1692,
9,
4671,
198,
9,
686,
198,
4164,
747,
14,
515,
14,
6292,
8,
3972,
1692,
2042,
304,
1585,
198,
890,
275,
747,
14,
515,
14,
20733,
8,
3972,
1692,
2042,
9,
1585,
198,
692,
1568,
690,
378,
26,
1871,
198,
890,
275,
6168,
8,
890,
15,
7727,
9,
1871,
198,
692,
1568,
665,
413,
26,
4671,
198,
890,
275,
413,
1585,
198,
1725,
847,
8894,
1173,
536,
5961,
83,
2,
1568,
5961,
68,
2,
7082,
624,
450,
334,
4671,
198,
21880,
8672,
1646,
8,
3972,
1692,
395,
4671,
198,
890,
4671,
198,
9,
507,
198,
3,
15524,
314,
16533,
1182,
1584,
1031,
507,
198,
15171,
847,
408,
1108,
7850,
83,
11193,
507,
198,
1725,
847,
408,
1108,
5535,
11193,
507,
198,
1107,
16533,
435,
1584,
199,
199,
533,
2790,
7850,
3110,
4256,
334,
785,
304,
199,
198,
318,
1218,
7850,
8,
277,
12,
2073,
804,
12,
1453,
7850,
304,
507,
198,
624,
507,
198,
14959,
4070,
26,
1414,
370,
1218,
282,
892,
4922,
507,
198,
624,
507,
198,
705,
1944,
275,
378,
27,
1125,
6173,
275,
891,
27,
507,
198,
692,
291,
14,
1069,
14,
1989,
63,
498,
480,
4665,
7850,
985,
2349,
686,
198,
1222,
7850,
275,
291,
14,
1069,
14,
362,
480,
4665,
7850,
985,
401,
488,
9,
686,
198,
1222,
7850,
275,
21077,
7850,
985,
334,
1222,
7850,
9,
686,
198,
893,
26,
1585,
198,
1222,
7850,
2042,
275,
2341,
3120,
7850,
8,
277,
14,
751,
5535,
7850,
12,
13323,
11804,
8,
1818,
7850,
12,
892,
7850,
430,
1585,
198,
277,
14,
981,
3120,
7850,
8,
1222,
7850,
2042,
9,
686,
198,
2590,
2186,
12,
325,
26,
1585,
198,
705,
6173,
275,
620,
8,
69,
680,
2708,
360,
4595,
13,
4830,
13,
17,
1959,
2143,
360,
1624,
13,
24,
358,
327,
5721,
543,
655,
331,
18367,
561,
21512,
1585,
198,
692,
2688,
8,
69,
2584,
7931,
735,
1871,
198,
692,
325,
14,
7931,
389,
1196,
26,
327,
493,
2575,
3495,
4671,
198,
705,
1944,
29,
16,
1871,
198,
4164,
325,
14,
7931,
389,
969,
26,
327,
4983,
23355,
4671,
198,
705,
1944,
275,
22363,
1871,
198,
4164,
325,
14,
7931,
389,
1344,
503,
325,
14,
7931,
389,
18,
503,
325,
14,
7931,
389,
1081,
26,
327,
1788,
4634,
1846,
1182,
949,
4066,
570,
1182,
3866,
536,
4671,
198,
705,
1944,
275,
12996,
1585,
198,
2836,
26,
1871,
198,
705,
1944,
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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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
] |
Arno-Nymous/pyload
|
module/plugins/accounts/FastixRu.py
|
7
|
1982
|
# -*- coding: utf-8 -*-
from ..internal.misc import json
from ..internal.MultiAccount import MultiAccount
class FastixRu(MultiAccount):
__name__ = "FastixRu"
__type__ = "account"
__version__ = "0.12"
__status__ = "testing"
__config__ = [("mh_mode", "all;listed;unlisted", "Filter hosters to use", "all"),
("mh_list", "str", "Hoster list (comma separated)", ""),
("mh_interval", "int", "Reload interval in hours", 12)]
__description__ = """Fastix account plugin"""
__license__ = "GPLv3"
__authors__ = [("Massimo Rosamilia", "max@spiritix.eu")]
def grab_hosters(self, user, password, data):
html = self.load("http://fastix.ru/api_v2",
get={'apikey': "5182964c3f8f9a7f0b00000a_kelmFB4n1IrnCDYuIFn2y",
'sub': "allowed_sources"})
host_list = json.loads(html)
host_list = host_list['allow']
return host_list
def grab_info(self, user, password, data):
html = self.load("http://fastix.ru/api_v2/",
get={'apikey': data['apikey'],
'sub': "getaccountdetails"})
json_data = json.loads(html)
points = json_data['points']
kb = float(points) * 1024 ** 2 / 1000
if points > 0:
account_info = {'validuntil': -1, 'trafficleft': kb}
else:
account_info = {
'validuntil': None,
'trafficleft': None,
'premium': False}
return account_info
def signin(self, user, password, data):
html = self.load("https://fastix.ru/api_v2/",
get={'sub': "get_apikey",
'email': user,
'password': password})
api = json.loads(html)
if 'error' in api:
self.fail_login(api['error_txt'])
else:
data['apikey'] = api['apikey']
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
504,
2508,
4672,
14,
9923,
492,
2022,
199,
504,
2508,
4672,
14,
3947,
6009,
492,
6879,
6009,
421,
199,
533,
22613,
1148,
50,
85,
8,
3947,
6009,
304,
272,
636,
354,
363,
275,
298,
16976,
1148,
50,
85,
2,
272,
636,
466,
363,
275,
298,
2048,
2,
272,
636,
1023,
363,
275,
298,
16,
14,
713,
2,
272,
636,
1205,
363,
275,
298,
4776,
2,
339,
636,
888,
363,
275,
10003,
17077,
63,
632,
401,
298,
452,
27,
15023,
27,
324,
15023,
401,
298,
4131,
394,
736,
878,
370,
675,
401,
298,
452,
1288,
2116,
1689,
17077,
63,
513,
401,
298,
495,
401,
298,
40,
29895,
769,
334,
13184,
11673,
4186,
16241,
2116,
1689,
17077,
63,
4284,
401,
298,
442,
401,
298,
30590,
6252,
315,
10857,
401,
3144,
1874,
339,
636,
1802,
363,
275,
408,
16976,
1148,
2933,
3589,
624,
272,
636,
1682,
363,
275,
298,
28863,
19,
2,
272,
636,
8149,
363,
275,
10003,
45,
2608,
573,
820,
736,
455,
1638,
65,
401,
298,
988,
32,
8721,
322,
31625,
14,
16913,
11323,
339,
347,
18200,
63,
526,
83,
878,
8,
277,
12,
922,
12,
2505,
12,
666,
304,
267,
3517,
275,
291,
14,
912,
480,
1014,
921,
7015,
1148,
14,
6558,
15,
1246,
63,
86,
18,
401,
586,
664,
3713,
28181,
356,
298,
27015,
1398,
772,
67,
19,
70,
24,
70,
25,
65,
23,
70,
16,
66,
5345,
65,
63,
75,
21226,
8223,
20,
78,
17,
41,
11641,
7695,
24388,
4656,
78,
18,
89,
401,
2892,
283,
954,
356,
298,
6541,
63,
4553,
5984,
267,
1591,
63,
513,
275,
2022,
14,
3640,
8,
1360,
9,
267,
1591,
63,
513,
275,
1591,
63,
513,
459,
3306,
418,
267,
372,
1591,
63,
513,
339,
347,
18200,
63,
815,
8,
277,
12,
922,
12,
2505,
12,
666,
304,
267,
3517,
275,
291,
14,
912,
480,
1014,
921,
7015,
1148,
14,
6558,
15,
1246,
63,
86,
18,
10665,
586,
664,
3713,
28181,
356,
666,
459,
28181,
995,
2892,
283,
954,
356,
298,
362,
2048,
5087,
5984,
267,
2022,
63,
576,
275,
2022,
14,
3640,
8,
1360,
9,
398,
4501,
275,
2022,
63,
576,
459,
3438,
418,
267,
19932,
275,
2069,
8,
3438,
9,
627,
6619,
1011,
499,
1182,
5198,
398,
340,
4501,
690,
378,
26,
288,
2933,
63,
815,
275,
791,
1078,
8111,
356,
446,
17,
12,
283,
17297,
3039,
356,
19932,
93,
267,
587,
26,
288,
2933,
63,
815,
275,
469,
355,
283,
1078,
8111,
356,
488,
12,
355,
283,
17297,
3039,
356,
488,
12,
355,
283,
657,
23481,
356,
756,
93,
267,
372,
2933,
63,
815,
339,
347,
2070,
262,
8,
277,
12,
922,
12,
2505,
12,
666,
304,
267,
3517,
275,
291,
14,
912,
480,
2859,
921,
7015,
1148,
14,
6558,
15,
1246,
63,
86,
18,
10665,
586,
664,
3713,
954,
356,
298,
362,
63,
28181,
401,
2892,
283,
2123,
356,
922,
12,
2892,
283,
2060,
356,
2505,
1552,
267,
2986,
275,
2022,
14,
3640,
8,
1360,
9,
398,
340,
283,
705,
7,
315,
2986,
26,
288,
291,
14,
1633,
63,
2886,
8,
1246,
459,
705,
63,
2424,
1105,
398,
587,
26,
288,
666,
459,
28181,
418,
275,
2986,
459,
28181,
418,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
504,
2508,
4672,
14,
9923,
492,
2022,
199,
504,
2508,
4672,
14,
3947,
6009,
492,
6879,
6009,
421,
199,
533,
22613,
1148,
50,
85,
8,
3947,
6009,
304,
272,
636,
354,
363,
275,
298,
16976,
1148,
50,
85,
2,
272,
636,
466,
363,
275,
298,
2048,
2,
272,
636,
1023,
363,
275,
298,
16,
14,
713,
2,
272,
636,
1205,
363,
275,
298,
4776,
2,
339,
636,
888,
363,
275,
10003,
17077,
63,
632,
401,
298,
452,
27,
15023,
27,
324,
15023,
401,
298,
4131,
394,
736,
878,
370,
675,
401,
298,
452,
1288,
2116,
1689,
17077,
63,
513,
401,
298,
495,
401,
298,
40,
29895,
769,
334,
13184,
11673,
4186,
16241,
2116,
1689,
17077,
63,
4284,
401,
298,
442,
401,
298,
30590,
6252,
315,
10857,
401,
3144,
1874,
339,
636,
1802,
363,
275,
408,
16976,
1148,
2933,
3589,
624,
272,
636,
1682,
363,
275,
298,
28863,
19,
2,
272,
636,
8149,
363,
275,
10003,
45,
2608,
573,
820,
736,
455,
1638,
65,
401,
298,
988,
32,
8721,
322,
31625,
14,
16913,
11323,
339,
347,
18200,
63,
526,
83,
878,
8,
277,
12,
922,
12,
2505,
12,
666,
304,
267,
3517,
275,
291,
14,
912,
480,
1014,
921,
7015,
1148,
14,
6558,
15,
1246,
63,
86,
18,
401,
586,
664,
3713,
28181,
356,
298,
27015,
1398,
772,
67,
19,
70,
24,
70,
25,
65,
23,
70,
16,
66,
5345,
65,
63,
75,
21226,
8223,
20,
78,
17,
41,
11641,
7695,
24388,
4656,
78,
18,
89,
401,
2892,
283,
954,
356,
298,
6541,
63,
4553,
5984,
267,
1591,
63,
513,
275,
2022,
14,
3640,
8,
1360,
9,
267,
1591,
63,
513,
275,
1591,
63,
513,
459,
3306,
418,
267,
372,
1591,
63,
513,
339,
347,
18200,
63,
815,
8,
277,
12,
922,
12,
2505,
12,
666,
304,
267,
3517,
275,
291,
14,
912,
480,
1014,
921,
7015,
1148,
14,
6558,
15,
1246,
63,
86,
18,
10665,
586,
664,
3713,
28181,
356,
666,
459,
28181,
995,
2892,
283,
954,
356,
298,
362,
2048,
5087,
5984,
267,
2022,
63,
576,
275,
2022,
14,
3640,
8,
1360,
9,
398,
4501,
275,
2022,
63,
576,
459,
3438,
418,
267,
19932,
275,
2069,
8,
3438,
9,
627,
6619,
1011,
499,
1182,
5198,
398,
340,
4501,
690,
378,
26,
288,
2933,
63,
815,
275,
791,
1078,
8111,
356,
446,
17,
12,
283,
17297,
3039,
356,
19932,
93,
267,
587,
26,
288,
2933,
63,
815,
275,
469,
355,
283,
1078,
8111,
356,
488,
12,
355,
283,
17297,
3039,
356,
488,
12,
355,
283,
657,
23481,
356,
756,
93,
267,
372,
2933,
63,
815,
339,
347,
2070,
262,
8,
277,
12,
922,
12,
2505,
12,
666,
304,
267,
3517,
275,
291,
14,
912,
480,
2859,
921,
7015,
1148,
14,
6558,
15,
1246,
63,
86,
18,
10665,
586,
664,
3713,
954,
356,
298,
362,
63,
28181,
401,
2892,
283,
2123,
356,
922,
12,
2892,
283,
2060,
356,
2505,
1552,
267,
2986,
275,
2022,
14,
3640,
8,
1360,
9,
398,
340,
283,
705,
7,
315,
2986,
26,
288,
291,
14,
1633,
63,
2886,
8,
1246,
459,
705,
63,
2424,
1105,
398,
587,
26,
288,
666,
459,
28181,
418,
275,
2986,
459,
28181,
418,
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,
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,
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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
] |
prheenan/prhUtil
|
python/IgorUtil.py
|
2
|
8803
|
# force floating point division. Can still use integer with //
from __future__ import division
# This file is used for importing the common utilities classes.
import numpy as np
import matplotlib.pyplot as plt
# import the patrick-specific utilities
import GenUtilities as pGenUtil
import PlotUtilities as pPlotUtil
import CheckpointUtilities as pCheckUtil
from scipy.signal import savgol_filter
DEF_FILTER_CONST = 0.005 # 0.5%
BASE_GROUP = "/Volumes/group/4Patrick/"
SUBDIR_BINARIES = "PRH_AFM_Databases/BinaryFilesTimeSeparationForce/"
def getDatabaseFolder():
"""
Returns the location of the database binary folder location
Args:
None
Returns:
Where the database is, as a string.
"""
# XXX TODO: right now assumes mac-style mounting...
return BASE_GROUP + SUBDIR_BINARIES
def getDatabaseFile(fileName,extension=".hdf"):
"""
Returns the absolute path to a previously-saved file with the given filename
Path is *not* guaranteed to exist, if the file hasn't been saved already.
Args:
fileName: the name of the file (usually according to the "TraceData"
table, field "FileTimSepFor")
extension: the recquired extension
Returns:
Where the file is located, an absolute path. Doesn't guarantee the file
*does* exist, just that *if* it does, it would be there.
"""
fileWithExt = pGenUtil.ensureEnds(fileName,extension)
return getDatabaseFolder() + fileWithExt
def DemoDir():
'''
:return: the absolute path to the demo directory
'''
return BASE_GROUP + "DemoData/IgorDemos/"
# all demo directories should have an input and output directory
def GetDemoInOut(demoName,baseDir=DemoDir(),raiseOnError=True):
"""
Returns the demo input and output directories, given a path baseDir and
name demoName. Recquires files to exist at "<baseDir><demoName>". If
encountering an error (e.g. permissions, something isn't mounted), raises
an error.
Args:
demoName: The name of the demo. Assumed to be the subdir under "basedir"
we want to use
baseDir: the base directory. Input and output directories are
"<baseDir><demoName>Input/" and "<baseDir><demoName>Output/", resp.
raiseOnError : if true, raises an error on an OS. otherwise, just
prints a warning that something went wrong.
Returns:
tuple of <inputDir>,<outputDir>
"""
fullBase = baseDir + demoName
inputV = pGenUtil.getSanitaryPath(fullBase + "/Input/")
outputV = pGenUtil.getSanitaryPath(fullBase + "/Output/")
try:
pGenUtil.ensureDirExists(inputV)
pGenUtil.ensureDirExists(outputV)
except OSError as e:
if (raiseOnError):
raise(e)
print("Warning, couldn't open demo directories based in " + fullBase +
". Most likely, not connected to JILA network")
return inputV,outputV
def DemoJilaOrLocal(demoName,localPath):
"""
Looks for the demo dir in the default (jila-hosted) space. If nothing is
found, looks in the paths specified by localpath (where it puts input
and output directories according to its name)
Args:
demoName: see GetDemoInOut
localPath: equivalent of baseDir in GetDemoInOut. Where we put the input and Output directories for the unit test if JILA can't be found.
Returns:
tuple of <inputDir>,<outputDir>
"""
inDir,outDir = GetDemoInOut(demoName,raiseOnError=False)
if (not pGenUtil.dirExists(inDir)):
print("Warning: Couldn't connect to JILA's Network. Using local data.")
# get "sanitary paths" which as OS-indepdent (in theory..)
localPath = pGenUtil.ensureEnds(localPath,"/")
inDir = pGenUtil.getSanitaryPath(localPath)
outDir = pGenUtil.getSanitaryPath(localPath + "Output" + demoName +"/")
pGenUtil.ensureDirExists(outDir)
if (not pGenUtil.dirExists(inDir)):
# whoops...
raise IOError("Demo Directory {:s} not found anywhere.".\
format(inDir))
return inDir,outDir
# read a txt or similarly formatted file
def readIgorWave(mFile,skip_header=3,skip_footer=1,comments="X "):
data = np.genfromtxt(mFile,comments=comments,skip_header=skip_header,
skip_footer=skip_footer)
return data
def savitskyFilter(inData,nSmooth = None,degree=2):
if (nSmooth is None):
nSmooth = int(len(inData)/200)
# POST: have an nSmooth
if (nSmooth % 2 == 0):
# must be odd
nSmooth += 1
# get the filtered version of the data
return savgol_filter(inData,nSmooth,degree)
def SplitIntoApproachAndRetract(sep,force,sepToSplit=None):
'''
Given a full force/sep curve, returns the approach/retract
according to before/after sepToSplit, cutting out the surface (assumed
at minimm separation )
:param sep: the separation, units not important. minimum is surface
:param force: the force, units not important
:param sepToSplot: the separation where we think the surface is. same units
as sep
'''
# find where sep is closest to sepToSplit before/after minIdx (surface)
if (sepToSplit is None):
sepToSplit = np.min(sep)
surfIdx = np.argmin(sep)
sepAppr = sep[:surfIdx]
sepRetr = sep[surfIdx:]
apprIdx = np.argmin(np.abs(sepAppr-sepToSplit))
retrIdx = surfIdx + np.argmin(np.abs(sepRetr-sepToSplit))
forceAppr = force[:apprIdx]
forceRetr = force[retrIdx:]
sepAppr = sep[:apprIdx]
sepRetr = sep[retrIdx:]
return sepAppr,sepRetr,forceAppr,forceRetr
def NormalizeSepForce(sep,force,surfIdx=None,normalizeSep=True,
normalizeFor=True,sensibleUnits=True):
if (sensibleUnits):
sepUnits = sep * 1e9
forceUnits = force * 1e12
else:
sepUnits = sep
forceUnits= force
if (surfIdx is None):
surfIdx = np.argmin(sep)
if (normalizeSep):
sepUnits -= sepUnits[surfIdx]
if (normalizeFor):
# reverse: sort low to high
sortIdx = np.argsort(sep)[::-1]
# get the percentage of points we want
percent = 0.05
nPoints = int(percent*sortIdx.size)
idxForMedian = sortIdx[:nPoints]
# get the median force at these indices
forceMedUnits = np.median(forceUnits[idxForMedian])
# correct the force
forceUnits -= forceMedUnits
# multiply it by -1 (flip)
forceUnits *= -1
return sepUnits,forceUnits
# plot a force extension curve with approach and retract
def PlotFec(sep,force,surfIdx = None,normalizeSep=True,normalizeFor=True,
filterN=None,sensibleUnits=True):
"""
Plot a force extension curve
:param sep: The separation in meters
:param force: The force in meters
:param surfIdx: The index between approach and retract. if not present,
intuits approximate index from minmmum Sep
:param normalizeSep: If true, then zeros sep to its minimum
:paran normalizeFor: If true, then zeros force to the median-filtered last
5% of data, by separation (presummably, already detached)
:param filterT: Plots the raw data in grey, and filters
the force to the Number of points given. If none, assumes default % of curve
:param sensibleUnits: Plots in nm and pN, defaults to true
"""
if (surfIdx is None):
surfIdx = np.argmin(sep)
sepUnits,forceUnits = NormalizeSepForce(sep,force,surfIdx,normalizeSep,
normalizeFor,sensibleUnits)
if (filterN is None):
filterN = int(np.ceil(DEF_FILTER_CONST*sepUnits.size))
# POST: go ahead and normalize/color
sepAppr = sepUnits[:surfIdx]
sepRetr = sepUnits[surfIdx:]
forceAppr = forceUnits[:surfIdx]
forceRetr = forceUnits[surfIdx:]
PlotFilteredSepForce(sepAppr,forceAppr,filterN=filterN,color='r',
label="Approach")
PlotFilteredSepForce(sepRetr,forceRetr,filterN=filterN,color='b',
label="Retract")
plt.xlim([min(sepUnits),max(sepUnits)])
pPlotUtil.lazyLabel("Separation [nm]","Force [pN]","Force Extension Curve")
return sepUnits,forceUnits
def filterForce(force,filterN=None):
if (filterN is None):
filterN = int(np.ceil(DEF_FILTER_CONST*force.size))
return savitskyFilter(force,filterN)
def PlotFilteredSepForce(sep,force,filterN=None,labelRaw=None,
linewidthFilt=2.0,color='r',**kwargs):
forceFilt =filterForce(force,filterN)
plt.plot(sep,forceFilt,color=color,lw=linewidthFilt,**kwargs)
# plot the raw data as grey
plt.plot(sep,force,color='k',label=labelRaw,alpha=0.3)
return forceFilt
|
gpl-2.0
|
[
3,
3542,
8402,
2376,
4629,
14,
6855,
5139,
675,
3000,
543,
5001,
199,
504,
636,
2443,
363,
492,
4629,
199,
3,
961,
570,
365,
1202,
367,
16306,
314,
2863,
15841,
3992,
14,
199,
646,
2680,
465,
980,
199,
646,
8027,
14,
13563,
465,
4488,
199,
3,
492,
314,
12713,
27091,
13,
6100,
15841,
199,
646,
18870,
22905,
221,
465,
299,
8168,
9562,
199,
646,
14794,
22905,
465,
299,
10711,
9562,
199,
646,
2670,
1403,
22905,
465,
299,
1799,
9562,
199,
504,
7026,
14,
4653,
492,
308,
8595,
393,
63,
1541,
199,
5638,
63,
9905,
63,
13310,
275,
378,
14,
7972,
327,
378,
14,
21,
5,
199,
199,
5825,
63,
7823,
275,
3286,
32480,
15,
923,
15,
20,
48,
292,
27091,
6687,
199,
6348,
3022,
63,
9431,
25244,
275,
298,
3311,
40,
63,
5699,
45,
63,
7243,
83,
15,
6636,
5535,
1366,
12653,
425,
13606,
6687,
199,
199,
318,
664,
7243,
7850,
837,
272,
408,
272,
1803,
314,
2909,
402,
314,
3050,
3366,
4922,
2909,
2286,
3033,
26,
267,
488,
272,
1803,
26,
267,
17685,
314,
3050,
365,
12,
465,
282,
1059,
14,
5591,
408,
272,
327,
5787,
3254,
26,
2451,
3063,
15194,
4497,
13,
2487,
10760,
316,
1396,
272,
372,
19721,
63,
7823,
435,
7605,
3022,
63,
9431,
25244,
199,
199,
318,
664,
7243,
1173,
8,
15450,
12,
3435,
25356,
19912,
2349,
272,
408,
272,
1803,
314,
3679,
931,
370,
282,
10889,
13,
8420,
570,
543,
314,
1627,
1788,
272,
6912,
365,
627,
1397,
10,
17334,
370,
2187,
12,
340,
314,
570,
18699,
1133,
2757,
6290,
2575,
14,
2286,
3033,
26,
267,
18305,
26,
314,
536,
402,
314,
570,
334,
25118,
7182,
370,
314,
298,
3921,
1451,
2,
4960,
1817,
12,
901,
298,
1173,
23853,
23337,
1858,
531,
398,
3329,
26,
314,
6488,
1087,
3329,
272,
1803,
26,
267,
17685,
314,
570,
365,
16180,
12,
376,
3679,
931,
14,
12078,
78,
1133,
24197,
314,
570,
267,
627,
9105,
10,
2187,
12,
2951,
626,
627,
692,
10,
652,
1630,
12,
652,
3955,
506,
2337,
14,
272,
408,
272,
570,
3007,
4942,
275,
299,
8168,
9562,
14,
7505,
1327,
795,
8,
15450,
12,
3435,
9,
272,
372,
221,
664,
7243,
7850,
342,
435,
570,
3007,
4942,
199,
199,
318,
28939,
3567,
837,
272,
1449,
272,
520,
1107,
26,
314,
3679,
931,
370,
314,
14779,
2082,
272,
1449,
5591,
372,
19721,
63,
7823,
435,
298,
21493,
1451,
15,
41,
2904,
872,
16908,
6687,
199,
199,
3,
1006,
14779,
6602,
1077,
1172,
376,
1324,
436,
1072,
2082,
199,
318,
2372,
21493,
607,
2204,
8,
8768,
985,
12,
1095,
3567,
29,
21493,
3567,
1062,
3730,
3314,
547,
29,
549,
304,
272,
408,
272,
1803,
314,
14779,
1324,
436,
1072,
6602,
12,
1627,
282,
931,
1300,
3567,
436,
272,
536,
14779,
985,
14,
799,
67,
3340,
1584,
370,
2187,
737,
3886,
1095,
3567,
2535,
8768,
985,
23167,
982,
272,
655,
5337,
316,
376,
1125,
334,
69,
14,
71,
14,
3443,
12,
6020,
5712,
1133,
27979,
395,
6534,
272,
376,
1125,
14,
221,
2286,
3033,
26,
267,
14779,
985,
26,
710,
536,
402,
314,
14779,
14,
16269,
68,
370,
506,
314,
15488,
1334,
298,
12484,
2,
267,
781,
2934,
370,
675,
24807,
1300,
3567,
26,
314,
1300,
2082,
14,
6924,
436,
1072,
6602,
787,
267,
3886,
1095,
3567,
2535,
8768,
985,
30,
3205,
6687,
436,
3886,
1095,
3567,
2535,
8768,
985,
30,
2959,
10665,
3085,
14,
398,
746,
3314,
547,
520,
340,
2549,
12,
6534,
376,
1125,
641,
376,
4403,
14,
4257,
12,
2951,
267,
14767,
282,
5721,
626,
6020,
22396,
6835,
14,
5591,
1803,
26,
267,
2008,
402,
665,
1210,
3567,
32659,
1199,
3567,
30,
5591,
408,
272,
2615,
1563,
275,
221,
1300,
3567,
435,
14779,
985,
272,
1324,
54,
275,
299,
8168,
9562,
14,
362,
23906,
390,
695,
2042,
8,
2861,
1563,
435,
3286,
3205,
13589,
272,
1072,
54,
275,
299,
8168,
9562,
14,
362,
23906,
390,
695,
2042,
8,
2861,
1563,
435,
3286,
2959,
13589,
272,
862,
26,
267,
299,
8168,
9562,
14,
7505,
3567,
7965,
8,
1210,
54,
9,
267,
299,
8168,
9562,
14,
7505,
3567,
7965,
8,
1199,
54,
9,
272,
871,
6440,
465,
325,
26,
267,
340,
334,
3730,
3314,
547,
304,
288,
746,
8,
69,
9,
267,
870,
480,
3849,
12,
21554,
1133,
1551,
14779,
6602,
4079,
315,
298,
435,
2615,
1563,
435,
1598,
3680,
17536,
12060,
12,
440,
8539,
370,
1603,
1193,
33,
2784,
531,
272,
372,
1324,
54,
12,
1199,
54,
199,
199,
318,
28939,
42,
25330,
2844,
5339,
8,
8768,
985,
12,
1832,
2042,
304,
272,
408,
272,
12077,
83,
367,
314,
14779,
2935,
315,
314,
849,
334,
74,
25330,
13,
24127,
9,
4601,
14,
982,
6548,
365,
272,
1911,
12,
10734,
315,
314,
3792,
2013,
701,
2257,
515,
334,
4509,
652,
27000,
1324,
5591,
436,
1072,
6602,
7182,
370,
2399,
536,
9,
221,
2286,
3033,
26,
267,
14779,
985,
26,
1937,
2372,
21493,
607,
2204,
398,
2257,
2042,
26,
7353,
402,
1300,
3567,
315,
2372,
21493,
607,
2204,
14,
17685,
781,
5324,
314,
1324,
263,
436,
7242,
6602,
367,
314,
4137,
511,
340,
1603,
1193,
33,
883,
1133,
506,
1911,
14,
339,
1803,
26,
267,
2008,
402,
665,
1210,
3567,
32659,
1199,
3567,
30,
5591,
408,
272,
315,
3567,
12,
548,
3567,
275,
2372,
21493,
607,
2204,
8,
8768,
985,
12,
3730,
3314,
547,
29,
797,
9,
272,
340,
334,
1397,
299,
8168,
9562,
14,
694,
7965,
8,
262,
3567,
2298,
267,
870,
480,
3849,
26,
18615,
78,
1133,
4907,
370,
1603,
1193,
33,
1159,
7220,
14,
11719,
2257,
666,
2685,
267,
327,
664,
298,
18904,
390,
695,
3792,
2,
1314,
465,
4403,
13,
262,
2601,
1326,
334,
262,
30629,
703,
9,
267,
2257,
2042,
275,
299,
8168,
9562,
14,
7505,
1327,
795,
8,
1832,
2042,
4589,
13589,
267,
315,
3567,
275,
299,
8168,
9562,
14,
362,
23906,
390,
695,
2042,
8,
1832,
2042,
9,
267,
734,
3567,
275,
299,
8168,
9562,
14,
362,
23906,
390,
695,
2042,
8,
1832,
2042,
435,
298,
2959,
2,
435,
14779,
985,
435,
2,
13589,
267,
299,
8168,
9562,
14,
7505,
3567,
7965,
8,
548,
3567,
9,
267,
340,
334,
1397,
299,
8168,
9562,
14,
694,
7965,
8,
262,
3567,
2298,
288,
327,
3963
] |
[
3542,
8402,
2376,
4629,
14,
6855,
5139,
675,
3000,
543,
5001,
199,
504,
636,
2443,
363,
492,
4629,
199,
3,
961,
570,
365,
1202,
367,
16306,
314,
2863,
15841,
3992,
14,
199,
646,
2680,
465,
980,
199,
646,
8027,
14,
13563,
465,
4488,
199,
3,
492,
314,
12713,
27091,
13,
6100,
15841,
199,
646,
18870,
22905,
221,
465,
299,
8168,
9562,
199,
646,
14794,
22905,
465,
299,
10711,
9562,
199,
646,
2670,
1403,
22905,
465,
299,
1799,
9562,
199,
504,
7026,
14,
4653,
492,
308,
8595,
393,
63,
1541,
199,
5638,
63,
9905,
63,
13310,
275,
378,
14,
7972,
327,
378,
14,
21,
5,
199,
199,
5825,
63,
7823,
275,
3286,
32480,
15,
923,
15,
20,
48,
292,
27091,
6687,
199,
6348,
3022,
63,
9431,
25244,
275,
298,
3311,
40,
63,
5699,
45,
63,
7243,
83,
15,
6636,
5535,
1366,
12653,
425,
13606,
6687,
199,
199,
318,
664,
7243,
7850,
837,
272,
408,
272,
1803,
314,
2909,
402,
314,
3050,
3366,
4922,
2909,
2286,
3033,
26,
267,
488,
272,
1803,
26,
267,
17685,
314,
3050,
365,
12,
465,
282,
1059,
14,
5591,
408,
272,
327,
5787,
3254,
26,
2451,
3063,
15194,
4497,
13,
2487,
10760,
316,
1396,
272,
372,
19721,
63,
7823,
435,
7605,
3022,
63,
9431,
25244,
199,
199,
318,
664,
7243,
1173,
8,
15450,
12,
3435,
25356,
19912,
2349,
272,
408,
272,
1803,
314,
3679,
931,
370,
282,
10889,
13,
8420,
570,
543,
314,
1627,
1788,
272,
6912,
365,
627,
1397,
10,
17334,
370,
2187,
12,
340,
314,
570,
18699,
1133,
2757,
6290,
2575,
14,
2286,
3033,
26,
267,
18305,
26,
314,
536,
402,
314,
570,
334,
25118,
7182,
370,
314,
298,
3921,
1451,
2,
4960,
1817,
12,
901,
298,
1173,
23853,
23337,
1858,
531,
398,
3329,
26,
314,
6488,
1087,
3329,
272,
1803,
26,
267,
17685,
314,
570,
365,
16180,
12,
376,
3679,
931,
14,
12078,
78,
1133,
24197,
314,
570,
267,
627,
9105,
10,
2187,
12,
2951,
626,
627,
692,
10,
652,
1630,
12,
652,
3955,
506,
2337,
14,
272,
408,
272,
570,
3007,
4942,
275,
299,
8168,
9562,
14,
7505,
1327,
795,
8,
15450,
12,
3435,
9,
272,
372,
221,
664,
7243,
7850,
342,
435,
570,
3007,
4942,
199,
199,
318,
28939,
3567,
837,
272,
1449,
272,
520,
1107,
26,
314,
3679,
931,
370,
314,
14779,
2082,
272,
1449,
5591,
372,
19721,
63,
7823,
435,
298,
21493,
1451,
15,
41,
2904,
872,
16908,
6687,
199,
199,
3,
1006,
14779,
6602,
1077,
1172,
376,
1324,
436,
1072,
2082,
199,
318,
2372,
21493,
607,
2204,
8,
8768,
985,
12,
1095,
3567,
29,
21493,
3567,
1062,
3730,
3314,
547,
29,
549,
304,
272,
408,
272,
1803,
314,
14779,
1324,
436,
1072,
6602,
12,
1627,
282,
931,
1300,
3567,
436,
272,
536,
14779,
985,
14,
799,
67,
3340,
1584,
370,
2187,
737,
3886,
1095,
3567,
2535,
8768,
985,
23167,
982,
272,
655,
5337,
316,
376,
1125,
334,
69,
14,
71,
14,
3443,
12,
6020,
5712,
1133,
27979,
395,
6534,
272,
376,
1125,
14,
221,
2286,
3033,
26,
267,
14779,
985,
26,
710,
536,
402,
314,
14779,
14,
16269,
68,
370,
506,
314,
15488,
1334,
298,
12484,
2,
267,
781,
2934,
370,
675,
24807,
1300,
3567,
26,
314,
1300,
2082,
14,
6924,
436,
1072,
6602,
787,
267,
3886,
1095,
3567,
2535,
8768,
985,
30,
3205,
6687,
436,
3886,
1095,
3567,
2535,
8768,
985,
30,
2959,
10665,
3085,
14,
398,
746,
3314,
547,
520,
340,
2549,
12,
6534,
376,
1125,
641,
376,
4403,
14,
4257,
12,
2951,
267,
14767,
282,
5721,
626,
6020,
22396,
6835,
14,
5591,
1803,
26,
267,
2008,
402,
665,
1210,
3567,
32659,
1199,
3567,
30,
5591,
408,
272,
2615,
1563,
275,
221,
1300,
3567,
435,
14779,
985,
272,
1324,
54,
275,
299,
8168,
9562,
14,
362,
23906,
390,
695,
2042,
8,
2861,
1563,
435,
3286,
3205,
13589,
272,
1072,
54,
275,
299,
8168,
9562,
14,
362,
23906,
390,
695,
2042,
8,
2861,
1563,
435,
3286,
2959,
13589,
272,
862,
26,
267,
299,
8168,
9562,
14,
7505,
3567,
7965,
8,
1210,
54,
9,
267,
299,
8168,
9562,
14,
7505,
3567,
7965,
8,
1199,
54,
9,
272,
871,
6440,
465,
325,
26,
267,
340,
334,
3730,
3314,
547,
304,
288,
746,
8,
69,
9,
267,
870,
480,
3849,
12,
21554,
1133,
1551,
14779,
6602,
4079,
315,
298,
435,
2615,
1563,
435,
1598,
3680,
17536,
12060,
12,
440,
8539,
370,
1603,
1193,
33,
2784,
531,
272,
372,
1324,
54,
12,
1199,
54,
199,
199,
318,
28939,
42,
25330,
2844,
5339,
8,
8768,
985,
12,
1832,
2042,
304,
272,
408,
272,
12077,
83,
367,
314,
14779,
2935,
315,
314,
849,
334,
74,
25330,
13,
24127,
9,
4601,
14,
982,
6548,
365,
272,
1911,
12,
10734,
315,
314,
3792,
2013,
701,
2257,
515,
334,
4509,
652,
27000,
1324,
5591,
436,
1072,
6602,
7182,
370,
2399,
536,
9,
221,
2286,
3033,
26,
267,
14779,
985,
26,
1937,
2372,
21493,
607,
2204,
398,
2257,
2042,
26,
7353,
402,
1300,
3567,
315,
2372,
21493,
607,
2204,
14,
17685,
781,
5324,
314,
1324,
263,
436,
7242,
6602,
367,
314,
4137,
511,
340,
1603,
1193,
33,
883,
1133,
506,
1911,
14,
339,
1803,
26,
267,
2008,
402,
665,
1210,
3567,
32659,
1199,
3567,
30,
5591,
408,
272,
315,
3567,
12,
548,
3567,
275,
2372,
21493,
607,
2204,
8,
8768,
985,
12,
3730,
3314,
547,
29,
797,
9,
272,
340,
334,
1397,
299,
8168,
9562,
14,
694,
7965,
8,
262,
3567,
2298,
267,
870,
480,
3849,
26,
18615,
78,
1133,
4907,
370,
1603,
1193,
33,
1159,
7220,
14,
11719,
2257,
666,
2685,
267,
327,
664,
298,
18904,
390,
695,
3792,
2,
1314,
465,
4403,
13,
262,
2601,
1326,
334,
262,
30629,
703,
9,
267,
2257,
2042,
275,
299,
8168,
9562,
14,
7505,
1327,
795,
8,
1832,
2042,
4589,
13589,
267,
315,
3567,
275,
299,
8168,
9562,
14,
362,
23906,
390,
695,
2042,
8,
1832,
2042,
9,
267,
734,
3567,
275,
299,
8168,
9562,
14,
362,
23906,
390,
695,
2042,
8,
1832,
2042,
435,
298,
2959,
2,
435,
14779,
985,
435,
2,
13589,
267,
299,
8168,
9562,
14,
7505,
3567,
7965,
8,
548,
3567,
9,
267,
340,
334,
1397,
299,
8168,
9562,
14,
694,
7965,
8,
262,
3567,
2298,
288,
327,
3963,
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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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
diplomacy/research
|
diplomacy_research/players/player.py
|
1
|
20892
|
# ==============================================================================
# Copyright 2019 - Philip Paquette
#
# NOTICE: 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, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# ==============================================================================
""" Player
- Contains the abstract class representing a player
"""
from abc import abstractmethod, ABCMeta
import logging
from tornado import gen
from diplomacy import Game
from diplomacy_research.models.state_space import extract_state_proto, extract_phase_history_proto, \
extract_possible_orders_proto, get_orderable_locs_for_powers
from diplomacy_research.utils.model import strip_keys
from diplomacy_research.utils.openings import get_standard_openings
# Constants
LOGGER = logging.getLogger(__name__)
class Player(metaclass=ABCMeta):
""" Abstract Player Class """
def __init__(self, name=None):
""" Constructor """
self._player_seed = 0
self._noise = 0.
self._temperature = 0.
self._dropout_rate = 0.
self.name = name or self.__class__.__name__
# ---------- Properties -------------
@property
@abstractmethod
def is_trainable(self):
""" Returns a boolean that indicates if the player wants to be trained or not """
raise NotImplementedError()
@property
def player_seed(self):
""" Getter - player_seed """
return self._player_seed
@player_seed.setter
def player_seed(self, value):
""" Setter - player_seed """
self._player_seed = int(value)
@property
def noise(self):
""" Getter - noise """
return self._noise
@property
def temperature(self):
""" Getter - temperature """
return self._temperature
@property
def dropout_rate(self):
""" Getter - dropout_rate """
return self._dropout_rate
@property
def kwargs(self):
""" Getter - kwargs"""
return {'player_seed': self.player_seed,
'noise': self.noise,
'temperature': self.temperature,
'dropout_rate': self.dropout_rate}
# ---------- Methods -------------
@gen.coroutine
def get_orders(self, game, power_names, *, retry_on_failure=True, **kwargs):
""" Gets the orders the power(s) should play.
:param game: The game object
:param power_names: A list of power names we are playing, or alternatively a single power name.
:param retry_on_failure: Boolean that indicates to retry querying from the model if an error is encountered.
:param kwargs: Additional optional kwargs:
- player_seed: If set. Override the player_seed to use for the model based player.
- noise: If set. Override the noise to use for the model based player.
- temperature: If set. Override the temperature to use for the model based player.
- dropout_rate: If set. Override the dropout_rate to use for the model based player.
- with_draw: If set, also returns whether to accept a draw or not
:return: One of the following:
1) If power_name is a string and with_draw == False (or is not set):
- A list of orders the power should play
2) If power_name is a list and with_draw == False (or is not set):
- A list of list, which contains orders for each power
3) If power_name is a string and with_draw == True:
- A tuple of 1) the list of orders for the power, 2) a boolean to accept a draw or not
4) If power_name is a list and with_draw == True:
- A list of tuples, each tuple having the list of orders and the draw boolean
:type game: diplomacy.Game
"""
state_proto = extract_state_proto(game)
phase_history_proto = extract_phase_history_proto(game)
possible_orders_proto = extract_possible_orders_proto(game)
# Determining if we have a single or multiple powers
if not isinstance(power_names, list):
is_single_power = True
power_names = [power_names]
else:
is_single_power = False
# Getting orders (and optional draw)
orders_with_maybe_draw = yield [self.get_orders_with_proto(state_proto,
power_name,
phase_history_proto,
possible_orders_proto,
retry_on_failure=retry_on_failure,
**kwargs) for power_name in power_names]
# Returning a single instance, or a list
orders_with_maybe_draw = orders_with_maybe_draw[0] if is_single_power else orders_with_maybe_draw
return orders_with_maybe_draw
@gen.coroutine
def get_orders_with_proto(self, state_proto, power_name, phase_history_proto, possible_orders_proto, **kwargs):
""" Gets the orders the power should play
:param state_proto: A `.proto.game.State` representation of the state of the game.
:param power_name: The name of the power we are playing
:param phase_history_proto: A list of `.proto.game.PhaseHistory`. This represents prev phases.
:param possible_orders_proto: A `proto.game.PossibleOrders` object representing possible order for each loc.
:param kwargs: Additional optional kwargs:
- player_seed: If set. Override the player_seed to use for the model based player.
- noise: If set. Override the noise to use for the model based player.
- temperature: If set. Override the temperature to use for the model based player.
- dropout_rate: If set. Override the dropout_rate to use for the model based player.
- with_draw: If set, also returns if we should accept a draw or not.
- retry_on_failure: Boolean that indicates to retry querying from the model if an error is encountered.
:return: If with_draw is not set or is False:
- the list of orders the power should play (e.g. ['A PAR H', 'A MAR - BUR', ...])
If with_draw is set, a tuple consisting of
1) the list of orders the power should play (e.g. ['A PAR H', 'A MAR - BUR', ...])
2) a boolean that indicates if we should accept a draw or not
"""
with_draw = kwargs.get('with_draw', False)
orders, policy_details = yield self.get_orders_details_with_proto(state_proto,
power_name,
phase_history_proto,
possible_orders_proto,
**strip_keys(kwargs, ['with_state_value']))
# Returning orders, or orders and draw_action
if not with_draw:
return orders
return orders, policy_details['draw_action']
@gen.coroutine
def get_policy_details(self, game, power_names, *, retry_on_failure=True, **kwargs):
""" Gets the details of the current policy
:param game: The game object
:param power_names: A list of power names we are playing, or alternatively a single power name.
:param retry_on_failure: Boolean that indicates to retry querying from the model if an error is encountered.
:param kwargs: Additional optional kwargs:
- player_seed: If set. Override the player_seed to use for the model based player.
- noise: If set. Override the noise to use for the model based player.
- temperature: If set. Override the temperature to use for the model based player.
- dropout_rate: If set. Override the dropout_rate to use for the model based player.
:return: 1) If power_names is a string, the policy details
==> {'locs', 'tokens', 'log_probs', 'draw_action', 'draw_prob'}
2) If power_names is a list, a list of policy details, one for each power.
:type game: diplomacy.Game
"""
state_proto = extract_state_proto(game)
phase_history_proto = extract_phase_history_proto(game)
possible_orders_proto = extract_possible_orders_proto(game)
# Determining if we have a single or multiple powers
if not isinstance(power_names, list):
is_single_power = True
power_names = [power_names]
else:
is_single_power = False
# Getting policy details
policy_details = yield [self.get_policy_details_with_proto(state_proto,
power_name,
phase_history_proto,
possible_orders_proto,
retry_on_failure=retry_on_failure,
**kwargs)
for power_name in power_names]
policy_details = policy_details[0] if is_single_power else policy_details
return policy_details
@gen.coroutine
def get_policy_details_with_proto(self, state_proto, power_name, phase_history_proto, possible_orders_proto,
**kwargs):
""" Gets the details of the current policy
:param state_proto: A `.proto.game.State` representation of the state of the game.
:param power_name: The name of the power we are playing
:param phase_history_proto: A list of `.proto.game.PhaseHistory`. This represents prev phases.
:param possible_orders_proto: A `proto.game.PossibleOrders` object representing possible order for each loc.
:param kwargs: Additional optional kwargs:
- player_seed: If set. Override the player_seed to use for the model based player.
- noise: If set. Override the noise to use for the model based player.
- temperature: If set. Override the temperature to use for the model based player.
- dropout_rate: If set. Override the dropout_rate to use for the model based player.
- retry_on_failure: Boolean that indicates to retry querying from the model if an error is encountered.
:return: The policy details ==> {'locs', 'tokens', 'log_probs', 'draw_action', 'draw_prob'}
"""
_, policy_details = yield self.get_orders_details_with_proto(state_proto,
power_name,
phase_history_proto,
possible_orders_proto,
**strip_keys(kwargs, ['with_state_value']))
return policy_details
@abstractmethod
@gen.coroutine
def get_orders_details_with_proto(self, state_proto, power_name, phase_history_proto, possible_orders_proto,
**kwargs):
""" Gets the orders (and the corresponding policy details) for the locs the power should play.
:param state_proto: A `.proto.game.State` representation of the state of the game.
:param power_name: The name of the power we are playing
:param phase_history_proto: A list of `.proto.game.PhaseHistory`. This represents prev phases.
:param possible_orders_proto: A `proto.game.PossibleOrders` object representing possible order for each loc.
:param kwargs: Additional optional kwargs:
- player_seed: If set. Override the player_seed to use for the model based player.
- noise: If set. Override the noise to use for the model based player.
- temperature: If set. Override the temperature to use for the model based player.
- dropout_rate: If set. Override the dropout_rate to use for the model based player.
- with_state_value: Boolean that indicates to also query the value function.
- retry_on_failure: Boolean that indicates to retry querying from the model if an error is encountered.
:return: If with_state_value=False (default), a tuple consisting of:
1) The list of orders the power should play (e.g. ['A PAR H', 'A MAR - BUR', ...])
2) The policy details ==> {'locs', 'tokens', 'log_probs', 'draw_action', 'draw_prob'}
If with_state_value=True, a tuple consisting of:
1) The list of orders the power should play (e.g. ['A PAR H', 'A MAR - BUR', ...])
2) The policy details ==> {'locs', 'tokens', 'log_probs', 'draw_action', 'draw_prob'}
3) The state value for the given state
"""
raise NotImplementedError()
@gen.coroutine
def get_state_value(self, game, power_names, *, retry_on_failure=True, **kwargs):
""" Calculates the player's value of the state of the game for the given power(s)
:param game: A game object
:param power_names: A list of power names for which we want the value, or alternatively a single power name.
:param retry_on_failure: Boolean that indicates to retry querying from the model if an error is encountered.
:param kwargs: Additional optional kwargs:
- player_seed: If set. Override the player_seed to use for the model based player.
- noise: If set. Override the noise to use for the model based player.
- temperature: If set. Override the temperature to use for the model based player.
- dropout_rate: If set. Override the dropout_rate to use for the model based player.
:return: 1) If power_names is a string, a single float representing the value of the state for the power
2) If power_names is a list, a list of floats representing the value for each power.
:type game: diplomacy.Game
"""
state_proto = extract_state_proto(game)
phase_history_proto = extract_phase_history_proto(game)
possible_order_proto = extract_possible_orders_proto(game)
# Determining if we have a single or multiple powers
if not isinstance(power_names, list):
is_single_power = True
power_names = [power_names]
else:
is_single_power = False
# Getting state value
state_value = yield [self.get_state_value_with_proto(state_proto,
power_name,
phase_history_proto,
possible_order_proto,
retry_on_failure=retry_on_failure,
**kwargs)
for power_name in power_names]
state_value = state_value[0] if is_single_power else state_value
return state_value
@abstractmethod
@gen.coroutine
def get_state_value_with_proto(self, state_proto, power_name, phase_history_proto, possible_orders_proto=None,
**kwargs):
""" Calculates the player's value of the state of the game for a given power
:param state_proto: A `.proto.game.State` representation of the state of the game.
:param power_name: The power name for which we want to retrieve the value
:param phase_history_proto: A list of `.proto.game.PhaseHistory`. This represents prev phases.
:param possible_orders_proto: A `proto.game.PossibleOrders` object representing possible order for each loc.
:param kwargs: Additional optional kwargs:
- player_seed: If set. Override the player_seed to use for the model based player.
- noise: If set. Override the noise to use for the model based player.
- temperature: If set. Override the temperature to use for the model based player.
- dropout_rate: If set. Override the dropout_rate to use for the model based player.
- retry_on_failure: Boolean that indicates to retry querying from the model if an error is encountered.
:return: A float representing the value of the state of the game to the specified power
"""
raise NotImplementedError()
@gen.coroutine
def get_opening_orders(self):
""" Returns a dictionary of power_name: [orders] for each power
The orders represent the opening orders that would have been submitted by the player
"""
game = Game()
state_proto = extract_state_proto(game)
phase_history_proto = extract_phase_history_proto(game)
possible_orders_proto = extract_possible_orders_proto(game)
# Retrieving all orders
# Not using kwargs - Using default player_seed, noise, temperature, and dropout_rate.
power_orders = yield [self.get_orders_with_proto(state_proto,
power_name,
phase_history_proto,
possible_orders_proto,
retry_on_failure=False) for power_name in game.powers]
return {power_name: orders for power_name, orders in zip(game.powers.keys(), power_orders)}
@gen.coroutine
def check_openings(self):
""" Validates the opening move of a player against the database of standard openings """
nb_pass, nb_total = 0, 0
opening_orders = yield self.get_opening_orders()
# Validating against database
for power_name in opening_orders:
standard_openings = get_standard_openings(power_name)
normalized_orders = sorted([order for order in opening_orders[power_name] if len(order.split()) >= 2],
key=lambda order_string: order_string.split()[1])
# Displaying status
if normalized_orders in standard_openings:
LOGGER.info('%s - OK', power_name)
nb_pass += 1
else:
LOGGER.info('%s - FAIL -- %s', power_name, normalized_orders)
nb_total += 1
# Displaying total success
LOGGER.info('Summary: %d / %d powers submitted orders in the database.', nb_pass, nb_total)
@staticmethod
def get_nb_centers(state_proto, power_name):
""" Calculates the number of supply centers a power has
:param state_proto: A `.proto.game.State` representation of the state of the game.
:param power_name: The name of the power for which we want the value of the state
:return: A integer representing the number of supply centers the power controls
"""
return len(state_proto.centers[power_name].value)
@staticmethod
def get_orderable_locations(state_proto, power_name):
""" Calculates the list of locations where unit can receive orders
:param state_proto: A `.proto.game.State` representation of the state of the game.
:param power_name: The name of the power for which we want orderable locations
:return: A list of locations where units can receive orders
"""
_, orderable_locs = get_orderable_locs_for_powers(state_proto, [power_name])
return orderable_locs[power_name]
|
mit
|
[
3,
11148,
199,
3,
1898,
20312,
446,
11308,
1638,
80,
10164,
544,
14586,
199,
3,
199,
3,
12840,
26,
221,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
199,
3,
257,
282,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
298,
10337,
1288,
199,
3,
257,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
1928,
12305,
314,
199,
3,
257,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
199,
3,
257,
12743,
6866,
402,
314,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
2290,
365,
199,
3,
257,
13985,
370,
886,
880,
12,
5420,
370,
314,
2569,
3704,
26,
199,
3,
199,
3,
257,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
315,
1006,
199,
3,
257,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
11148,
199,
624,
25610,
272,
446,
22493,
314,
9006,
1021,
6144,
282,
7748,
199,
624,
199,
504,
13022,
492,
9006,
765,
12,
29565,
199,
646,
2050,
199,
504,
12148,
492,
3805,
199,
504,
487,
80,
320,
391,
1480,
492,
25132,
199,
504,
487,
80,
320,
391,
1480,
63,
31788,
14,
992,
14,
929,
63,
2638,
492,
5536,
63,
929,
63,
2625,
12,
5536,
63,
6971,
63,
5570,
63,
2625,
12,
971,
272,
5536,
63,
13893,
63,
14387,
63,
2625,
12,
664,
63,
27788,
6842,
63,
15781,
63,
509,
63,
8278,
1192,
199,
504,
487,
80,
320,
391,
1480,
63,
31788,
14,
1208,
14,
1238,
492,
6202,
63,
1612,
199,
504,
487,
80,
320,
391,
1480,
63,
31788,
14,
1208,
14,
1490,
780,
492,
664,
63,
6807,
63,
1490,
780,
199,
199,
3,
22296,
199,
10186,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
533,
25610,
8,
6577,
29,
22254,
304,
272,
408,
11836,
25610,
8089,
408,
339,
347,
636,
826,
721,
277,
12,
536,
29,
403,
304,
267,
408,
20297,
408,
267,
291,
423,
6147,
63,
5176,
275,
378,
267,
291,
423,
11838,
275,
378,
14,
267,
291,
423,
12954,
275,
378,
14,
267,
291,
423,
17953,
63,
1866,
275,
378,
14,
267,
291,
14,
354,
275,
536,
503,
291,
855,
533,
4914,
354,
363,
339,
327,
4143,
19329,
3001,
9858,
272,
768,
1829,
272,
768,
10315,
272,
347,
365,
63,
18575,
8,
277,
304,
267,
408,
1803,
282,
5046,
626,
9126,
340,
314,
7748,
15061,
370,
506,
28161,
503,
440,
408,
267,
746,
4279,
342,
339,
768,
1829,
272,
347,
7748,
63,
5176,
8,
277,
304,
267,
408,
2372,
351,
446,
7748,
63,
5176,
408,
267,
372,
291,
423,
6147,
63,
5176,
339,
768,
6147,
63,
5176,
14,
8345,
272,
347,
7748,
63,
5176,
8,
277,
12,
574,
304,
267,
408,
2494,
351,
446,
7748,
63,
5176,
408,
267,
291,
423,
6147,
63,
5176,
275,
1109,
8,
585,
9,
339,
768,
1829,
272,
347,
11145,
8,
277,
304,
267,
408,
2372,
351,
446,
11145,
408,
267,
372,
291,
423,
11838,
339,
768,
1829,
272,
347,
14843,
8,
277,
304,
267,
408,
2372,
351,
446,
14843,
408,
267,
372,
291,
423,
12954,
339,
768,
1829,
272,
347,
19795,
63,
1866,
8,
277,
304,
267,
408,
2372,
351,
446,
19795,
63,
1866,
408,
267,
372,
291,
423,
17953,
63,
1866,
339,
768,
1829,
272,
347,
2074,
8,
277,
304,
267,
408,
2372,
351,
446,
2074,
624,
267,
372,
791,
6147,
63,
5176,
356,
291,
14,
6147,
63,
5176,
12,
355,
283,
11838,
356,
291,
14,
11838,
12,
355,
283,
12954,
356,
291,
14,
12954,
12,
355,
283,
17953,
63,
1866,
356,
291,
14,
17953,
63,
1866,
93,
339,
327,
4143,
17653,
3001,
9858,
272,
768,
2268,
14,
16675,
272,
347,
664,
63,
14387,
8,
277,
12,
9219,
12,
7074,
63,
1247,
12,
9889,
7269,
63,
265,
63,
5328,
29,
549,
12,
1011,
958,
304,
267,
408,
14509,
314,
15460,
314,
7074,
8,
83,
9,
1077,
5232,
14,
288,
520,
635,
9219,
26,
710,
9219,
909,
288,
520,
635,
7074,
63,
1247,
26,
437,
769,
402,
7074,
1561,
781,
787,
25692,
12,
503,
8679,
17330,
282,
2849,
7074,
536,
14,
288,
520,
635,
7269,
63,
265,
63,
5328,
26,
9411,
626,
9126,
370,
7269,
27405,
687,
314,
1402,
340,
376,
1125,
365,
14556,
14,
288,
520,
635,
2074,
26,
10961,
2716,
2074,
26,
355,
446,
7748,
63,
5176,
26,
982,
663,
14,
11041,
314,
7748,
63,
5176,
370,
675,
367,
314,
1402,
4079,
7748,
14,
355,
446,
11145,
26,
982,
663,
14,
11041,
314,
11145,
370,
675,
367,
314,
1402,
4079,
7748,
14,
355,
446,
14843,
26,
982,
663,
14,
11041,
314,
14843,
370,
675,
367,
314,
1402,
4079,
7748,
14,
355,
446,
19795,
63,
1866,
26,
982,
663,
14,
11041,
314,
19795,
63,
1866,
370,
675,
367,
314,
1402,
4079,
7748,
14,
355,
446,
543,
63,
5485,
26,
982,
663,
12,
2597,
2529,
3775,
370,
4729,
282,
5954,
503,
440,
288,
520,
1107,
26,
7309,
402,
314,
2569,
26,
355,
413,
9,
982,
7074,
63,
354,
365,
282,
1059,
436,
543,
63,
5485,
508,
756,
334,
269,
365,
440,
663,
304,
490,
446,
437,
769,
402,
15460,
314,
7074,
1077,
5232,
355,
499,
9,
982,
7074,
63,
354,
365,
282,
769,
436,
543,
63,
5485,
508,
756,
334,
269,
365,
440,
663,
304,
490,
446,
437,
769,
402,
769,
12,
1314,
3509,
15460,
367,
1924,
7074,
355,
650,
9,
982,
7074,
63,
354,
365,
282,
1059,
436,
543,
63,
5485,
508,
715,
26,
490,
446,
437,
2008,
402,
413,
9,
314,
769,
402,
15460,
367,
314,
7074,
12,
499,
9,
282,
5046,
370,
4729,
282,
5954,
503,
440,
355,
841,
9,
982,
7074,
63,
354,
365,
282,
769,
436,
543,
63,
5485,
508,
715,
26,
490,
446,
437,
769,
402,
6346,
12,
1924,
2008,
9445,
314,
769,
402,
15460,
436,
314,
5954,
5046,
288,
520,
466,
9219,
26,
487,
80,
320,
391,
1480,
14,
11454,
267,
408,
267,
1174,
63,
2625,
275,
5536,
63,
929,
63,
2625,
8,
5097,
9,
267,
7669,
63,
5570,
63,
2625,
275,
5536,
63,
6971,
63,
5570,
63,
2625,
8,
5097,
9,
267,
3962,
63,
14387,
63,
2625,
275,
5536,
63,
13893,
63,
14387,
63,
2625,
8,
5097,
9
] |
[
11148,
199,
3,
1898,
20312,
446,
11308,
1638,
80,
10164,
544,
14586,
199,
3,
199,
3,
12840,
26,
221,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
199,
3,
257,
282,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
298,
10337,
1288,
199,
3,
257,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
1928,
12305,
314,
199,
3,
257,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
199,
3,
257,
12743,
6866,
402,
314,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
2290,
365,
199,
3,
257,
13985,
370,
886,
880,
12,
5420,
370,
314,
2569,
3704,
26,
199,
3,
199,
3,
257,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
315,
1006,
199,
3,
257,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
11148,
199,
624,
25610,
272,
446,
22493,
314,
9006,
1021,
6144,
282,
7748,
199,
624,
199,
504,
13022,
492,
9006,
765,
12,
29565,
199,
646,
2050,
199,
504,
12148,
492,
3805,
199,
504,
487,
80,
320,
391,
1480,
492,
25132,
199,
504,
487,
80,
320,
391,
1480,
63,
31788,
14,
992,
14,
929,
63,
2638,
492,
5536,
63,
929,
63,
2625,
12,
5536,
63,
6971,
63,
5570,
63,
2625,
12,
971,
272,
5536,
63,
13893,
63,
14387,
63,
2625,
12,
664,
63,
27788,
6842,
63,
15781,
63,
509,
63,
8278,
1192,
199,
504,
487,
80,
320,
391,
1480,
63,
31788,
14,
1208,
14,
1238,
492,
6202,
63,
1612,
199,
504,
487,
80,
320,
391,
1480,
63,
31788,
14,
1208,
14,
1490,
780,
492,
664,
63,
6807,
63,
1490,
780,
199,
199,
3,
22296,
199,
10186,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
533,
25610,
8,
6577,
29,
22254,
304,
272,
408,
11836,
25610,
8089,
408,
339,
347,
636,
826,
721,
277,
12,
536,
29,
403,
304,
267,
408,
20297,
408,
267,
291,
423,
6147,
63,
5176,
275,
378,
267,
291,
423,
11838,
275,
378,
14,
267,
291,
423,
12954,
275,
378,
14,
267,
291,
423,
17953,
63,
1866,
275,
378,
14,
267,
291,
14,
354,
275,
536,
503,
291,
855,
533,
4914,
354,
363,
339,
327,
4143,
19329,
3001,
9858,
272,
768,
1829,
272,
768,
10315,
272,
347,
365,
63,
18575,
8,
277,
304,
267,
408,
1803,
282,
5046,
626,
9126,
340,
314,
7748,
15061,
370,
506,
28161,
503,
440,
408,
267,
746,
4279,
342,
339,
768,
1829,
272,
347,
7748,
63,
5176,
8,
277,
304,
267,
408,
2372,
351,
446,
7748,
63,
5176,
408,
267,
372,
291,
423,
6147,
63,
5176,
339,
768,
6147,
63,
5176,
14,
8345,
272,
347,
7748,
63,
5176,
8,
277,
12,
574,
304,
267,
408,
2494,
351,
446,
7748,
63,
5176,
408,
267,
291,
423,
6147,
63,
5176,
275,
1109,
8,
585,
9,
339,
768,
1829,
272,
347,
11145,
8,
277,
304,
267,
408,
2372,
351,
446,
11145,
408,
267,
372,
291,
423,
11838,
339,
768,
1829,
272,
347,
14843,
8,
277,
304,
267,
408,
2372,
351,
446,
14843,
408,
267,
372,
291,
423,
12954,
339,
768,
1829,
272,
347,
19795,
63,
1866,
8,
277,
304,
267,
408,
2372,
351,
446,
19795,
63,
1866,
408,
267,
372,
291,
423,
17953,
63,
1866,
339,
768,
1829,
272,
347,
2074,
8,
277,
304,
267,
408,
2372,
351,
446,
2074,
624,
267,
372,
791,
6147,
63,
5176,
356,
291,
14,
6147,
63,
5176,
12,
355,
283,
11838,
356,
291,
14,
11838,
12,
355,
283,
12954,
356,
291,
14,
12954,
12,
355,
283,
17953,
63,
1866,
356,
291,
14,
17953,
63,
1866,
93,
339,
327,
4143,
17653,
3001,
9858,
272,
768,
2268,
14,
16675,
272,
347,
664,
63,
14387,
8,
277,
12,
9219,
12,
7074,
63,
1247,
12,
9889,
7269,
63,
265,
63,
5328,
29,
549,
12,
1011,
958,
304,
267,
408,
14509,
314,
15460,
314,
7074,
8,
83,
9,
1077,
5232,
14,
288,
520,
635,
9219,
26,
710,
9219,
909,
288,
520,
635,
7074,
63,
1247,
26,
437,
769,
402,
7074,
1561,
781,
787,
25692,
12,
503,
8679,
17330,
282,
2849,
7074,
536,
14,
288,
520,
635,
7269,
63,
265,
63,
5328,
26,
9411,
626,
9126,
370,
7269,
27405,
687,
314,
1402,
340,
376,
1125,
365,
14556,
14,
288,
520,
635,
2074,
26,
10961,
2716,
2074,
26,
355,
446,
7748,
63,
5176,
26,
982,
663,
14,
11041,
314,
7748,
63,
5176,
370,
675,
367,
314,
1402,
4079,
7748,
14,
355,
446,
11145,
26,
982,
663,
14,
11041,
314,
11145,
370,
675,
367,
314,
1402,
4079,
7748,
14,
355,
446,
14843,
26,
982,
663,
14,
11041,
314,
14843,
370,
675,
367,
314,
1402,
4079,
7748,
14,
355,
446,
19795,
63,
1866,
26,
982,
663,
14,
11041,
314,
19795,
63,
1866,
370,
675,
367,
314,
1402,
4079,
7748,
14,
355,
446,
543,
63,
5485,
26,
982,
663,
12,
2597,
2529,
3775,
370,
4729,
282,
5954,
503,
440,
288,
520,
1107,
26,
7309,
402,
314,
2569,
26,
355,
413,
9,
982,
7074,
63,
354,
365,
282,
1059,
436,
543,
63,
5485,
508,
756,
334,
269,
365,
440,
663,
304,
490,
446,
437,
769,
402,
15460,
314,
7074,
1077,
5232,
355,
499,
9,
982,
7074,
63,
354,
365,
282,
769,
436,
543,
63,
5485,
508,
756,
334,
269,
365,
440,
663,
304,
490,
446,
437,
769,
402,
769,
12,
1314,
3509,
15460,
367,
1924,
7074,
355,
650,
9,
982,
7074,
63,
354,
365,
282,
1059,
436,
543,
63,
5485,
508,
715,
26,
490,
446,
437,
2008,
402,
413,
9,
314,
769,
402,
15460,
367,
314,
7074,
12,
499,
9,
282,
5046,
370,
4729,
282,
5954,
503,
440,
355,
841,
9,
982,
7074,
63,
354,
365,
282,
769,
436,
543,
63,
5485,
508,
715,
26,
490,
446,
437,
769,
402,
6346,
12,
1924,
2008,
9445,
314,
769,
402,
15460,
436,
314,
5954,
5046,
288,
520,
466,
9219,
26,
487,
80,
320,
391,
1480,
14,
11454,
267,
408,
267,
1174,
63,
2625,
275,
5536,
63,
929,
63,
2625,
8,
5097,
9,
267,
7669,
63,
5570,
63,
2625,
275,
5536,
63,
6971,
63,
5570,
63,
2625,
8,
5097,
9,
267,
3962,
63,
14387,
63,
2625,
275,
5536,
63,
13893,
63,
14387,
63,
2625,
8,
5097,
9,
0
] |
[
1,
1,
1,
1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v-web
|
pbem/mailstatus.py
|
1
|
3008
|
'''**********************************************************************
Copyright (C) 2009-2016 The Freeciv-web project
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 threading import Thread
from tornado import web, ioloop, httpserver
import json
from mailsender import MailSender
import time
STATUS_PORT = 4003
"""Serves the PBEM status page, on the url: /mailstatus """
class MailStatus(Thread):
def __init__(self):
Thread.__init__(self)
self.last_request = time.time()
self.last_invitation = None
def run(self):
application = web.Application([
(r"/mailstatus", StatusHandler, dict(mailchecker=self)),
])
http_server = httpserver.HTTPServer(application)
http_server.listen(STATUS_PORT)
ioloop.IOLoop.instance().start()
class StatusHandler(web.RequestHandler):
def initialize(self, mailchecker):
self.mailchecker = mailchecker
def ratelimit(self):
if (time.time() - self.mailchecker.last_request < 1):
self.mailchecker.last_request = time.time()
raise Exception("too frequent requests")
self.mailchecker.last_request = time.time()
def get(self):
games = []
for key, value in self.mailchecker.games.items():
games.append([value['turn'], value['phase'], value['players'], value['time_str'], int((value['time_int'] + self.mailchecker.expiry - time.time()) / (60*60))])
games_sorted = sorted(games, key=lambda tup: tup[4])
self.write(json.dumps(games_sorted))
def post(self):
req_ip = self.request.headers.get("X-Real-IP", "missing")
self.mailchecker.invitation_emails_sent += 1
invite_to = self.get_argument("to", None, True)
action=self.get_argument("action", None, True)
print("request from " + req_ip + " to " + invite_to)
self.ratelimit()
if (self.mailchecker.last_invitation == invite_to):
self.set_status(502)
print("error: invitation to same e-mail twice.")
return;
self.mailchecker.last_invitation = invite_to
if (action == "invite"):
invite_from = self.get_argument("from", None, True)
if (invite_from != None and invite_to != None and "@" in invite_to and len(invite_from) < 50 and len(invite_to) < 50):
m = MailSender()
m.send_invitation(invite_from, invite_to)
self.write("done!")
|
agpl-3.0
|
[
2344,
12360,
26537,
272,
1898,
334,
35,
9,
8937,
13,
9261,
221,
710,
2868,
559,
86,
13,
2520,
2199,
339,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
272,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
3267,
701,
272,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
272,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
339,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
272,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
272,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
272,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
339,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
272,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
12360,
1116,
9153,
2344,
199,
199,
504,
5796,
492,
11086,
199,
504,
12148,
492,
3330,
12,
5890,
3813,
12,
1455,
1000,
199,
646,
2022,
199,
504,
6016,
8114,
492,
18027,
28002,
199,
646,
900,
199,
199,
6305,
63,
3657,
275,
841,
8262,
199,
199,
624,
1505,
2310,
314,
510,
34,
2769,
2004,
2034,
12,
641,
314,
1166,
26,
221,
1182,
1198,
1205,
408,
199,
533,
18027,
3694,
8,
4436,
304,
523,
347,
636,
826,
721,
277,
304,
272,
11086,
855,
826,
721,
277,
9,
272,
291,
14,
2019,
63,
1069,
275,
900,
14,
521,
342,
272,
291,
14,
2019,
63,
5350,
5314,
275,
488,
819,
347,
1255,
8,
277,
304,
272,
4223,
275,
3330,
14,
5039,
779,
288,
334,
82,
15313,
1198,
1205,
401,
9795,
2461,
12,
1211,
8,
1198,
6743,
29,
277,
1826,
272,
4794,
339,
1455,
63,
1000,
275,
1455,
1000,
14,
14938,
8,
3578,
9,
272,
1455,
63,
1000,
14,
5859,
8,
6305,
63,
3657,
9,
272,
5890,
3813,
14,
23152,
14,
842,
1252,
928,
342,
199,
199,
533,
9795,
2461,
8,
2520,
14,
11149,
304,
523,
347,
8265,
8,
277,
12,
6016,
6743,
304,
272,
291,
14,
1198,
6743,
275,
6016,
6743,
819,
347,
6634,
3097,
8,
277,
304,
2043,
340,
334,
521,
14,
521,
342,
446,
291,
14,
1198,
6743,
14,
2019,
63,
1069,
665,
413,
304,
489,
291,
14,
1198,
6743,
14,
2019,
63,
1069,
275,
900,
14,
521,
342,
489,
746,
2186,
480,
7354,
28914,
4145,
531,
2043,
291,
14,
1198,
6743,
14,
2019,
63,
1069,
275,
900,
14,
521,
342,
8330,
347,
664,
8,
277,
304,
272,
9219,
83,
275,
942,
272,
367,
790,
12,
574,
315,
291,
14,
1198,
6743,
14,
28129,
14,
1744,
837,
489,
9219,
83,
14,
740,
779,
585,
459,
353,
995,
574,
459,
6971,
995,
574,
459,
20716,
995,
574,
459,
521,
63,
495,
995,
1109,
1332,
585,
459,
521,
63,
442,
418,
435,
291,
14,
1198,
6743,
14,
16844,
446,
900,
14,
521,
1012,
1182,
334,
2259,
10,
2259,
18229,
272,
9219,
83,
63,
5917,
275,
3355,
8,
28129,
12,
790,
29,
2734,
16477,
26,
16477,
59,
20,
566,
339,
291,
14,
952,
8,
1001,
14,
4180,
8,
28129,
63,
5917,
430,
819,
347,
2963,
8,
277,
304,
272,
2648,
63,
711,
275,
291,
14,
1069,
14,
2139,
14,
362,
480,
56,
13,
10099,
13,
1772,
401,
298,
4752,
531,
272,
291,
14,
1198,
6743,
14,
5350,
5314,
63,
14170,
63,
1150,
847,
413,
272,
24542,
63,
475,
275,
291,
14,
362,
63,
2094,
480,
475,
401,
488,
12,
715,
9,
339,
1595,
29,
277,
14,
362,
63,
2094,
480,
1287,
401,
488,
12,
715,
9,
272,
870,
480,
1069,
687,
298,
435,
2648,
63,
711,
435,
298,
370,
298,
435,
24542,
63,
475,
9,
272,
291,
14,
1866,
3097,
342,
272,
340,
334,
277,
14,
1198,
6743,
14,
2019,
63,
5350,
5314,
508,
24542,
63,
475,
304,
489,
291,
14,
409,
63,
1205,
8,
24653,
9,
489,
870,
480,
705,
26,
4572,
5314,
370,
2011,
325,
13,
1198,
13373,
2685,
489,
372,
27,
339,
291,
14,
1198,
6743,
14,
2019,
63,
5350,
5314,
275,
24542,
63,
475,
272,
340,
334,
1287,
508,
298,
19061,
2349,
489,
24542,
63,
504,
275,
291,
14,
362,
63,
2094,
480,
504,
401,
488,
12,
715,
9,
489,
340,
334,
19061,
63,
504,
1137,
488,
436,
24542,
63,
475,
1137,
488,
436,
9244,
2,
315,
24542,
63,
475,
436,
822,
8,
19061,
63,
504,
9,
665,
5238,
436,
822,
8,
19061,
63,
475,
9,
665,
5238,
304,
267,
333,
275,
18027,
28002,
342,
267,
333,
14,
2254,
63,
5350,
5314,
8,
19061,
63,
504,
12,
24542,
63,
475,
9,
272,
291,
14,
952,
480,
4456,
9124,
4388,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
12360,
26537,
272,
1898,
334,
35,
9,
8937,
13,
9261,
221,
710,
2868,
559,
86,
13,
2520,
2199,
339,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
272,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
3267,
701,
272,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
272,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
339,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
272,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
272,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
272,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
339,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
272,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
12360,
1116,
9153,
2344,
199,
199,
504,
5796,
492,
11086,
199,
504,
12148,
492,
3330,
12,
5890,
3813,
12,
1455,
1000,
199,
646,
2022,
199,
504,
6016,
8114,
492,
18027,
28002,
199,
646,
900,
199,
199,
6305,
63,
3657,
275,
841,
8262,
199,
199,
624,
1505,
2310,
314,
510,
34,
2769,
2004,
2034,
12,
641,
314,
1166,
26,
221,
1182,
1198,
1205,
408,
199,
533,
18027,
3694,
8,
4436,
304,
523,
347,
636,
826,
721,
277,
304,
272,
11086,
855,
826,
721,
277,
9,
272,
291,
14,
2019,
63,
1069,
275,
900,
14,
521,
342,
272,
291,
14,
2019,
63,
5350,
5314,
275,
488,
819,
347,
1255,
8,
277,
304,
272,
4223,
275,
3330,
14,
5039,
779,
288,
334,
82,
15313,
1198,
1205,
401,
9795,
2461,
12,
1211,
8,
1198,
6743,
29,
277,
1826,
272,
4794,
339,
1455,
63,
1000,
275,
1455,
1000,
14,
14938,
8,
3578,
9,
272,
1455,
63,
1000,
14,
5859,
8,
6305,
63,
3657,
9,
272,
5890,
3813,
14,
23152,
14,
842,
1252,
928,
342,
199,
199,
533,
9795,
2461,
8,
2520,
14,
11149,
304,
523,
347,
8265,
8,
277,
12,
6016,
6743,
304,
272,
291,
14,
1198,
6743,
275,
6016,
6743,
819,
347,
6634,
3097,
8,
277,
304,
2043,
340,
334,
521,
14,
521,
342,
446,
291,
14,
1198,
6743,
14,
2019,
63,
1069,
665,
413,
304,
489,
291,
14,
1198,
6743,
14,
2019,
63,
1069,
275,
900,
14,
521,
342,
489,
746,
2186,
480,
7354,
28914,
4145,
531,
2043,
291,
14,
1198,
6743,
14,
2019,
63,
1069,
275,
900,
14,
521,
342,
8330,
347,
664,
8,
277,
304,
272,
9219,
83,
275,
942,
272,
367,
790,
12,
574,
315,
291,
14,
1198,
6743,
14,
28129,
14,
1744,
837,
489,
9219,
83,
14,
740,
779,
585,
459,
353,
995,
574,
459,
6971,
995,
574,
459,
20716,
995,
574,
459,
521,
63,
495,
995,
1109,
1332,
585,
459,
521,
63,
442,
418,
435,
291,
14,
1198,
6743,
14,
16844,
446,
900,
14,
521,
1012,
1182,
334,
2259,
10,
2259,
18229,
272,
9219,
83,
63,
5917,
275,
3355,
8,
28129,
12,
790,
29,
2734,
16477,
26,
16477,
59,
20,
566,
339,
291,
14,
952,
8,
1001,
14,
4180,
8,
28129,
63,
5917,
430,
819,
347,
2963,
8,
277,
304,
272,
2648,
63,
711,
275,
291,
14,
1069,
14,
2139,
14,
362,
480,
56,
13,
10099,
13,
1772,
401,
298,
4752,
531,
272,
291,
14,
1198,
6743,
14,
5350,
5314,
63,
14170,
63,
1150,
847,
413,
272,
24542,
63,
475,
275,
291,
14,
362,
63,
2094,
480,
475,
401,
488,
12,
715,
9,
339,
1595,
29,
277,
14,
362,
63,
2094,
480,
1287,
401,
488,
12,
715,
9,
272,
870,
480,
1069,
687,
298,
435,
2648,
63,
711,
435,
298,
370,
298,
435,
24542,
63,
475,
9,
272,
291,
14,
1866,
3097,
342,
272,
340,
334,
277,
14,
1198,
6743,
14,
2019,
63,
5350,
5314,
508,
24542,
63,
475,
304,
489,
291,
14,
409,
63,
1205,
8,
24653,
9,
489,
870,
480,
705,
26,
4572,
5314,
370,
2011,
325,
13,
1198,
13373,
2685,
489,
372,
27,
339,
291,
14,
1198,
6743,
14,
2019,
63,
5350,
5314,
275,
24542,
63,
475,
272,
340,
334,
1287,
508,
298,
19061,
2349,
489,
24542,
63,
504,
275,
291,
14,
362,
63,
2094,
480,
504,
401,
488,
12,
715,
9,
489,
340,
334,
19061,
63,
504,
1137,
488,
436,
24542,
63,
475,
1137,
488,
436,
9244,
2,
315,
24542,
63,
475,
436,
822,
8,
19061,
63,
504,
9,
665,
5238,
436,
822,
8,
19061,
63,
475,
9,
665,
5238,
304,
267,
333,
275,
18027,
28002,
342,
267,
333,
14,
2254,
63,
5350,
5314,
8,
19061,
63,
504,
12,
24542,
63,
475,
9,
272,
291,
14,
952,
480,
4456,
9124,
4388,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32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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
] |
labsanmartin/Bika-LIMS
|
bika/lims/upgrade/to3018.py
|
3
|
1249
|
from Acquisition import aq_inner
from Acquisition import aq_parent
from bika.lims import logger
from bika.lims.permissions import *
from Products.CMFCore import permissions
from Products.CMFCore.utils import getToolByName
from zExceptions import BadRequest
def upgrade(tool):
# Hack prevent out-of-date upgrading
# Related: PR #1484
# https://github.com/bikalabs/Bika-LIMS/pull/1484
from bika.lims.upgrade import skip_pre315
if skip_pre315(aq_parent(aq_inner(tool))):
return True
portal = aq_parent(aq_inner(tool))
setup = portal.portal_setup
typestool = getToolByName(portal, 'portal_types')
# Add the object to bika_setup
try:
portal.bika_setup.manage_delObjects('bika_arpriorities')
except BadRequest:
logger.info("Folder doesn't exist")
try:
typestool.constructContent(type_name="ARPriorities",
container=portal.bika_setup,
id='bika_arpriorities',
title='AR Priorities')
obj = portal.bika_setup.bika_arpriorities
obj.unmarkCreationFlag()
obj.reindexObject()
except BadRequest:
# folder already exists
pass
return True
|
agpl-3.0
|
[
504,
4473,
21523,
492,
282,
81,
63,
5216,
199,
504,
4473,
21523,
492,
282,
81,
63,
1708,
199,
504,
330,
26966,
14,
31689,
492,
2512,
199,
504,
330,
26966,
14,
31689,
14,
6060,
492,
627,
199,
504,
32411,
14,
9249,
4161,
720,
492,
3443,
199,
504,
32411,
14,
9249,
4161,
720,
14,
1208,
492,
664,
5157,
11190,
199,
504,
1315,
16836,
492,
8857,
2017,
421,
199,
318,
10754,
8,
3557,
304,
272,
327,
30802,
7981,
734,
13,
1618,
13,
602,
1536,
16050,
272,
327,
20116,
26,
12218,
327,
1079,
1349,
272,
327,
4178,
921,
5031,
14,
957,
15,
66,
3258,
279,
2101,
15,
34,
26966,
13,
44,
1469,
51,
15,
9302,
15,
1079,
1349,
272,
687,
330,
26966,
14,
31689,
14,
9375,
492,
3372,
63,
657,
9927,
272,
340,
3372,
63,
657,
9927,
8,
30030,
63,
1708,
8,
30030,
63,
5216,
8,
3557,
15206,
267,
372,
715,
339,
18428,
275,
282,
81,
63,
1708,
8,
30030,
63,
5216,
8,
3557,
430,
272,
3272,
275,
18428,
14,
8707,
63,
2758,
272,
730,
14308,
393,
275,
664,
5157,
11190,
8,
8707,
12,
283,
8707,
63,
1313,
358,
339,
327,
2654,
314,
909,
370,
330,
26966,
63,
2758,
272,
862,
26,
267,
18428,
14,
66,
26966,
63,
2758,
14,
9053,
63,
2264,
11188,
360,
66,
26966,
63,
285,
13775,
12107,
358,
272,
871,
8857,
2017,
26,
267,
2512,
14,
815,
480,
7850,
3181,
1133,
2187,
531,
339,
862,
26,
267,
730,
14308,
393,
14,
8514,
2714,
8,
466,
63,
354,
628,
689,
4562,
269,
12107,
401,
3044,
3970,
29,
8707,
14,
66,
26966,
63,
2758,
12,
3044,
1305,
534,
66,
26966,
63,
285,
13775,
12107,
297,
3044,
2538,
534,
689,
8538,
269,
12107,
358,
267,
1559,
275,
18428,
14,
66,
26966,
63,
2758,
14,
66,
26966,
63,
285,
13775,
12107,
267,
1559,
14,
324,
1657,
13921,
5318,
342,
267,
1559,
14,
21764,
1692,
342,
272,
871,
8857,
2017,
26,
267,
327,
4922,
2575,
3495,
267,
986,
339,
372,
715,
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
] |
[
4473,
21523,
492,
282,
81,
63,
5216,
199,
504,
4473,
21523,
492,
282,
81,
63,
1708,
199,
504,
330,
26966,
14,
31689,
492,
2512,
199,
504,
330,
26966,
14,
31689,
14,
6060,
492,
627,
199,
504,
32411,
14,
9249,
4161,
720,
492,
3443,
199,
504,
32411,
14,
9249,
4161,
720,
14,
1208,
492,
664,
5157,
11190,
199,
504,
1315,
16836,
492,
8857,
2017,
421,
199,
318,
10754,
8,
3557,
304,
272,
327,
30802,
7981,
734,
13,
1618,
13,
602,
1536,
16050,
272,
327,
20116,
26,
12218,
327,
1079,
1349,
272,
327,
4178,
921,
5031,
14,
957,
15,
66,
3258,
279,
2101,
15,
34,
26966,
13,
44,
1469,
51,
15,
9302,
15,
1079,
1349,
272,
687,
330,
26966,
14,
31689,
14,
9375,
492,
3372,
63,
657,
9927,
272,
340,
3372,
63,
657,
9927,
8,
30030,
63,
1708,
8,
30030,
63,
5216,
8,
3557,
15206,
267,
372,
715,
339,
18428,
275,
282,
81,
63,
1708,
8,
30030,
63,
5216,
8,
3557,
430,
272,
3272,
275,
18428,
14,
8707,
63,
2758,
272,
730,
14308,
393,
275,
664,
5157,
11190,
8,
8707,
12,
283,
8707,
63,
1313,
358,
339,
327,
2654,
314,
909,
370,
330,
26966,
63,
2758,
272,
862,
26,
267,
18428,
14,
66,
26966,
63,
2758,
14,
9053,
63,
2264,
11188,
360,
66,
26966,
63,
285,
13775,
12107,
358,
272,
871,
8857,
2017,
26,
267,
2512,
14,
815,
480,
7850,
3181,
1133,
2187,
531,
339,
862,
26,
267,
730,
14308,
393,
14,
8514,
2714,
8,
466,
63,
354,
628,
689,
4562,
269,
12107,
401,
3044,
3970,
29,
8707,
14,
66,
26966,
63,
2758,
12,
3044,
1305,
534,
66,
26966,
63,
285,
13775,
12107,
297,
3044,
2538,
534,
689,
8538,
269,
12107,
358,
267,
1559,
275,
18428,
14,
66,
26966,
63,
2758,
14,
66,
26966,
63,
285,
13775,
12107,
267,
1559,
14,
324,
1657,
13921,
5318,
342,
267,
1559,
14,
21764,
1692,
342,
272,
871,
8857,
2017,
26,
267,
327,
4922,
2575,
3495,
267,
986,
339,
372,
715,
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,
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
] |
MoRgUiJu/morguiju.repo
|
plugin.video.pelisalacarta/lib/requests/packages/urllib3/packages/six.py
|
2375
|
11628
|
"""Utilities for writing code that runs on Python 2 and 3"""
#Copyright (c) 2010-2011 Benjamin Peterson
#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, distribute, sublicense, and/or sell copies of
#the Software, and to permit persons to whom the Software is furnished to do so,
#subject to the following 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 MERCHANTABILITY, FITNESS
#FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
#COPYRIGHT HOLDERS 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.
import operator
import sys
import types
__author__ = "Benjamin Peterson <benjamin@python.org>"
__version__ = "1.2.0" # Revision 41c74fef2ded
# True if we are running on Python 3.
PY3 = sys.version_info[0] == 3
if PY3:
string_types = str,
integer_types = int,
class_types = type,
text_type = str
binary_type = bytes
MAXSIZE = sys.maxsize
else:
string_types = basestring,
integer_types = (int, long)
class_types = (type, types.ClassType)
text_type = unicode
binary_type = str
if sys.platform.startswith("java"):
# Jython always uses 32 bits.
MAXSIZE = int((1 << 31) - 1)
else:
# It's possible to have sizeof(long) != sizeof(Py_ssize_t).
class X(object):
def __len__(self):
return 1 << 31
try:
len(X())
except OverflowError:
# 32-bit
MAXSIZE = int((1 << 31) - 1)
else:
# 64-bit
MAXSIZE = int((1 << 63) - 1)
del X
def _add_doc(func, doc):
"""Add documentation to a function."""
func.__doc__ = doc
def _import_module(name):
"""Import module, returning the module after the last dot."""
__import__(name)
return sys.modules[name]
class _LazyDescr(object):
def __init__(self, name):
self.name = name
def __get__(self, obj, tp):
result = self._resolve()
setattr(obj, self.name, result)
# This is a bit ugly, but it avoids running this again.
delattr(tp, self.name)
return result
class MovedModule(_LazyDescr):
def __init__(self, name, old, new=None):
super(MovedModule, self).__init__(name)
if PY3:
if new is None:
new = name
self.mod = new
else:
self.mod = old
def _resolve(self):
return _import_module(self.mod)
class MovedAttribute(_LazyDescr):
def __init__(self, name, old_mod, new_mod, old_attr=None, new_attr=None):
super(MovedAttribute, self).__init__(name)
if PY3:
if new_mod is None:
new_mod = name
self.mod = new_mod
if new_attr is None:
if old_attr is None:
new_attr = name
else:
new_attr = old_attr
self.attr = new_attr
else:
self.mod = old_mod
if old_attr is None:
old_attr = name
self.attr = old_attr
def _resolve(self):
module = _import_module(self.mod)
return getattr(module, self.attr)
class _MovedItems(types.ModuleType):
"""Lazy loading of moved objects"""
_moved_attributes = [
MovedAttribute("cStringIO", "cStringIO", "io", "StringIO"),
MovedAttribute("filter", "itertools", "builtins", "ifilter", "filter"),
MovedAttribute("input", "__builtin__", "builtins", "raw_input", "input"),
MovedAttribute("map", "itertools", "builtins", "imap", "map"),
MovedAttribute("reload_module", "__builtin__", "imp", "reload"),
MovedAttribute("reduce", "__builtin__", "functools"),
MovedAttribute("StringIO", "StringIO", "io"),
MovedAttribute("xrange", "__builtin__", "builtins", "xrange", "range"),
MovedAttribute("zip", "itertools", "builtins", "izip", "zip"),
MovedModule("builtins", "__builtin__"),
MovedModule("configparser", "ConfigParser"),
MovedModule("copyreg", "copy_reg"),
MovedModule("http_cookiejar", "cookielib", "http.cookiejar"),
MovedModule("http_cookies", "Cookie", "http.cookies"),
MovedModule("html_entities", "htmlentitydefs", "html.entities"),
MovedModule("html_parser", "HTMLParser", "html.parser"),
MovedModule("http_client", "httplib", "http.client"),
MovedModule("BaseHTTPServer", "BaseHTTPServer", "http.server"),
MovedModule("CGIHTTPServer", "CGIHTTPServer", "http.server"),
MovedModule("SimpleHTTPServer", "SimpleHTTPServer", "http.server"),
MovedModule("cPickle", "cPickle", "pickle"),
MovedModule("queue", "Queue"),
MovedModule("reprlib", "repr"),
MovedModule("socketserver", "SocketServer"),
MovedModule("tkinter", "Tkinter"),
MovedModule("tkinter_dialog", "Dialog", "tkinter.dialog"),
MovedModule("tkinter_filedialog", "FileDialog", "tkinter.filedialog"),
MovedModule("tkinter_scrolledtext", "ScrolledText", "tkinter.scrolledtext"),
MovedModule("tkinter_simpledialog", "SimpleDialog", "tkinter.simpledialog"),
MovedModule("tkinter_tix", "Tix", "tkinter.tix"),
MovedModule("tkinter_constants", "Tkconstants", "tkinter.constants"),
MovedModule("tkinter_dnd", "Tkdnd", "tkinter.dnd"),
MovedModule("tkinter_colorchooser", "tkColorChooser",
"tkinter.colorchooser"),
MovedModule("tkinter_commondialog", "tkCommonDialog",
"tkinter.commondialog"),
MovedModule("tkinter_tkfiledialog", "tkFileDialog", "tkinter.filedialog"),
MovedModule("tkinter_font", "tkFont", "tkinter.font"),
MovedModule("tkinter_messagebox", "tkMessageBox", "tkinter.messagebox"),
MovedModule("tkinter_tksimpledialog", "tkSimpleDialog",
"tkinter.simpledialog"),
MovedModule("urllib_robotparser", "robotparser", "urllib.robotparser"),
MovedModule("winreg", "_winreg"),
]
for attr in _moved_attributes:
setattr(_MovedItems, attr.name, attr)
del attr
moves = sys.modules[__name__ + ".moves"] = _MovedItems("moves")
def add_move(move):
"""Add an item to six.moves."""
setattr(_MovedItems, move.name, move)
def remove_move(name):
"""Remove item from six.moves."""
try:
delattr(_MovedItems, name)
except AttributeError:
try:
del moves.__dict__[name]
except KeyError:
raise AttributeError("no such move, %r" % (name,))
if PY3:
_meth_func = "__func__"
_meth_self = "__self__"
_func_code = "__code__"
_func_defaults = "__defaults__"
_iterkeys = "keys"
_itervalues = "values"
_iteritems = "items"
else:
_meth_func = "im_func"
_meth_self = "im_self"
_func_code = "func_code"
_func_defaults = "func_defaults"
_iterkeys = "iterkeys"
_itervalues = "itervalues"
_iteritems = "iteritems"
try:
advance_iterator = next
except NameError:
def advance_iterator(it):
return it.next()
next = advance_iterator
if PY3:
def get_unbound_function(unbound):
return unbound
Iterator = object
def callable(obj):
return any("__call__" in klass.__dict__ for klass in type(obj).__mro__)
else:
def get_unbound_function(unbound):
return unbound.im_func
class Iterator(object):
def next(self):
return type(self).__next__(self)
callable = callable
_add_doc(get_unbound_function,
"""Get the function out of a possibly unbound function""")
get_method_function = operator.attrgetter(_meth_func)
get_method_self = operator.attrgetter(_meth_self)
get_function_code = operator.attrgetter(_func_code)
get_function_defaults = operator.attrgetter(_func_defaults)
def iterkeys(d):
"""Return an iterator over the keys of a dictionary."""
return iter(getattr(d, _iterkeys)())
def itervalues(d):
"""Return an iterator over the values of a dictionary."""
return iter(getattr(d, _itervalues)())
def iteritems(d):
"""Return an iterator over the (key, value) pairs of a dictionary."""
return iter(getattr(d, _iteritems)())
if PY3:
def b(s):
return s.encode("latin-1")
def u(s):
return s
if sys.version_info[1] <= 1:
def int2byte(i):
return bytes((i,))
else:
# This is about 2x faster than the implementation above on 3.2+
int2byte = operator.methodcaller("to_bytes", 1, "big")
import io
StringIO = io.StringIO
BytesIO = io.BytesIO
else:
def b(s):
return s
def u(s):
return unicode(s, "unicode_escape")
int2byte = chr
import StringIO
StringIO = BytesIO = StringIO.StringIO
_add_doc(b, """Byte literal""")
_add_doc(u, """Text literal""")
if PY3:
import builtins
exec_ = getattr(builtins, "exec")
def reraise(tp, value, tb=None):
if value.__traceback__ is not tb:
raise value.with_traceback(tb)
raise value
print_ = getattr(builtins, "print")
del builtins
else:
def exec_(code, globs=None, locs=None):
"""Execute code in a namespace."""
if globs is None:
frame = sys._getframe(1)
globs = frame.f_globals
if locs is None:
locs = frame.f_locals
del frame
elif locs is None:
locs = globs
exec("""exec code in globs, locs""")
exec_("""def reraise(tp, value, tb=None):
raise tp, value, tb
""")
def print_(*args, **kwargs):
"""The new-style print function."""
fp = kwargs.pop("file", sys.stdout)
if fp is None:
return
def write(data):
if not isinstance(data, basestring):
data = str(data)
fp.write(data)
want_unicode = False
sep = kwargs.pop("sep", None)
if sep is not None:
if isinstance(sep, unicode):
want_unicode = True
elif not isinstance(sep, str):
raise TypeError("sep must be None or a string")
end = kwargs.pop("end", None)
if end is not None:
if isinstance(end, unicode):
want_unicode = True
elif not isinstance(end, str):
raise TypeError("end must be None or a string")
if kwargs:
raise TypeError("invalid keyword arguments to print()")
if not want_unicode:
for arg in args:
if isinstance(arg, unicode):
want_unicode = True
break
if want_unicode:
newline = unicode("\n")
space = unicode(" ")
else:
newline = "\n"
space = " "
if sep is None:
sep = space
if end is None:
end = newline
for i, arg in enumerate(args):
if i:
write(sep)
write(arg)
write(end)
_add_doc(reraise, """Reraise an exception.""")
def with_metaclass(meta, base=object):
"""Create a base class with a metaclass."""
return meta("NewBase", (base,), {})
|
gpl-2.0
|
[
624,
22905,
367,
3575,
1233,
626,
7858,
641,
2018,
499,
436,
650,
624,
199,
199,
3,
7384,
334,
67,
9,
7129,
13,
8128,
26844,
16997,
262,
22912,
834,
199,
199,
3,
7980,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
1331,
402,
199,
3,
3749,
2032,
436,
4568,
3794,
1584,
334,
1589,
298,
10337,
1288,
370,
7962,
315,
199,
3,
1589,
2290,
1928,
10588,
12,
5893,
1928,
12305,
314,
4481,
370,
199,
3,
1180,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
199,
3,
1589,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
199,
3,
5875,
370,
314,
2569,
3704,
26,
199,
199,
3,
1918,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
315,
1006,
199,
3,
16847,
503,
13393,
12468,
402,
314,
2290,
14,
199,
199,
3,
18061,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
1549,
199,
3,
8947,
5177,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
3169,
12,
3092,
199,
3,
2707,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
7000,
2334,
10610,
1549,
199,
3,
32324,
5716,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
7061,
199,
3,
568,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
5738,
1634,
1549,
1621,
199,
3,
18389,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
4141,
14,
199,
199,
646,
4182,
199,
646,
984,
199,
646,
2943,
199,
199,
363,
2502,
363,
275,
298,
31231,
16997,
262,
22912,
834,
665,
18486,
16997,
262,
32,
1548,
14,
1308,
4335,
199,
363,
1023,
363,
275,
298,
17,
14,
18,
14,
16,
2,
221,
327,
27095,
13385,
67,
1342,
32688,
18,
770,
421,
199,
3,
715,
340,
781,
787,
3879,
641,
2018,
650,
14,
199,
4521,
19,
275,
984,
14,
1023,
63,
815,
59,
16,
61,
508,
650,
199,
199,
692,
7843,
19,
26,
272,
1059,
63,
1313,
275,
620,
12,
272,
3000,
63,
1313,
275,
1109,
12,
272,
1021,
63,
1313,
275,
730,
12,
272,
1318,
63,
466,
275,
620,
272,
3366,
63,
466,
275,
2783,
339,
9141,
4305,
275,
984,
14,
13634,
199,
2836,
26,
272,
1059,
63,
1313,
275,
7116,
12,
272,
3000,
63,
1313,
275,
334,
442,
12,
1846,
9,
272,
1021,
63,
1313,
275,
334,
466,
12,
2943,
14,
31165,
9,
272,
1318,
63,
466,
275,
2649,
272,
3366,
63,
466,
275,
620,
339,
340,
984,
14,
3246,
14,
2460,
480,
6138,
2349,
267,
327,
25333,
3544,
4440,
4337,
5821,
14,
267,
9141,
4305,
275,
1109,
1332,
17,
5213,
7105,
9,
446,
413,
9,
272,
587,
26,
267,
327,
2779,
1159,
3962,
370,
1172,
13855,
8,
2809,
9,
1137,
13855,
8,
2713,
63,
30104,
63,
84,
680,
267,
1021,
1323,
8,
785,
304,
288,
347,
636,
552,
721,
277,
304,
355,
372,
413,
5213,
7105,
267,
862,
26,
288,
822,
8,
56,
1012,
267,
871,
23870,
26,
288,
327,
4337,
13,
2075,
288,
9141,
4305,
275,
1109,
1332,
17,
5213,
7105,
9,
446,
413,
9,
267,
587,
26,
288,
327,
5049,
13,
2075,
288,
9141,
4305,
275,
1109,
1332,
17,
5213,
13668,
9,
446,
413,
9,
288,
2150,
1323,
421,
199,
318,
485,
525,
63,
1301,
8,
1532,
12,
1382,
304,
272,
408,
1123,
3794,
370,
282,
805,
1041,
272,
2562,
855,
1301,
363,
275,
1382,
421,
199,
318,
485,
646,
63,
578,
8,
354,
304,
272,
408,
6295,
859,
12,
8152,
314,
859,
2410,
314,
2061,
6308,
1041,
272,
636,
646,
721,
354,
9,
272,
372,
984,
14,
3112,
59,
354,
61,
421,
199,
533,
485,
14269,
28782,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
536,
304,
267,
291,
14,
354,
275,
536,
339,
347,
636,
362,
721,
277,
12,
1559,
12,
9253,
304,
267,
754,
275,
291,
423,
6983,
342,
267,
5371,
8,
1113,
12,
291,
14,
354,
12,
754,
9,
267,
327,
961,
365,
282,
4546,
23761,
12,
1325,
652,
23674,
3879,
642,
4020,
14,
267,
24358,
8,
683,
12,
291,
14,
354,
9,
267,
372,
754,
421,
199,
533,
11147,
1547,
14269,
28782,
304,
339,
347,
636,
826,
721,
277,
12,
536,
12,
2269,
12,
892,
29,
403,
304,
267,
1613,
8,
20774,
2377,
12,
291,
2843,
826,
721,
354,
9,
267,
340,
7843,
19,
26,
288,
340,
892,
365,
488,
26,
355,
892,
275,
536,
288,
291,
14,
1494,
275,
892,
267,
587,
26,
288,
291,
14,
1494,
275,
2269,
339,
347,
485,
6983,
8,
277,
304,
267,
372,
485,
646,
63,
578,
8,
277,
14,
1494,
9,
421,
199,
533,
8863,
1547,
14269,
28782,
304,
339,
347,
636,
826,
721,
277,
12,
536,
12,
2269,
63,
1494,
12,
892,
63,
1494,
12,
2269,
63,
962,
29,
403,
12,
892,
63,
962,
29,
403,
304,
267,
1613,
8,
20774,
1646,
12,
291,
2843,
826,
721,
354,
9,
267,
340,
7843,
19,
26,
288,
340,
892,
63,
1494,
365,
488,
26,
355,
892,
63,
1494,
275,
536,
288,
291,
14,
1494,
275,
892,
63,
1494,
288,
340,
892,
63,
962,
365,
488,
26,
355,
340,
2269,
63,
962,
365,
488,
26,
490,
892,
63,
962,
275,
536,
355,
587,
26,
490,
892,
63,
962,
275,
2269,
63,
962,
288,
291,
14,
962,
275,
892,
63,
962,
267,
587,
26,
288,
291,
14,
1494,
275,
2269,
63,
1494,
288,
340,
2269,
63,
962,
365,
488,
26,
355,
2269,
63,
962,
275,
536,
288,
291,
14,
962,
275,
2269,
63,
962,
339,
347,
485,
6983,
8,
277,
304,
267,
859,
275,
485,
646,
63,
578,
8,
277,
14,
1494,
9,
267,
372,
2519,
8,
578,
12,
291,
14,
962,
9,
4388,
199,
533,
485,
20774,
7412,
8,
1313,
14,
21820,
304,
272,
408,
14269,
8697,
402,
12155,
2251,
624,
421,
199,
63,
3539,
63,
2987,
275,
359,
272,
8863,
480,
67,
6424,
401,
298,
67,
6424,
401,
298,
2308,
401,
298,
6424,
1288,
272,
8863,
480,
1541,
401,
298,
17691,
401,
298,
10372,
401,
298,
73,
1541,
401,
298,
1541,
1288,
272,
8863,
480,
1210,
401,
4396,
5351,
13915,
298
] |
[
22905,
367,
3575,
1233,
626,
7858,
641,
2018,
499,
436,
650,
624,
199,
199,
3,
7384,
334,
67,
9,
7129,
13,
8128,
26844,
16997,
262,
22912,
834,
199,
199,
3,
7980,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
1331,
402,
199,
3,
3749,
2032,
436,
4568,
3794,
1584,
334,
1589,
298,
10337,
1288,
370,
7962,
315,
199,
3,
1589,
2290,
1928,
10588,
12,
5893,
1928,
12305,
314,
4481,
370,
199,
3,
1180,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
199,
3,
1589,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
199,
3,
5875,
370,
314,
2569,
3704,
26,
199,
199,
3,
1918,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
315,
1006,
199,
3,
16847,
503,
13393,
12468,
402,
314,
2290,
14,
199,
199,
3,
18061,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
1549,
199,
3,
8947,
5177,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
3169,
12,
3092,
199,
3,
2707,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
7000,
2334,
10610,
1549,
199,
3,
32324,
5716,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
7061,
199,
3,
568,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
5738,
1634,
1549,
1621,
199,
3,
18389,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
4141,
14,
199,
199,
646,
4182,
199,
646,
984,
199,
646,
2943,
199,
199,
363,
2502,
363,
275,
298,
31231,
16997,
262,
22912,
834,
665,
18486,
16997,
262,
32,
1548,
14,
1308,
4335,
199,
363,
1023,
363,
275,
298,
17,
14,
18,
14,
16,
2,
221,
327,
27095,
13385,
67,
1342,
32688,
18,
770,
421,
199,
3,
715,
340,
781,
787,
3879,
641,
2018,
650,
14,
199,
4521,
19,
275,
984,
14,
1023,
63,
815,
59,
16,
61,
508,
650,
199,
199,
692,
7843,
19,
26,
272,
1059,
63,
1313,
275,
620,
12,
272,
3000,
63,
1313,
275,
1109,
12,
272,
1021,
63,
1313,
275,
730,
12,
272,
1318,
63,
466,
275,
620,
272,
3366,
63,
466,
275,
2783,
339,
9141,
4305,
275,
984,
14,
13634,
199,
2836,
26,
272,
1059,
63,
1313,
275,
7116,
12,
272,
3000,
63,
1313,
275,
334,
442,
12,
1846,
9,
272,
1021,
63,
1313,
275,
334,
466,
12,
2943,
14,
31165,
9,
272,
1318,
63,
466,
275,
2649,
272,
3366,
63,
466,
275,
620,
339,
340,
984,
14,
3246,
14,
2460,
480,
6138,
2349,
267,
327,
25333,
3544,
4440,
4337,
5821,
14,
267,
9141,
4305,
275,
1109,
1332,
17,
5213,
7105,
9,
446,
413,
9,
272,
587,
26,
267,
327,
2779,
1159,
3962,
370,
1172,
13855,
8,
2809,
9,
1137,
13855,
8,
2713,
63,
30104,
63,
84,
680,
267,
1021,
1323,
8,
785,
304,
288,
347,
636,
552,
721,
277,
304,
355,
372,
413,
5213,
7105,
267,
862,
26,
288,
822,
8,
56,
1012,
267,
871,
23870,
26,
288,
327,
4337,
13,
2075,
288,
9141,
4305,
275,
1109,
1332,
17,
5213,
7105,
9,
446,
413,
9,
267,
587,
26,
288,
327,
5049,
13,
2075,
288,
9141,
4305,
275,
1109,
1332,
17,
5213,
13668,
9,
446,
413,
9,
288,
2150,
1323,
421,
199,
318,
485,
525,
63,
1301,
8,
1532,
12,
1382,
304,
272,
408,
1123,
3794,
370,
282,
805,
1041,
272,
2562,
855,
1301,
363,
275,
1382,
421,
199,
318,
485,
646,
63,
578,
8,
354,
304,
272,
408,
6295,
859,
12,
8152,
314,
859,
2410,
314,
2061,
6308,
1041,
272,
636,
646,
721,
354,
9,
272,
372,
984,
14,
3112,
59,
354,
61,
421,
199,
533,
485,
14269,
28782,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
536,
304,
267,
291,
14,
354,
275,
536,
339,
347,
636,
362,
721,
277,
12,
1559,
12,
9253,
304,
267,
754,
275,
291,
423,
6983,
342,
267,
5371,
8,
1113,
12,
291,
14,
354,
12,
754,
9,
267,
327,
961,
365,
282,
4546,
23761,
12,
1325,
652,
23674,
3879,
642,
4020,
14,
267,
24358,
8,
683,
12,
291,
14,
354,
9,
267,
372,
754,
421,
199,
533,
11147,
1547,
14269,
28782,
304,
339,
347,
636,
826,
721,
277,
12,
536,
12,
2269,
12,
892,
29,
403,
304,
267,
1613,
8,
20774,
2377,
12,
291,
2843,
826,
721,
354,
9,
267,
340,
7843,
19,
26,
288,
340,
892,
365,
488,
26,
355,
892,
275,
536,
288,
291,
14,
1494,
275,
892,
267,
587,
26,
288,
291,
14,
1494,
275,
2269,
339,
347,
485,
6983,
8,
277,
304,
267,
372,
485,
646,
63,
578,
8,
277,
14,
1494,
9,
421,
199,
533,
8863,
1547,
14269,
28782,
304,
339,
347,
636,
826,
721,
277,
12,
536,
12,
2269,
63,
1494,
12,
892,
63,
1494,
12,
2269,
63,
962,
29,
403,
12,
892,
63,
962,
29,
403,
304,
267,
1613,
8,
20774,
1646,
12,
291,
2843,
826,
721,
354,
9,
267,
340,
7843,
19,
26,
288,
340,
892,
63,
1494,
365,
488,
26,
355,
892,
63,
1494,
275,
536,
288,
291,
14,
1494,
275,
892,
63,
1494,
288,
340,
892,
63,
962,
365,
488,
26,
355,
340,
2269,
63,
962,
365,
488,
26,
490,
892,
63,
962,
275,
536,
355,
587,
26,
490,
892,
63,
962,
275,
2269,
63,
962,
288,
291,
14,
962,
275,
892,
63,
962,
267,
587,
26,
288,
291,
14,
1494,
275,
2269,
63,
1494,
288,
340,
2269,
63,
962,
365,
488,
26,
355,
2269,
63,
962,
275,
536,
288,
291,
14,
962,
275,
2269,
63,
962,
339,
347,
485,
6983,
8,
277,
304,
267,
859,
275,
485,
646,
63,
578,
8,
277,
14,
1494,
9,
267,
372,
2519,
8,
578,
12,
291,
14,
962,
9,
4388,
199,
533,
485,
20774,
7412,
8,
1313,
14,
21820,
304,
272,
408,
14269,
8697,
402,
12155,
2251,
624,
421,
199,
63,
3539,
63,
2987,
275,
359,
272,
8863,
480,
67,
6424,
401,
298,
67,
6424,
401,
298,
2308,
401,
298,
6424,
1288,
272,
8863,
480,
1541,
401,
298,
17691,
401,
298,
10372,
401,
298,
73,
1541,
401,
298,
1541,
1288,
272,
8863,
480,
1210,
401,
4396,
5351,
13915,
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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
sudheesh001/oh-mainline
|
vendor/packages/Django/tests/regressiontests/generic_views/views.py
|
47
|
6507
|
from __future__ import absolute_import
from django.contrib.auth.decorators import login_required
from django.core.paginator import Paginator
from django.core.urlresolvers import reverse, reverse_lazy
from django.utils.decorators import method_decorator
from django.views import generic
from .forms import AuthorForm, ContactForm
from .models import Artist, Author, Book, Page, BookSigning
class CustomTemplateView(generic.TemplateView):
template_name = 'generic_views/about.html'
def get_context_data(self, **kwargs):
context = super(CustomTemplateView, self).get_context_data(**kwargs)
context.update({'key': 'value'})
return context
class ObjectDetail(generic.DetailView):
template_name = 'generic_views/detail.html'
def get_object(self):
return {'foo': 'bar'}
class ArtistDetail(generic.DetailView):
queryset = Artist.objects.all()
class AuthorDetail(generic.DetailView):
queryset = Author.objects.all()
class PageDetail(generic.DetailView):
queryset = Page.objects.all()
template_name_field = 'template'
class DictList(generic.ListView):
"""A ListView that doesn't use a model."""
queryset = [
{'first': 'John', 'last': 'Lennon'},
{'first': 'Yoko', 'last': 'Ono'}
]
template_name = 'generic_views/list.html'
class ArtistList(generic.ListView):
template_name = 'generic_views/list.html'
queryset = Artist.objects.all()
class AuthorList(generic.ListView):
queryset = Author.objects.all()
class CustomPaginator(Paginator):
def __init__(self, queryset, page_size, orphans=0, allow_empty_first_page=True):
super(CustomPaginator, self).__init__(
queryset,
page_size,
orphans=2,
allow_empty_first_page=allow_empty_first_page)
class AuthorListCustomPaginator(AuthorList):
paginate_by = 5
def get_paginator(self, queryset, page_size, orphans=0, allow_empty_first_page=True):
return super(AuthorListCustomPaginator, self).get_paginator(
queryset,
page_size,
orphans=2,
allow_empty_first_page=allow_empty_first_page)
class ContactView(generic.FormView):
form_class = ContactForm
success_url = reverse_lazy('authors_list')
template_name = 'generic_views/form.html'
class ArtistCreate(generic.CreateView):
model = Artist
class NaiveAuthorCreate(generic.CreateView):
queryset = Author.objects.all()
class AuthorCreate(generic.CreateView):
model = Author
success_url = '/list/authors/'
class SpecializedAuthorCreate(generic.CreateView):
model = Author
form_class = AuthorForm
template_name = 'generic_views/form.html'
context_object_name = 'thingy'
def get_success_url(self):
return reverse('author_detail', args=[self.object.id,])
class AuthorCreateRestricted(AuthorCreate):
post = method_decorator(login_required)(AuthorCreate.post)
class ArtistUpdate(generic.UpdateView):
model = Artist
class NaiveAuthorUpdate(generic.UpdateView):
queryset = Author.objects.all()
class AuthorUpdate(generic.UpdateView):
model = Author
success_url = '/list/authors/'
class OneAuthorUpdate(generic.UpdateView):
success_url = '/list/authors/'
def get_object(self):
return Author.objects.get(pk=1)
class SpecializedAuthorUpdate(generic.UpdateView):
model = Author
form_class = AuthorForm
template_name = 'generic_views/form.html'
context_object_name = 'thingy'
def get_success_url(self):
return reverse('author_detail', args=[self.object.id,])
class NaiveAuthorDelete(generic.DeleteView):
queryset = Author.objects.all()
class AuthorDelete(generic.DeleteView):
model = Author
success_url = '/list/authors/'
class SpecializedAuthorDelete(generic.DeleteView):
queryset = Author.objects.all()
template_name = 'generic_views/confirm_delete.html'
context_object_name = 'thingy'
def get_success_url(self):
return reverse('authors_list')
class BookConfig(object):
queryset = Book.objects.all()
date_field = 'pubdate'
class BookArchive(BookConfig, generic.ArchiveIndexView):
pass
class BookYearArchive(BookConfig, generic.YearArchiveView):
pass
class BookMonthArchive(BookConfig, generic.MonthArchiveView):
pass
class BookWeekArchive(BookConfig, generic.WeekArchiveView):
pass
class BookDayArchive(BookConfig, generic.DayArchiveView):
pass
class BookTodayArchive(BookConfig, generic.TodayArchiveView):
pass
class BookDetail(BookConfig, generic.DateDetailView):
pass
class AuthorGetQuerySetFormView(generic.edit.ModelFormMixin):
def get_queryset(self):
return Author.objects.all()
class BookDetailGetObjectCustomQueryset(BookDetail):
def get_object(self, queryset=None):
return super(BookDetailGetObjectCustomQueryset,self).get_object(
queryset=Book.objects.filter(pk=2))
class CustomContextView(generic.detail.SingleObjectMixin, generic.View):
model = Book
object = Book(name='dummy')
def get_object(self):
return Book(name="dummy")
def get_context_data(self, **kwargs):
context = {'custom_key': 'custom_value'}
context.update(kwargs)
return super(CustomContextView, self).get_context_data(**context)
def get_context_object_name(self, obj):
return "test_name"
class BookSigningConfig(object):
model = BookSigning
date_field = 'event_date'
# use the same templates as for books
def get_template_names(self):
return ['generic_views/book%s.html' % self.template_name_suffix]
class BookSigningArchive(BookSigningConfig, generic.ArchiveIndexView):
pass
class BookSigningYearArchive(BookSigningConfig, generic.YearArchiveView):
pass
class BookSigningMonthArchive(BookSigningConfig, generic.MonthArchiveView):
pass
class BookSigningWeekArchive(BookSigningConfig, generic.WeekArchiveView):
pass
class BookSigningDayArchive(BookSigningConfig, generic.DayArchiveView):
pass
class BookSigningTodayArchive(BookSigningConfig, generic.TodayArchiveView):
pass
class BookSigningDetail(BookSigningConfig, generic.DateDetailView):
context_object_name = 'book'
class NonModel(object):
id = "non_model_1"
_meta = None
class NonModelDetail(generic.DetailView):
template_name = 'generic_views/detail.html'
model = NonModel
def get_object(self, queryset=None):
return NonModel()
|
agpl-3.0
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
504,
1639,
14,
2828,
14,
1178,
14,
11582,
492,
4676,
63,
2427,
199,
504,
1639,
14,
1018,
14,
22073,
492,
28006,
8566,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
12,
3837,
63,
6395,
199,
504,
1639,
14,
1208,
14,
11582,
492,
1083,
63,
11547,
199,
504,
1639,
14,
4196,
492,
7809,
199,
199,
504,
1275,
3351,
492,
6529,
2821,
12,
18684,
2821,
199,
504,
1275,
992,
492,
1952,
5011,
12,
6529,
12,
8944,
12,
10331,
12,
8944,
4940,
316,
421,
199,
533,
8388,
4231,
2768,
8,
6767,
14,
4231,
2768,
304,
272,
1978,
63,
354,
275,
283,
6767,
63,
4196,
15,
10254,
14,
1360,
7,
339,
347,
664,
63,
1100,
63,
576,
8,
277,
12,
1011,
958,
304,
267,
1067,
275,
1613,
8,
7223,
4231,
2768,
12,
291,
680,
362,
63,
1100,
63,
576,
3682,
958,
9,
267,
1067,
14,
873,
3252,
498,
356,
283,
585,
3071,
267,
372,
1067,
421,
199,
533,
6935,
8064,
8,
6767,
14,
28539,
304,
272,
1978,
63,
354,
275,
283,
6767,
63,
4196,
15,
5506,
14,
1360,
7,
339,
347,
664,
63,
785,
8,
277,
304,
267,
372,
791,
1421,
356,
283,
1700,
936,
421,
199,
533,
1952,
5011,
8064,
8,
6767,
14,
28539,
304,
272,
7594,
275,
1952,
5011,
14,
1462,
14,
452,
342,
421,
199,
533,
6529,
8064,
8,
6767,
14,
28539,
304,
272,
7594,
275,
6529,
14,
1462,
14,
452,
342,
421,
199,
533,
10331,
8064,
8,
6767,
14,
28539,
304,
272,
7594,
275,
10331,
14,
1462,
14,
452,
342,
272,
1978,
63,
354,
63,
698,
275,
283,
1160,
7,
421,
199,
533,
7448,
1296,
8,
6767,
14,
23239,
304,
272,
408,
33,
3820,
2768,
626,
3181,
1133,
675,
282,
1402,
1041,
272,
7594,
275,
359,
267,
791,
2246,
356,
283,
12923,
297,
283,
2019,
356,
283,
3166,
2865,
2267,
267,
791,
2246,
356,
283,
57,
745,
79,
297,
221,
283,
2019,
356,
283,
47,
889,
936,
272,
1622,
272,
1978,
63,
354,
275,
283,
6767,
63,
4196,
15,
513,
14,
1360,
7,
421,
199,
533,
1952,
5011,
1296,
8,
6767,
14,
23239,
304,
272,
1978,
63,
354,
275,
283,
6767,
63,
4196,
15,
513,
14,
1360,
7,
272,
7594,
275,
1952,
5011,
14,
1462,
14,
452,
342,
421,
199,
533,
6529,
1296,
8,
6767,
14,
23239,
304,
272,
7594,
275,
6529,
14,
1462,
14,
452,
342,
421,
199,
533,
8388,
23862,
8566,
8,
23862,
8566,
304,
272,
347,
636,
826,
721,
277,
12,
7594,
12,
2034,
63,
890,
12,
503,
838,
796,
29,
16,
12,
2040,
63,
1667,
63,
2246,
63,
1606,
29,
549,
304,
267,
1613,
8,
7223,
23862,
8566,
12,
291,
2843,
826,
721,
288,
7594,
12,
288,
2034,
63,
890,
12,
288,
503,
838,
796,
29,
18,
12,
288,
2040,
63,
1667,
63,
2246,
63,
1606,
29,
3306,
63,
1667,
63,
2246,
63,
1606,
9,
199,
199,
533,
6529,
1296,
7223,
23862,
8566,
8,
5949,
1296,
304,
272,
9881,
23043,
63,
991,
275,
959,
339,
347,
664,
63,
22073,
8,
277,
12,
7594,
12,
2034,
63,
890,
12,
503,
838,
796,
29,
16,
12,
2040,
63,
1667,
63,
2246,
63,
1606,
29,
549,
304,
267,
372,
1613,
8,
5949,
1296,
7223,
23862,
8566,
12,
291,
680,
362,
63,
22073,
8,
288,
7594,
12,
288,
2034,
63,
890,
12,
288,
503,
838,
796,
29,
18,
12,
288,
2040,
63,
1667,
63,
2246,
63,
1606,
29,
3306,
63,
1667,
63,
2246,
63,
1606,
9,
421,
199,
533,
18684,
2768,
8,
6767,
14,
2821,
2768,
304,
272,
1824,
63,
533,
275,
18684,
2821,
272,
3182,
63,
633,
275,
3837,
63,
6395,
360,
8149,
63,
513,
358,
272,
1978,
63,
354,
275,
283,
6767,
63,
4196,
15,
964,
14,
1360,
7,
421,
199,
533,
1952,
5011,
2499,
8,
6767,
14,
2499,
2768,
304,
272,
1402,
275,
1952,
5011,
421,
199,
533,
11290,
1912,
5949,
2499,
8,
6767,
14,
2499,
2768,
304,
272,
7594,
275,
6529,
14,
1462,
14,
452,
342,
421,
199,
533,
6529,
2499,
8,
6767,
14,
2499,
2768,
304,
272,
1402,
275,
6529,
272,
3182,
63,
633,
275,
1994,
513,
15,
8149,
4805,
421,
199,
533,
12568,
1759,
5949,
2499,
8,
6767,
14,
2499,
2768,
304,
272,
1402,
275,
6529,
272,
1824,
63,
533,
275,
6529,
2821,
272,
1978,
63,
354,
275,
283,
6767,
63,
4196,
15,
964,
14,
1360,
7,
272,
1067,
63,
785,
63,
354,
275,
283,
2127,
89,
7,
339,
347,
664,
63,
3742,
63,
633,
8,
277,
304,
267,
372,
3837,
360,
2502,
63,
5506,
297,
1249,
1524,
277,
14,
785,
14,
344,
30453,
421,
199,
533,
6529,
2499,
28850,
8,
5949,
2499,
304,
272,
2963,
275,
1083,
63,
11547,
8,
2886,
63,
2427,
5130,
5949,
2499,
14,
1932,
9,
421,
199,
533,
1952,
5011,
4152,
8,
6767,
14,
4152,
2768,
304,
272,
1402,
275,
1952,
5011,
421,
199,
533,
11290,
1912,
5949,
4152,
8,
6767,
14,
4152,
2768,
304,
272,
7594,
275,
6529,
14,
1462,
14,
452,
342,
421,
199,
533,
6529,
4152,
8,
6767,
14,
4152,
2768,
304,
272,
1402,
275,
6529,
272,
3182,
63,
633,
275,
1994,
513,
15,
8149,
4805,
421,
199,
533,
7309,
5949,
4152,
8,
6767,
14,
4152,
2768,
304,
272,
3182,
63,
633,
275,
1994,
513,
15,
8149,
4805,
339,
347,
664,
63,
785,
8,
277,
304,
267,
372,
6529,
14,
1462,
14,
362,
8,
2051,
29,
17,
9,
421,
199,
533,
12568,
1759,
5949,
4152,
8,
6767,
14,
4152,
2768,
304,
272,
1402,
275,
6529,
272,
1824,
63,
533,
275,
6529,
2821,
272,
1978,
63,
354,
275,
283,
6767,
63,
4196,
15,
964,
14,
1360,
7,
272,
1067,
63,
785,
63,
354,
275,
283,
2127,
89,
7,
339,
347,
664,
63,
3742,
63,
633,
8,
277,
304,
267,
372,
3837,
360,
2502,
63,
5506,
297,
1249,
1524,
277,
14,
785,
14,
344,
30453,
421,
199,
533,
11290,
1912,
5949,
5392,
8,
6767,
14,
5392,
2768,
304,
272,
7594,
275,
6529,
14,
1462,
14,
452,
342,
421,
199,
533,
6529,
5392,
8,
6767,
14,
5392,
2768,
304,
272,
1402,
275,
6529,
272,
3182,
63,
633,
275,
1994,
513,
15,
8149,
4805,
421,
199,
533,
12568,
1759,
5949,
5392,
8,
6767
] |
[
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
504,
1639,
14,
2828,
14,
1178,
14,
11582,
492,
4676,
63,
2427,
199,
504,
1639,
14,
1018,
14,
22073,
492,
28006,
8566,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
12,
3837,
63,
6395,
199,
504,
1639,
14,
1208,
14,
11582,
492,
1083,
63,
11547,
199,
504,
1639,
14,
4196,
492,
7809,
199,
199,
504,
1275,
3351,
492,
6529,
2821,
12,
18684,
2821,
199,
504,
1275,
992,
492,
1952,
5011,
12,
6529,
12,
8944,
12,
10331,
12,
8944,
4940,
316,
421,
199,
533,
8388,
4231,
2768,
8,
6767,
14,
4231,
2768,
304,
272,
1978,
63,
354,
275,
283,
6767,
63,
4196,
15,
10254,
14,
1360,
7,
339,
347,
664,
63,
1100,
63,
576,
8,
277,
12,
1011,
958,
304,
267,
1067,
275,
1613,
8,
7223,
4231,
2768,
12,
291,
680,
362,
63,
1100,
63,
576,
3682,
958,
9,
267,
1067,
14,
873,
3252,
498,
356,
283,
585,
3071,
267,
372,
1067,
421,
199,
533,
6935,
8064,
8,
6767,
14,
28539,
304,
272,
1978,
63,
354,
275,
283,
6767,
63,
4196,
15,
5506,
14,
1360,
7,
339,
347,
664,
63,
785,
8,
277,
304,
267,
372,
791,
1421,
356,
283,
1700,
936,
421,
199,
533,
1952,
5011,
8064,
8,
6767,
14,
28539,
304,
272,
7594,
275,
1952,
5011,
14,
1462,
14,
452,
342,
421,
199,
533,
6529,
8064,
8,
6767,
14,
28539,
304,
272,
7594,
275,
6529,
14,
1462,
14,
452,
342,
421,
199,
533,
10331,
8064,
8,
6767,
14,
28539,
304,
272,
7594,
275,
10331,
14,
1462,
14,
452,
342,
272,
1978,
63,
354,
63,
698,
275,
283,
1160,
7,
421,
199,
533,
7448,
1296,
8,
6767,
14,
23239,
304,
272,
408,
33,
3820,
2768,
626,
3181,
1133,
675,
282,
1402,
1041,
272,
7594,
275,
359,
267,
791,
2246,
356,
283,
12923,
297,
283,
2019,
356,
283,
3166,
2865,
2267,
267,
791,
2246,
356,
283,
57,
745,
79,
297,
221,
283,
2019,
356,
283,
47,
889,
936,
272,
1622,
272,
1978,
63,
354,
275,
283,
6767,
63,
4196,
15,
513,
14,
1360,
7,
421,
199,
533,
1952,
5011,
1296,
8,
6767,
14,
23239,
304,
272,
1978,
63,
354,
275,
283,
6767,
63,
4196,
15,
513,
14,
1360,
7,
272,
7594,
275,
1952,
5011,
14,
1462,
14,
452,
342,
421,
199,
533,
6529,
1296,
8,
6767,
14,
23239,
304,
272,
7594,
275,
6529,
14,
1462,
14,
452,
342,
421,
199,
533,
8388,
23862,
8566,
8,
23862,
8566,
304,
272,
347,
636,
826,
721,
277,
12,
7594,
12,
2034,
63,
890,
12,
503,
838,
796,
29,
16,
12,
2040,
63,
1667,
63,
2246,
63,
1606,
29,
549,
304,
267,
1613,
8,
7223,
23862,
8566,
12,
291,
2843,
826,
721,
288,
7594,
12,
288,
2034,
63,
890,
12,
288,
503,
838,
796,
29,
18,
12,
288,
2040,
63,
1667,
63,
2246,
63,
1606,
29,
3306,
63,
1667,
63,
2246,
63,
1606,
9,
199,
199,
533,
6529,
1296,
7223,
23862,
8566,
8,
5949,
1296,
304,
272,
9881,
23043,
63,
991,
275,
959,
339,
347,
664,
63,
22073,
8,
277,
12,
7594,
12,
2034,
63,
890,
12,
503,
838,
796,
29,
16,
12,
2040,
63,
1667,
63,
2246,
63,
1606,
29,
549,
304,
267,
372,
1613,
8,
5949,
1296,
7223,
23862,
8566,
12,
291,
680,
362,
63,
22073,
8,
288,
7594,
12,
288,
2034,
63,
890,
12,
288,
503,
838,
796,
29,
18,
12,
288,
2040,
63,
1667,
63,
2246,
63,
1606,
29,
3306,
63,
1667,
63,
2246,
63,
1606,
9,
421,
199,
533,
18684,
2768,
8,
6767,
14,
2821,
2768,
304,
272,
1824,
63,
533,
275,
18684,
2821,
272,
3182,
63,
633,
275,
3837,
63,
6395,
360,
8149,
63,
513,
358,
272,
1978,
63,
354,
275,
283,
6767,
63,
4196,
15,
964,
14,
1360,
7,
421,
199,
533,
1952,
5011,
2499,
8,
6767,
14,
2499,
2768,
304,
272,
1402,
275,
1952,
5011,
421,
199,
533,
11290,
1912,
5949,
2499,
8,
6767,
14,
2499,
2768,
304,
272,
7594,
275,
6529,
14,
1462,
14,
452,
342,
421,
199,
533,
6529,
2499,
8,
6767,
14,
2499,
2768,
304,
272,
1402,
275,
6529,
272,
3182,
63,
633,
275,
1994,
513,
15,
8149,
4805,
421,
199,
533,
12568,
1759,
5949,
2499,
8,
6767,
14,
2499,
2768,
304,
272,
1402,
275,
6529,
272,
1824,
63,
533,
275,
6529,
2821,
272,
1978,
63,
354,
275,
283,
6767,
63,
4196,
15,
964,
14,
1360,
7,
272,
1067,
63,
785,
63,
354,
275,
283,
2127,
89,
7,
339,
347,
664,
63,
3742,
63,
633,
8,
277,
304,
267,
372,
3837,
360,
2502,
63,
5506,
297,
1249,
1524,
277,
14,
785,
14,
344,
30453,
421,
199,
533,
6529,
2499,
28850,
8,
5949,
2499,
304,
272,
2963,
275,
1083,
63,
11547,
8,
2886,
63,
2427,
5130,
5949,
2499,
14,
1932,
9,
421,
199,
533,
1952,
5011,
4152,
8,
6767,
14,
4152,
2768,
304,
272,
1402,
275,
1952,
5011,
421,
199,
533,
11290,
1912,
5949,
4152,
8,
6767,
14,
4152,
2768,
304,
272,
7594,
275,
6529,
14,
1462,
14,
452,
342,
421,
199,
533,
6529,
4152,
8,
6767,
14,
4152,
2768,
304,
272,
1402,
275,
6529,
272,
3182,
63,
633,
275,
1994,
513,
15,
8149,
4805,
421,
199,
533,
7309,
5949,
4152,
8,
6767,
14,
4152,
2768,
304,
272,
3182,
63,
633,
275,
1994,
513,
15,
8149,
4805,
339,
347,
664,
63,
785,
8,
277,
304,
267,
372,
6529,
14,
1462,
14,
362,
8,
2051,
29,
17,
9,
421,
199,
533,
12568,
1759,
5949,
4152,
8,
6767,
14,
4152,
2768,
304,
272,
1402,
275,
6529,
272,
1824,
63,
533,
275,
6529,
2821,
272,
1978,
63,
354,
275,
283,
6767,
63,
4196,
15,
964,
14,
1360,
7,
272,
1067,
63,
785,
63,
354,
275,
283,
2127,
89,
7,
339,
347,
664,
63,
3742,
63,
633,
8,
277,
304,
267,
372,
3837,
360,
2502,
63,
5506,
297,
1249,
1524,
277,
14,
785,
14,
344,
30453,
421,
199,
533,
11290,
1912,
5949,
5392,
8,
6767,
14,
5392,
2768,
304,
272,
7594,
275,
6529,
14,
1462,
14,
452,
342,
421,
199,
533,
6529,
5392,
8,
6767,
14,
5392,
2768,
304,
272,
1402,
275,
6529,
272,
3182,
63,
633,
275,
1994,
513,
15,
8149,
4805,
421,
199,
533,
12568,
1759,
5949,
5392,
8,
6767,
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
] |
Myasuka/scikit-learn
|
setup.py
|
143
|
7364
|
#! /usr/bin/env python
#
# Copyright (C) 2007-2009 Cournapeau David <cournape@gmail.com>
# 2010 Fabian Pedregosa <fabian.pedregosa@inria.fr>
# License: 3-clause BSD
descr = """A set of python modules for machine learning and data mining"""
import sys
import os
import shutil
from distutils.command.clean import clean as Clean
if sys.version_info[0] < 3:
import __builtin__ as builtins
else:
import builtins
# This is a bit (!) hackish: we are setting a global variable so that the main
# sklearn __init__ can detect if it is being loaded by the setup routine, to
# avoid attempting to load components that aren't built yet:
# the numpy distutils extensions that are used by scikit-learn to recursively
# build the compiled extensions in sub-packages is based on the Python import
# machinery.
builtins.__SKLEARN_SETUP__ = True
DISTNAME = 'scikit-learn'
DESCRIPTION = 'A set of python modules for machine learning and data mining'
with open('README.rst') as f:
LONG_DESCRIPTION = f.read()
MAINTAINER = 'Andreas Mueller'
MAINTAINER_EMAIL = 'amueller@ais.uni-bonn.de'
URL = 'http://scikit-learn.org'
LICENSE = 'new BSD'
DOWNLOAD_URL = 'http://sourceforge.net/projects/scikit-learn/files/'
# We can actually import a restricted version of sklearn that
# does not need the compiled code
import sklearn
VERSION = sklearn.__version__
# Optional setuptools features
# We need to import setuptools early, if we want setuptools features,
# as it monkey-patches the 'setup' function
# For some commands, use setuptools
SETUPTOOLS_COMMANDS = set([
'develop', 'release', 'bdist_egg', 'bdist_rpm',
'bdist_wininst', 'install_egg_info', 'build_sphinx',
'egg_info', 'easy_install', 'upload', 'bdist_wheel',
'--single-version-externally-managed',
])
if SETUPTOOLS_COMMANDS.intersection(sys.argv):
import setuptools
extra_setuptools_args = dict(
zip_safe=False, # the package can run out of an .egg file
include_package_data=True,
)
else:
extra_setuptools_args = dict()
# Custom clean command to remove build artifacts
class CleanCommand(Clean):
description = "Remove build artifacts from the source tree"
def run(self):
Clean.run(self)
if os.path.exists('build'):
shutil.rmtree('build')
for dirpath, dirnames, filenames in os.walk('sklearn'):
for filename in filenames:
if (filename.endswith('.so') or filename.endswith('.pyd')
or filename.endswith('.dll')
or filename.endswith('.pyc')):
os.unlink(os.path.join(dirpath, filename))
for dirname in dirnames:
if dirname == '__pycache__':
shutil.rmtree(os.path.join(dirpath, dirname))
cmdclass = {'clean': CleanCommand}
# Optional wheelhouse-uploader features
# To automate release of binary packages for scikit-learn we need a tool
# to download the packages generated by travis and appveyor workers (with
# version number matching the current release) and upload them all at once
# to PyPI at release time.
# The URL of the artifact repositories are configured in the setup.cfg file.
WHEELHOUSE_UPLOADER_COMMANDS = set(['fetch_artifacts', 'upload_all'])
if WHEELHOUSE_UPLOADER_COMMANDS.intersection(sys.argv):
import wheelhouse_uploader.cmd
cmdclass.update(vars(wheelhouse_uploader.cmd))
def configuration(parent_package='', top_path=None):
if os.path.exists('MANIFEST'):
os.remove('MANIFEST')
from numpy.distutils.misc_util import Configuration
config = Configuration(None, parent_package, top_path)
# Avoid non-useful msg:
# "Ignoring attempt to set 'name' (from ... "
config.set_options(ignore_setup_xxx_py=True,
assume_default_configuration=True,
delegate_options_to_subpackages=True,
quiet=True)
config.add_subpackage('sklearn')
return config
def is_scipy_installed():
try:
import scipy
except ImportError:
return False
return True
def is_numpy_installed():
try:
import numpy
except ImportError:
return False
return True
def setup_package():
metadata = dict(name=DISTNAME,
maintainer=MAINTAINER,
maintainer_email=MAINTAINER_EMAIL,
description=DESCRIPTION,
license=LICENSE,
url=URL,
version=VERSION,
download_url=DOWNLOAD_URL,
long_description=LONG_DESCRIPTION,
classifiers=['Intended Audience :: Science/Research',
'Intended Audience :: Developers',
'License :: OSI Approved',
'Programming Language :: C',
'Programming Language :: Python',
'Topic :: Software Development',
'Topic :: Scientific/Engineering',
'Operating System :: Microsoft :: Windows',
'Operating System :: POSIX',
'Operating System :: Unix',
'Operating System :: MacOS',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
],
cmdclass=cmdclass,
**extra_setuptools_args)
if (len(sys.argv) >= 2
and ('--help' in sys.argv[1:] or sys.argv[1]
in ('--help-commands', 'egg_info', '--version', 'clean'))):
# For these actions, NumPy is not required.
#
# They are required to succeed without Numpy for example when
# pip is used to install Scikit-learn when Numpy is not yet present in
# the system.
try:
from setuptools import setup
except ImportError:
from distutils.core import setup
metadata['version'] = VERSION
else:
if is_numpy_installed() is False:
raise ImportError("Numerical Python (NumPy) is not installed.\n"
"scikit-learn requires NumPy.\n"
"Installation instructions are available on scikit-learn website: "
"http://scikit-learn.org/stable/install.html\n")
if is_scipy_installed() is False:
raise ImportError("Scientific Python (SciPy) is not installed.\n"
"scikit-learn requires SciPy.\n"
"Installation instructions are available on scikit-learn website: "
"http://scikit-learn.org/stable/install.html\n")
from numpy.distutils.core import setup
metadata['configuration'] = configuration
setup(**metadata)
if __name__ == "__main__":
setup_package()
|
bsd-3-clause
|
[
3168,
1182,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
334,
35,
9,
10219,
13,
8664,
1849,
349,
924,
3844,
20232,
665,
331,
349,
924,
32,
6799,
14,
957,
30,
199,
3,
5185,
7129,
481,
371,
5653,
510,
379,
1135,
29295,
665,
21159,
5653,
14,
1915,
1135,
29295,
32,
262,
23714,
14,
4391,
30,
199,
3,
844,
26,
650,
13,
8501,
6289,
199,
199,
12113,
275,
408,
33,
663,
402,
2366,
4621,
367,
6844,
9328,
436,
666,
1748,
316,
624,
199,
199,
646,
984,
199,
646,
747,
199,
646,
5145,
199,
504,
7065,
14,
1531,
14,
3118,
492,
3633,
465,
12762,
421,
199,
692,
984,
14,
1023,
63,
815,
59,
16,
61,
665,
650,
26,
272,
492,
636,
5351,
363,
465,
12963,
199,
2836,
26,
272,
492,
12963,
199,
199,
3,
961,
365,
282,
4546,
19452,
9,
11176,
2453,
26,
781,
787,
4260,
282,
2288,
1750,
880,
626,
314,
2446,
199,
3,
6357,
636,
826,
363,
883,
9696,
340,
652,
365,
3769,
6511,
701,
314,
3272,
12981,
12,
370,
199,
3,
5126,
19595,
370,
2248,
7323,
626,
10621,
1133,
6137,
5966,
26,
199,
3,
314,
2680,
7065,
5478,
626,
787,
1202,
701,
6276,
6065,
13,
4643,
370,
15035,
199,
3,
1900,
314,
10311,
5478,
315,
1007,
13,
5154,
365,
4079,
641,
314,
2018,
492,
199,
3,
28540,
14,
199,
10372,
855,
8656,
906,
26513,
63,
20836,
363,
275,
715,
199,
199,
13783,
2339,
275,
283,
551,
3258,
390,
13,
4643,
7,
199,
17705,
275,
283,
33,
663,
402,
2366,
4621,
367,
6844,
9328,
436,
666,
1748,
316,
7,
199,
1045,
1551,
360,
18195,
14,
8332,
358,
465,
289,
26,
272,
26594,
63,
17705,
275,
289,
14,
739,
342,
199,
2054,
2919,
9021,
540,
275,
283,
3325,
264,
305,
603,
13086,
1435,
7,
199,
2054,
2919,
9021,
540,
63,
10089,
275,
283,
455,
13086,
1435,
32,
65,
374,
14,
5411,
13,
13520,
78,
14,
271,
7,
199,
2632,
275,
283,
1014,
921,
551,
3258,
390,
13,
4643,
14,
1308,
7,
199,
3961,
275,
283,
1222,
6289,
7,
199,
24930,
63,
2632,
275,
283,
1014,
921,
22943,
14,
846,
15,
6776,
15,
551,
3258,
390,
13,
4643,
15,
1725,
4805,
199,
199,
3,
2136,
883,
5965,
492,
282,
15297,
1015,
402,
6357,
626,
199,
3,
1630,
440,
1929,
314,
10311,
1233,
199,
646,
6357,
199,
4612,
275,
6357,
855,
1023,
363,
421,
199,
3,
4879,
9116,
4534,
199,
3,
2136,
1929,
370,
492,
9116,
14670,
12,
340,
781,
2934,
9116,
4534,
12,
199,
3,
465,
652,
14198,
13,
11350,
314,
283,
2758,
7,
805,
199,
3,
2104,
2005,
3718,
12,
675,
9116,
199,
20836,
20261,
63,
28442,
275,
663,
779,
272,
283,
32176,
297,
283,
3221,
297,
283,
17403,
63,
5799,
297,
283,
17403,
63,
14191,
297,
272,
283,
17403,
63,
2676,
3615,
297,
283,
3174,
63,
5799,
63,
815,
297,
283,
1506,
63,
8008,
297,
272,
283,
5799,
63,
815,
297,
283,
13581,
63,
3174,
297,
283,
5064,
297,
283,
17403,
63,
11798,
297,
272,
2850,
4780,
13,
1023,
13,
18587,
1183,
13,
11122,
297,
199,
566,
199,
692,
11543,
2160,
20261,
63,
28442,
14,
12569,
8,
1274,
14,
3020,
304,
272,
492,
9116,
272,
2402,
63,
13623,
63,
589,
275,
1211,
8,
267,
3482,
63,
3489,
29,
797,
12,
221,
327,
314,
2559,
883,
1255,
734,
402,
376,
1275,
5799,
570,
267,
2387,
63,
2491,
63,
576,
29,
549,
12,
272,
776,
199,
2836,
26,
272,
2402,
63,
13623,
63,
589,
275,
1211,
342,
421,
199,
3,
8388,
3633,
1414,
370,
2813,
1900,
27990,
199,
199,
533,
12762,
3110,
8,
6580,
304,
272,
1369,
275,
298,
5587,
1900,
27990,
687,
314,
1350,
3123,
2,
339,
347,
1255,
8,
277,
304,
267,
12762,
14,
1065,
8,
277,
9,
267,
340,
747,
14,
515,
14,
2444,
360,
1506,
735,
288,
5145,
14,
9242,
360,
1506,
358,
267,
367,
20648,
12,
22310,
12,
6203,
315,
747,
14,
7757,
360,
27993,
735,
288,
367,
1788,
315,
6203,
26,
355,
340,
334,
1501,
14,
4130,
5175,
1152,
358,
503,
1788,
14,
4130,
5175,
647,
68,
358,
717,
503,
1788,
14,
4130,
5175,
9259,
358,
717,
503,
1788,
14,
4130,
5175,
11357,
8109,
490,
747,
14,
7162,
8,
736,
14,
515,
14,
904,
8,
17254,
12,
1788,
430,
288,
367,
9017,
315,
22310,
26,
355,
340,
9017,
508,
2560,
647,
1637,
3706,
490,
5145,
14,
9242,
8,
736,
14,
515,
14,
904,
8,
17254,
12,
9017,
430,
199,
199,
1760,
533,
275,
791,
3118,
356,
12762,
3110,
93,
421,
199,
3,
4879,
9989,
6740,
13,
13671,
4534,
199,
3,
4005,
6384,
676,
323,
4683,
402,
3366,
6117,
367,
6276,
6065,
13,
4643,
781,
1929,
282,
4744,
199,
3,
370,
5235,
314,
6117,
4046,
701,
1468,
5068,
436,
1145,
7158,
269,
14123,
334,
1045,
199,
3,
1015,
1329,
4877,
314,
1453,
4683,
9,
436,
5802,
3062,
1006,
737,
5403,
199,
3,
370,
24330,
737,
4683,
900,
14,
199,
3,
710,
2851,
402,
314,
18115,
23737,
787,
7526,
315,
314,
3272,
14,
4128,
570,
14,
199,
199,
31588,
2901,
2979,
4701,
63,
16418,
540,
63,
28442,
275,
663,
2941,
3535,
63,
30129,
297,
283,
5064,
63,
452,
1105,
199,
692,
644,
1645,
2901,
2979,
4701,
63,
16418,
540,
63,
28442,
14,
12569,
8,
1274,
14,
3020,
304,
272,
492,
9989,
6740,
63,
13671,
14,
1760,
272,
2088,
533,
14,
873,
8,
2936,
8,
11798,
6740,
63,
13671,
14,
1760,
430,
421,
199,
318,
2897,
8,
1708,
63,
2491,
4581,
2746,
63,
515,
29,
403,
304,
272,
340,
747,
14,
515,
14,
2444,
360,
24067,
735,
267,
747,
14,
2168,
360,
24067,
358,
339,
687,
2680,
14,
13350,
14,
9923,
63,
1974,
492,
11595,
272,
1101,
275,
11595,
8,
403,
12,
1676,
63,
2491,
12,
2746,
63,
515,
9,
339,
327,
19503,
2222,
13,
1180,
1893,
1499,
26,
272,
327,
298,
32390,
7427,
370,
663,
283,
354,
7,
334,
504,
2263,
298,
272,
1101,
14,
409,
63,
1419,
8,
4247,
63,
2758,
63,
10013,
63,
647,
29,
549,
12,
2432,
5534,
63,
885,
63,
4758,
29,
549,
12,
2432,
13080,
63,
1419,
63,
475,
63,
954,
5154,
29,
549,
12,
2432,
11971,
29,
549,
9,
339,
1101,
14,
525,
63
] |
[
1182,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
334,
35,
9,
10219,
13,
8664,
1849,
349,
924,
3844,
20232,
665,
331,
349,
924,
32,
6799,
14,
957,
30,
199,
3,
5185,
7129,
481,
371,
5653,
510,
379,
1135,
29295,
665,
21159,
5653,
14,
1915,
1135,
29295,
32,
262,
23714,
14,
4391,
30,
199,
3,
844,
26,
650,
13,
8501,
6289,
199,
199,
12113,
275,
408,
33,
663,
402,
2366,
4621,
367,
6844,
9328,
436,
666,
1748,
316,
624,
199,
199,
646,
984,
199,
646,
747,
199,
646,
5145,
199,
504,
7065,
14,
1531,
14,
3118,
492,
3633,
465,
12762,
421,
199,
692,
984,
14,
1023,
63,
815,
59,
16,
61,
665,
650,
26,
272,
492,
636,
5351,
363,
465,
12963,
199,
2836,
26,
272,
492,
12963,
199,
199,
3,
961,
365,
282,
4546,
19452,
9,
11176,
2453,
26,
781,
787,
4260,
282,
2288,
1750,
880,
626,
314,
2446,
199,
3,
6357,
636,
826,
363,
883,
9696,
340,
652,
365,
3769,
6511,
701,
314,
3272,
12981,
12,
370,
199,
3,
5126,
19595,
370,
2248,
7323,
626,
10621,
1133,
6137,
5966,
26,
199,
3,
314,
2680,
7065,
5478,
626,
787,
1202,
701,
6276,
6065,
13,
4643,
370,
15035,
199,
3,
1900,
314,
10311,
5478,
315,
1007,
13,
5154,
365,
4079,
641,
314,
2018,
492,
199,
3,
28540,
14,
199,
10372,
855,
8656,
906,
26513,
63,
20836,
363,
275,
715,
199,
199,
13783,
2339,
275,
283,
551,
3258,
390,
13,
4643,
7,
199,
17705,
275,
283,
33,
663,
402,
2366,
4621,
367,
6844,
9328,
436,
666,
1748,
316,
7,
199,
1045,
1551,
360,
18195,
14,
8332,
358,
465,
289,
26,
272,
26594,
63,
17705,
275,
289,
14,
739,
342,
199,
2054,
2919,
9021,
540,
275,
283,
3325,
264,
305,
603,
13086,
1435,
7,
199,
2054,
2919,
9021,
540,
63,
10089,
275,
283,
455,
13086,
1435,
32,
65,
374,
14,
5411,
13,
13520,
78,
14,
271,
7,
199,
2632,
275,
283,
1014,
921,
551,
3258,
390,
13,
4643,
14,
1308,
7,
199,
3961,
275,
283,
1222,
6289,
7,
199,
24930,
63,
2632,
275,
283,
1014,
921,
22943,
14,
846,
15,
6776,
15,
551,
3258,
390,
13,
4643,
15,
1725,
4805,
199,
199,
3,
2136,
883,
5965,
492,
282,
15297,
1015,
402,
6357,
626,
199,
3,
1630,
440,
1929,
314,
10311,
1233,
199,
646,
6357,
199,
4612,
275,
6357,
855,
1023,
363,
421,
199,
3,
4879,
9116,
4534,
199,
3,
2136,
1929,
370,
492,
9116,
14670,
12,
340,
781,
2934,
9116,
4534,
12,
199,
3,
465,
652,
14198,
13,
11350,
314,
283,
2758,
7,
805,
199,
3,
2104,
2005,
3718,
12,
675,
9116,
199,
20836,
20261,
63,
28442,
275,
663,
779,
272,
283,
32176,
297,
283,
3221,
297,
283,
17403,
63,
5799,
297,
283,
17403,
63,
14191,
297,
272,
283,
17403,
63,
2676,
3615,
297,
283,
3174,
63,
5799,
63,
815,
297,
283,
1506,
63,
8008,
297,
272,
283,
5799,
63,
815,
297,
283,
13581,
63,
3174,
297,
283,
5064,
297,
283,
17403,
63,
11798,
297,
272,
2850,
4780,
13,
1023,
13,
18587,
1183,
13,
11122,
297,
199,
566,
199,
692,
11543,
2160,
20261,
63,
28442,
14,
12569,
8,
1274,
14,
3020,
304,
272,
492,
9116,
272,
2402,
63,
13623,
63,
589,
275,
1211,
8,
267,
3482,
63,
3489,
29,
797,
12,
221,
327,
314,
2559,
883,
1255,
734,
402,
376,
1275,
5799,
570,
267,
2387,
63,
2491,
63,
576,
29,
549,
12,
272,
776,
199,
2836,
26,
272,
2402,
63,
13623,
63,
589,
275,
1211,
342,
421,
199,
3,
8388,
3633,
1414,
370,
2813,
1900,
27990,
199,
199,
533,
12762,
3110,
8,
6580,
304,
272,
1369,
275,
298,
5587,
1900,
27990,
687,
314,
1350,
3123,
2,
339,
347,
1255,
8,
277,
304,
267,
12762,
14,
1065,
8,
277,
9,
267,
340,
747,
14,
515,
14,
2444,
360,
1506,
735,
288,
5145,
14,
9242,
360,
1506,
358,
267,
367,
20648,
12,
22310,
12,
6203,
315,
747,
14,
7757,
360,
27993,
735,
288,
367,
1788,
315,
6203,
26,
355,
340,
334,
1501,
14,
4130,
5175,
1152,
358,
503,
1788,
14,
4130,
5175,
647,
68,
358,
717,
503,
1788,
14,
4130,
5175,
9259,
358,
717,
503,
1788,
14,
4130,
5175,
11357,
8109,
490,
747,
14,
7162,
8,
736,
14,
515,
14,
904,
8,
17254,
12,
1788,
430,
288,
367,
9017,
315,
22310,
26,
355,
340,
9017,
508,
2560,
647,
1637,
3706,
490,
5145,
14,
9242,
8,
736,
14,
515,
14,
904,
8,
17254,
12,
9017,
430,
199,
199,
1760,
533,
275,
791,
3118,
356,
12762,
3110,
93,
421,
199,
3,
4879,
9989,
6740,
13,
13671,
4534,
199,
3,
4005,
6384,
676,
323,
4683,
402,
3366,
6117,
367,
6276,
6065,
13,
4643,
781,
1929,
282,
4744,
199,
3,
370,
5235,
314,
6117,
4046,
701,
1468,
5068,
436,
1145,
7158,
269,
14123,
334,
1045,
199,
3,
1015,
1329,
4877,
314,
1453,
4683,
9,
436,
5802,
3062,
1006,
737,
5403,
199,
3,
370,
24330,
737,
4683,
900,
14,
199,
3,
710,
2851,
402,
314,
18115,
23737,
787,
7526,
315,
314,
3272,
14,
4128,
570,
14,
199,
199,
31588,
2901,
2979,
4701,
63,
16418,
540,
63,
28442,
275,
663,
2941,
3535,
63,
30129,
297,
283,
5064,
63,
452,
1105,
199,
692,
644,
1645,
2901,
2979,
4701,
63,
16418,
540,
63,
28442,
14,
12569,
8,
1274,
14,
3020,
304,
272,
492,
9989,
6740,
63,
13671,
14,
1760,
272,
2088,
533,
14,
873,
8,
2936,
8,
11798,
6740,
63,
13671,
14,
1760,
430,
421,
199,
318,
2897,
8,
1708,
63,
2491,
4581,
2746,
63,
515,
29,
403,
304,
272,
340,
747,
14,
515,
14,
2444,
360,
24067,
735,
267,
747,
14,
2168,
360,
24067,
358,
339,
687,
2680,
14,
13350,
14,
9923,
63,
1974,
492,
11595,
272,
1101,
275,
11595,
8,
403,
12,
1676,
63,
2491,
12,
2746,
63,
515,
9,
339,
327,
19503,
2222,
13,
1180,
1893,
1499,
26,
272,
327,
298,
32390,
7427,
370,
663,
283,
354,
7,
334,
504,
2263,
298,
272,
1101,
14,
409,
63,
1419,
8,
4247,
63,
2758,
63,
10013,
63,
647,
29,
549,
12,
2432,
5534,
63,
885,
63,
4758,
29,
549,
12,
2432,
13080,
63,
1419,
63,
475,
63,
954,
5154,
29,
549,
12,
2432,
11971,
29,
549,
9,
339,
1101,
14,
525,
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,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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
] |
garthomp/ruby_blog
|
node_modules/grunt-docker/node_modules/docker/node_modules/pygmentize-bundled/vendor/pygments/pygments/lexers/agile.py
|
197
|
100441
|
# -*- coding: utf-8 -*-
"""
pygments.lexers.agile
~~~~~~~~~~~~~~~~~~~~~
Lexers for agile languages.
:copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
import re
from pygments.lexer import Lexer, RegexLexer, ExtendedRegexLexer, \
LexerContext, include, combined, do_insertions, bygroups, using, this
from pygments.token import Error, Text, Other, \
Comment, Operator, Keyword, Name, String, Number, Generic, Punctuation
from pygments.util import get_bool_opt, get_list_opt, shebang_matches
from pygments import unistring as uni
__all__ = ['PythonLexer', 'PythonConsoleLexer', 'PythonTracebackLexer',
'Python3Lexer', 'Python3TracebackLexer', 'RubyLexer',
'RubyConsoleLexer', 'PerlLexer', 'LuaLexer', 'MoonScriptLexer',
'CrocLexer', 'MiniDLexer', 'IoLexer', 'TclLexer', 'FactorLexer',
'FancyLexer', 'DgLexer', 'Perl6Lexer']
# b/w compatibility
from pygments.lexers.functional import SchemeLexer
from pygments.lexers.jvm import IokeLexer, ClojureLexer
line_re = re.compile('.*?\n')
class PythonLexer(RegexLexer):
"""
For `Python <http://www.python.org>`_ source code.
"""
name = 'Python'
aliases = ['python', 'py', 'sage']
filenames = ['*.py', '*.pyw', '*.sc', 'SConstruct', 'SConscript', '*.tac', '*.sage']
mimetypes = ['text/x-python', 'application/x-python']
tokens = {
'root': [
(r'\n', Text),
(r'^(\s*)([rRuU]{,2}"""(?:.|\n)*?""")', bygroups(Text, String.Doc)),
(r"^(\s*)([rRuU]{,2}'''(?:.|\n)*?''')", bygroups(Text, String.Doc)),
(r'[^\S\n]+', Text),
(r'#.*$', Comment),
(r'[]{}:(),;[]', Punctuation),
(r'\\\n', Text),
(r'\\', Text),
(r'(in|is|and|or|not)\b', Operator.Word),
(r'!=|==|<<|>>|[-~+/*%=<>&^|.]', Operator),
include('keywords'),
(r'(def)((?:\s|\\\s)+)', bygroups(Keyword, Text), 'funcname'),
(r'(class)((?:\s|\\\s)+)', bygroups(Keyword, Text), 'classname'),
(r'(from)((?:\s|\\\s)+)', bygroups(Keyword.Namespace, Text),
'fromimport'),
(r'(import)((?:\s|\\\s)+)', bygroups(Keyword.Namespace, Text),
'import'),
include('builtins'),
include('backtick'),
('(?:[rR]|[uU][rR]|[rR][uU])"""', String, 'tdqs'),
("(?:[rR]|[uU][rR]|[rR][uU])'''", String, 'tsqs'),
('(?:[rR]|[uU][rR]|[rR][uU])"', String, 'dqs'),
("(?:[rR]|[uU][rR]|[rR][uU])'", String, 'sqs'),
('[uU]?"""', String, combined('stringescape', 'tdqs')),
("[uU]?'''", String, combined('stringescape', 'tsqs')),
('[uU]?"', String, combined('stringescape', 'dqs')),
("[uU]?'", String, combined('stringescape', 'sqs')),
include('name'),
include('numbers'),
],
'keywords': [
(r'(assert|break|continue|del|elif|else|except|exec|'
r'finally|for|global|if|lambda|pass|print|raise|'
r'return|try|while|yield(\s+from)?|as|with)\b', Keyword),
],
'builtins': [
(r'(?<!\.)(__import__|abs|all|any|apply|basestring|bin|bool|buffer|'
r'bytearray|bytes|callable|chr|classmethod|cmp|coerce|compile|'
r'complex|delattr|dict|dir|divmod|enumerate|eval|execfile|exit|'
r'file|filter|float|frozenset|getattr|globals|hasattr|hash|hex|id|'
r'input|int|intern|isinstance|issubclass|iter|len|list|locals|'
r'long|map|max|min|next|object|oct|open|ord|pow|property|range|'
r'raw_input|reduce|reload|repr|reversed|round|set|setattr|slice|'
r'sorted|staticmethod|str|sum|super|tuple|type|unichr|unicode|'
r'vars|xrange|zip)\b', Name.Builtin),
(r'(?<!\.)(self|None|Ellipsis|NotImplemented|False|True'
r')\b', Name.Builtin.Pseudo),
(r'(?<!\.)(ArithmeticError|AssertionError|AttributeError|'
r'BaseException|DeprecationWarning|EOFError|EnvironmentError|'
r'Exception|FloatingPointError|FutureWarning|GeneratorExit|IOError|'
r'ImportError|ImportWarning|IndentationError|IndexError|KeyError|'
r'KeyboardInterrupt|LookupError|MemoryError|NameError|'
r'NotImplemented|NotImplementedError|OSError|OverflowError|'
r'OverflowWarning|PendingDeprecationWarning|ReferenceError|'
r'RuntimeError|RuntimeWarning|StandardError|StopIteration|'
r'SyntaxError|SyntaxWarning|SystemError|SystemExit|TabError|'
r'TypeError|UnboundLocalError|UnicodeDecodeError|'
r'UnicodeEncodeError|UnicodeError|UnicodeTranslateError|'
r'UnicodeWarning|UserWarning|ValueError|VMSError|Warning|'
r'WindowsError|ZeroDivisionError)\b', Name.Exception),
],
'numbers': [
(r'(\d+\.\d*|\d*\.\d+)([eE][+-]?[0-9]+)?j?', Number.Float),
(r'\d+[eE][+-]?[0-9]+j?', Number.Float),
(r'0[0-7]+j?', Number.Oct),
(r'0[xX][a-fA-F0-9]+', Number.Hex),
(r'\d+L', Number.Integer.Long),
(r'\d+j?', Number.Integer)
],
'backtick': [
('`.*?`', String.Backtick),
],
'name': [
(r'@[a-zA-Z0-9_.]+', Name.Decorator),
('[a-zA-Z_][a-zA-Z0-9_]*', Name),
],
'funcname': [
('[a-zA-Z_][a-zA-Z0-9_]*', Name.Function, '#pop')
],
'classname': [
('[a-zA-Z_][a-zA-Z0-9_]*', Name.Class, '#pop')
],
'import': [
(r'(?:[ \t]|\\\n)+', Text),
(r'as\b', Keyword.Namespace),
(r',', Operator),
(r'[a-zA-Z_][a-zA-Z0-9_.]*', Name.Namespace),
(r'', Text, '#pop') # all else: go back
],
'fromimport': [
(r'(?:[ \t]|\\\n)+', Text),
(r'import\b', Keyword.Namespace, '#pop'),
# if None occurs here, it's "raise x from None", since None can
# never be a module name
(r'None\b', Name.Builtin.Pseudo, '#pop'),
# sadly, in "raise x from y" y will be highlighted as namespace too
(r'[a-zA-Z_.][a-zA-Z0-9_.]*', Name.Namespace),
# anything else here also means "raise x from y" and is therefore
# not an error
(r'', Text, '#pop'),
],
'stringescape': [
(r'\\([\\abfnrtv"\']|\n|N{.*?}|u[a-fA-F0-9]{4}|'
r'U[a-fA-F0-9]{8}|x[a-fA-F0-9]{2}|[0-7]{1,3})', String.Escape)
],
'strings': [
(r'%(\([a-zA-Z0-9_]+\))?[-#0 +]*([0-9]+|[*])?(\.([0-9]+|[*]))?'
'[hlL]?[diouxXeEfFgGcrs%]', String.Interpol),
(r'[^\\\'"%\n]+', String),
# quotes, percents and backslashes must be parsed one at a time
(r'[\'"\\]', String),
# unhandled string formatting sign
(r'%', String)
# newlines are an error (use "nl" state)
],
'nl': [
(r'\n', String)
],
'dqs': [
(r'"', String, '#pop'),
(r'\\\\|\\"|\\\n', String.Escape), # included here for raw strings
include('strings')
],
'sqs': [
(r"'", String, '#pop'),
(r"\\\\|\\'|\\\n", String.Escape), # included here for raw strings
include('strings')
],
'tdqs': [
(r'"""', String, '#pop'),
include('strings'),
include('nl')
],
'tsqs': [
(r"'''", String, '#pop'),
include('strings'),
include('nl')
],
}
def analyse_text(text):
return shebang_matches(text, r'pythonw?(2(\.\d)?)?') or \
'import ' in text[:1000]
class Python3Lexer(RegexLexer):
"""
For `Python <http://www.python.org>`_ source code (version 3.0).
*New in Pygments 0.10.*
"""
name = 'Python 3'
aliases = ['python3', 'py3']
filenames = [] # Nothing until Python 3 gets widespread
mimetypes = ['text/x-python3', 'application/x-python3']
flags = re.MULTILINE | re.UNICODE
uni_name = "[%s][%s]*" % (uni.xid_start, uni.xid_continue)
tokens = PythonLexer.tokens.copy()
tokens['keywords'] = [
(r'(assert|break|continue|del|elif|else|except|'
r'finally|for|global|if|lambda|pass|raise|nonlocal|'
r'return|try|while|yield(\s+from)?|as|with|True|False|None)\b',
Keyword),
]
tokens['builtins'] = [
(r'(?<!\.)(__import__|abs|all|any|bin|bool|bytearray|bytes|'
r'chr|classmethod|cmp|compile|complex|delattr|dict|dir|'
r'divmod|enumerate|eval|filter|float|format|frozenset|getattr|'
r'globals|hasattr|hash|hex|id|input|int|isinstance|issubclass|'
r'iter|len|list|locals|map|max|memoryview|min|next|object|oct|'
r'open|ord|pow|print|property|range|repr|reversed|round|'
r'set|setattr|slice|sorted|staticmethod|str|sum|super|tuple|type|'
r'vars|zip)\b', Name.Builtin),
(r'(?<!\.)(self|Ellipsis|NotImplemented)\b', Name.Builtin.Pseudo),
(r'(?<!\.)(ArithmeticError|AssertionError|AttributeError|'
r'BaseException|BufferError|BytesWarning|DeprecationWarning|'
r'EOFError|EnvironmentError|Exception|FloatingPointError|'
r'FutureWarning|GeneratorExit|IOError|ImportError|'
r'ImportWarning|IndentationError|IndexError|KeyError|'
r'KeyboardInterrupt|LookupError|MemoryError|NameError|'
r'NotImplementedError|OSError|OverflowError|'
r'PendingDeprecationWarning|ReferenceError|'
r'RuntimeError|RuntimeWarning|StopIteration|'
r'SyntaxError|SyntaxWarning|SystemError|SystemExit|TabError|'
r'TypeError|UnboundLocalError|UnicodeDecodeError|'
r'UnicodeEncodeError|UnicodeError|UnicodeTranslateError|'
r'UnicodeWarning|UserWarning|ValueError|VMSError|Warning|'
r'WindowsError|ZeroDivisionError|'
# new builtin exceptions from PEP 3151
r'BlockingIOError|ChildProcessError|ConnectionError|'
r'BrokenPipeError|ConnectionAbortedError|ConnectionRefusedError|'
r'ConnectionResetError|FileExistsError|FileNotFoundError|'
r'InterruptedError|IsADirectoryError|NotADirectoryError|'
r'PermissionError|ProcessLookupError|TimeoutError)\b',
Name.Exception),
]
tokens['numbers'] = [
(r'(\d+\.\d*|\d*\.\d+)([eE][+-]?[0-9]+)?', Number.Float),
(r'0[oO][0-7]+', Number.Oct),
(r'0[bB][01]+', Number.Bin),
(r'0[xX][a-fA-F0-9]+', Number.Hex),
(r'\d+', Number.Integer)
]
tokens['backtick'] = []
tokens['name'] = [
(r'@[a-zA-Z0-9_]+', Name.Decorator),
(uni_name, Name),
]
tokens['funcname'] = [
(uni_name, Name.Function, '#pop')
]
tokens['classname'] = [
(uni_name, Name.Class, '#pop')
]
tokens['import'] = [
(r'(\s+)(as)(\s+)', bygroups(Text, Keyword, Text)),
(r'\.', Name.Namespace),
(uni_name, Name.Namespace),
(r'(\s*)(,)(\s*)', bygroups(Text, Operator, Text)),
(r'', Text, '#pop') # all else: go back
]
tokens['fromimport'] = [
(r'(\s+)(import)\b', bygroups(Text, Keyword), '#pop'),
(r'\.', Name.Namespace),
(uni_name, Name.Namespace),
(r'', Text, '#pop'),
]
# don't highlight "%s" substitutions
tokens['strings'] = [
(r'[^\\\'"%\n]+', String),
# quotes, percents and backslashes must be parsed one at a time
(r'[\'"\\]', String),
# unhandled string formatting sign
(r'%', String)
# newlines are an error (use "nl" state)
]
def analyse_text(text):
return shebang_matches(text, r'pythonw?3(\.\d)?')
class PythonConsoleLexer(Lexer):
"""
For Python console output or doctests, such as:
.. sourcecode:: pycon
>>> a = 'foo'
>>> print a
foo
>>> 1 / 0
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ZeroDivisionError: integer division or modulo by zero
Additional options:
`python3`
Use Python 3 lexer for code. Default is ``False``.
*New in Pygments 1.0.*
"""
name = 'Python console session'
aliases = ['pycon']
mimetypes = ['text/x-python-doctest']
def __init__(self, **options):
self.python3 = get_bool_opt(options, 'python3', False)
Lexer.__init__(self, **options)
def get_tokens_unprocessed(self, text):
if self.python3:
pylexer = Python3Lexer(**self.options)
tblexer = Python3TracebackLexer(**self.options)
else:
pylexer = PythonLexer(**self.options)
tblexer = PythonTracebackLexer(**self.options)
curcode = ''
insertions = []
curtb = ''
tbindex = 0
tb = 0
for match in line_re.finditer(text):
line = match.group()
if line.startswith(u'>>> ') or line.startswith(u'... '):
tb = 0
insertions.append((len(curcode),
[(0, Generic.Prompt, line[:4])]))
curcode += line[4:]
elif line.rstrip() == u'...' and not tb:
# only a new >>> prompt can end an exception block
# otherwise an ellipsis in place of the traceback frames
# will be mishandled
insertions.append((len(curcode),
[(0, Generic.Prompt, u'...')]))
curcode += line[3:]
else:
if curcode:
for item in do_insertions(insertions,
pylexer.get_tokens_unprocessed(curcode)):
yield item
curcode = ''
insertions = []
if (line.startswith(u'Traceback (most recent call last):') or
re.match(ur' File "[^"]+", line \d+\n$', line)):
tb = 1
curtb = line
tbindex = match.start()
elif line == 'KeyboardInterrupt\n':
yield match.start(), Name.Class, line
elif tb:
curtb += line
if not (line.startswith(' ') or line.strip() == u'...'):
tb = 0
for i, t, v in tblexer.get_tokens_unprocessed(curtb):
yield tbindex+i, t, v
else:
yield match.start(), Generic.Output, line
if curcode:
for item in do_insertions(insertions,
pylexer.get_tokens_unprocessed(curcode)):
yield item
class PythonTracebackLexer(RegexLexer):
"""
For Python tracebacks.
*New in Pygments 0.7.*
"""
name = 'Python Traceback'
aliases = ['pytb']
filenames = ['*.pytb']
mimetypes = ['text/x-python-traceback']
tokens = {
'root': [
(r'^Traceback \(most recent call last\):\n',
Generic.Traceback, 'intb'),
# SyntaxError starts with this.
(r'^(?= File "[^"]+", line \d+)', Generic.Traceback, 'intb'),
(r'^.*\n', Other),
],
'intb': [
(r'^( File )("[^"]+")(, line )(\d+)(, in )(.+)(\n)',
bygroups(Text, Name.Builtin, Text, Number, Text, Name, Text)),
(r'^( File )("[^"]+")(, line )(\d+)(\n)',
bygroups(Text, Name.Builtin, Text, Number, Text)),
(r'^( )(.+)(\n)',
bygroups(Text, using(PythonLexer), Text)),
(r'^([ \t]*)(\.\.\.)(\n)',
bygroups(Text, Comment, Text)), # for doctests...
(r'^([^:]+)(: )(.+)(\n)',
bygroups(Generic.Error, Text, Name, Text), '#pop'),
(r'^([a-zA-Z_][a-zA-Z0-9_]*)(:?\n)',
bygroups(Generic.Error, Text), '#pop')
],
}
class Python3TracebackLexer(RegexLexer):
"""
For Python 3.0 tracebacks, with support for chained exceptions.
*New in Pygments 1.0.*
"""
name = 'Python 3.0 Traceback'
aliases = ['py3tb']
filenames = ['*.py3tb']
mimetypes = ['text/x-python3-traceback']
tokens = {
'root': [
(r'\n', Text),
(r'^Traceback \(most recent call last\):\n', Generic.Traceback, 'intb'),
(r'^During handling of the above exception, another '
r'exception occurred:\n\n', Generic.Traceback),
(r'^The above exception was the direct cause of the '
r'following exception:\n\n', Generic.Traceback),
(r'^(?= File "[^"]+", line \d+)', Generic.Traceback, 'intb'),
],
'intb': [
(r'^( File )("[^"]+")(, line )(\d+)(, in )(.+)(\n)',
bygroups(Text, Name.Builtin, Text, Number, Text, Name, Text)),
(r'^( File )("[^"]+")(, line )(\d+)(\n)',
bygroups(Text, Name.Builtin, Text, Number, Text)),
(r'^( )(.+)(\n)',
bygroups(Text, using(Python3Lexer), Text)),
(r'^([ \t]*)(\.\.\.)(\n)',
bygroups(Text, Comment, Text)), # for doctests...
(r'^([^:]+)(: )(.+)(\n)',
bygroups(Generic.Error, Text, Name, Text), '#pop'),
(r'^([a-zA-Z_][a-zA-Z0-9_]*)(:?\n)',
bygroups(Generic.Error, Text), '#pop')
],
}
class RubyLexer(ExtendedRegexLexer):
"""
For `Ruby <http://www.ruby-lang.org>`_ source code.
"""
name = 'Ruby'
aliases = ['rb', 'ruby', 'duby']
filenames = ['*.rb', '*.rbw', 'Rakefile', '*.rake', '*.gemspec',
'*.rbx', '*.duby']
mimetypes = ['text/x-ruby', 'application/x-ruby']
flags = re.DOTALL | re.MULTILINE
def heredoc_callback(self, match, ctx):
# okay, this is the hardest part of parsing Ruby...
# match: 1 = <<-?, 2 = quote? 3 = name 4 = quote? 5 = rest of line
start = match.start(1)
yield start, Operator, match.group(1) # <<-?
yield match.start(2), String.Heredoc, match.group(2) # quote ", ', `
yield match.start(3), Name.Constant, match.group(3) # heredoc name
yield match.start(4), String.Heredoc, match.group(4) # quote again
heredocstack = ctx.__dict__.setdefault('heredocstack', [])
outermost = not bool(heredocstack)
heredocstack.append((match.group(1) == '<<-', match.group(3)))
ctx.pos = match.start(5)
ctx.end = match.end(5)
# this may find other heredocs
for i, t, v in self.get_tokens_unprocessed(context=ctx):
yield i, t, v
ctx.pos = match.end()
if outermost:
# this is the outer heredoc again, now we can process them all
for tolerant, hdname in heredocstack:
lines = []
for match in line_re.finditer(ctx.text, ctx.pos):
if tolerant:
check = match.group().strip()
else:
check = match.group().rstrip()
if check == hdname:
for amatch in lines:
yield amatch.start(), String.Heredoc, amatch.group()
yield match.start(), Name.Constant, match.group()
ctx.pos = match.end()
break
else:
lines.append(match)
else:
# end of heredoc not found -- error!
for amatch in lines:
yield amatch.start(), Error, amatch.group()
ctx.end = len(ctx.text)
del heredocstack[:]
def gen_rubystrings_rules():
def intp_regex_callback(self, match, ctx):
yield match.start(1), String.Regex, match.group(1) # begin
nctx = LexerContext(match.group(3), 0, ['interpolated-regex'])
for i, t, v in self.get_tokens_unprocessed(context=nctx):
yield match.start(3)+i, t, v
yield match.start(4), String.Regex, match.group(4) # end[mixounse]*
ctx.pos = match.end()
def intp_string_callback(self, match, ctx):
yield match.start(1), String.Other, match.group(1)
nctx = LexerContext(match.group(3), 0, ['interpolated-string'])
for i, t, v in self.get_tokens_unprocessed(context=nctx):
yield match.start(3)+i, t, v
yield match.start(4), String.Other, match.group(4) # end
ctx.pos = match.end()
states = {}
states['strings'] = [
# easy ones
(r'\:@{0,2}([a-zA-Z_]\w*[\!\?]?|\*\*?|[-+]@?|'
r'[/%&|^`~]|\[\]=?|<<|>>|<=?>|>=?|===?)', String.Symbol),
(r":'(\\\\|\\'|[^'])*'", String.Symbol),
(r"'(\\\\|\\'|[^'])*'", String.Single),
(r':"', String.Symbol, 'simple-sym'),
(r'([a-zA-Z_][a-zA-Z0-9]*)(:)(?!:)',
bygroups(String.Symbol, Punctuation)), # Since Ruby 1.9
(r'"', String.Double, 'simple-string'),
(r'(?<!\.)`', String.Backtick, 'simple-backtick'),
]
# double-quoted string and symbol
for name, ttype, end in ('string', String.Double, '"'), \
('sym', String.Symbol, '"'), \
('backtick', String.Backtick, '`'):
states['simple-'+name] = [
include('string-intp-escaped'),
(r'[^\\%s#]+' % end, ttype),
(r'[\\#]', ttype),
(end, ttype, '#pop'),
]
# braced quoted strings
for lbrace, rbrace, name in ('\\{', '\\}', 'cb'), \
('\\[', '\\]', 'sb'), \
('\\(', '\\)', 'pa'), \
('<', '>', 'ab'):
states[name+'-intp-string'] = [
(r'\\[\\' + lbrace + rbrace + ']', String.Other),
(r'(?<!\\)' + lbrace, String.Other, '#push'),
(r'(?<!\\)' + rbrace, String.Other, '#pop'),
include('string-intp-escaped'),
(r'[\\#' + lbrace + rbrace + ']', String.Other),
(r'[^\\#' + lbrace + rbrace + ']+', String.Other),
]
states['strings'].append((r'%[QWx]?' + lbrace, String.Other,
name+'-intp-string'))
states[name+'-string'] = [
(r'\\[\\' + lbrace + rbrace + ']', String.Other),
(r'(?<!\\)' + lbrace, String.Other, '#push'),
(r'(?<!\\)' + rbrace, String.Other, '#pop'),
(r'[\\#' + lbrace + rbrace + ']', String.Other),
(r'[^\\#' + lbrace + rbrace + ']+', String.Other),
]
states['strings'].append((r'%[qsw]' + lbrace, String.Other,
name+'-string'))
states[name+'-regex'] = [
(r'\\[\\' + lbrace + rbrace + ']', String.Regex),
(r'(?<!\\)' + lbrace, String.Regex, '#push'),
(r'(?<!\\)' + rbrace + '[mixounse]*', String.Regex, '#pop'),
include('string-intp'),
(r'[\\#' + lbrace + rbrace + ']', String.Regex),
(r'[^\\#' + lbrace + rbrace + ']+', String.Regex),
]
states['strings'].append((r'%r' + lbrace, String.Regex,
name+'-regex'))
# these must come after %<brace>!
states['strings'] += [
# %r regex
(r'(%r([^a-zA-Z0-9]))((?:\\\2|(?!\2).)*)(\2[mixounse]*)',
intp_regex_callback),
# regular fancy strings with qsw
(r'%[qsw]([^a-zA-Z0-9])((?:\\\1|(?!\1).)*)\1', String.Other),
(r'(%[QWx]([^a-zA-Z0-9]))((?:\\\2|(?!\2).)*)(\2)',
intp_string_callback),
# special forms of fancy strings after operators or
# in method calls with braces
(r'(?<=[-+/*%=<>&!^|~,(])(\s*)(%([\t ])(?:(?:\\\3|(?!\3).)*)\3)',
bygroups(Text, String.Other, None)),
# and because of fixed width lookbehinds the whole thing a
# second time for line startings...
(r'^(\s*)(%([\t ])(?:(?:\\\3|(?!\3).)*)\3)',
bygroups(Text, String.Other, None)),
# all regular fancy strings without qsw
(r'(%([^a-zA-Z0-9\s]))((?:\\\2|(?!\2).)*)(\2)',
intp_string_callback),
]
return states
tokens = {
'root': [
(r'#.*?$', Comment.Single),
(r'=begin\s.*?\n=end.*?$', Comment.Multiline),
# keywords
(r'(BEGIN|END|alias|begin|break|case|defined\?|'
r'do|else|elsif|end|ensure|for|if|in|next|redo|'
r'rescue|raise|retry|return|super|then|undef|unless|until|when|'
r'while|yield)\b', Keyword),
# start of function, class and module names
(r'(module)(\s+)([a-zA-Z_][a-zA-Z0-9_]*'
r'(?:::[a-zA-Z_][a-zA-Z0-9_]*)*)',
bygroups(Keyword, Text, Name.Namespace)),
(r'(def)(\s+)', bygroups(Keyword, Text), 'funcname'),
(r'def(?=[*%&^`~+-/\[<>=])', Keyword, 'funcname'),
(r'(class)(\s+)', bygroups(Keyword, Text), 'classname'),
# special methods
(r'(initialize|new|loop|include|extend|raise|attr_reader|'
r'attr_writer|attr_accessor|attr|catch|throw|private|'
r'module_function|public|protected|true|false|nil)\b',
Keyword.Pseudo),
(r'(not|and|or)\b', Operator.Word),
(r'(autoload|block_given|const_defined|eql|equal|frozen|include|'
r'instance_of|is_a|iterator|kind_of|method_defined|nil|'
r'private_method_defined|protected_method_defined|'
r'public_method_defined|respond_to|tainted)\?', Name.Builtin),
(r'(chomp|chop|exit|gsub|sub)!', Name.Builtin),
(r'(?<!\.)(Array|Float|Integer|String|__id__|__send__|abort|'
r'ancestors|at_exit|autoload|binding|callcc|caller|'
r'catch|chomp|chop|class_eval|class_variables|'
r'clone|const_defined\?|const_get|const_missing|const_set|'
r'constants|display|dup|eval|exec|exit|extend|fail|fork|'
r'format|freeze|getc|gets|global_variables|gsub|'
r'hash|id|included_modules|inspect|instance_eval|'
r'instance_method|instance_methods|'
r'instance_variable_get|instance_variable_set|instance_variables|'
r'lambda|load|local_variables|loop|'
r'method|method_missing|methods|module_eval|name|'
r'object_id|open|p|print|printf|private_class_method|'
r'private_instance_methods|'
r'private_methods|proc|protected_instance_methods|'
r'protected_methods|public_class_method|'
r'public_instance_methods|public_methods|'
r'putc|puts|raise|rand|readline|readlines|require|'
r'scan|select|self|send|set_trace_func|singleton_methods|sleep|'
r'split|sprintf|srand|sub|syscall|system|taint|'
r'test|throw|to_a|to_s|trace_var|trap|untaint|untrace_var|'
r'warn)\b', Name.Builtin),
(r'__(FILE|LINE)__\b', Name.Builtin.Pseudo),
# normal heredocs
(r'(?<!\w)(<<-?)(["`\']?)([a-zA-Z_]\w*)(\2)(.*?\n)',
heredoc_callback),
# empty string heredocs
(r'(<<-?)("|\')()(\2)(.*?\n)', heredoc_callback),
(r'__END__', Comment.Preproc, 'end-part'),
# multiline regex (after keywords or assignments)
(r'(?:^|(?<=[=<>~!:])|'
r'(?<=(?:\s|;)when\s)|'
r'(?<=(?:\s|;)or\s)|'
r'(?<=(?:\s|;)and\s)|'
r'(?<=(?:\s|;|\.)index\s)|'
r'(?<=(?:\s|;|\.)scan\s)|'
r'(?<=(?:\s|;|\.)sub\s)|'
r'(?<=(?:\s|;|\.)sub!\s)|'
r'(?<=(?:\s|;|\.)gsub\s)|'
r'(?<=(?:\s|;|\.)gsub!\s)|'
r'(?<=(?:\s|;|\.)match\s)|'
r'(?<=(?:\s|;)if\s)|'
r'(?<=(?:\s|;)elsif\s)|'
r'(?<=^when\s)|'
r'(?<=^index\s)|'
r'(?<=^scan\s)|'
r'(?<=^sub\s)|'
r'(?<=^gsub\s)|'
r'(?<=^sub!\s)|'
r'(?<=^gsub!\s)|'
r'(?<=^match\s)|'
r'(?<=^if\s)|'
r'(?<=^elsif\s)'
r')(\s*)(/)', bygroups(Text, String.Regex), 'multiline-regex'),
# multiline regex (in method calls or subscripts)
(r'(?<=\(|,|\[)/', String.Regex, 'multiline-regex'),
# multiline regex (this time the funny no whitespace rule)
(r'(\s+)(/)(?![\s=])', bygroups(Text, String.Regex),
'multiline-regex'),
# lex numbers and ignore following regular expressions which
# are division operators in fact (grrrr. i hate that. any
# better ideas?)
# since pygments 0.7 we also eat a "?" operator after numbers
# so that the char operator does not work. Chars are not allowed
# there so that you can use the ternary operator.
# stupid example:
# x>=0?n[x]:""
(r'(0_?[0-7]+(?:_[0-7]+)*)(\s*)([/?])?',
bygroups(Number.Oct, Text, Operator)),
(r'(0x[0-9A-Fa-f]+(?:_[0-9A-Fa-f]+)*)(\s*)([/?])?',
bygroups(Number.Hex, Text, Operator)),
(r'(0b[01]+(?:_[01]+)*)(\s*)([/?])?',
bygroups(Number.Bin, Text, Operator)),
(r'([\d]+(?:_\d+)*)(\s*)([/?])?',
bygroups(Number.Integer, Text, Operator)),
# Names
(r'@@[a-zA-Z_][a-zA-Z0-9_]*', Name.Variable.Class),
(r'@[a-zA-Z_][a-zA-Z0-9_]*', Name.Variable.Instance),
(r'\$[a-zA-Z0-9_]+', Name.Variable.Global),
(r'\$[!@&`\'+~=/\\,;.<>_*$?:"]', Name.Variable.Global),
(r'\$-[0adFiIlpvw]', Name.Variable.Global),
(r'::', Operator),
include('strings'),
# chars
(r'\?(\\[MC]-)*' # modifiers
r'(\\([\\abefnrstv#"\']|x[a-fA-F0-9]{1,2}|[0-7]{1,3})|\S)'
r'(?!\w)',
String.Char),
(r'[A-Z][a-zA-Z0-9_]+', Name.Constant),
# this is needed because ruby attributes can look
# like keywords (class) or like this: ` ?!?
(r'(\.|::)([a-zA-Z_]\w*[\!\?]?|[*%&^`~+-/\[<>=])',
bygroups(Operator, Name)),
(r'[a-zA-Z_]\w*[\!\?]?', Name),
(r'(\[|\]|\*\*|<<?|>>?|>=|<=|<=>|=~|={3}|'
r'!~|&&?|\|\||\.{1,3})', Operator),
(r'[-+/*%=<>&!^|~]=?', Operator),
(r'[(){};,/?:\\]', Punctuation),
(r'\s+', Text)
],
'funcname': [
(r'\(', Punctuation, 'defexpr'),
(r'(?:([a-zA-Z_][a-zA-Z0-9_]*)(\.))?'
r'([a-zA-Z_]\w*[\!\?]?|\*\*?|[-+]@?|'
r'[/%&|^`~]|\[\]=?|<<|>>|<=?>|>=?|===?)',
bygroups(Name.Class, Operator, Name.Function), '#pop'),
(r'', Text, '#pop')
],
'classname': [
(r'\(', Punctuation, 'defexpr'),
(r'<<', Operator, '#pop'),
(r'[A-Z_]\w*', Name.Class, '#pop'),
(r'', Text, '#pop')
],
'defexpr': [
(r'(\))(\.|::)?', bygroups(Punctuation, Operator), '#pop'),
(r'\(', Operator, '#push'),
include('root')
],
'in-intp': [
('}', String.Interpol, '#pop'),
include('root'),
],
'string-intp': [
(r'#{', String.Interpol, 'in-intp'),
(r'#@@?[a-zA-Z_][a-zA-Z0-9_]*', String.Interpol),
(r'#\$[a-zA-Z_][a-zA-Z0-9_]*', String.Interpol)
],
'string-intp-escaped': [
include('string-intp'),
(r'\\([\\abefnrstv#"\']|x[a-fA-F0-9]{1,2}|[0-7]{1,3})',
String.Escape)
],
'interpolated-regex': [
include('string-intp'),
(r'[\\#]', String.Regex),
(r'[^\\#]+', String.Regex),
],
'interpolated-string': [
include('string-intp'),
(r'[\\#]', String.Other),
(r'[^\\#]+', String.Other),
],
'multiline-regex': [
include('string-intp'),
(r'\\\\', String.Regex),
(r'\\/', String.Regex),
(r'[\\#]', String.Regex),
(r'[^\\/#]+', String.Regex),
(r'/[mixounse]*', String.Regex, '#pop'),
],
'end-part': [
(r'.+', Comment.Preproc, '#pop')
]
}
tokens.update(gen_rubystrings_rules())
def analyse_text(text):
return shebang_matches(text, r'ruby(1\.\d)?')
class RubyConsoleLexer(Lexer):
"""
For Ruby interactive console (**irb**) output like:
.. sourcecode:: rbcon
irb(main):001:0> a = 1
=> 1
irb(main):002:0> puts a
1
=> nil
"""
name = 'Ruby irb session'
aliases = ['rbcon', 'irb']
mimetypes = ['text/x-ruby-shellsession']
_prompt_re = re.compile('irb\([a-zA-Z_][a-zA-Z0-9_]*\):\d{3}:\d+[>*"\'] '
'|>> |\?> ')
def get_tokens_unprocessed(self, text):
rblexer = RubyLexer(**self.options)
curcode = ''
insertions = []
for match in line_re.finditer(text):
line = match.group()
m = self._prompt_re.match(line)
if m is not None:
end = m.end()
insertions.append((len(curcode),
[(0, Generic.Prompt, line[:end])]))
curcode += line[end:]
else:
if curcode:
for item in do_insertions(insertions,
rblexer.get_tokens_unprocessed(curcode)):
yield item
curcode = ''
insertions = []
yield match.start(), Generic.Output, line
if curcode:
for item in do_insertions(insertions,
rblexer.get_tokens_unprocessed(curcode)):
yield item
class PerlLexer(RegexLexer):
"""
For `Perl <http://www.perl.org>`_ source code.
"""
name = 'Perl'
aliases = ['perl', 'pl']
filenames = ['*.pl', '*.pm']
mimetypes = ['text/x-perl', 'application/x-perl']
flags = re.DOTALL | re.MULTILINE
# TODO: give this to a perl guy who knows how to parse perl...
tokens = {
'balanced-regex': [
(r'/(\\\\|\\[^\\]|[^\\/])*/[egimosx]*', String.Regex, '#pop'),
(r'!(\\\\|\\[^\\]|[^\\!])*![egimosx]*', String.Regex, '#pop'),
(r'\\(\\\\|[^\\])*\\[egimosx]*', String.Regex, '#pop'),
(r'{(\\\\|\\[^\\]|[^\\}])*}[egimosx]*', String.Regex, '#pop'),
(r'<(\\\\|\\[^\\]|[^\\>])*>[egimosx]*', String.Regex, '#pop'),
(r'\[(\\\\|\\[^\\]|[^\\\]])*\][egimosx]*', String.Regex, '#pop'),
(r'\((\\\\|\\[^\\]|[^\\\)])*\)[egimosx]*', String.Regex, '#pop'),
(r'@(\\\\|\\[^\\]|[^\\\@])*@[egimosx]*', String.Regex, '#pop'),
(r'%(\\\\|\\[^\\]|[^\\\%])*%[egimosx]*', String.Regex, '#pop'),
(r'\$(\\\\|\\[^\\]|[^\\\$])*\$[egimosx]*', String.Regex, '#pop'),
],
'root': [
(r'\#.*?$', Comment.Single),
(r'^=[a-zA-Z0-9]+\s+.*?\n=cut', Comment.Multiline),
(r'(case|continue|do|else|elsif|for|foreach|if|last|my|'
r'next|our|redo|reset|then|unless|until|while|use|'
r'print|new|BEGIN|CHECK|INIT|END|return)\b', Keyword),
(r'(format)(\s+)([a-zA-Z0-9_]+)(\s*)(=)(\s*\n)',
bygroups(Keyword, Text, Name, Text, Punctuation, Text), 'format'),
(r'(eq|lt|gt|le|ge|ne|not|and|or|cmp)\b', Operator.Word),
# common delimiters
(r's/(\\\\|\\[^\\]|[^\\/])*/(\\\\|\\[^\\]|[^\\/])*/[egimosx]*',
String.Regex),
(r's!(\\\\|\\!|[^!])*!(\\\\|\\!|[^!])*![egimosx]*', String.Regex),
(r's\\(\\\\|[^\\])*\\(\\\\|[^\\])*\\[egimosx]*', String.Regex),
(r's@(\\\\|\\[^\\]|[^\\@])*@(\\\\|\\[^\\]|[^\\@])*@[egimosx]*',
String.Regex),
(r's%(\\\\|\\[^\\]|[^\\%])*%(\\\\|\\[^\\]|[^\\%])*%[egimosx]*',
String.Regex),
# balanced delimiters
(r's{(\\\\|\\[^\\]|[^\\}])*}\s*', String.Regex, 'balanced-regex'),
(r's<(\\\\|\\[^\\]|[^\\>])*>\s*', String.Regex, 'balanced-regex'),
(r's\[(\\\\|\\[^\\]|[^\\\]])*\]\s*', String.Regex,
'balanced-regex'),
(r's\((\\\\|\\[^\\]|[^\\\)])*\)\s*', String.Regex,
'balanced-regex'),
(r'm?/(\\\\|\\[^\\]|[^\\/\n])*/[gcimosx]*', String.Regex),
(r'm(?=[/!\\{<\[\(@%\$])', String.Regex, 'balanced-regex'),
(r'((?<==~)|(?<=\())\s*/(\\\\|\\[^\\]|[^\\/])*/[gcimosx]*',
String.Regex),
(r'\s+', Text),
(r'(abs|accept|alarm|atan2|bind|binmode|bless|caller|chdir|'
r'chmod|chomp|chop|chown|chr|chroot|close|closedir|connect|'
r'continue|cos|crypt|dbmclose|dbmopen|defined|delete|die|'
r'dump|each|endgrent|endhostent|endnetent|endprotoent|'
r'endpwent|endservent|eof|eval|exec|exists|exit|exp|fcntl|'
r'fileno|flock|fork|format|formline|getc|getgrent|getgrgid|'
r'getgrnam|gethostbyaddr|gethostbyname|gethostent|getlogin|'
r'getnetbyaddr|getnetbyname|getnetent|getpeername|getpgrp|'
r'getppid|getpriority|getprotobyname|getprotobynumber|'
r'getprotoent|getpwent|getpwnam|getpwuid|getservbyname|'
r'getservbyport|getservent|getsockname|getsockopt|glob|gmtime|'
r'goto|grep|hex|import|index|int|ioctl|join|keys|kill|last|'
r'lc|lcfirst|length|link|listen|local|localtime|log|lstat|'
r'map|mkdir|msgctl|msgget|msgrcv|msgsnd|my|next|no|oct|open|'
r'opendir|ord|our|pack|package|pipe|pop|pos|printf|'
r'prototype|push|quotemeta|rand|read|readdir|'
r'readline|readlink|readpipe|recv|redo|ref|rename|require|'
r'reverse|rewinddir|rindex|rmdir|scalar|seek|seekdir|'
r'select|semctl|semget|semop|send|setgrent|sethostent|setnetent|'
r'setpgrp|setpriority|setprotoent|setpwent|setservent|'
r'setsockopt|shift|shmctl|shmget|shmread|shmwrite|shutdown|'
r'sin|sleep|socket|socketpair|sort|splice|split|sprintf|sqrt|'
r'srand|stat|study|substr|symlink|syscall|sysopen|sysread|'
r'sysseek|system|syswrite|tell|telldir|tie|tied|time|times|tr|'
r'truncate|uc|ucfirst|umask|undef|unlink|unpack|unshift|untie|'
r'utime|values|vec|wait|waitpid|wantarray|warn|write'
r')\b', Name.Builtin),
(r'((__(DATA|DIE|WARN)__)|(STD(IN|OUT|ERR)))\b', Name.Builtin.Pseudo),
(r'<<([\'"]?)([a-zA-Z_][a-zA-Z0-9_]*)\1;?\n.*?\n\2\n', String),
(r'__END__', Comment.Preproc, 'end-part'),
(r'\$\^[ADEFHILMOPSTWX]', Name.Variable.Global),
(r"\$[\\\"\[\]'&`+*.,;=%~?@$!<>(^|/-](?!\w)", Name.Variable.Global),
(r'[$@%#]+', Name.Variable, 'varname'),
(r'0_?[0-7]+(_[0-7]+)*', Number.Oct),
(r'0x[0-9A-Fa-f]+(_[0-9A-Fa-f]+)*', Number.Hex),
(r'0b[01]+(_[01]+)*', Number.Bin),
(r'(?i)(\d*(_\d*)*\.\d+(_\d*)*|\d+(_\d*)*\.\d+(_\d*)*)(e[+-]?\d+)?',
Number.Float),
(r'(?i)\d+(_\d*)*e[+-]?\d+(_\d*)*', Number.Float),
(r'\d+(_\d+)*', Number.Integer),
(r"'(\\\\|\\[^\\]|[^'\\])*'", String),
(r'"(\\\\|\\[^\\]|[^"\\])*"', String),
(r'`(\\\\|\\[^\\]|[^`\\])*`', String.Backtick),
(r'<([^\s>]+)>', String.Regex),
(r'(q|qq|qw|qr|qx)\{', String.Other, 'cb-string'),
(r'(q|qq|qw|qr|qx)\(', String.Other, 'rb-string'),
(r'(q|qq|qw|qr|qx)\[', String.Other, 'sb-string'),
(r'(q|qq|qw|qr|qx)\<', String.Other, 'lt-string'),
(r'(q|qq|qw|qr|qx)([^a-zA-Z0-9])(.|\n)*?\2', String.Other),
(r'package\s+', Keyword, 'modulename'),
(r'sub\s+', Keyword, 'funcname'),
(r'(\[\]|\*\*|::|<<|>>|>=|<=>|<=|={3}|!=|=~|'
r'!~|&&?|\|\||\.{1,3})', Operator),
(r'[-+/*%=<>&^|!\\~]=?', Operator),
(r'[\(\)\[\]:;,<>/\?\{\}]', Punctuation), # yes, there's no shortage
# of punctuation in Perl!
(r'(?=\w)', Name, 'name'),
],
'format': [
(r'\.\n', String.Interpol, '#pop'),
(r'[^\n]*\n', String.Interpol),
],
'varname': [
(r'\s+', Text),
(r'\{', Punctuation, '#pop'), # hash syntax?
(r'\)|,', Punctuation, '#pop'), # argument specifier
(r'[a-zA-Z0-9_]+::', Name.Namespace),
(r'[a-zA-Z0-9_:]+', Name.Variable, '#pop'),
],
'name': [
(r'[a-zA-Z0-9_]+::', Name.Namespace),
(r'[a-zA-Z0-9_:]+', Name, '#pop'),
(r'[A-Z_]+(?=[^a-zA-Z0-9_])', Name.Constant, '#pop'),
(r'(?=[^a-zA-Z0-9_])', Text, '#pop'),
],
'modulename': [
(r'[a-zA-Z_]\w*', Name.Namespace, '#pop')
],
'funcname': [
(r'[a-zA-Z_]\w*[\!\?]?', Name.Function),
(r'\s+', Text),
# argument declaration
(r'(\([$@%]*\))(\s*)', bygroups(Punctuation, Text)),
(r'.*?{', Punctuation, '#pop'),
(r';', Punctuation, '#pop'),
],
'cb-string': [
(r'\\[\{\}\\]', String.Other),
(r'\\', String.Other),
(r'\{', String.Other, 'cb-string'),
(r'\}', String.Other, '#pop'),
(r'[^\{\}\\]+', String.Other)
],
'rb-string': [
(r'\\[\(\)\\]', String.Other),
(r'\\', String.Other),
(r'\(', String.Other, 'rb-string'),
(r'\)', String.Other, '#pop'),
(r'[^\(\)]+', String.Other)
],
'sb-string': [
(r'\\[\[\]\\]', String.Other),
(r'\\', String.Other),
(r'\[', String.Other, 'sb-string'),
(r'\]', String.Other, '#pop'),
(r'[^\[\]]+', String.Other)
],
'lt-string': [
(r'\\[\<\>\\]', String.Other),
(r'\\', String.Other),
(r'\<', String.Other, 'lt-string'),
(r'\>', String.Other, '#pop'),
(r'[^\<\>]+', String.Other)
],
'end-part': [
(r'.+', Comment.Preproc, '#pop')
]
}
def analyse_text(text):
if shebang_matches(text, r'perl'):
return True
if 'my $' in text:
return 0.9
return 0.1 # who knows, might still be perl!
class LuaLexer(RegexLexer):
"""
For `Lua <http://www.lua.org>`_ source code.
Additional options accepted:
`func_name_highlighting`
If given and ``True``, highlight builtin function names
(default: ``True``).
`disabled_modules`
If given, must be a list of module names whose function names
should not be highlighted. By default all modules are highlighted.
To get a list of allowed modules have a look into the
`_luabuiltins` module:
.. sourcecode:: pycon
>>> from pygments.lexers._luabuiltins import MODULES
>>> MODULES.keys()
['string', 'coroutine', 'modules', 'io', 'basic', ...]
"""
name = 'Lua'
aliases = ['lua']
filenames = ['*.lua', '*.wlua']
mimetypes = ['text/x-lua', 'application/x-lua']
tokens = {
'root': [
# lua allows a file to start with a shebang
(r'#!(.*?)$', Comment.Preproc),
(r'', Text, 'base'),
],
'base': [
(r'(?s)--\[(=*)\[.*?\]\1\]', Comment.Multiline),
('--.*$', Comment.Single),
(r'(?i)(\d*\.\d+|\d+\.\d*)(e[+-]?\d+)?', Number.Float),
(r'(?i)\d+e[+-]?\d+', Number.Float),
('(?i)0x[0-9a-f]*', Number.Hex),
(r'\d+', Number.Integer),
(r'\n', Text),
(r'[^\S\n]', Text),
# multiline strings
(r'(?s)\[(=*)\[.*?\]\1\]', String),
(r'(==|~=|<=|>=|\.\.\.|\.\.|[=+\-*/%^<>#])', Operator),
(r'[\[\]\{\}\(\)\.,:;]', Punctuation),
(r'(and|or|not)\b', Operator.Word),
('(break|do|else|elseif|end|for|if|in|repeat|return|then|until|'
r'while)\b', Keyword),
(r'(local)\b', Keyword.Declaration),
(r'(true|false|nil)\b', Keyword.Constant),
(r'(function)\b', Keyword, 'funcname'),
(r'[A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z_][A-Za-z0-9_]*)?', Name),
("'", String.Single, combined('stringescape', 'sqs')),
('"', String.Double, combined('stringescape', 'dqs'))
],
'funcname': [
(r'\s+', Text),
('(?:([A-Za-z_][A-Za-z0-9_]*)(\.))?([A-Za-z_][A-Za-z0-9_]*)',
bygroups(Name.Class, Punctuation, Name.Function), '#pop'),
# inline function
('\(', Punctuation, '#pop'),
],
# if I understand correctly, every character is valid in a lua string,
# so this state is only for later corrections
'string': [
('.', String)
],
'stringescape': [
(r'''\\([abfnrtv\\"']|\d{1,3})''', String.Escape)
],
'sqs': [
("'", String, '#pop'),
include('string')
],
'dqs': [
('"', String, '#pop'),
include('string')
]
}
def __init__(self, **options):
self.func_name_highlighting = get_bool_opt(
options, 'func_name_highlighting', True)
self.disabled_modules = get_list_opt(options, 'disabled_modules', [])
self._functions = set()
if self.func_name_highlighting:
from pygments.lexers._luabuiltins import MODULES
for mod, func in MODULES.iteritems():
if mod not in self.disabled_modules:
self._functions.update(func)
RegexLexer.__init__(self, **options)
def get_tokens_unprocessed(self, text):
for index, token, value in \
RegexLexer.get_tokens_unprocessed(self, text):
if token is Name:
if value in self._functions:
yield index, Name.Builtin, value
continue
elif '.' in value:
a, b = value.split('.')
yield index, Name, a
yield index + len(a), Punctuation, u'.'
yield index + len(a) + 1, Name, b
continue
yield index, token, value
class MoonScriptLexer(LuaLexer):
"""
For `MoonScript <http://moonscript.org.org>`_ source code.
*New in Pygments 1.5.*
"""
name = "MoonScript"
aliases = ["moon", "moonscript"]
filenames = ["*.moon"]
mimetypes = ['text/x-moonscript', 'application/x-moonscript']
tokens = {
'root': [
(r'#!(.*?)$', Comment.Preproc),
(r'', Text, 'base'),
],
'base': [
('--.*$', Comment.Single),
(r'(?i)(\d*\.\d+|\d+\.\d*)(e[+-]?\d+)?', Number.Float),
(r'(?i)\d+e[+-]?\d+', Number.Float),
(r'(?i)0x[0-9a-f]*', Number.Hex),
(r'\d+', Number.Integer),
(r'\n', Text),
(r'[^\S\n]+', Text),
(r'(?s)\[(=*)\[.*?\]\1\]', String),
(r'(->|=>)', Name.Function),
(r':[a-zA-Z_][a-zA-Z0-9_]*', Name.Variable),
(r'(==|!=|~=|<=|>=|\.\.\.|\.\.|[=+\-*/%^<>#!.\\:])', Operator),
(r'[;,]', Punctuation),
(r'[\[\]\{\}\(\)]', Keyword.Type),
(r'[a-zA-Z_][a-zA-Z0-9_]*:', Name.Variable),
(r"(class|extends|if|then|super|do|with|import|export|"
r"while|elseif|return|for|in|from|when|using|else|"
r"and|or|not|switch|break)\b", Keyword),
(r'(true|false|nil)\b', Keyword.Constant),
(r'(and|or|not)\b', Operator.Word),
(r'(self)\b', Name.Builtin.Pseudo),
(r'@@?([a-zA-Z_][a-zA-Z0-9_]*)?', Name.Variable.Class),
(r'[A-Z]\w*', Name.Class), # proper name
(r'[A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z_][A-Za-z0-9_]*)?', Name),
("'", String.Single, combined('stringescape', 'sqs')),
('"', String.Double, combined('stringescape', 'dqs'))
],
'stringescape': [
(r'''\\([abfnrtv\\"']|\d{1,3})''', String.Escape)
],
'sqs': [
("'", String.Single, '#pop'),
(".", String)
],
'dqs': [
('"', String.Double, '#pop'),
(".", String)
]
}
def get_tokens_unprocessed(self, text):
# set . as Operator instead of Punctuation
for index, token, value in \
LuaLexer.get_tokens_unprocessed(self, text):
if token == Punctuation and value == ".":
token = Operator
yield index, token, value
class CrocLexer(RegexLexer):
"""
For `Croc <http://jfbillingsley.com/croc>`_ source.
"""
name = 'Croc'
filenames = ['*.croc']
aliases = ['croc']
mimetypes = ['text/x-crocsrc']
tokens = {
'root': [
(r'\n', Text),
(r'\s+', Text),
# Comments
(r'//(.*?)\n', Comment.Single),
(r'/\*', Comment.Multiline, 'nestedcomment'),
# Keywords
(r'(as|assert|break|case|catch|class|continue|default'
r'|do|else|finally|for|foreach|function|global|namespace'
r'|if|import|in|is|local|module|return|scope|super|switch'
r'|this|throw|try|vararg|while|with|yield)\b', Keyword),
(r'(false|true|null)\b', Keyword.Constant),
# FloatLiteral
(r'([0-9][0-9_]*)(?=[.eE])(\.[0-9][0-9_]*)?([eE][+\-]?[0-9_]+)?',
Number.Float),
# IntegerLiteral
# -- Binary
(r'0[bB][01][01_]*', Number),
# -- Hexadecimal
(r'0[xX][0-9a-fA-F][0-9a-fA-F_]*', Number.Hex),
# -- Decimal
(r'([0-9][0-9_]*)(?![.eE])', Number.Integer),
# CharacterLiteral
(r"""'(\\['"\\nrt]|\\x[0-9a-fA-F]{2}|\\[0-9]{1,3}"""
r"""|\\u[0-9a-fA-F]{4}|\\U[0-9a-fA-F]{8}|.)'""",
String.Char
),
# StringLiteral
# -- WysiwygString
(r'@"(""|[^"])*"', String),
(r'@`(``|[^`])*`', String),
(r"@'(''|[^'])*'", String),
# -- DoubleQuotedString
(r'"(\\\\|\\"|[^"])*"', String),
# Tokens
(
r'(~=|\^=|%=|\*=|==|!=|>>>=|>>>|>>=|>>|>=|<=>|\?=|-\>'
r'|<<=|<<|<=|\+\+|\+=|--|-=|\|\||\|=|&&|&=|\.\.|/=)'
r'|[-/.&$@|\+<>!()\[\]{}?,;:=*%^~#\\]', Punctuation
),
# Identifier
(r'[a-zA-Z_]\w*', Name),
],
'nestedcomment': [
(r'[^*/]+', Comment.Multiline),
(r'/\*', Comment.Multiline, '#push'),
(r'\*/', Comment.Multiline, '#pop'),
(r'[*/]', Comment.Multiline),
],
}
class MiniDLexer(CrocLexer):
"""
For MiniD source. MiniD is now known as Croc.
"""
name = 'MiniD'
filenames = ['*.md']
aliases = ['minid']
mimetypes = ['text/x-minidsrc']
class IoLexer(RegexLexer):
"""
For `Io <http://iolanguage.com/>`_ (a small, prototype-based
programming language) source.
*New in Pygments 0.10.*
"""
name = 'Io'
filenames = ['*.io']
aliases = ['io']
mimetypes = ['text/x-iosrc']
tokens = {
'root': [
(r'\n', Text),
(r'\s+', Text),
# Comments
(r'//(.*?)\n', Comment.Single),
(r'#(.*?)\n', Comment.Single),
(r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline),
(r'/\+', Comment.Multiline, 'nestedcomment'),
# DoubleQuotedString
(r'"(\\\\|\\"|[^"])*"', String),
# Operators
(r'::=|:=|=|\(|\)|;|,|\*|-|\+|>|<|@|!|/|\||\^|\.|%|&|\[|\]|\{|\}',
Operator),
# keywords
(r'(clone|do|doFile|doString|method|for|if|else|elseif|then)\b',
Keyword),
# constants
(r'(nil|false|true)\b', Name.Constant),
# names
(r'(Object|list|List|Map|args|Sequence|Coroutine|File)\b',
Name.Builtin),
('[a-zA-Z_][a-zA-Z0-9_]*', Name),
# numbers
(r'(\d+\.?\d*|\d*\.\d+)([eE][+-]?[0-9]+)?', Number.Float),
(r'\d+', Number.Integer)
],
'nestedcomment': [
(r'[^+/]+', Comment.Multiline),
(r'/\+', Comment.Multiline, '#push'),
(r'\+/', Comment.Multiline, '#pop'),
(r'[+/]', Comment.Multiline),
]
}
class TclLexer(RegexLexer):
"""
For Tcl source code.
*New in Pygments 0.10.*
"""
keyword_cmds_re = (
r'\b(after|apply|array|break|catch|continue|elseif|else|error|'
r'eval|expr|for|foreach|global|if|namespace|proc|rename|return|'
r'set|switch|then|trace|unset|update|uplevel|upvar|variable|'
r'vwait|while)\b'
)
builtin_cmds_re = (
r'\b(append|bgerror|binary|cd|chan|clock|close|concat|dde|dict|'
r'encoding|eof|exec|exit|fblocked|fconfigure|fcopy|file|'
r'fileevent|flush|format|gets|glob|history|http|incr|info|interp|'
r'join|lappend|lassign|lindex|linsert|list|llength|load|loadTk|'
r'lrange|lrepeat|lreplace|lreverse|lsearch|lset|lsort|mathfunc|'
r'mathop|memory|msgcat|open|package|pid|pkg::create|pkg_mkIndex|'
r'platform|platform::shell|puts|pwd|re_syntax|read|refchan|'
r'regexp|registry|regsub|scan|seek|socket|source|split|string|'
r'subst|tell|time|tm|unknown|unload)\b'
)
name = 'Tcl'
aliases = ['tcl']
filenames = ['*.tcl']
mimetypes = ['text/x-tcl', 'text/x-script.tcl', 'application/x-tcl']
def _gen_command_rules(keyword_cmds_re, builtin_cmds_re, context=""):
return [
(keyword_cmds_re, Keyword, 'params' + context),
(builtin_cmds_re, Name.Builtin, 'params' + context),
(r'([\w\.\-]+)', Name.Variable, 'params' + context),
(r'#', Comment, 'comment'),
]
tokens = {
'root': [
include('command'),
include('basic'),
include('data'),
(r'}', Keyword), # HACK: somehow we miscounted our braces
],
'command': _gen_command_rules(keyword_cmds_re, builtin_cmds_re),
'command-in-brace': _gen_command_rules(keyword_cmds_re,
builtin_cmds_re,
"-in-brace"),
'command-in-bracket': _gen_command_rules(keyword_cmds_re,
builtin_cmds_re,
"-in-bracket"),
'command-in-paren': _gen_command_rules(keyword_cmds_re,
builtin_cmds_re,
"-in-paren"),
'basic': [
(r'\(', Keyword, 'paren'),
(r'\[', Keyword, 'bracket'),
(r'\{', Keyword, 'brace'),
(r'"', String.Double, 'string'),
(r'(eq|ne|in|ni)\b', Operator.Word),
(r'!=|==|<<|>>|<=|>=|&&|\|\||\*\*|[-+~!*/%<>&^|?:]', Operator),
],
'data': [
(r'\s+', Text),
(r'0x[a-fA-F0-9]+', Number.Hex),
(r'0[0-7]+', Number.Oct),
(r'\d+\.\d+', Number.Float),
(r'\d+', Number.Integer),
(r'\$([\w\.\-\:]+)', Name.Variable),
(r'([\w\.\-\:]+)', Text),
],
'params': [
(r';', Keyword, '#pop'),
(r'\n', Text, '#pop'),
(r'(else|elseif|then)\b', Keyword),
include('basic'),
include('data'),
],
'params-in-brace': [
(r'}', Keyword, ('#pop', '#pop')),
include('params')
],
'params-in-paren': [
(r'\)', Keyword, ('#pop', '#pop')),
include('params')
],
'params-in-bracket': [
(r'\]', Keyword, ('#pop', '#pop')),
include('params')
],
'string': [
(r'\[', String.Double, 'string-square'),
(r'(?s)(\\\\|\\[0-7]+|\\.|[^"\\])', String.Double),
(r'"', String.Double, '#pop')
],
'string-square': [
(r'\[', String.Double, 'string-square'),
(r'(?s)(\\\\|\\[0-7]+|\\.|\\\n|[^\]\\])', String.Double),
(r'\]', String.Double, '#pop')
],
'brace': [
(r'}', Keyword, '#pop'),
include('command-in-brace'),
include('basic'),
include('data'),
],
'paren': [
(r'\)', Keyword, '#pop'),
include('command-in-paren'),
include('basic'),
include('data'),
],
'bracket': [
(r'\]', Keyword, '#pop'),
include('command-in-bracket'),
include('basic'),
include('data'),
],
'comment': [
(r'.*[^\\]\n', Comment, '#pop'),
(r'.*\\\n', Comment),
],
}
def analyse_text(text):
return shebang_matches(text, r'(tcl)')
class FactorLexer(RegexLexer):
"""
Lexer for the `Factor <http://factorcode.org>`_ language.
*New in Pygments 1.4.*
"""
name = 'Factor'
aliases = ['factor']
filenames = ['*.factor']
mimetypes = ['text/x-factor']
flags = re.MULTILINE | re.UNICODE
builtin_kernel = (
r'(?:or|2bi|2tri|while|wrapper|nip|4dip|wrapper\\?|bi\\*|'
r'callstack>array|both\\?|hashcode|die|dupd|callstack|'
r'callstack\\?|3dup|tri@|pick|curry|build|\\?execute|3bi|'
r'prepose|>boolean|\\?if|clone|eq\\?|tri\\*|\\?|=|swapd|'
r'2over|2keep|3keep|clear|2dup|when|not|tuple\\?|dup|2bi\\*|'
r'2tri\\*|call|tri-curry|object|bi@|do|unless\\*|if\\*|loop|'
r'bi-curry\\*|drop|when\\*|assert=|retainstack|assert\\?|-rot|'
r'execute|2bi@|2tri@|boa|with|either\\?|3drop|bi|curry\\?|'
r'datastack|until|3dip|over|3curry|tri-curry\\*|tri-curry@|swap|'
r'and|2nip|throw|bi-curry|\\(clone\\)|hashcode\\*|compose|2dip|if|3tri|'
r'unless|compose\\?|tuple|keep|2curry|equal\\?|assert|tri|2drop|'
r'most|<wrapper>|boolean\\?|identity-hashcode|identity-tuple\\?|'
r'null|new|dip|bi-curry@|rot|xor|identity-tuple|boolean)\s'
)
builtin_assocs = (
r'(?:\\?at|assoc\\?|assoc-clone-like|assoc=|delete-at\\*|'
r'assoc-partition|extract-keys|new-assoc|value\\?|assoc-size|'
r'map>assoc|push-at|assoc-like|key\\?|assoc-intersect|'
r'assoc-refine|update|assoc-union|assoc-combine|at\\*|'
r'assoc-empty\\?|at\\+|set-at|assoc-all\\?|assoc-subset\\?|'
r'assoc-hashcode|change-at|assoc-each|assoc-diff|zip|values|'
r'value-at|rename-at|inc-at|enum\\?|at|cache|assoc>map|<enum>|'
r'assoc|assoc-map|enum|value-at\\*|assoc-map-as|>alist|'
r'assoc-filter-as|clear-assoc|assoc-stack|maybe-set-at|'
r'substitute|assoc-filter|2cache|delete-at|assoc-find|keys|'
r'assoc-any\\?|unzip)\s'
)
builtin_combinators = (
r'(?:case|execute-effect|no-cond|no-case\\?|3cleave>quot|2cleave|'
r'cond>quot|wrong-values\\?|no-cond\\?|cleave>quot|no-case|'
r'case>quot|3cleave|wrong-values|to-fixed-point|alist>quot|'
r'case-find|cond|cleave|call-effect|2cleave>quot|recursive-hashcode|'
r'linear-case-quot|spread|spread>quot)\s'
)
builtin_math = (
r'(?:number=|if-zero|next-power-of-2|each-integer|\\?1\\+|'
r'fp-special\\?|imaginary-part|unless-zero|float>bits|number\\?|'
r'fp-infinity\\?|bignum\\?|fp-snan\\?|denominator|fp-bitwise=|\\*|'
r'\\+|power-of-2\\?|-|u>=|/|>=|bitand|log2-expects-positive|<|'
r'log2|>|integer\\?|number|bits>double|2/|zero\\?|(find-integer)|'
r'bits>float|float\\?|shift|ratio\\?|even\\?|ratio|fp-sign|bitnot|'
r'>fixnum|complex\\?|/i|/f|byte-array>bignum|when-zero|sgn|>bignum|'
r'next-float|u<|u>|mod|recip|rational|find-last-integer|>float|'
r'(all-integers\\?)|2^|times|integer|fixnum\\?|neg|fixnum|sq|'
r'bignum|(each-integer)|bit\\?|fp-qnan\\?|find-integer|complex|'
r'<fp-nan>|real|double>bits|bitor|rem|fp-nan-payload|all-integers\\?|'
r'real-part|log2-expects-positive\\?|prev-float|align|unordered\\?|'
r'float|fp-nan\\?|abs|bitxor|u<=|odd\\?|<=|/mod|rational\\?|>integer|'
r'real\\?|numerator)\s'
)
builtin_sequences = (
r'(?:member-eq\\?|append|assert-sequence=|find-last-from|trim-head-slice|'
r'clone-like|3sequence|assert-sequence\\?|map-as|last-index-from|'
r'reversed|index-from|cut\\*|pad-tail|remove-eq!|concat-as|'
r'but-last|snip|trim-tail|nths|nth|2selector|sequence|slice\\?|'
r'<slice>|partition|remove-nth|tail-slice|empty\\?|tail\\*|'
r'if-empty|find-from|virtual-sequence\\?|member\\?|set-length|'
r'drop-prefix|unclip|unclip-last-slice|iota|map-sum|'
r'bounds-error\\?|sequence-hashcode-step|selector-for|'
r'accumulate-as|map|start|midpoint@|\\(accumulate\\)|rest-slice|'
r'prepend|fourth|sift|accumulate!|new-sequence|follow|map!|'
r'like|first4|1sequence|reverse|slice|unless-empty|padding|'
r'virtual@|repetition\\?|set-last|index|4sequence|max-length|'
r'set-second|immutable-sequence|first2|first3|replicate-as|'
r'reduce-index|unclip-slice|supremum|suffix!|insert-nth|'
r'trim-tail-slice|tail|3append|short|count|suffix|concat|'
r'flip|filter|sum|immutable\\?|reverse!|2sequence|map-integers|'
r'delete-all|start\\*|indices|snip-slice|check-slice|sequence\\?|'
r'head|map-find|filter!|append-as|reduce|sequence=|halves|'
r'collapse-slice|interleave|2map|filter-as|binary-reduce|'
r'slice-error\\?|product|bounds-check\\?|bounds-check|harvest|'
r'immutable|virtual-exemplar|find|produce|remove|pad-head|last|'
r'replicate|set-fourth|remove-eq|shorten|reversed\\?|'
r'map-find-last|3map-as|2unclip-slice|shorter\\?|3map|find-last|'
r'head-slice|pop\\*|2map-as|tail-slice\\*|but-last-slice|'
r'2map-reduce|iota\\?|collector-for|accumulate|each|selector|'
r'append!|new-resizable|cut-slice|each-index|head-slice\\*|'
r'2reverse-each|sequence-hashcode|pop|set-nth|\\?nth|'
r'<flat-slice>|second|join|when-empty|collector|'
r'immutable-sequence\\?|<reversed>|all\\?|3append-as|'
r'virtual-sequence|subseq\\?|remove-nth!|push-either|new-like|'
r'length|last-index|push-if|2all\\?|lengthen|assert-sequence|'
r'copy|map-reduce|move|third|first|3each|tail\\?|set-first|'
r'prefix|bounds-error|any\\?|<repetition>|trim-slice|exchange|'
r'surround|2reduce|cut|change-nth|min-length|set-third|produce-as|'
r'push-all|head\\?|delete-slice|rest|sum-lengths|2each|head\\*|'
r'infimum|remove!|glue|slice-error|subseq|trim|replace-slice|'
r'push|repetition|map-index|trim-head|unclip-last|mismatch)\s'
)
builtin_namespaces = (
r'(?:global|\\+@|change|set-namestack|change-global|init-namespaces|'
r'on|off|set-global|namespace|set|with-scope|bind|with-variable|'
r'inc|dec|counter|initialize|namestack|get|get-global|make-assoc)\s'
)
builtin_arrays = (
r'(?:<array>|2array|3array|pair|>array|1array|4array|pair\\?|'
r'array|resize-array|array\\?)\s'
)
builtin_io = (
r'(?:\\+character\\+|bad-seek-type\\?|readln|each-morsel|stream-seek|'
r'read|print|with-output-stream|contents|write1|stream-write1|'
r'stream-copy|stream-element-type|with-input-stream|'
r'stream-print|stream-read|stream-contents|stream-tell|'
r'tell-output|bl|seek-output|bad-seek-type|nl|stream-nl|write|'
r'flush|stream-lines|\\+byte\\+|stream-flush|read1|'
r'seek-absolute\\?|stream-read1|lines|stream-readln|'
r'stream-read-until|each-line|seek-end|with-output-stream\\*|'
r'seek-absolute|with-streams|seek-input|seek-relative\\?|'
r'input-stream|stream-write|read-partial|seek-end\\?|'
r'seek-relative|error-stream|read-until|with-input-stream\\*|'
r'with-streams\\*|tell-input|each-block|output-stream|'
r'stream-read-partial|each-stream-block|each-stream-line)\s'
)
builtin_strings = (
r'(?:resize-string|>string|<string>|1string|string|string\\?)\s'
)
builtin_vectors = (
r'(?:vector\\?|<vector>|\\?push|vector|>vector|1vector)\s'
)
builtin_continuations = (
r'(?:with-return|restarts|return-continuation|with-datastack|'
r'recover|rethrow-restarts|<restart>|ifcc|set-catchstack|'
r'>continuation<|cleanup|ignore-errors|restart\\?|'
r'compute-restarts|attempt-all-error|error-thread|continue|'
r'<continuation>|attempt-all-error\\?|condition\\?|'
r'<condition>|throw-restarts|error|catchstack|continue-with|'
r'thread-error-hook|continuation|rethrow|callcc1|'
r'error-continuation|callcc0|attempt-all|condition|'
r'continuation\\?|restart|return)\s'
)
tokens = {
'root': [
# TODO: (( inputs -- outputs ))
# TODO: << ... >>
# defining words
(r'(\s*)(:|::|MACRO:|MEMO:)(\s+)(\S+)',
bygroups(Text, Keyword, Text, Name.Function)),
(r'(\s*)(M:)(\s+)(\S+)(\s+)(\S+)',
bygroups(Text, Keyword, Text, Name.Class, Text, Name.Function)),
(r'(\s*)(GENERIC:)(\s+)(\S+)',
bygroups(Text, Keyword, Text, Name.Function)),
(r'(\s*)(HOOK:|GENERIC#)(\s+)(\S+)(\s+)(\S+)',
bygroups(Text, Keyword, Text, Name.Function, Text, Name.Function)),
(r'(\()(\s+)', bygroups(Name.Function, Text), 'stackeffect'),
(r'\;\s', Keyword),
# imports and namespaces
(r'(USING:)((?:\s|\\\s)+)',
bygroups(Keyword.Namespace, Text), 'import'),
(r'(USE:)(\s+)(\S+)',
bygroups(Keyword.Namespace, Text, Name.Namespace)),
(r'(UNUSE:)(\s+)(\S+)',
bygroups(Keyword.Namespace, Text, Name.Namespace)),
(r'(QUALIFIED:)(\s+)(\S+)',
bygroups(Keyword.Namespace, Text, Name.Namespace)),
(r'(QUALIFIED-WITH:)(\s+)(\S+)',
bygroups(Keyword.Namespace, Text, Name.Namespace)),
(r'(FROM:|EXCLUDE:)(\s+)(\S+)(\s+)(=>)',
bygroups(Keyword.Namespace, Text, Name.Namespace, Text, Text)),
(r'(IN:)(\s+)(\S+)',
bygroups(Keyword.Namespace, Text, Name.Namespace)),
(r'(?:ALIAS|DEFER|FORGET|POSTPONE):', Keyword.Namespace),
# tuples and classes
(r'(TUPLE:)(\s+)(\S+)(\s+<\s+)(\S+)',
bygroups(Keyword, Text, Name.Class, Text, Name.Class), 'slots'),
(r'(TUPLE:)(\s+)(\S+)',
bygroups(Keyword, Text, Name.Class), 'slots'),
(r'(UNION:)(\s+)(\S+)', bygroups(Keyword, Text, Name.Class)),
(r'(INTERSECTION:)(\s+)(\S+)', bygroups(Keyword, Text, Name.Class)),
(r'(PREDICATE:)(\s+)(\S+)(\s+<\s+)(\S+)',
bygroups(Keyword, Text, Name.Class, Text, Name.Class)),
(r'(C:)(\s+)(\S+)(\s+)(\S+)',
bygroups(Keyword, Text, Name.Function, Text, Name.Class)),
(r'INSTANCE:', Keyword),
(r'SLOT:', Keyword),
(r'MIXIN:', Keyword),
(r'(?:SINGLETON|SINGLETONS):', Keyword),
# other syntax
(r'CONSTANT:', Keyword),
(r'(?:SYMBOL|SYMBOLS):', Keyword),
(r'ERROR:', Keyword),
(r'SYNTAX:', Keyword),
(r'(HELP:)(\s+)(\S+)', bygroups(Keyword, Text, Name.Function)),
(r'(MAIN:)(\s+)(\S+)',
bygroups(Keyword.Namespace, Text, Name.Function)),
(r'(?:ALIEN|TYPEDEF|FUNCTION|STRUCT):', Keyword),
# vocab.private
# TODO: words inside vocab.private should have red names?
(r'(?:<PRIVATE|PRIVATE>)', Keyword.Namespace),
# strings
(r'"""\s+(?:.|\n)*?\s+"""', String),
(r'"(?:\\\\|\\"|[^"])*"', String),
(r'CHAR:\s+(\\[\\abfnrstv]*|\S)\s', String.Char),
# comments
(r'\!\s+.*$', Comment),
(r'#\!\s+.*$', Comment),
# boolean constants
(r'(t|f)\s', Name.Constant),
# numbers
(r'-?\d+\.\d+\s', Number.Float),
(r'-?\d+\s', Number.Integer),
(r'HEX:\s+[a-fA-F\d]+\s', Number.Hex),
(r'BIN:\s+[01]+\s', Number.Integer),
(r'OCT:\s+[0-7]+\s', Number.Oct),
# operators
(r'[-+/*=<>^]\s', Operator),
# keywords
(r'(?:deprecated|final|foldable|flushable|inline|recursive)\s',
Keyword),
# builtins
(builtin_kernel, Name.Builtin),
(builtin_assocs, Name.Builtin),
(builtin_combinators, Name.Builtin),
(builtin_math, Name.Builtin),
(builtin_sequences, Name.Builtin),
(builtin_namespaces, Name.Builtin),
(builtin_arrays, Name.Builtin),
(builtin_io, Name.Builtin),
(builtin_strings, Name.Builtin),
(builtin_vectors, Name.Builtin),
(builtin_continuations, Name.Builtin),
# whitespaces - usually not relevant
(r'\s+', Text),
# everything else is text
(r'\S+', Text),
],
'stackeffect': [
(r'\s*\(', Name.Function, 'stackeffect'),
(r'\)', Name.Function, '#pop'),
(r'\-\-', Name.Function),
(r'\s+', Text),
(r'\S+', Name.Variable),
],
'slots': [
(r'\s+', Text),
(r';\s', Keyword, '#pop'),
(r'\S+', Name.Variable),
],
'import': [
(r';', Keyword, '#pop'),
(r'\S+', Name.Namespace),
(r'\s+', Text),
],
}
class FancyLexer(RegexLexer):
"""
Pygments Lexer For `Fancy <http://www.fancy-lang.org/>`_.
Fancy is a self-hosted, pure object-oriented, dynamic,
class-based, concurrent general-purpose programming language
running on Rubinius, the Ruby VM.
*New in Pygments 1.5.*
"""
name = 'Fancy'
filenames = ['*.fy', '*.fancypack']
aliases = ['fancy', 'fy']
mimetypes = ['text/x-fancysrc']
tokens = {
# copied from PerlLexer:
'balanced-regex': [
(r'/(\\\\|\\/|[^/])*/[egimosx]*', String.Regex, '#pop'),
(r'!(\\\\|\\!|[^!])*![egimosx]*', String.Regex, '#pop'),
(r'\\(\\\\|[^\\])*\\[egimosx]*', String.Regex, '#pop'),
(r'{(\\\\|\\}|[^}])*}[egimosx]*', String.Regex, '#pop'),
(r'<(\\\\|\\>|[^>])*>[egimosx]*', String.Regex, '#pop'),
(r'\[(\\\\|\\\]|[^\]])*\][egimosx]*', String.Regex, '#pop'),
(r'\((\\\\|\\\)|[^\)])*\)[egimosx]*', String.Regex, '#pop'),
(r'@(\\\\|\\\@|[^\@])*@[egimosx]*', String.Regex, '#pop'),
(r'%(\\\\|\\\%|[^\%])*%[egimosx]*', String.Regex, '#pop'),
(r'\$(\\\\|\\\$|[^\$])*\$[egimosx]*', String.Regex, '#pop'),
],
'root': [
(r'\s+', Text),
# balanced delimiters (copied from PerlLexer):
(r's{(\\\\|\\}|[^}])*}\s*', String.Regex, 'balanced-regex'),
(r's<(\\\\|\\>|[^>])*>\s*', String.Regex, 'balanced-regex'),
(r's\[(\\\\|\\\]|[^\]])*\]\s*', String.Regex, 'balanced-regex'),
(r's\((\\\\|\\\)|[^\)])*\)\s*', String.Regex, 'balanced-regex'),
(r'm?/(\\\\|\\/|[^/\n])*/[gcimosx]*', String.Regex),
(r'm(?=[/!\\{<\[\(@%\$])', String.Regex, 'balanced-regex'),
# Comments
(r'#(.*?)\n', Comment.Single),
# Symbols
(r'\'([^\'\s\[\]\(\)\{\}]+|\[\])', String.Symbol),
# Multi-line DoubleQuotedString
(r'"""(\\\\|\\"|[^"])*"""', String),
# DoubleQuotedString
(r'"(\\\\|\\"|[^"])*"', String),
# keywords
(r'(def|class|try|catch|finally|retry|return|return_local|match|'
r'case|->|=>)\b', Keyword),
# constants
(r'(self|super|nil|false|true)\b', Name.Constant),
(r'[(){};,/?\|:\\]', Punctuation),
# names
(r'(Object|Array|Hash|Directory|File|Class|String|Number|'
r'Enumerable|FancyEnumerable|Block|TrueClass|NilClass|'
r'FalseClass|Tuple|Symbol|Stack|Set|FancySpec|Method|Package|'
r'Range)\b', Name.Builtin),
# functions
(r'[a-zA-Z]([a-zA-Z0-9_]|[-+?!=*/^><%])*:', Name.Function),
# operators, must be below functions
(r'[-+*/~,<>=&!?%^\[\]\.$]+', Operator),
('[A-Z][a-zA-Z0-9_]*', Name.Constant),
('@[a-zA-Z_][a-zA-Z0-9_]*', Name.Variable.Instance),
('@@[a-zA-Z_][a-zA-Z0-9_]*', Name.Variable.Class),
('@@?', Operator),
('[a-zA-Z_][a-zA-Z0-9_]*', Name),
# numbers - / checks are necessary to avoid mismarking regexes,
# see comment in RubyLexer
(r'(0[oO]?[0-7]+(?:_[0-7]+)*)(\s*)([/?])?',
bygroups(Number.Oct, Text, Operator)),
(r'(0[xX][0-9A-Fa-f]+(?:_[0-9A-Fa-f]+)*)(\s*)([/?])?',
bygroups(Number.Hex, Text, Operator)),
(r'(0[bB][01]+(?:_[01]+)*)(\s*)([/?])?',
bygroups(Number.Bin, Text, Operator)),
(r'([\d]+(?:_\d+)*)(\s*)([/?])?',
bygroups(Number.Integer, Text, Operator)),
(r'\d+([eE][+-]?[0-9]+)|\d+\.\d+([eE][+-]?[0-9]+)?', Number.Float),
(r'\d+', Number.Integer)
]
}
class DgLexer(RegexLexer):
"""
Lexer for `dg <http://pyos.github.com/dg>`_,
a functional and object-oriented programming language
running on the CPython 3 VM.
*New in Pygments 1.6.*
"""
name = 'dg'
aliases = ['dg']
filenames = ['*.dg']
mimetypes = ['text/x-dg']
tokens = {
'root': [
# Whitespace:
(r'\s+', Text),
(r'#.*?$', Comment.Single),
# Lexemes:
# Numbers
(r'0[bB][01]+', Number.Bin),
(r'0[oO][0-7]+', Number.Oct),
(r'0[xX][\da-fA-F]+', Number.Hex),
(r'[+-]?\d+\.\d+([eE][+-]?\d+)?[jJ]?', Number.Float),
(r'[+-]?\d+[eE][+-]?\d+[jJ]?', Number.Float),
(r'[+-]?\d+[jJ]?', Number.Integer),
# Character/String Literals
(r"[br]*'''", String, combined('stringescape', 'tsqs', 'string')),
(r'[br]*"""', String, combined('stringescape', 'tdqs', 'string')),
(r"[br]*'", String, combined('stringescape', 'sqs', 'string')),
(r'[br]*"', String, combined('stringescape', 'dqs', 'string')),
# Operators
(r"`\w+'*`", Operator), # Infix links
# Reserved infix links
(r'\b(or|and|if|else|where|is|in)\b', Operator.Word),
(r'[!$%&*+\-./:<-@\\^|~;,]+', Operator),
# Identifiers
# Python 3 types
(r"(?<!\.)(bool|bytearray|bytes|classmethod|complex|dict'?|"
r"float|frozenset|int|list'?|memoryview|object|property|range|"
r"set'?|slice|staticmethod|str|super|tuple'?|type)"
r"(?!['\w])", Name.Builtin),
# Python 3 builtins + some more
(r'(?<!\.)(__import__|abs|all|any|bin|bind|chr|cmp|compile|complex|'
r'delattr|dir|divmod|drop|dropwhile|enumerate|eval|filter|flip|'
r'foldl1?|format|fst|getattr|globals|hasattr|hash|head|hex|id|'
r'init|input|isinstance|issubclass|iter|iterate|last|len|locals|'
r'map|max|min|next|oct|open|ord|pow|print|repr|reversed|round|'
r'setattr|scanl1?|snd|sorted|sum|tail|take|takewhile|vars|zip)'
r"(?!['\w])", Name.Builtin),
(r"(?<!\.)(self|Ellipsis|NotImplemented|None|True|False)(?!['\w])",
Name.Builtin.Pseudo),
(r"(?<!\.)[A-Z]\w*(Error|Exception|Warning)'*(?!['\w])",
Name.Exception),
(r"(?<!\.)(KeyboardInterrupt|SystemExit|StopIteration|"
r"GeneratorExit)(?!['\w])", Name.Exception),
# Compiler-defined identifiers
(r"(?<![\.\w])(import|inherit|for|while|switch|not|raise|unsafe|"
r"yield|with)(?!['\w])", Keyword.Reserved),
# Other links
(r"[A-Z_']+\b", Name),
(r"[A-Z][\w']*\b", Keyword.Type),
(r"\w+'*", Name),
# Blocks
(r'[()]', Punctuation),
],
'stringescape': [
(r'\\([\\abfnrtv"\']|\n|N{.*?}|u[a-fA-F0-9]{4}|'
r'U[a-fA-F0-9]{8}|x[a-fA-F0-9]{2}|[0-7]{1,3})', String.Escape)
],
'string': [
(r'%(\([a-zA-Z0-9_]+\))?[-#0 +]*([0-9]+|[*])?(\.([0-9]+|[*]))?'
'[hlL]?[diouxXeEfFgGcrs%]', String.Interpol),
(r'[^\\\'"%\n]+', String),
# quotes, percents and backslashes must be parsed one at a time
(r'[\'"\\]', String),
# unhandled string formatting sign
(r'%', String),
(r'\n', String)
],
'dqs': [
(r'"', String, '#pop')
],
'sqs': [
(r"'", String, '#pop')
],
'tdqs': [
(r'"""', String, '#pop')
],
'tsqs': [
(r"'''", String, '#pop')
],
}
class Perl6Lexer(ExtendedRegexLexer):
"""
For `Perl 6 <http://www.perl6.org>`_ source code.
*New in Pygments 1.7.*
"""
name = 'Perl6'
aliases = ['perl6', 'pl6']
filenames = ['*.pl', '*.pm', '*.nqp', '*.p6', '*.6pl', '*.p6l', '*.pl6',
'*.6pm', '*.p6m', '*.pm6']
mimetypes = ['text/x-perl6', 'application/x-perl6']
flags = re.MULTILINE | re.DOTALL | re.UNICODE
PERL6_IDENTIFIER_RANGE = "['a-zA-Z0-9_:-]"
PERL6_KEYWORDS = (
'BEGIN', 'CATCH', 'CHECK', 'CONTROL', 'END', 'ENTER', 'FIRST', 'INIT',
'KEEP', 'LAST', 'LEAVE', 'NEXT', 'POST', 'PRE', 'START', 'TEMP',
'UNDO', 'as', 'assoc', 'async', 'augment', 'binary', 'break', 'but',
'cached', 'category', 'class', 'constant', 'contend', 'continue',
'copy', 'deep', 'default', 'defequiv', 'defer', 'die', 'do', 'else',
'elsif', 'enum', 'equiv', 'exit', 'export', 'fail', 'fatal', 'for',
'gather', 'given', 'goto', 'grammar', 'handles', 'has', 'if', 'inline',
'irs', 'is', 'last', 'leave', 'let', 'lift', 'loop', 'looser', 'macro',
'make', 'maybe', 'method', 'module', 'multi', 'my', 'next', 'of',
'ofs', 'only', 'oo', 'ors', 'our', 'package', 'parsed', 'prec',
'proto', 'readonly', 'redo', 'ref', 'regex', 'reparsed', 'repeat',
'require', 'required', 'return', 'returns', 'role', 'rule', 'rw',
'self', 'slang', 'state', 'sub', 'submethod', 'subset', 'supersede',
'take', 'temp', 'tighter', 'token', 'trusts', 'try', 'unary',
'unless', 'until', 'use', 'warn', 'when', 'where', 'while', 'will',
)
PERL6_BUILTINS = (
'ACCEPTS', 'HOW', 'REJECTS', 'VAR', 'WHAT', 'WHENCE', 'WHERE', 'WHICH',
'WHO', 'abs', 'acos', 'acosec', 'acosech', 'acosh', 'acotan', 'acotanh',
'all', 'any', 'approx', 'arity', 'asec', 'asech', 'asin', 'asinh'
'assuming', 'atan', 'atan2', 'atanh', 'attr', 'bless', 'body', 'by'
'bytes', 'caller', 'callsame', 'callwith', 'can', 'capitalize', 'cat',
'ceiling', 'chars', 'chmod', 'chomp', 'chop', 'chr', 'chroot',
'circumfix', 'cis', 'classify', 'clone', 'close', 'cmp_ok', 'codes',
'comb', 'connect', 'contains', 'context', 'cos', 'cosec', 'cosech',
'cosh', 'cotan', 'cotanh', 'count', 'defined', 'delete', 'diag',
'dies_ok', 'does', 'e', 'each', 'eager', 'elems', 'end', 'eof', 'eval',
'eval_dies_ok', 'eval_elsewhere', 'eval_lives_ok', 'evalfile', 'exists',
'exp', 'first', 'flip', 'floor', 'flunk', 'flush', 'fmt', 'force_todo',
'fork', 'from', 'getc', 'gethost', 'getlogin', 'getpeername', 'getpw',
'gmtime', 'graphs', 'grep', 'hints', 'hyper', 'im', 'index', 'infix',
'invert', 'is_approx', 'is_deeply', 'isa', 'isa_ok', 'isnt', 'iterator',
'join', 'key', 'keys', 'kill', 'kv', 'lastcall', 'lazy', 'lc', 'lcfirst',
'like', 'lines', 'link', 'lives_ok', 'localtime', 'log', 'log10', 'map',
'max', 'min', 'minmax', 'name', 'new', 'nextsame', 'nextwith', 'nfc',
'nfd', 'nfkc', 'nfkd', 'nok_error', 'nonce', 'none', 'normalize', 'not',
'nothing', 'ok', 'once', 'one', 'open', 'opendir', 'operator', 'ord',
'p5chomp', 'p5chop', 'pack', 'pair', 'pairs', 'pass', 'perl', 'pi',
'pick', 'plan', 'plan_ok', 'polar', 'pop', 'pos', 'postcircumfix',
'postfix', 'pred', 'prefix', 'print', 'printf', 'push', 'quasi',
'quotemeta', 'rand', 're', 'read', 'readdir', 'readline', 'reduce',
'reverse', 'rewind', 'rewinddir', 'rindex', 'roots', 'round',
'roundrobin', 'run', 'runinstead', 'sameaccent', 'samecase', 'say',
'sec', 'sech', 'sech', 'seek', 'shape', 'shift', 'sign', 'signature',
'sin', 'sinh', 'skip', 'skip_rest', 'sleep', 'slurp', 'sort', 'splice',
'split', 'sprintf', 'sqrt', 'srand', 'strand', 'subst', 'substr', 'succ',
'sum', 'symlink', 'tan', 'tanh', 'throws_ok', 'time', 'times', 'to',
'todo', 'trim', 'trim_end', 'trim_start', 'true', 'truncate', 'uc',
'ucfirst', 'undef', 'undefine', 'uniq', 'unlike', 'unlink', 'unpack',
'unpolar', 'unshift', 'unwrap', 'use_ok', 'value', 'values', 'vec',
'version_lt', 'void', 'wait', 'want', 'wrap', 'write', 'zip',
)
PERL6_BUILTIN_CLASSES = (
'Abstraction', 'Any', 'AnyChar', 'Array', 'Associative', 'Bag', 'Bit',
'Blob', 'Block', 'Bool', 'Buf', 'Byte', 'Callable', 'Capture', 'Char', 'Class',
'Code', 'Codepoint', 'Comparator', 'Complex', 'Decreasing', 'Exception',
'Failure', 'False', 'Grammar', 'Grapheme', 'Hash', 'IO', 'Increasing',
'Int', 'Junction', 'KeyBag', 'KeyExtractor', 'KeyHash', 'KeySet',
'KitchenSink', 'List', 'Macro', 'Mapping', 'Match', 'Matcher', 'Method',
'Module', 'Num', 'Object', 'Ordered', 'Ordering', 'OrderingPair',
'Package', 'Pair', 'Positional', 'Proxy', 'Range', 'Rat', 'Regex',
'Role', 'Routine', 'Scalar', 'Seq', 'Set', 'Signature', 'Str', 'StrLen',
'StrPos', 'Sub', 'Submethod', 'True', 'UInt', 'Undef', 'Version', 'Void',
'Whatever', 'bit', 'bool', 'buf', 'buf1', 'buf16', 'buf2', 'buf32',
'buf4', 'buf64', 'buf8', 'complex', 'int', 'int1', 'int16', 'int2',
'int32', 'int4', 'int64', 'int8', 'num', 'rat', 'rat1', 'rat16', 'rat2',
'rat32', 'rat4', 'rat64', 'rat8', 'uint', 'uint1', 'uint16', 'uint2',
'uint32', 'uint4', 'uint64', 'uint8', 'utf16', 'utf32', 'utf8',
)
PERL6_OPERATORS = (
'X', 'Z', 'after', 'also', 'and', 'andthen', 'before', 'cmp', 'div',
'eq', 'eqv', 'extra', 'ff', 'fff', 'ge', 'gt', 'le', 'leg', 'lt', 'm',
'mm', 'mod', 'ne', 'or', 'orelse', 'rx', 's', 'tr', 'x', 'xor', 'xx',
'++', '--', '**', '!', '+', '-', '~', '?', '|', '||', '+^', '~^', '?^',
'^', '*', '/', '%', '%%', '+&', '+<', '+>', '~&', '~<', '~>', '?&',
'gcd', 'lcm', '+', '-', '+|', '+^', '~|', '~^', '?|', '?^',
'~', '&', '^', 'but', 'does', '<=>', '..', '..^', '^..', '^..^',
'!=', '==', '<', '<=', '>', '>=', '~~', '===', '!eqv',
'&&', '||', '^^', '//', 'min', 'max', '??', '!!', 'ff', 'fff', 'so',
'not', '<==', '==>', '<<==', '==>>',
)
# Perl 6 has a *lot* of possible bracketing characters
# this list was lifted from STD.pm6 (https://github.com/perl6/std)
PERL6_BRACKETS = {
u'\u0028' : u'\u0029', u'\u003c' : u'\u003e', u'\u005b' : u'\u005d', u'\u007b' : u'\u007d',
u'\u00ab' : u'\u00bb', u'\u0f3a' : u'\u0f3b', u'\u0f3c' : u'\u0f3d', u'\u169b' : u'\u169c',
u'\u2018' : u'\u2019', u'\u201a' : u'\u2019', u'\u201b' : u'\u2019', u'\u201c' : u'\u201d',
u'\u201e' : u'\u201d', u'\u201f' : u'\u201d', u'\u2039' : u'\u203a', u'\u2045' : u'\u2046',
u'\u207d' : u'\u207e', u'\u208d' : u'\u208e', u'\u2208' : u'\u220b', u'\u2209' : u'\u220c',
u'\u220a' : u'\u220d', u'\u2215' : u'\u29f5', u'\u223c' : u'\u223d', u'\u2243' : u'\u22cd',
u'\u2252' : u'\u2253', u'\u2254' : u'\u2255', u'\u2264' : u'\u2265', u'\u2266' : u'\u2267',
u'\u2268' : u'\u2269', u'\u226a' : u'\u226b', u'\u226e' : u'\u226f', u'\u2270' : u'\u2271',
u'\u2272' : u'\u2273', u'\u2274' : u'\u2275', u'\u2276' : u'\u2277', u'\u2278' : u'\u2279',
u'\u227a' : u'\u227b', u'\u227c' : u'\u227d', u'\u227e' : u'\u227f', u'\u2280' : u'\u2281',
u'\u2282' : u'\u2283', u'\u2284' : u'\u2285', u'\u2286' : u'\u2287', u'\u2288' : u'\u2289',
u'\u228a' : u'\u228b', u'\u228f' : u'\u2290', u'\u2291' : u'\u2292', u'\u2298' : u'\u29b8',
u'\u22a2' : u'\u22a3', u'\u22a6' : u'\u2ade', u'\u22a8' : u'\u2ae4', u'\u22a9' : u'\u2ae3',
u'\u22ab' : u'\u2ae5', u'\u22b0' : u'\u22b1', u'\u22b2' : u'\u22b3', u'\u22b4' : u'\u22b5',
u'\u22b6' : u'\u22b7', u'\u22c9' : u'\u22ca', u'\u22cb' : u'\u22cc', u'\u22d0' : u'\u22d1',
u'\u22d6' : u'\u22d7', u'\u22d8' : u'\u22d9', u'\u22da' : u'\u22db', u'\u22dc' : u'\u22dd',
u'\u22de' : u'\u22df', u'\u22e0' : u'\u22e1', u'\u22e2' : u'\u22e3', u'\u22e4' : u'\u22e5',
u'\u22e6' : u'\u22e7', u'\u22e8' : u'\u22e9', u'\u22ea' : u'\u22eb', u'\u22ec' : u'\u22ed',
u'\u22f0' : u'\u22f1', u'\u22f2' : u'\u22fa', u'\u22f3' : u'\u22fb', u'\u22f4' : u'\u22fc',
u'\u22f6' : u'\u22fd', u'\u22f7' : u'\u22fe', u'\u2308' : u'\u2309', u'\u230a' : u'\u230b',
u'\u2329' : u'\u232a', u'\u23b4' : u'\u23b5', u'\u2768' : u'\u2769', u'\u276a' : u'\u276b',
u'\u276c' : u'\u276d', u'\u276e' : u'\u276f', u'\u2770' : u'\u2771', u'\u2772' : u'\u2773',
u'\u2774' : u'\u2775', u'\u27c3' : u'\u27c4', u'\u27c5' : u'\u27c6', u'\u27d5' : u'\u27d6',
u'\u27dd' : u'\u27de', u'\u27e2' : u'\u27e3', u'\u27e4' : u'\u27e5', u'\u27e6' : u'\u27e7',
u'\u27e8' : u'\u27e9', u'\u27ea' : u'\u27eb', u'\u2983' : u'\u2984', u'\u2985' : u'\u2986',
u'\u2987' : u'\u2988', u'\u2989' : u'\u298a', u'\u298b' : u'\u298c', u'\u298d' : u'\u298e',
u'\u298f' : u'\u2990', u'\u2991' : u'\u2992', u'\u2993' : u'\u2994', u'\u2995' : u'\u2996',
u'\u2997' : u'\u2998', u'\u29c0' : u'\u29c1', u'\u29c4' : u'\u29c5', u'\u29cf' : u'\u29d0',
u'\u29d1' : u'\u29d2', u'\u29d4' : u'\u29d5', u'\u29d8' : u'\u29d9', u'\u29da' : u'\u29db',
u'\u29f8' : u'\u29f9', u'\u29fc' : u'\u29fd', u'\u2a2b' : u'\u2a2c', u'\u2a2d' : u'\u2a2e',
u'\u2a34' : u'\u2a35', u'\u2a3c' : u'\u2a3d', u'\u2a64' : u'\u2a65', u'\u2a79' : u'\u2a7a',
u'\u2a7d' : u'\u2a7e', u'\u2a7f' : u'\u2a80', u'\u2a81' : u'\u2a82', u'\u2a83' : u'\u2a84',
u'\u2a8b' : u'\u2a8c', u'\u2a91' : u'\u2a92', u'\u2a93' : u'\u2a94', u'\u2a95' : u'\u2a96',
u'\u2a97' : u'\u2a98', u'\u2a99' : u'\u2a9a', u'\u2a9b' : u'\u2a9c', u'\u2aa1' : u'\u2aa2',
u'\u2aa6' : u'\u2aa7', u'\u2aa8' : u'\u2aa9', u'\u2aaa' : u'\u2aab', u'\u2aac' : u'\u2aad',
u'\u2aaf' : u'\u2ab0', u'\u2ab3' : u'\u2ab4', u'\u2abb' : u'\u2abc', u'\u2abd' : u'\u2abe',
u'\u2abf' : u'\u2ac0', u'\u2ac1' : u'\u2ac2', u'\u2ac3' : u'\u2ac4', u'\u2ac5' : u'\u2ac6',
u'\u2acd' : u'\u2ace', u'\u2acf' : u'\u2ad0', u'\u2ad1' : u'\u2ad2', u'\u2ad3' : u'\u2ad4',
u'\u2ad5' : u'\u2ad6', u'\u2aec' : u'\u2aed', u'\u2af7' : u'\u2af8', u'\u2af9' : u'\u2afa',
u'\u2e02' : u'\u2e03', u'\u2e04' : u'\u2e05', u'\u2e09' : u'\u2e0a', u'\u2e0c' : u'\u2e0d',
u'\u2e1c' : u'\u2e1d', u'\u2e20' : u'\u2e21', u'\u3008' : u'\u3009', u'\u300a' : u'\u300b',
u'\u300c' : u'\u300d', u'\u300e' : u'\u300f', u'\u3010' : u'\u3011', u'\u3014' : u'\u3015',
u'\u3016' : u'\u3017', u'\u3018' : u'\u3019', u'\u301a' : u'\u301b', u'\u301d' : u'\u301e',
u'\ufd3e' : u'\ufd3f', u'\ufe17' : u'\ufe18', u'\ufe35' : u'\ufe36', u'\ufe37' : u'\ufe38',
u'\ufe39' : u'\ufe3a', u'\ufe3b' : u'\ufe3c', u'\ufe3d' : u'\ufe3e', u'\ufe3f' : u'\ufe40',
u'\ufe41' : u'\ufe42', u'\ufe43' : u'\ufe44', u'\ufe47' : u'\ufe48', u'\ufe59' : u'\ufe5a',
u'\ufe5b' : u'\ufe5c', u'\ufe5d' : u'\ufe5e', u'\uff08' : u'\uff09', u'\uff1c' : u'\uff1e',
u'\uff3b' : u'\uff3d', u'\uff5b' : u'\uff5d', u'\uff5f' : u'\uff60', u'\uff62' : u'\uff63',
}
def _build_word_match(words, boundary_regex_fragment = None, prefix = '', suffix = ''):
if boundary_regex_fragment is None:
return r'\b(' + prefix + r'|'.join([ re.escape(x) for x in words]) + suffix + r')\b'
else:
return r'(?<!' + boundary_regex_fragment + ')' + prefix + '(' + \
r'|'.join([ re.escape(x) for x in words]) + r')' + suffix + '(?!' + boundary_regex_fragment + ')'
def brackets_callback(token_class):
def callback(lexer, match, context):
groups = match.groupdict()
opening_chars = groups['delimiter']
n_chars = len(opening_chars)
adverbs = groups.get('adverbs')
closer = Perl6Lexer.PERL6_BRACKETS.get(opening_chars[0])
text = context.text
if closer is None: # it's not a mirrored character, which means we
# just need to look for the next occurrence
end_pos = text.find(opening_chars, match.start('delimiter') + n_chars)
else: # we need to look for the corresponding closing character,
# keep nesting in mind
closing_chars = closer * n_chars
nesting_level = 1
search_pos = match.start('delimiter')
while nesting_level > 0:
next_open_pos = text.find(opening_chars, search_pos + n_chars)
next_close_pos = text.find(closing_chars, search_pos + n_chars)
if next_close_pos == -1:
next_close_pos = len(text)
nesting_level = 0
elif next_open_pos != -1 and next_open_pos < next_close_pos:
nesting_level += 1
search_pos = next_open_pos
else: # next_close_pos < next_open_pos
nesting_level -= 1
search_pos = next_close_pos
end_pos = next_close_pos
if adverbs is not None and re.search(r':to\b', adverbs):
heredoc_terminator = text[match.start('delimiter') + n_chars : end_pos]
end_heredoc = re.search(r'^\s*' + re.escape(heredoc_terminator) + r'\s*$', text[ match.end('delimiter') : ], re.MULTILINE)
if end_heredoc:
end_pos = match.end('delimiter') + end_heredoc.end()
else:
end_pos = len(text)
yield match.start(), token_class, text[match.start() : end_pos + n_chars]
context.pos = end_pos + n_chars
return callback
def opening_brace_callback(lexer, match, context):
stack = context.stack
yield match.start(), Text, context.text[match.start() : match.end()]
context.pos = match.end()
# if we encounter an opening brace and we're one level
# below a token state, it means we need to increment
# the nesting level for braces so we know later when
# we should return to the token rules.
if len(stack) > 2 and stack[-2] == 'token':
context.perl6_token_nesting_level += 1
def closing_brace_callback(lexer, match, context):
stack = context.stack
yield match.start(), Text, context.text[match.start() : match.end()]
context.pos = match.end()
# if we encounter a free closing brace and we're one level
# below a token state, it means we need to check the nesting
# level to see if we need to return to the token state.
if len(stack) > 2 and stack[-2] == 'token':
context.perl6_token_nesting_level -= 1
if context.perl6_token_nesting_level == 0:
stack.pop()
def embedded_perl6_callback(lexer, match, context):
context.perl6_token_nesting_level = 1
yield match.start(), Text, context.text[match.start() : match.end()]
context.pos = match.end()
context.stack.append('root')
# If you're modifying these rules, be careful if you need to process '{' or '}' characters.
# We have special logic for processing these characters (due to the fact that you can nest
# Perl 6 code in regex blocks), so if you need to process one of them, make sure you also
# process the corresponding one!
tokens = {
'common' : [
(r'#[`|=](?P<delimiter>(?P<first_char>[' + ''.join(PERL6_BRACKETS.keys()) + r'])(?P=first_char)*)', brackets_callback(Comment.Multiline)),
(r'#[^\n]*$', Comment.Singleline),
(r'^(\s*)=begin\s+(\w+)\b.*?^\1=end\s+\2', Comment.Multiline),
(r'^(\s*)=for.*?\n\s*?\n', Comment.Multiline),
(r'^=.*?\n\s*?\n', Comment.Multiline),
(r'(regex|token|rule)(\s*' + PERL6_IDENTIFIER_RANGE + '+:sym)', bygroups(Keyword, Name), 'token-sym-brackets'),
(r'(regex|token|rule)(?!' + PERL6_IDENTIFIER_RANGE + ')(\s*' + PERL6_IDENTIFIER_RANGE + '+)?', bygroups(Keyword, Name), 'pre-token'),
# deal with a special case in the Perl 6 grammar (role q { ... })
(r'(role)(\s+)(q)(\s*)', bygroups(Keyword, Text, Name, Text)),
(_build_word_match(PERL6_KEYWORDS, PERL6_IDENTIFIER_RANGE), Keyword),
(_build_word_match(PERL6_BUILTIN_CLASSES, PERL6_IDENTIFIER_RANGE, suffix = '(?::[UD])?'), Name.Builtin),
(_build_word_match(PERL6_BUILTINS, PERL6_IDENTIFIER_RANGE), Name.Builtin),
# copied from PerlLexer
(r'[$@%&][.^:?=!~]?' + PERL6_IDENTIFIER_RANGE + u'+(?:<<.*?>>|<.*?>|«.*?»)*', Name.Variable),
(r'\$[!/](?:<<.*?>>|<.*?>|«.*?»)*', Name.Variable.Global),
(r'::\?\w+', Name.Variable.Global),
(r'[$@%&]\*' + PERL6_IDENTIFIER_RANGE + u'+(?:<<.*?>>|<.*?>|«.*?»)*', Name.Variable.Global),
(r'\$(?:<.*?>)+', Name.Variable),
(r'(?:q|qq|Q)[a-zA-Z]?\s*(?P<adverbs>:[\w\s:]+)?\s*(?P<delimiter>(?P<first_char>[^0-9a-zA-Z:\s])(?P=first_char)*)', brackets_callback(String)),
# copied from PerlLexer
(r'0_?[0-7]+(_[0-7]+)*', Number.Oct),
(r'0x[0-9A-Fa-f]+(_[0-9A-Fa-f]+)*', Number.Hex),
(r'0b[01]+(_[01]+)*', Number.Bin),
(r'(?i)(\d*(_\d*)*\.\d+(_\d*)*|\d+(_\d*)*\.\d+(_\d*)*)(e[+-]?\d+)?', Number.Float),
(r'(?i)\d+(_\d*)*e[+-]?\d+(_\d*)*', Number.Float),
(r'\d+(_\d+)*', Number.Integer),
(r'(?<=~~)\s*/(?:\\\\|\\/|.)*?/', String.Regex),
(r'(?<=[=(,])\s*/(?:\\\\|\\/|.)*?/', String.Regex),
(r'm\w+(?=\()', Name),
(r'(?:m|ms|rx)\s*(?P<adverbs>:[\w\s:]+)?\s*(?P<delimiter>(?P<first_char>[^0-9a-zA-Z:\s])(?P=first_char)*)', brackets_callback(String.Regex)),
(r'(?:s|ss|tr)\s*(?::[\w\s:]+)?\s*/(?:\\\\|\\/|.)*?/(?:\\\\|\\/|.)*?/', String.Regex),
(r'<[^\s=].*?\S>', String),
(_build_word_match(PERL6_OPERATORS), Operator),
(r'[0-9a-zA-Z_]' + PERL6_IDENTIFIER_RANGE + '*', Name),
(r"'(\\\\|\\[^\\]|[^'\\])*'", String),
(r'"(\\\\|\\[^\\]|[^"\\])*"', String),
],
'root' : [
include('common'),
(r'\{', opening_brace_callback),
(r'\}', closing_brace_callback),
(r'.+?', Text),
],
'pre-token' : [
include('common'),
(r'\{', Text, ('#pop', 'token')),
(r'.+?', Text),
],
'token-sym-brackets' : [
(r'(?P<delimiter>(?P<first_char>[' + ''.join(PERL6_BRACKETS.keys()) + '])(?P=first_char)*)', brackets_callback(Name), ('#pop', 'pre-token')),
(r'', Name, ('#pop', 'pre-token')),
],
'token': [
(r'}', Text, '#pop'),
(r'(?<=:)(?:my|our|state|constant|temp|let).*?;', using(this)),
# make sure that quotes in character classes aren't treated as strings
(r'<(?:[-!?+.]\s*)?\[.*?\]>', String.Regex),
# make sure that '#' characters in quotes aren't treated as comments
(r"(?<!\\)'(\\\\|\\[^\\]|[^'\\])*'", String.Regex),
(r'(?<!\\)"(\\\\|\\[^\\]|[^"\\])*"', String.Regex),
(r'#.*?$', Comment.Singleline),
(r'\{', embedded_perl6_callback),
('.+?', String.Regex),
],
}
def analyse_text(text):
def strip_pod(lines):
in_pod = False
stripped_lines = []
for line in lines:
if re.match(r'^=(?:end|cut)', line):
in_pod = False
elif re.match(r'^=\w+', line):
in_pod = True
elif not in_pod:
stripped_lines.append(line)
return stripped_lines
lines = text.splitlines()
lines = strip_pod(lines)
text = '\n'.join(lines)
if shebang_matches(text, r'perl6|rakudo|niecza'):
return True
if 'use v6' in text:
return 0.91 # 0.01 greater than Perl says for 'my $'
if re.search(r'[$@%]\*[A-Z]+', text): # Perl 6-style globals ($*OS)
return 0.91
if re.search(r'[$@%]\?[A-Z]+', text): # Perl 6 compiler variables ($?PACKAGE)
return 0.91
if re.search(r'[$@%][!.][A-Za-z0-9_-]+', text): # Perl 6 member variables
return 0.91
for line in text.splitlines():
if re.match(r'\s*(?:my|our)?\s*module', line): # module declarations
return 0.91
if re.match(r'\s*(?:my|our)?\s*role', line): # role declarations
return 0.91
if re.match(r'\s*(?:my|our)?\s*class\b', line): # class declarations
return 0.91
return False
def __init__(self, **options):
super(Perl6Lexer, self).__init__(**options)
self.encoding = options.get('encoding', 'utf-8')
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
13277,
14,
12245,
14,
643,
441,
272,
18294,
2878,
94,
339,
491,
476,
1192,
367,
1839,
441,
10815,
14,
339,
520,
7307,
26,
1898,
8315,
13,
6965,
701,
314,
14493,
8099,
12,
1937,
10610,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
2436,
14,
199,
624,
199,
199,
646,
295,
199,
199,
504,
13277,
14,
11729,
492,
21125,
12,
12939,
5838,
12,
13706,
19856,
12,
971,
1362,
21125,
2998,
12,
2387,
12,
12149,
12,
886,
63,
262,
13049,
12,
10259,
12,
1808,
12,
642,
199,
504,
13277,
14,
1418,
492,
4520,
12,
4516,
12,
5439,
12,
971,
1362,
6819,
12,
11013,
12,
6431,
12,
2812,
12,
2624,
12,
4860,
12,
8307,
12,
10357,
199,
504,
13277,
14,
1974,
492,
664,
63,
2245,
63,
2992,
12,
664,
63,
513,
63,
2992,
12,
25591,
63,
6742,
199,
504,
13277,
492,
15439,
875,
465,
15439,
421,
199,
363,
452,
363,
275,
788,
4718,
5838,
297,
283,
4718,
9270,
5838,
297,
283,
4718,
15905,
5838,
297,
1779,
283,
4718,
19,
5838,
297,
283,
4718,
19,
15905,
5838,
297,
283,
50,
10972,
5838,
297,
1779,
283,
50,
10972,
9270,
5838,
297,
283,
2623,
76,
5838,
297,
283,
44,
1458,
5838,
297,
283,
3716,
265,
5229,
5838,
297,
1779,
283,
35,
26786,
5838,
297,
283,
26822,
36,
5838,
297,
283,
16512,
5838,
297,
283,
29175,
5838,
297,
283,
12666,
5838,
297,
1779,
283,
38,
9844,
5838,
297,
283,
36,
71,
5838,
297,
283,
2623,
76,
22,
5838,
418,
199,
199,
3,
330,
15,
87,
7163,
199,
504,
13277,
14,
12245,
14,
15481,
492,
428,
3453,
5838,
199,
504,
13277,
14,
12245,
14,
15813,
492,
473,
79,
415,
5838,
12,
5980,
74,
608,
5838,
199,
199,
604,
63,
264,
221,
275,
295,
14,
2014,
360,
21040,
78,
358,
421,
199,
533,
2018,
5838,
8,
19856,
304,
272,
408,
272,
2104,
658,
4718,
665,
1014,
921,
1544,
14,
1548,
14,
1308,
18740,
1350,
1233,
14,
272,
408,
339,
536,
275,
283,
4718,
7,
272,
5481,
275,
788,
1548,
297,
283,
647,
297,
283,
5648,
418,
272,
6203,
275,
17855,
647,
297,
11937,
647,
87,
297,
11937,
551,
297,
283,
51,
11493,
297,
283,
51,
29687,
297,
11937,
27308,
297,
11937,
5648,
418,
272,
13290,
275,
788,
505,
15,
88,
13,
1548,
297,
283,
3578,
15,
88,
13,
1548,
418,
339,
4645,
275,
469,
267,
283,
1231,
356,
359,
288,
334,
82,
1154,
78,
297,
4516,
395,
288,
334,
82,
31344,
83,
13278,
779,
82,
50,
85,
53,
8194,
12,
18,
30437,
5169,
14,
6113,
78,
3342,
31,
6141,
297,
10259,
8,
1872,
12,
2624,
14,
3768,
1826,
288,
334,
82,
16136,
2961,
83,
13278,
779,
82,
50,
85,
53,
8194,
12,
18,
93,
2344,
5169,
14,
6113,
78,
3342,
31,
12310,
401,
10259,
8,
1872,
12,
2624,
14,
3768,
1826,
288,
334,
82,
29538,
51,
60,
78,
11529,
4516,
395,
288,
334,
82,
11525,
2795,
4268,
6819,
395,
288,
334,
82,
3894,
61,
2440,
26,
1062,
27,
59,
4300,
10357,
395,
288,
334,
82,
32190,
78,
297,
4516,
395,
288,
334,
82,
8124,
297,
4516,
395,
288,
334,
82,
6774,
262,
92,
374,
92,
460,
92,
269,
92,
1397,
2862,
66,
297,
11013,
14,
10155,
395,
288,
334,
82,
7,
1111,
92,
389,
92,
8999,
92,
1140,
92,
1988,
94,
11,
6331,
5,
29,
16137,
6,
62,
18257,
4300,
11013,
395,
288,
2387,
360,
7511,
659,
288,
334,
82,
6774,
318,
9,
17304,
3427,
83,
92,
9780,
83,
6393,
3196,
10259,
8,
10650,
12,
4516,
395,
283,
29577,
659,
288,
334,
82,
6774,
533,
9,
17304,
3427,
83,
92,
9780,
83,
6393,
3196,
10259,
8,
10650,
12,
4516,
395,
283,
19851,
659,
288,
334,
82,
6774,
504,
9,
17304,
3427,
83,
92,
9780,
83,
6393,
3196,
10259,
8,
10650,
14,
8814,
12,
4516,
395,
1467,
283,
504,
646,
659,
288,
334,
82,
6774,
646,
9,
17304,
3427,
83,
92,
9780,
83,
6393,
3196,
10259,
8,
10650,
14,
8814,
12,
4516,
395,
1467,
283,
646,
659,
288,
2387,
360,
10372,
659,
288,
2387,
360,
894,
8284,
659,
288,
661,
25060,
82,
50,
32673,
85,
53,
1527,
82,
50,
32673,
82,
50,
1527,
85,
53,
566,
624,
297,
2624,
12,
283,
2076,
6177,
659,
288,
1689,
25060,
82,
50,
32673,
85,
53,
1527,
82,
50,
32673,
82,
50,
1527,
85,
53,
566,
2344,
401,
2624,
12,
283,
1086,
6177,
659,
288,
661,
25060,
82,
50,
32673,
85,
53,
1527,
82,
50,
32673,
82,
50,
1527,
85,
53,
566,
6949,
2624,
12,
283,
68,
6177,
659,
288,
1689,
25060,
82,
50,
32673,
85,
53,
1527,
82,
50,
32673,
82,
50,
1527,
85,
53,
566,
4662,
2624,
12,
283,
31603,
659,
288,
23734,
85,
53,
11843,
624,
297,
2624,
12,
12149,
360,
495,
17081,
3588,
297,
283,
2076,
6177,
3855,
288,
1689,
59,
85,
53,
11843,
2344,
401,
2624,
12,
12149,
360,
495,
17081,
3588,
297,
283,
1086,
6177,
3855,
288,
23734,
85,
53,
11843,
6949,
2624,
12,
12149,
360,
495,
17081,
3588,
297,
283,
68,
6177,
3855,
288,
1689,
59,
85,
53,
11843,
4662,
2624,
12,
12149,
360,
495,
17081,
3588,
297,
283,
31603,
3855,
288,
2387,
360,
354,
659,
288,
2387,
360,
10548,
659,
267,
2156,
267,
283,
7511,
356,
359,
288,
334,
82,
6774,
479,
92,
4785,
92,
6958,
92,
2264,
92,
4164,
92,
2836,
92,
2590,
92,
1628,
5227,
1467,
519,
7,
15172,
92,
509,
92,
2966,
92,
692,
92,
2734,
92,
1529,
92,
1361,
92,
3730,
5227,
1467,
519,
3984,
353,
92,
893,
92,
6710,
92,
11481,
2961,
83,
11,
504,
5547,
92,
305,
92,
1045,
2862,
66,
297,
6431,
395,
267,
2156,
267,
283,
10372,
356,
359,
288,
334,
82,
10120,
11230,
4537,
9,
3460,
646,
363,
92,
2101,
92,
452,
92,
1629,
92,
4998,
92,
17628,
92,
1393,
92,
2245,
92,
2738,
5227,
1467,
519,
7,
20108,
92,
2394,
92,
8296,
92,
10194,
92,
3744,
92,
5730,
92,
14141,
92,
2014,
5227,
1467,
519,
7,
5254,
92,
30831,
92,
807,
92,
694,
92,
26997,
92,
26318,
92,
2579,
92,
1628,
493,
92,
2224,
5227,
1467,
519,
7,
493,
92,
1541,
92,
1609,
92,
21362,
92,
5675
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
13277,
14,
12245,
14,
643,
441,
272,
18294,
2878,
94,
339,
491,
476,
1192,
367,
1839,
441,
10815,
14,
339,
520,
7307,
26,
1898,
8315,
13,
6965,
701,
314,
14493,
8099,
12,
1937,
10610,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
2436,
14,
199,
624,
199,
199,
646,
295,
199,
199,
504,
13277,
14,
11729,
492,
21125,
12,
12939,
5838,
12,
13706,
19856,
12,
971,
1362,
21125,
2998,
12,
2387,
12,
12149,
12,
886,
63,
262,
13049,
12,
10259,
12,
1808,
12,
642,
199,
504,
13277,
14,
1418,
492,
4520,
12,
4516,
12,
5439,
12,
971,
1362,
6819,
12,
11013,
12,
6431,
12,
2812,
12,
2624,
12,
4860,
12,
8307,
12,
10357,
199,
504,
13277,
14,
1974,
492,
664,
63,
2245,
63,
2992,
12,
664,
63,
513,
63,
2992,
12,
25591,
63,
6742,
199,
504,
13277,
492,
15439,
875,
465,
15439,
421,
199,
363,
452,
363,
275,
788,
4718,
5838,
297,
283,
4718,
9270,
5838,
297,
283,
4718,
15905,
5838,
297,
1779,
283,
4718,
19,
5838,
297,
283,
4718,
19,
15905,
5838,
297,
283,
50,
10972,
5838,
297,
1779,
283,
50,
10972,
9270,
5838,
297,
283,
2623,
76,
5838,
297,
283,
44,
1458,
5838,
297,
283,
3716,
265,
5229,
5838,
297,
1779,
283,
35,
26786,
5838,
297,
283,
26822,
36,
5838,
297,
283,
16512,
5838,
297,
283,
29175,
5838,
297,
283,
12666,
5838,
297,
1779,
283,
38,
9844,
5838,
297,
283,
36,
71,
5838,
297,
283,
2623,
76,
22,
5838,
418,
199,
199,
3,
330,
15,
87,
7163,
199,
504,
13277,
14,
12245,
14,
15481,
492,
428,
3453,
5838,
199,
504,
13277,
14,
12245,
14,
15813,
492,
473,
79,
415,
5838,
12,
5980,
74,
608,
5838,
199,
199,
604,
63,
264,
221,
275,
295,
14,
2014,
360,
21040,
78,
358,
421,
199,
533,
2018,
5838,
8,
19856,
304,
272,
408,
272,
2104,
658,
4718,
665,
1014,
921,
1544,
14,
1548,
14,
1308,
18740,
1350,
1233,
14,
272,
408,
339,
536,
275,
283,
4718,
7,
272,
5481,
275,
788,
1548,
297,
283,
647,
297,
283,
5648,
418,
272,
6203,
275,
17855,
647,
297,
11937,
647,
87,
297,
11937,
551,
297,
283,
51,
11493,
297,
283,
51,
29687,
297,
11937,
27308,
297,
11937,
5648,
418,
272,
13290,
275,
788,
505,
15,
88,
13,
1548,
297,
283,
3578,
15,
88,
13,
1548,
418,
339,
4645,
275,
469,
267,
283,
1231,
356,
359,
288,
334,
82,
1154,
78,
297,
4516,
395,
288,
334,
82,
31344,
83,
13278,
779,
82,
50,
85,
53,
8194,
12,
18,
30437,
5169,
14,
6113,
78,
3342,
31,
6141,
297,
10259,
8,
1872,
12,
2624,
14,
3768,
1826,
288,
334,
82,
16136,
2961,
83,
13278,
779,
82,
50,
85,
53,
8194,
12,
18,
93,
2344,
5169,
14,
6113,
78,
3342,
31,
12310,
401,
10259,
8,
1872,
12,
2624,
14,
3768,
1826,
288,
334,
82,
29538,
51,
60,
78,
11529,
4516,
395,
288,
334,
82,
11525,
2795,
4268,
6819,
395,
288,
334,
82,
3894,
61,
2440,
26,
1062,
27,
59,
4300,
10357,
395,
288,
334,
82,
32190,
78,
297,
4516,
395,
288,
334,
82,
8124,
297,
4516,
395,
288,
334,
82,
6774,
262,
92,
374,
92,
460,
92,
269,
92,
1397,
2862,
66,
297,
11013,
14,
10155,
395,
288,
334,
82,
7,
1111,
92,
389,
92,
8999,
92,
1140,
92,
1988,
94,
11,
6331,
5,
29,
16137,
6,
62,
18257,
4300,
11013,
395,
288,
2387,
360,
7511,
659,
288,
334,
82,
6774,
318,
9,
17304,
3427,
83,
92,
9780,
83,
6393,
3196,
10259,
8,
10650,
12,
4516,
395,
283,
29577,
659,
288,
334,
82,
6774,
533,
9,
17304,
3427,
83,
92,
9780,
83,
6393,
3196,
10259,
8,
10650,
12,
4516,
395,
283,
19851,
659,
288,
334,
82,
6774,
504,
9,
17304,
3427,
83,
92,
9780,
83,
6393,
3196,
10259,
8,
10650,
14,
8814,
12,
4516,
395,
1467,
283,
504,
646,
659,
288,
334,
82,
6774,
646,
9,
17304,
3427,
83,
92,
9780,
83,
6393,
3196,
10259,
8,
10650,
14,
8814,
12,
4516,
395,
1467,
283,
646,
659,
288,
2387,
360,
10372,
659,
288,
2387,
360,
894,
8284,
659,
288,
661,
25060,
82,
50,
32673,
85,
53,
1527,
82,
50,
32673,
82,
50,
1527,
85,
53,
566,
624,
297,
2624,
12,
283,
2076,
6177,
659,
288,
1689,
25060,
82,
50,
32673,
85,
53,
1527,
82,
50,
32673,
82,
50,
1527,
85,
53,
566,
2344,
401,
2624,
12,
283,
1086,
6177,
659,
288,
661,
25060,
82,
50,
32673,
85,
53,
1527,
82,
50,
32673,
82,
50,
1527,
85,
53,
566,
6949,
2624,
12,
283,
68,
6177,
659,
288,
1689,
25060,
82,
50,
32673,
85,
53,
1527,
82,
50,
32673,
82,
50,
1527,
85,
53,
566,
4662,
2624,
12,
283,
31603,
659,
288,
23734,
85,
53,
11843,
624,
297,
2624,
12,
12149,
360,
495,
17081,
3588,
297,
283,
2076,
6177,
3855,
288,
1689,
59,
85,
53,
11843,
2344,
401,
2624,
12,
12149,
360,
495,
17081,
3588,
297,
283,
1086,
6177,
3855,
288,
23734,
85,
53,
11843,
6949,
2624,
12,
12149,
360,
495,
17081,
3588,
297,
283,
68,
6177,
3855,
288,
1689,
59,
85,
53,
11843,
4662,
2624,
12,
12149,
360,
495,
17081,
3588,
297,
283,
31603,
3855,
288,
2387,
360,
354,
659,
288,
2387,
360,
10548,
659,
267,
2156,
267,
283,
7511,
356,
359,
288,
334,
82,
6774,
479,
92,
4785,
92,
6958,
92,
2264,
92,
4164,
92,
2836,
92,
2590,
92,
1628,
5227,
1467,
519,
7,
15172,
92,
509,
92,
2966,
92,
692,
92,
2734,
92,
1529,
92,
1361,
92,
3730,
5227,
1467,
519,
3984,
353,
92,
893,
92,
6710,
92,
11481,
2961,
83,
11,
504,
5547,
92,
305,
92,
1045,
2862,
66,
297,
6431,
395,
267,
2156,
267,
283,
10372,
356,
359,
288,
334,
82,
10120,
11230,
4537,
9,
3460,
646,
363,
92,
2101,
92,
452,
92,
1629,
92,
4998,
92,
17628,
92,
1393,
92,
2245,
92,
2738,
5227,
1467,
519,
7,
20108,
92,
2394,
92,
8296,
92,
10194,
92,
3744,
92,
5730,
92,
14141,
92,
2014,
5227,
1467,
519,
7,
5254,
92,
30831,
92,
807,
92,
694,
92,
26997,
92,
26318,
92,
2579,
92,
1628,
493,
92,
2224,
5227,
1467,
519,
7,
493,
92,
1541,
92,
1609,
92,
21362,
92,
5675,
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,
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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
] |
dqnykamp/sympy
|
sympy/assumptions/handlers/matrices.py
|
71
|
13732
|
"""
This module contains query handlers responsible for calculus queries:
infinitesimal, bounded, etc.
"""
from __future__ import print_function, division
from sympy.logic.boolalg import conjuncts
from sympy.assumptions import Q, ask
from sympy.assumptions.handlers import CommonHandler, test_closed_group
from sympy.matrices.expressions import MatMul, MatrixExpr
from sympy.core.logic import fuzzy_and
from sympy.utilities.iterables import sift
from sympy.core import Basic
from functools import partial
def _Factorization(predicate, expr, assumptions):
if predicate in expr.predicates:
return True
class AskSquareHandler(CommonHandler):
"""
Handler for key 'square'
"""
@staticmethod
def MatrixExpr(expr, assumptions):
return expr.shape[0] == expr.shape[1]
class AskSymmetricHandler(CommonHandler):
"""
Handler for key 'symmetric'
"""
@staticmethod
def MatMul(expr, assumptions):
factor, mmul = expr.as_coeff_mmul()
if all(ask(Q.symmetric(arg), assumptions) for arg in mmul.args):
return True
if len(mmul.args) >= 2 and mmul.args[0] == mmul.args[-1].T:
return ask(Q.symmetric(MatMul(*mmul.args[1:-1])), assumptions)
@staticmethod
def MatAdd(expr, assumptions):
return all(ask(Q.symmetric(arg), assumptions) for arg in expr.args)
@staticmethod
def MatrixSymbol(expr, assumptions):
if not expr.is_square:
return False
if Q.symmetric(expr) in conjuncts(assumptions):
return True
@staticmethod
def ZeroMatrix(expr, assumptions):
return ask(Q.square(expr), assumptions)
@staticmethod
def Transpose(expr, assumptions):
return ask(Q.symmetric(expr.arg), assumptions)
Inverse = Transpose
@staticmethod
def MatrixSlice(expr, assumptions):
if not expr.on_diag:
return None
else:
return ask(Q.symmetric(expr.parent), assumptions)
Identity = staticmethod(CommonHandler.AlwaysTrue)
class AskInvertibleHandler(CommonHandler):
"""
Handler for key 'invertible'
"""
@staticmethod
def MatMul(expr, assumptions):
factor, mmul = expr.as_coeff_mmul()
if all(ask(Q.invertible(arg), assumptions) for arg in mmul.args):
return True
if any(ask(Q.invertible(arg), assumptions) is False
for arg in mmul.args):
return False
@staticmethod
def MatAdd(expr, assumptions):
return None
@staticmethod
def MatrixSymbol(expr, assumptions):
if not expr.is_square:
return False
if Q.invertible(expr) in conjuncts(assumptions):
return True
Identity, Inverse = [staticmethod(CommonHandler.AlwaysTrue)]*2
ZeroMatrix = staticmethod(CommonHandler.AlwaysFalse)
@staticmethod
def Transpose(expr, assumptions):
return ask(Q.invertible(expr.arg), assumptions)
@staticmethod
def MatrixSlice(expr, assumptions):
if not expr.on_diag:
return None
else:
return ask(Q.invertible(expr.parent), assumptions)
class AskOrthogonalHandler(CommonHandler):
"""
Handler for key 'orthogonal'
"""
predicate = Q.orthogonal
@staticmethod
def MatMul(expr, assumptions):
factor, mmul = expr.as_coeff_mmul()
if (all(ask(Q.orthogonal(arg), assumptions) for arg in mmul.args) and
factor == 1):
return True
if any(ask(Q.invertible(arg), assumptions) is False
for arg in mmul.args):
return False
@staticmethod
def MatAdd(expr, assumptions):
if (len(expr.args) == 1 and
ask(Q.orthogonal(expr.args[0]), assumptions)):
return True
@staticmethod
def MatrixSymbol(expr, assumptions):
if not expr.is_square:
return False
if Q.orthogonal(expr) in conjuncts(assumptions):
return True
Identity = staticmethod(CommonHandler.AlwaysTrue)
ZeroMatrix = staticmethod(CommonHandler.AlwaysFalse)
@staticmethod
def Transpose(expr, assumptions):
return ask(Q.orthogonal(expr.arg), assumptions)
Inverse = Transpose
@staticmethod
def MatrixSlice(expr, assumptions):
if not expr.on_diag:
return None
else:
return ask(Q.orthogonal(expr.parent), assumptions)
Factorization = staticmethod(partial(_Factorization, Q.orthogonal))
class AskUnitaryHandler(CommonHandler):
"""
Handler for key 'unitary'
"""
predicate = Q.unitary
@staticmethod
def MatMul(expr, assumptions):
factor, mmul = expr.as_coeff_mmul()
if (all(ask(Q.unitary(arg), assumptions) for arg in mmul.args) and
abs(factor) == 1):
return True
if any(ask(Q.invertible(arg), assumptions) is False
for arg in mmul.args):
return False
@staticmethod
def MatrixSymbol(expr, assumptions):
if not expr.is_square:
return False
if Q.unitary(expr) in conjuncts(assumptions):
return True
@staticmethod
def Transpose(expr, assumptions):
return ask(Q.unitary(expr.arg), assumptions)
Inverse = Transpose
@staticmethod
def MatrixSlice(expr, assumptions):
if not expr.on_diag:
return None
else:
return ask(Q.unitary(expr.parent), assumptions)
@staticmethod
def DFT(expr, assumptions):
return True
Factorization = staticmethod(partial(_Factorization, Q.unitary))
Identity = staticmethod(CommonHandler.AlwaysTrue)
ZeroMatrix = staticmethod(CommonHandler.AlwaysFalse)
class AskFullRankHandler(CommonHandler):
"""
Handler for key 'fullrank'
"""
@staticmethod
def MatMul(expr, assumptions):
if all(ask(Q.fullrank(arg), assumptions) for arg in expr.args):
return True
Identity = staticmethod(CommonHandler.AlwaysTrue)
ZeroMatrix = staticmethod(CommonHandler.AlwaysFalse)
@staticmethod
def Transpose(expr, assumptions):
return ask(Q.fullrank(expr.arg), assumptions)
Inverse = Transpose
@staticmethod
def MatrixSlice(expr, assumptions):
if ask(Q.orthogonal(expr.parent), assumptions):
return True
class AskPositiveDefiniteHandler(CommonHandler):
"""
Handler for key 'positive_definite'
"""
@staticmethod
def MatMul(expr, assumptions):
factor, mmul = expr.as_coeff_mmul()
if (all(ask(Q.positive_definite(arg), assumptions)
for arg in mmul.args) and factor > 0):
return True
if (len(mmul.args) >= 2
and mmul.args[0] == mmul.args[-1].T
and ask(Q.fullrank(mmul.args[0]), assumptions)):
return ask(Q.positive_definite(
MatMul(*mmul.args[1:-1])), assumptions)
@staticmethod
def MatAdd(expr, assumptions):
if all(ask(Q.positive_definite(arg), assumptions)
for arg in expr.args):
return True
@staticmethod
def MatrixSymbol(expr, assumptions):
if not expr.is_square:
return False
if Q.positive_definite(expr) in conjuncts(assumptions):
return True
Identity = staticmethod(CommonHandler.AlwaysTrue)
ZeroMatrix = staticmethod(CommonHandler.AlwaysFalse)
@staticmethod
def Transpose(expr, assumptions):
return ask(Q.positive_definite(expr.arg), assumptions)
Inverse = Transpose
@staticmethod
def MatrixSlice(expr, assumptions):
if not expr.on_diag:
return None
else:
return ask(Q.positive_definite(expr.parent), assumptions)
class AskUpperTriangularHandler(CommonHandler):
"""
Handler for key 'upper_triangular'
"""
@staticmethod
def MatMul(expr, assumptions):
factor, matrices = expr.as_coeff_matrices()
if all(ask(Q.upper_triangular(m), assumptions) for m in matrices):
return True
@staticmethod
def MatAdd(expr, assumptions):
if all(ask(Q.upper_triangular(arg), assumptions) for arg in expr.args):
return True
@staticmethod
def MatrixSymbol(expr, assumptions):
if Q.upper_triangular(expr) in conjuncts(assumptions):
return True
Identity, ZeroMatrix = [staticmethod(CommonHandler.AlwaysTrue)]*2
@staticmethod
def Transpose(expr, assumptions):
return ask(Q.lower_triangular(expr.arg), assumptions)
@staticmethod
def Inverse(expr, assumptions):
return ask(Q.upper_triangular(expr.arg), assumptions)
@staticmethod
def MatrixSlice(expr, assumptions):
if not expr.on_diag:
return None
else:
return ask(Q.upper_triangular(expr.parent), assumptions)
Factorization = staticmethod(partial(_Factorization, Q.upper_triangular))
class AskLowerTriangularHandler(CommonHandler):
"""
Handler for key 'lower_triangular'
"""
@staticmethod
def MatMul(expr, assumptions):
factor, matrices = expr.as_coeff_matrices()
if all(ask(Q.lower_triangular(m), assumptions) for m in matrices):
return True
@staticmethod
def MatAdd(expr, assumptions):
if all(ask(Q.lower_triangular(arg), assumptions) for arg in expr.args):
return True
@staticmethod
def MatrixSymbol(expr, assumptions):
if Q.lower_triangular(expr) in conjuncts(assumptions):
return True
Identity, ZeroMatrix = [staticmethod(CommonHandler.AlwaysTrue)]*2
@staticmethod
def Transpose(expr, assumptions):
return ask(Q.upper_triangular(expr.arg), assumptions)
@staticmethod
def Inverse(expr, assumptions):
return ask(Q.lower_triangular(expr.arg), assumptions)
@staticmethod
def MatrixSlice(expr, assumptions):
if not expr.on_diag:
return None
else:
return ask(Q.lower_triangular(expr.parent), assumptions)
Factorization = staticmethod(partial(_Factorization, Q.lower_triangular))
class AskDiagonalHandler(CommonHandler):
"""
Handler for key 'diagonal'
"""
@staticmethod
def MatMul(expr, assumptions):
factor, matrices = expr.as_coeff_matrices()
if all(ask(Q.diagonal(m), assumptions) for m in matrices):
return True
@staticmethod
def MatAdd(expr, assumptions):
if all(ask(Q.diagonal(arg), assumptions) for arg in expr.args):
return True
@staticmethod
def MatrixSymbol(expr, assumptions):
if Q.diagonal(expr) in conjuncts(assumptions):
return True
Identity, ZeroMatrix = [staticmethod(CommonHandler.AlwaysTrue)]*2
@staticmethod
def Transpose(expr, assumptions):
return ask(Q.diagonal(expr.arg), assumptions)
@staticmethod
def Inverse(expr, assumptions):
return ask(Q.diagonal(expr.arg), assumptions)
@staticmethod
def MatrixSlice(expr, assumptions):
if not expr.on_diag:
return None
else:
return ask(Q.diagonal(expr.parent), assumptions)
@staticmethod
def DiagonalMatrix(expr, assumptions):
return True
Factorization = staticmethod(partial(_Factorization, Q.diagonal))
def BM_elements(predicate, expr, assumptions):
""" Block Matrix elements """
return all(ask(predicate(b), assumptions) for b in expr.blocks)
def MS_elements(predicate, expr, assumptions):
""" Matrix Slice elements """
return ask(predicate(expr.parent), assumptions)
def MatMul_elements(matrix_predicate, scalar_predicate, expr, assumptions):
d = sift(expr.args, lambda x: isinstance(x, MatrixExpr))
factors, matrices = d[False], d[True]
return fuzzy_and([
test_closed_group(Basic(*factors), assumptions, scalar_predicate),
test_closed_group(Basic(*matrices), assumptions, matrix_predicate)])
class AskIntegerElementsHandler(CommonHandler):
@staticmethod
def MatAdd(expr, assumptions):
return test_closed_group(expr, assumptions, Q.integer_elements)
HadamardProduct, Determinant, Trace, Transpose = [MatAdd]*4
ZeroMatrix, Identity = [staticmethod(CommonHandler.AlwaysTrue)]*2
MatMul = staticmethod(partial(MatMul_elements, Q.integer_elements,
Q.integer))
MatrixSlice = staticmethod(partial(MS_elements, Q.integer_elements))
BlockMatrix = staticmethod(partial(BM_elements, Q.integer_elements))
class AskRealElementsHandler(CommonHandler):
@staticmethod
def MatAdd(expr, assumptions):
return test_closed_group(expr, assumptions, Q.real_elements)
HadamardProduct, Determinant, Trace, Transpose, Inverse, \
Factorization = [MatAdd]*6
MatMul = staticmethod(partial(MatMul_elements, Q.real_elements, Q.real))
MatrixSlice = staticmethod(partial(MS_elements, Q.real_elements))
BlockMatrix = staticmethod(partial(BM_elements, Q.real_elements))
class AskComplexElementsHandler(CommonHandler):
@staticmethod
def MatAdd(expr, assumptions):
return test_closed_group(expr, assumptions, Q.complex_elements)
HadamardProduct, Determinant, Trace, Transpose, Inverse, \
Factorization = [MatAdd]*6
MatMul = staticmethod(partial(MatMul_elements, Q.complex_elements,
Q.complex))
MatrixSlice = staticmethod(partial(MS_elements, Q.complex_elements))
BlockMatrix = staticmethod(partial(BM_elements, Q.complex_elements))
DFT = staticmethod(CommonHandler.AlwaysTrue)
|
bsd-3-clause
|
[
624,
199,
2765,
859,
3509,
1827,
8297,
17845,
367,
6966,
527,
9212,
26,
199,
30757,
338,
2174,
12,
1234,
4585,
12,
5423,
14,
199,
624,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
12,
4629,
199,
199,
504,
5840,
14,
15370,
14,
2245,
6731,
492,
14643,
324,
3021,
199,
504,
5840,
14,
405,
18064,
492,
1413,
12,
7198,
199,
504,
5840,
14,
405,
18064,
14,
5586,
492,
13964,
2461,
12,
511,
63,
5938,
63,
923,
199,
504,
5840,
14,
19032,
14,
15264,
492,
18619,
16867,
12,
8449,
8561,
199,
504,
5840,
14,
1018,
14,
15370,
492,
24101,
63,
460,
199,
504,
5840,
14,
16355,
14,
8147,
83,
492,
308,
2949,
199,
504,
5840,
14,
1018,
492,
10082,
199,
504,
9143,
492,
7417,
421,
199,
318,
485,
12666,
2072,
8,
14463,
12,
5348,
12,
21546,
304,
272,
340,
11944,
315,
5348,
14,
14463,
83,
26,
267,
372,
715,
199,
199,
533,
30481,
23373,
2461,
8,
7844,
2461,
304,
272,
408,
272,
18599,
367,
790,
283,
9646,
7,
272,
408,
339,
768,
4639,
272,
347,
8449,
8561,
8,
3684,
12,
21546,
304,
267,
372,
5348,
14,
1392,
59,
16,
61,
508,
5348,
14,
1392,
59,
17,
61,
421,
199,
533,
30481,
16594,
5165,
2461,
8,
7844,
2461,
304,
272,
408,
272,
18599,
367,
790,
283,
18422,
7,
272,
408,
339,
768,
4639,
272,
347,
18619,
16867,
8,
3684,
12,
21546,
304,
267,
6535,
12,
333,
3703,
275,
5348,
14,
305,
63,
8903,
63,
596,
348,
342,
267,
340,
1006,
8,
813,
8,
49,
14,
18422,
8,
1273,
395,
21546,
9,
367,
1680,
315,
333,
3703,
14,
589,
304,
288,
372,
715,
267,
340,
822,
8,
596,
348,
14,
589,
9,
2356,
499,
436,
333,
3703,
14,
589,
59,
16,
61,
508,
333,
3703,
14,
589,
1988,
17,
1055,
52,
26,
288,
372,
7198,
8,
49,
14,
18422,
8,
14817,
16867,
2031,
596,
348,
14,
589,
59,
17,
6809,
17,
12884,
21546,
9,
339,
768,
4639,
272,
347,
18619,
1123,
8,
3684,
12,
21546,
304,
267,
372,
1006,
8,
813,
8,
49,
14,
18422,
8,
1273,
395,
21546,
9,
367,
1680,
315,
5348,
14,
589,
9,
339,
768,
4639,
272,
347,
8449,
8169,
8,
3684,
12,
21546,
304,
267,
340,
440,
5348,
14,
374,
63,
9646,
26,
288,
372,
756,
267,
340,
1413,
14,
18422,
8,
3684,
9,
315,
14643,
324,
3021,
8,
405,
18064,
304,
288,
372,
715,
339,
768,
4639,
272,
347,
15708,
6443,
8,
3684,
12,
21546,
304,
267,
372,
7198,
8,
49,
14,
9646,
8,
3684,
395,
21546,
9,
339,
768,
4639,
272,
347,
6266,
4070,
8,
3684,
12,
21546,
304,
267,
372,
7198,
8,
49,
14,
18422,
8,
3684,
14,
1273,
395,
21546,
9,
339,
1010,
2077,
275,
6266,
4070,
339,
768,
4639,
272,
347,
8449,
14034,
8,
3684,
12,
21546,
304,
267,
340,
440,
5348,
14,
265,
63,
6706,
26,
288,
372,
488,
267,
587,
26,
288,
372,
7198,
8,
49,
14,
18422,
8,
3684,
14,
1708,
395,
21546,
9,
339,
22034,
275,
12822,
8,
7844,
2461,
14,
2439,
2885,
549,
9,
421,
199,
533,
30481,
607,
12101,
830,
2461,
8,
7844,
2461,
304,
272,
408,
272,
18599,
367,
790,
283,
262,
12101,
830,
7,
272,
408,
339,
768,
4639,
272,
347,
18619,
16867,
8,
3684,
12,
21546,
304,
267,
6535,
12,
333,
3703,
275,
5348,
14,
305,
63,
8903,
63,
596,
348,
342,
267,
340,
1006,
8,
813,
8,
49,
14,
262,
12101,
830,
8,
1273,
395,
21546,
9,
367,
1680,
315,
333,
3703,
14,
589,
304,
288,
372,
715,
267,
340,
1263,
8,
813,
8,
49,
14,
262,
12101,
830,
8,
1273,
395,
21546,
9,
365,
756,
2049,
367,
1680,
315,
333,
3703,
14,
589,
304,
288,
372,
756,
339,
768,
4639,
272,
347,
18619,
1123,
8,
3684,
12,
21546,
304,
267,
372,
488,
339,
768,
4639,
272,
347,
8449,
8169,
8,
3684,
12,
21546,
304,
267,
340,
440,
5348,
14,
374,
63,
9646,
26,
288,
372,
756,
267,
340,
1413,
14,
262,
12101,
830,
8,
3684,
9,
315,
14643,
324,
3021,
8,
405,
18064,
304,
288,
372,
715,
339,
22034,
12,
1010,
2077,
275,
359,
4639,
8,
7844,
2461,
14,
2439,
2885,
549,
1874,
10,
18,
339,
15708,
6443,
275,
12822,
8,
7844,
2461,
14,
2439,
2885,
797,
9,
339,
768,
4639,
272,
347,
6266,
4070,
8,
3684,
12,
21546,
304,
267,
372,
7198,
8,
49,
14,
262,
12101,
830,
8,
3684,
14,
1273,
395,
21546,
9,
339,
768,
4639,
272,
347,
8449,
14034,
8,
3684,
12,
21546,
304,
267,
340,
440,
5348,
14,
265,
63,
6706,
26,
288,
372,
488,
267,
587,
26,
288,
372,
7198,
8,
49,
14,
262,
12101,
830,
8,
3684,
14,
1708,
395,
21546,
9,
199,
199,
533,
30481,
2844,
273,
19133,
2461,
8,
7844,
2461,
304,
272,
408,
272,
18599,
367,
790,
283,
11297,
19133,
7,
272,
408,
272,
11944,
275,
1413,
14,
11297,
19133,
339,
768,
4639,
272,
347,
18619,
16867,
8,
3684,
12,
21546,
304,
267,
6535,
12,
333,
3703,
275,
5348,
14,
305,
63,
8903,
63,
596,
348,
342,
267,
340,
334,
452,
8,
813,
8,
49,
14,
11297,
19133,
8,
1273,
395,
21546,
9,
367,
1680,
315,
333,
3703,
14,
589,
9,
436,
355,
6535,
508,
413,
304,
288,
372,
715,
267,
340,
1263,
8,
813,
8,
49,
14,
262,
12101,
830,
8,
1273,
395,
21546,
9,
365,
756,
355,
367,
1680,
315,
333,
3703,
14,
589,
304,
288,
372,
756,
339,
768,
4639,
272,
347,
18619,
1123,
8,
3684,
12,
21546,
304,
267,
340,
334,
552,
8,
3684,
14,
589,
9,
508,
413,
436,
355,
7198,
8,
49,
14,
11297,
19133,
8,
3684,
14,
589,
59,
16,
2522,
21546,
2298,
288,
372,
715,
339,
768,
4639,
272,
347,
8449,
8169,
8,
3684,
12,
21546,
304,
267,
340,
440,
5348,
14,
374,
63,
9646,
26,
288,
372,
756,
267,
340,
1413,
14,
11297,
19133,
8,
3684,
9,
315,
14643,
324,
3021,
8,
405,
18064,
304,
288,
372,
715,
339,
22034,
275,
12822,
8,
7844,
2461,
14,
2439,
2885,
549,
9,
339,
15708,
6443,
275,
12822,
8,
7844,
2461,
14,
2439,
2885,
797,
9,
339,
768,
4639,
272,
347,
6266,
4070,
8,
3684,
12,
21546,
304,
267,
372
] |
[
199,
2765,
859,
3509,
1827,
8297,
17845,
367,
6966,
527,
9212,
26,
199,
30757,
338,
2174,
12,
1234,
4585,
12,
5423,
14,
199,
624,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
12,
4629,
199,
199,
504,
5840,
14,
15370,
14,
2245,
6731,
492,
14643,
324,
3021,
199,
504,
5840,
14,
405,
18064,
492,
1413,
12,
7198,
199,
504,
5840,
14,
405,
18064,
14,
5586,
492,
13964,
2461,
12,
511,
63,
5938,
63,
923,
199,
504,
5840,
14,
19032,
14,
15264,
492,
18619,
16867,
12,
8449,
8561,
199,
504,
5840,
14,
1018,
14,
15370,
492,
24101,
63,
460,
199,
504,
5840,
14,
16355,
14,
8147,
83,
492,
308,
2949,
199,
504,
5840,
14,
1018,
492,
10082,
199,
504,
9143,
492,
7417,
421,
199,
318,
485,
12666,
2072,
8,
14463,
12,
5348,
12,
21546,
304,
272,
340,
11944,
315,
5348,
14,
14463,
83,
26,
267,
372,
715,
199,
199,
533,
30481,
23373,
2461,
8,
7844,
2461,
304,
272,
408,
272,
18599,
367,
790,
283,
9646,
7,
272,
408,
339,
768,
4639,
272,
347,
8449,
8561,
8,
3684,
12,
21546,
304,
267,
372,
5348,
14,
1392,
59,
16,
61,
508,
5348,
14,
1392,
59,
17,
61,
421,
199,
533,
30481,
16594,
5165,
2461,
8,
7844,
2461,
304,
272,
408,
272,
18599,
367,
790,
283,
18422,
7,
272,
408,
339,
768,
4639,
272,
347,
18619,
16867,
8,
3684,
12,
21546,
304,
267,
6535,
12,
333,
3703,
275,
5348,
14,
305,
63,
8903,
63,
596,
348,
342,
267,
340,
1006,
8,
813,
8,
49,
14,
18422,
8,
1273,
395,
21546,
9,
367,
1680,
315,
333,
3703,
14,
589,
304,
288,
372,
715,
267,
340,
822,
8,
596,
348,
14,
589,
9,
2356,
499,
436,
333,
3703,
14,
589,
59,
16,
61,
508,
333,
3703,
14,
589,
1988,
17,
1055,
52,
26,
288,
372,
7198,
8,
49,
14,
18422,
8,
14817,
16867,
2031,
596,
348,
14,
589,
59,
17,
6809,
17,
12884,
21546,
9,
339,
768,
4639,
272,
347,
18619,
1123,
8,
3684,
12,
21546,
304,
267,
372,
1006,
8,
813,
8,
49,
14,
18422,
8,
1273,
395,
21546,
9,
367,
1680,
315,
5348,
14,
589,
9,
339,
768,
4639,
272,
347,
8449,
8169,
8,
3684,
12,
21546,
304,
267,
340,
440,
5348,
14,
374,
63,
9646,
26,
288,
372,
756,
267,
340,
1413,
14,
18422,
8,
3684,
9,
315,
14643,
324,
3021,
8,
405,
18064,
304,
288,
372,
715,
339,
768,
4639,
272,
347,
15708,
6443,
8,
3684,
12,
21546,
304,
267,
372,
7198,
8,
49,
14,
9646,
8,
3684,
395,
21546,
9,
339,
768,
4639,
272,
347,
6266,
4070,
8,
3684,
12,
21546,
304,
267,
372,
7198,
8,
49,
14,
18422,
8,
3684,
14,
1273,
395,
21546,
9,
339,
1010,
2077,
275,
6266,
4070,
339,
768,
4639,
272,
347,
8449,
14034,
8,
3684,
12,
21546,
304,
267,
340,
440,
5348,
14,
265,
63,
6706,
26,
288,
372,
488,
267,
587,
26,
288,
372,
7198,
8,
49,
14,
18422,
8,
3684,
14,
1708,
395,
21546,
9,
339,
22034,
275,
12822,
8,
7844,
2461,
14,
2439,
2885,
549,
9,
421,
199,
533,
30481,
607,
12101,
830,
2461,
8,
7844,
2461,
304,
272,
408,
272,
18599,
367,
790,
283,
262,
12101,
830,
7,
272,
408,
339,
768,
4639,
272,
347,
18619,
16867,
8,
3684,
12,
21546,
304,
267,
6535,
12,
333,
3703,
275,
5348,
14,
305,
63,
8903,
63,
596,
348,
342,
267,
340,
1006,
8,
813,
8,
49,
14,
262,
12101,
830,
8,
1273,
395,
21546,
9,
367,
1680,
315,
333,
3703,
14,
589,
304,
288,
372,
715,
267,
340,
1263,
8,
813,
8,
49,
14,
262,
12101,
830,
8,
1273,
395,
21546,
9,
365,
756,
2049,
367,
1680,
315,
333,
3703,
14,
589,
304,
288,
372,
756,
339,
768,
4639,
272,
347,
18619,
1123,
8,
3684,
12,
21546,
304,
267,
372,
488,
339,
768,
4639,
272,
347,
8449,
8169,
8,
3684,
12,
21546,
304,
267,
340,
440,
5348,
14,
374,
63,
9646,
26,
288,
372,
756,
267,
340,
1413,
14,
262,
12101,
830,
8,
3684,
9,
315,
14643,
324,
3021,
8,
405,
18064,
304,
288,
372,
715,
339,
22034,
12,
1010,
2077,
275,
359,
4639,
8,
7844,
2461,
14,
2439,
2885,
549,
1874,
10,
18,
339,
15708,
6443,
275,
12822,
8,
7844,
2461,
14,
2439,
2885,
797,
9,
339,
768,
4639,
272,
347,
6266,
4070,
8,
3684,
12,
21546,
304,
267,
372,
7198,
8,
49,
14,
262,
12101,
830,
8,
3684,
14,
1273,
395,
21546,
9,
339,
768,
4639,
272,
347,
8449,
14034,
8,
3684,
12,
21546,
304,
267,
340,
440,
5348,
14,
265,
63,
6706,
26,
288,
372,
488,
267,
587,
26,
288,
372,
7198,
8,
49,
14,
262,
12101,
830,
8,
3684,
14,
1708,
395,
21546,
9,
199,
199,
533,
30481,
2844,
273,
19133,
2461,
8,
7844,
2461,
304,
272,
408,
272,
18599,
367,
790,
283,
11297,
19133,
7,
272,
408,
272,
11944,
275,
1413,
14,
11297,
19133,
339,
768,
4639,
272,
347,
18619,
16867,
8,
3684,
12,
21546,
304,
267,
6535,
12,
333,
3703,
275,
5348,
14,
305,
63,
8903,
63,
596,
348,
342,
267,
340,
334,
452,
8,
813,
8,
49,
14,
11297,
19133,
8,
1273,
395,
21546,
9,
367,
1680,
315,
333,
3703,
14,
589,
9,
436,
355,
6535,
508,
413,
304,
288,
372,
715,
267,
340,
1263,
8,
813,
8,
49,
14,
262,
12101,
830,
8,
1273,
395,
21546,
9,
365,
756,
355,
367,
1680,
315,
333,
3703,
14,
589,
304,
288,
372,
756,
339,
768,
4639,
272,
347,
18619,
1123,
8,
3684,
12,
21546,
304,
267,
340,
334,
552,
8,
3684,
14,
589,
9,
508,
413,
436,
355,
7198,
8,
49,
14,
11297,
19133,
8,
3684,
14,
589,
59,
16,
2522,
21546,
2298,
288,
372,
715,
339,
768,
4639,
272,
347,
8449,
8169,
8,
3684,
12,
21546,
304,
267,
340,
440,
5348,
14,
374,
63,
9646,
26,
288,
372,
756,
267,
340,
1413,
14,
11297,
19133,
8,
3684,
9,
315,
14643,
324,
3021,
8,
405,
18064,
304,
288,
372,
715,
339,
22034,
275,
12822,
8,
7844,
2461,
14,
2439,
2885,
549,
9,
339,
15708,
6443,
275,
12822,
8,
7844,
2461,
14,
2439,
2885,
797,
9,
339,
768,
4639,
272,
347,
6266,
4070,
8,
3684,
12,
21546,
304,
267,
372,
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,
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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
] |
utecuy/edx-platform
|
cms/djangoapps/models/settings/course_grading.py
|
143
|
8907
|
from datetime import timedelta
from xmodule.modulestore.django import modulestore
class CourseGradingModel(object):
"""
Basically a DAO and Model combo for CRUD operations pertaining to grading policy.
"""
# Within this class, allow access to protected members of client classes.
# This comes up when accessing kvs data and caches during kvs saves and modulestore writes.
def __init__(self, course_descriptor):
self.graders = [
CourseGradingModel.jsonize_grader(i, grader) for i, grader in enumerate(course_descriptor.raw_grader)
] # weights transformed to ints [0..100]
self.grade_cutoffs = course_descriptor.grade_cutoffs
self.grace_period = CourseGradingModel.convert_set_grace_period(course_descriptor)
self.minimum_grade_credit = course_descriptor.minimum_grade_credit
@classmethod
def fetch(cls, course_key):
"""
Fetch the course grading policy for the given course from persistence and return a CourseGradingModel.
"""
descriptor = modulestore().get_course(course_key)
model = cls(descriptor)
return model
@staticmethod
def fetch_grader(course_key, index):
"""
Fetch the course's nth grader
Returns an empty dict if there's no such grader.
"""
descriptor = modulestore().get_course(course_key)
index = int(index)
if len(descriptor.raw_grader) > index:
return CourseGradingModel.jsonize_grader(index, descriptor.raw_grader[index])
# return empty model
else:
return {"id": index,
"type": "",
"min_count": 0,
"drop_count": 0,
"short_label": None,
"weight": 0
}
@staticmethod
def update_from_json(course_key, jsondict, user):
"""
Decode the json into CourseGradingModel and save any changes. Returns the modified model.
Probably not the usual path for updates as it's too coarse grained.
"""
descriptor = modulestore().get_course(course_key)
graders_parsed = [CourseGradingModel.parse_grader(jsonele) for jsonele in jsondict['graders']]
descriptor.raw_grader = graders_parsed
descriptor.grade_cutoffs = jsondict['grade_cutoffs']
modulestore().update_item(descriptor, user.id)
CourseGradingModel.update_grace_period_from_json(course_key, jsondict['grace_period'], user)
CourseGradingModel.update_minimum_grade_credit_from_json(course_key, jsondict['minimum_grade_credit'], user)
return CourseGradingModel.fetch(course_key)
@staticmethod
def update_grader_from_json(course_key, grader, user):
"""
Create or update the grader of the given type (string key) for the given course. Returns the modified
grader which is a full model on the client but not on the server (just a dict)
"""
descriptor = modulestore().get_course(course_key)
# parse removes the id; so, grab it before parse
index = int(grader.get('id', len(descriptor.raw_grader)))
grader = CourseGradingModel.parse_grader(grader)
if index < len(descriptor.raw_grader):
descriptor.raw_grader[index] = grader
else:
descriptor.raw_grader.append(grader)
modulestore().update_item(descriptor, user.id)
return CourseGradingModel.jsonize_grader(index, descriptor.raw_grader[index])
@staticmethod
def update_cutoffs_from_json(course_key, cutoffs, user):
"""
Create or update the grade cutoffs for the given course. Returns sent in cutoffs (ie., no extra
db fetch).
"""
descriptor = modulestore().get_course(course_key)
descriptor.grade_cutoffs = cutoffs
modulestore().update_item(descriptor, user.id)
return cutoffs
@staticmethod
def update_grace_period_from_json(course_key, graceperiodjson, user):
"""
Update the course's default grace period. Incoming dict is {hours: h, minutes: m} possibly as a
grace_period entry in an enclosing dict. It is also safe to call this method with a value of
None for graceperiodjson.
"""
descriptor = modulestore().get_course(course_key)
# Before a graceperiod has ever been created, it will be None (once it has been
# created, it cannot be set back to None).
if graceperiodjson is not None:
if 'grace_period' in graceperiodjson:
graceperiodjson = graceperiodjson['grace_period']
grace_timedelta = timedelta(**graceperiodjson)
descriptor.graceperiod = grace_timedelta
modulestore().update_item(descriptor, user.id)
@staticmethod
def update_minimum_grade_credit_from_json(course_key, minimum_grade_credit, user):
"""Update the course's default minimum grade requirement for credit.
Args:
course_key(CourseKey): The course identifier
minimum_grade_json(Float): Minimum grade value
user(User): The user object
"""
descriptor = modulestore().get_course(course_key)
# 'minimum_grade_credit' cannot be set to None
if minimum_grade_credit is not None:
minimum_grade_credit = minimum_grade_credit
descriptor.minimum_grade_credit = minimum_grade_credit
modulestore().update_item(descriptor, user.id)
@staticmethod
def delete_grader(course_key, index, user):
"""
Delete the grader of the given type from the given course.
"""
descriptor = modulestore().get_course(course_key)
index = int(index)
if index < len(descriptor.raw_grader):
del descriptor.raw_grader[index]
# force propagation to definition
descriptor.raw_grader = descriptor.raw_grader
modulestore().update_item(descriptor, user.id)
@staticmethod
def delete_grace_period(course_key, user):
"""
Delete the course's grace period.
"""
descriptor = modulestore().get_course(course_key)
del descriptor.graceperiod
modulestore().update_item(descriptor, user.id)
@staticmethod
def get_section_grader_type(location):
descriptor = modulestore().get_item(location)
return {
"graderType": descriptor.format if descriptor.format is not None else 'notgraded',
"location": unicode(location),
}
@staticmethod
def update_section_grader_type(descriptor, grader_type, user):
if grader_type is not None and grader_type != u'notgraded':
descriptor.format = grader_type
descriptor.graded = True
else:
del descriptor.format
del descriptor.graded
modulestore().update_item(descriptor, user.id)
return {'graderType': grader_type}
@staticmethod
def convert_set_grace_period(descriptor):
# 5 hours 59 minutes 59 seconds => converted to iso format
rawgrace = descriptor.graceperiod
if rawgrace:
hours_from_days = rawgrace.days * 24
seconds = rawgrace.seconds
hours_from_seconds = int(seconds / 3600)
hours = hours_from_days + hours_from_seconds
seconds -= hours_from_seconds * 3600
minutes = int(seconds / 60)
seconds -= minutes * 60
graceperiod = {'hours': 0, 'minutes': 0, 'seconds': 0}
if hours > 0:
graceperiod['hours'] = hours
if minutes > 0:
graceperiod['minutes'] = minutes
if seconds > 0:
graceperiod['seconds'] = seconds
return graceperiod
else:
return None
@staticmethod
def parse_grader(json_grader):
# manual to clear out kruft
result = {"type": json_grader["type"],
"min_count": int(json_grader.get('min_count', 0)),
"drop_count": int(json_grader.get('drop_count', 0)),
"short_label": json_grader.get('short_label', None),
"weight": float(json_grader.get('weight', 0)) / 100.0
}
return result
@staticmethod
def jsonize_grader(i, grader):
# Warning: converting weight to integer might give unwanted results due
# to the reason how floating point arithmetic works
# e.g, "0.29 * 100 = 28.999999999999996"
return {
"id": i,
"type": grader["type"],
"min_count": grader.get('min_count', 0),
"drop_count": grader.get('drop_count', 0),
"short_label": grader.get('short_label', ""),
"weight": grader.get('weight', 0) * 100,
}
|
agpl-3.0
|
[
504,
2197,
492,
6871,
199,
504,
9872,
14,
10012,
14,
1176,
492,
10996,
421,
199,
533,
5531,
5761,
1098,
1685,
8,
785,
304,
272,
408,
272,
10082,
1183,
282,
577,
23320,
436,
5822,
20972,
367,
17101,
3383,
5331,
1126,
24522,
370,
22815,
4592,
14,
272,
408,
272,
327,
8777,
262,
642,
1021,
12,
2040,
2879,
370,
17819,
7556,
402,
1890,
3992,
14,
272,
327,
961,
12477,
1536,
1380,
18549,
1022,
3122,
666,
436,
18014,
5309,
1022,
3122,
23050,
436,
10996,
14511,
14,
272,
347,
636,
826,
721,
277,
12,
2518,
63,
4120,
304,
267,
291,
14,
926,
7735,
275,
359,
288,
5531,
5761,
1098,
1685,
14,
1001,
794,
63,
17556,
8,
73,
12,
27741,
9,
367,
284,
12,
27741,
315,
3874,
8,
1972,
63,
4120,
14,
1773,
63,
17556,
9,
267,
1622,
221,
327,
4931,
14834,
370,
14526,
359,
16,
703,
1960,
61,
267,
291,
14,
4523,
63,
17708,
83,
275,
2518,
63,
4120,
14,
4523,
63,
17708,
83,
267,
291,
14,
20631,
63,
5191,
275,
5531,
5761,
1098,
1685,
14,
3916,
63,
409,
63,
20631,
63,
5191,
8,
1972,
63,
4120,
9,
267,
291,
14,
10700,
63,
4523,
63,
9365,
275,
2518,
63,
4120,
14,
10700,
63,
4523,
63,
9365,
339,
768,
3744,
272,
347,
5267,
8,
1886,
12,
2518,
63,
498,
304,
267,
408,
267,
16347,
314,
2518,
22815,
4592,
367,
314,
1627,
2518,
687,
26882,
436,
372,
282,
5531,
5761,
1098,
1685,
14,
267,
408,
267,
5872,
275,
10996,
1252,
362,
63,
1972,
8,
1972,
63,
498,
9,
267,
1402,
275,
843,
8,
4120,
9,
267,
372,
1402,
339,
768,
4639,
272,
347,
5267,
63,
17556,
8,
1972,
63,
498,
12,
1478,
304,
267,
408,
267,
16347,
314,
2518,
1159,
30564,
27741,
267,
1803,
376,
2701,
1211,
340,
2337,
1159,
949,
4066,
27741,
14,
267,
408,
267,
5872,
275,
10996,
1252,
362,
63,
1972,
8,
1972,
63,
498,
9,
267,
1478,
275,
1109,
8,
1080,
9,
267,
340,
822,
8,
4120,
14,
1773,
63,
17556,
9,
690,
1478,
26,
288,
372,
5531,
5761,
1098,
1685,
14,
1001,
794,
63,
17556,
8,
1080,
12,
5872,
14,
1773,
63,
17556,
59,
1080,
566,
398,
327,
372,
2701,
1402,
267,
587,
26,
288,
372,
2420,
344,
582,
1478,
12,
490,
298,
466,
582,
4873,
490,
298,
827,
63,
835,
582,
378,
12,
490,
298,
4824,
63,
835,
582,
378,
12,
490,
298,
3612,
63,
1302,
582,
488,
12,
490,
298,
3463,
582,
378,
490,
789,
339,
768,
4639,
272,
347,
1678,
63,
504,
63,
1001,
8,
1972,
63,
498,
12,
2022,
807,
12,
922,
304,
267,
408,
267,
22462,
314,
2022,
1901,
5531,
5761,
1098,
1685,
436,
3354,
1263,
4493,
14,
1803,
314,
6042,
1402,
14,
267,
22770,
6665,
440,
314,
20195,
931,
367,
7029,
465,
652,
1159,
4634,
512,
30672,
1999,
1942,
14,
267,
408,
267,
5872,
275,
10996,
1252,
362,
63,
1972,
8,
1972,
63,
498,
9,
398,
1999,
7735,
63,
6751,
275,
359,
6979,
5761,
1098,
1685,
14,
1122,
63,
17556,
8,
3596,
368,
274,
9,
367,
8586,
368,
274,
315,
2022,
807,
459,
926,
7735,
6538,
398,
5872,
14,
1773,
63,
17556,
275,
1999,
7735,
63,
6751,
267,
5872,
14,
4523,
63,
17708,
83,
275,
2022,
807,
459,
4523,
63,
17708,
83,
418,
398,
10996,
1252,
873,
63,
1053,
8,
4120,
12,
922,
14,
344,
9,
398,
5531,
5761,
1098,
1685,
14,
873,
63,
20631,
63,
5191,
63,
504,
63,
1001,
8,
1972,
63,
498,
12,
2022,
807,
459,
20631,
63,
5191,
995,
922,
9,
398,
5531,
5761,
1098,
1685,
14,
873,
63,
10700,
63,
4523,
63,
9365,
63,
504,
63,
1001,
8,
1972,
63,
498,
12,
2022,
807,
459,
10700,
63,
4523,
63,
9365,
995,
922,
9,
398,
372,
5531,
5761,
1098,
1685,
14,
3535,
8,
1972,
63,
498,
9,
339,
768,
4639,
272,
347,
1678,
63,
17556,
63,
504,
63,
1001,
8,
1972,
63,
498,
12,
27741,
12,
922,
304,
267,
408,
267,
2790,
503,
1678,
314,
27741,
402,
314,
1627,
730,
334,
875,
790,
9,
367,
314,
1627,
2518,
14,
1803,
314,
6042,
267,
27741,
1314,
365,
282,
2615,
1402,
641,
314,
1890,
1325,
440,
641,
314,
1654,
334,
4764,
282,
1211,
9,
267,
408,
267,
5872,
275,
10996,
1252,
362,
63,
1972,
8,
1972,
63,
498,
9,
398,
327,
2198,
14185,
314,
1305,
27,
880,
12,
18200,
652,
2544,
2198,
267,
1478,
275,
1109,
8,
17556,
14,
362,
360,
344,
297,
822,
8,
4120,
14,
1773,
63,
17556,
1724,
267,
27741,
275,
5531,
5761,
1098,
1685,
14,
1122,
63,
17556,
8,
17556,
9,
398,
340,
1478,
665,
822,
8,
4120,
14,
1773,
63,
17556,
304,
288,
5872,
14,
1773,
63,
17556,
59,
1080,
61,
275,
27741,
267,
587,
26,
288,
5872,
14,
1773,
63,
17556,
14,
740,
8,
17556,
9,
398,
10996,
1252,
873,
63,
1053,
8,
4120,
12,
922,
14,
344,
9,
398,
372,
5531,
5761,
1098,
1685,
14,
1001,
794,
63,
17556,
8,
1080,
12,
5872,
14,
1773,
63,
17556,
59,
1080,
566,
339,
768,
4639,
272,
347,
1678,
63,
17708,
83,
63,
504,
63,
1001,
8,
1972,
63,
498,
12,
17875,
83,
12,
922,
304,
267,
408,
267,
2790,
503,
1678,
314,
16183,
17875,
83,
367,
314,
1627,
2518,
14,
1803,
4847,
315,
17875,
83,
334,
1873,
2020,
949,
2402,
267,
1592,
5267,
680,
267,
408,
267,
5872,
275,
10996,
1252,
362,
63,
1972,
8,
1972,
63,
498,
9,
267,
5872,
14,
4523,
63,
17708,
83,
275,
17875,
83,
398,
10996,
1252,
873,
63,
1053,
8,
4120,
12,
922,
14,
344,
9,
398,
372,
17875,
83,
339,
768,
4639,
272,
347,
1678,
63,
20631,
63,
5191,
63,
504,
63,
1001,
8,
1972,
63,
498,
12,
19756,
5191,
1001,
12,
922,
304,
267,
408,
267,
6162,
314,
2518,
1159,
849,
19756,
6247,
14,
1010,
7909,
1211,
365,
469,
8419,
26,
394,
12,
9395,
26,
333,
93,
12570,
465,
282,
267,
19756,
63,
5191,
2397,
315,
376,
25188,
1211,
14,
2779,
365,
2597,
5048,
370,
1240,
642,
1083,
543,
282,
574,
402,
267,
488,
367,
19756,
5191,
1001,
14,
267,
408,
267,
5872,
275,
10996,
1252,
362,
63,
1972,
8,
1972,
63,
498,
9,
398,
327,
21467,
282,
19756,
5191,
965,
14433,
2757,
2737,
12
] |
[
2197,
492,
6871,
199,
504,
9872,
14,
10012,
14,
1176,
492,
10996,
421,
199,
533,
5531,
5761,
1098,
1685,
8,
785,
304,
272,
408,
272,
10082,
1183,
282,
577,
23320,
436,
5822,
20972,
367,
17101,
3383,
5331,
1126,
24522,
370,
22815,
4592,
14,
272,
408,
272,
327,
8777,
262,
642,
1021,
12,
2040,
2879,
370,
17819,
7556,
402,
1890,
3992,
14,
272,
327,
961,
12477,
1536,
1380,
18549,
1022,
3122,
666,
436,
18014,
5309,
1022,
3122,
23050,
436,
10996,
14511,
14,
272,
347,
636,
826,
721,
277,
12,
2518,
63,
4120,
304,
267,
291,
14,
926,
7735,
275,
359,
288,
5531,
5761,
1098,
1685,
14,
1001,
794,
63,
17556,
8,
73,
12,
27741,
9,
367,
284,
12,
27741,
315,
3874,
8,
1972,
63,
4120,
14,
1773,
63,
17556,
9,
267,
1622,
221,
327,
4931,
14834,
370,
14526,
359,
16,
703,
1960,
61,
267,
291,
14,
4523,
63,
17708,
83,
275,
2518,
63,
4120,
14,
4523,
63,
17708,
83,
267,
291,
14,
20631,
63,
5191,
275,
5531,
5761,
1098,
1685,
14,
3916,
63,
409,
63,
20631,
63,
5191,
8,
1972,
63,
4120,
9,
267,
291,
14,
10700,
63,
4523,
63,
9365,
275,
2518,
63,
4120,
14,
10700,
63,
4523,
63,
9365,
339,
768,
3744,
272,
347,
5267,
8,
1886,
12,
2518,
63,
498,
304,
267,
408,
267,
16347,
314,
2518,
22815,
4592,
367,
314,
1627,
2518,
687,
26882,
436,
372,
282,
5531,
5761,
1098,
1685,
14,
267,
408,
267,
5872,
275,
10996,
1252,
362,
63,
1972,
8,
1972,
63,
498,
9,
267,
1402,
275,
843,
8,
4120,
9,
267,
372,
1402,
339,
768,
4639,
272,
347,
5267,
63,
17556,
8,
1972,
63,
498,
12,
1478,
304,
267,
408,
267,
16347,
314,
2518,
1159,
30564,
27741,
267,
1803,
376,
2701,
1211,
340,
2337,
1159,
949,
4066,
27741,
14,
267,
408,
267,
5872,
275,
10996,
1252,
362,
63,
1972,
8,
1972,
63,
498,
9,
267,
1478,
275,
1109,
8,
1080,
9,
267,
340,
822,
8,
4120,
14,
1773,
63,
17556,
9,
690,
1478,
26,
288,
372,
5531,
5761,
1098,
1685,
14,
1001,
794,
63,
17556,
8,
1080,
12,
5872,
14,
1773,
63,
17556,
59,
1080,
566,
398,
327,
372,
2701,
1402,
267,
587,
26,
288,
372,
2420,
344,
582,
1478,
12,
490,
298,
466,
582,
4873,
490,
298,
827,
63,
835,
582,
378,
12,
490,
298,
4824,
63,
835,
582,
378,
12,
490,
298,
3612,
63,
1302,
582,
488,
12,
490,
298,
3463,
582,
378,
490,
789,
339,
768,
4639,
272,
347,
1678,
63,
504,
63,
1001,
8,
1972,
63,
498,
12,
2022,
807,
12,
922,
304,
267,
408,
267,
22462,
314,
2022,
1901,
5531,
5761,
1098,
1685,
436,
3354,
1263,
4493,
14,
1803,
314,
6042,
1402,
14,
267,
22770,
6665,
440,
314,
20195,
931,
367,
7029,
465,
652,
1159,
4634,
512,
30672,
1999,
1942,
14,
267,
408,
267,
5872,
275,
10996,
1252,
362,
63,
1972,
8,
1972,
63,
498,
9,
398,
1999,
7735,
63,
6751,
275,
359,
6979,
5761,
1098,
1685,
14,
1122,
63,
17556,
8,
3596,
368,
274,
9,
367,
8586,
368,
274,
315,
2022,
807,
459,
926,
7735,
6538,
398,
5872,
14,
1773,
63,
17556,
275,
1999,
7735,
63,
6751,
267,
5872,
14,
4523,
63,
17708,
83,
275,
2022,
807,
459,
4523,
63,
17708,
83,
418,
398,
10996,
1252,
873,
63,
1053,
8,
4120,
12,
922,
14,
344,
9,
398,
5531,
5761,
1098,
1685,
14,
873,
63,
20631,
63,
5191,
63,
504,
63,
1001,
8,
1972,
63,
498,
12,
2022,
807,
459,
20631,
63,
5191,
995,
922,
9,
398,
5531,
5761,
1098,
1685,
14,
873,
63,
10700,
63,
4523,
63,
9365,
63,
504,
63,
1001,
8,
1972,
63,
498,
12,
2022,
807,
459,
10700,
63,
4523,
63,
9365,
995,
922,
9,
398,
372,
5531,
5761,
1098,
1685,
14,
3535,
8,
1972,
63,
498,
9,
339,
768,
4639,
272,
347,
1678,
63,
17556,
63,
504,
63,
1001,
8,
1972,
63,
498,
12,
27741,
12,
922,
304,
267,
408,
267,
2790,
503,
1678,
314,
27741,
402,
314,
1627,
730,
334,
875,
790,
9,
367,
314,
1627,
2518,
14,
1803,
314,
6042,
267,
27741,
1314,
365,
282,
2615,
1402,
641,
314,
1890,
1325,
440,
641,
314,
1654,
334,
4764,
282,
1211,
9,
267,
408,
267,
5872,
275,
10996,
1252,
362,
63,
1972,
8,
1972,
63,
498,
9,
398,
327,
2198,
14185,
314,
1305,
27,
880,
12,
18200,
652,
2544,
2198,
267,
1478,
275,
1109,
8,
17556,
14,
362,
360,
344,
297,
822,
8,
4120,
14,
1773,
63,
17556,
1724,
267,
27741,
275,
5531,
5761,
1098,
1685,
14,
1122,
63,
17556,
8,
17556,
9,
398,
340,
1478,
665,
822,
8,
4120,
14,
1773,
63,
17556,
304,
288,
5872,
14,
1773,
63,
17556,
59,
1080,
61,
275,
27741,
267,
587,
26,
288,
5872,
14,
1773,
63,
17556,
14,
740,
8,
17556,
9,
398,
10996,
1252,
873,
63,
1053,
8,
4120,
12,
922,
14,
344,
9,
398,
372,
5531,
5761,
1098,
1685,
14,
1001,
794,
63,
17556,
8,
1080,
12,
5872,
14,
1773,
63,
17556,
59,
1080,
566,
339,
768,
4639,
272,
347,
1678,
63,
17708,
83,
63,
504,
63,
1001,
8,
1972,
63,
498,
12,
17875,
83,
12,
922,
304,
267,
408,
267,
2790,
503,
1678,
314,
16183,
17875,
83,
367,
314,
1627,
2518,
14,
1803,
4847,
315,
17875,
83,
334,
1873,
2020,
949,
2402,
267,
1592,
5267,
680,
267,
408,
267,
5872,
275,
10996,
1252,
362,
63,
1972,
8,
1972,
63,
498,
9,
267,
5872,
14,
4523,
63,
17708,
83,
275,
17875,
83,
398,
10996,
1252,
873,
63,
1053,
8,
4120,
12,
922,
14,
344,
9,
398,
372,
17875,
83,
339,
768,
4639,
272,
347,
1678,
63,
20631,
63,
5191,
63,
504,
63,
1001,
8,
1972,
63,
498,
12,
19756,
5191,
1001,
12,
922,
304,
267,
408,
267,
6162,
314,
2518,
1159,
849,
19756,
6247,
14,
1010,
7909,
1211,
365,
469,
8419,
26,
394,
12,
9395,
26,
333,
93,
12570,
465,
282,
267,
19756,
63,
5191,
2397,
315,
376,
25188,
1211,
14,
2779,
365,
2597,
5048,
370,
1240,
642,
1083,
543,
282,
574,
402,
267,
488,
367,
19756,
5191,
1001,
14,
267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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
] |
vipul-sharma20/oh-mainline
|
vendor/packages/django-assets/test/test_filters.py
|
16
|
4301
|
import os
from nose.tools import assert_raises
from django.conf import settings
from django_assets.filter import Filter, get_filter, register_filter
# TODO: Add tests for all the builtin filters.
class TestFilter:
"""Test the API ``Filter`` provides to descendants.
"""
def test_auto_name(self):
"""Test the automatic generation of the filter name.
"""
assert type('Foo', (Filter,), {}).name == 'foo'
assert type('FooFilter', (Filter,), {}).name == 'foo'
assert type('FooBarFilter', (Filter,), {}).name == 'foobar'
assert type('Foo', (Filter,), {'name': 'custom'}).name == 'custom'
assert type('Foo', (Filter,), {'name': None}).name == None
def test_get_config(self):
"""Test the ``get_config`` helper.
"""
get_config = Filter().get_config
# For the purposes of the following tests, we use a test
# name which we expect to be undefined in both settings
# and environment.
NAME = 'FOO1234'
assert not NAME in os.environ
assert not hasattr(settings, NAME)
# Test raising of error, and test not raising it.
assert_raises(EnvironmentError, get_config, NAME)
assert get_config(NAME, require=False) == None
# Start by creating the value as a setting.
setattr(settings, NAME, 'foo')
assert get_config(NAME) == 'foo'
assert get_config(setting=NAME, env=False) == 'foo'
assert_raises(EnvironmentError, get_config, env=NAME)
# Set the value in the environment as well.
os.environ[NAME] = 'bar'
# Ensure that settings take precedence.
assert get_config(NAME) == 'foo'
# Two different names can be supplied.
assert not hasattr(settings, NAME*2) # Must not yet exist.
assert get_config(setting=NAME*2, env=NAME) == 'bar'
# Unset the value in the settings. Note that due to the way
# Django's settings object works, we need to access ``_wrapped``.
delattr(settings._wrapped, NAME)
assert get_config(NAME) == 'bar'
assert get_config(env=NAME, setting=False) == 'bar'
assert_raises(EnvironmentError, get_config, setting=NAME, env=False)
def test_equality(self):
"""Test the ``unique`` method used to determine equality.
"""
class TestFilter(Filter):
def unique(self):
return getattr(self, 'token', None)
f1 = TestFilter();
f2 = TestFilter();
# As long as the two tokens are equal, the filters are
# considered to be the same.
assert f1 == f2
f1.token = 'foo'
assert f1 != f2
f2.token = 'foo'
assert f1 == f2
# However, unique() is only per class; two different filter
# classes will never match...
class AnotherFilter(TestFilter):
# ...even if they have the same name.
name = TestFilter.name
def unique(self):
return 'foo'
g = AnotherFilter()
assert f1 != g
def test_register_filter():
"""Test registration of custom filters.
"""
# Needs to be a ``Filter`` subclass.
assert_raises(ValueError, register_filter, object)
# A name is required.
class MyFilter(Filter):
name = None
assert_raises(ValueError, register_filter, MyFilter)
# The same filter cannot be registered under multiple names.
MyFilter.name = 'foo'
register_filter(MyFilter)
MyFilter.name = 'bar'
register_filter(MyFilter)
# But the same name cannot be registered multiple times.
assert_raises(KeyError, register_filter, MyFilter)
def test_get_filter():
"""Test filter resolving.
"""
# By name - here using one of the builtins.
assert isinstance(get_filter('jsmin'), Filter)
assert_raises(ValueError, get_filter, 'notafilteractually')
# By class.
class MyFilter(Filter): pass
assert isinstance(get_filter(MyFilter), MyFilter)
assert_raises(ValueError, get_filter, object())
# Passing an instance doesn't do anything.
f = MyFilter()
assert id(get_filter(f)) == id(f)
# Passing a lone callable will give us a a filter back as well.
assert hasattr(get_filter(lambda: None), 'apply')
|
agpl-3.0
|
[
646,
747,
199,
504,
11354,
14,
2537,
492,
702,
63,
3536,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
63,
12186,
14,
1541,
492,
9388,
12,
664,
63,
1541,
12,
2274,
63,
1541,
199,
199,
3,
3254,
26,
2654,
2295,
367,
1006,
314,
6762,
4766,
14,
421,
199,
533,
1379,
4131,
26,
272,
408,
774,
314,
3261,
1124,
4131,
1040,
6571,
370,
26061,
14,
272,
408,
339,
347,
511,
63,
2495,
63,
354,
8,
277,
304,
267,
408,
774,
314,
4834,
10152,
402,
314,
2457,
536,
14,
267,
408,
267,
702,
730,
360,
5686,
297,
334,
4131,
4706,
13056,
354,
508,
283,
1421,
7,
267,
702,
730,
360,
5686,
4131,
297,
334,
4131,
4706,
13056,
354,
508,
283,
1421,
7,
267,
702,
730,
360,
5686,
5281,
4131,
297,
334,
4131,
4706,
13056,
354,
508,
283,
9664,
7,
398,
702,
730,
360,
5686,
297,
334,
4131,
4706,
791,
354,
356,
283,
4229,
936,
680,
354,
508,
283,
4229,
7,
267,
702,
730,
360,
5686,
297,
334,
4131,
4706,
791,
354,
356,
488,
21385,
354,
508,
488,
339,
347,
511,
63,
362,
63,
888,
8,
277,
304,
267,
408,
774,
314,
1124,
362,
63,
888,
1040,
5922,
14,
267,
408,
267,
664,
63,
888,
275,
9388,
1252,
362,
63,
888,
398,
327,
2104,
314,
12901,
402,
314,
2569,
2295,
12,
781,
675,
282,
511,
267,
327,
536,
1314,
781,
4282,
370,
506,
10942,
315,
3865,
2202,
267,
327,
436,
3734,
14,
267,
13637,
275,
283,
13046,
4321,
7,
267,
702,
440,
13637,
315,
747,
14,
2314,
267,
702,
440,
2688,
8,
1751,
12,
13637,
9,
398,
327,
1379,
17026,
402,
1125,
12,
436,
511,
440,
17026,
652,
14,
267,
702,
63,
3536,
8,
8263,
547,
12,
664,
63,
888,
12,
13637,
9,
267,
702,
664,
63,
888,
8,
2339,
12,
4409,
29,
797,
9,
508,
488,
398,
327,
7707,
701,
6425,
314,
574,
465,
282,
4260,
14,
267,
5371,
8,
1751,
12,
13637,
12,
283,
1421,
358,
267,
702,
664,
63,
888,
8,
2339,
9,
508,
283,
1421,
7,
267,
702,
664,
63,
888,
8,
6031,
29,
2339,
12,
2589,
29,
797,
9,
508,
283,
1421,
7,
267,
702,
63,
3536,
8,
8263,
547,
12,
664,
63,
888,
12,
2589,
29,
2339,
9,
398,
327,
2494,
314,
574,
315,
314,
3734,
465,
5521,
14,
267,
747,
14,
2314,
59,
2339,
61,
275,
283,
1700,
7,
267,
327,
7523,
626,
2202,
5452,
13823,
14,
267,
702,
664,
63,
888,
8,
2339,
9,
508,
283,
1421,
7,
267,
327,
16853,
3365,
1561,
883,
506,
6841,
14,
267,
702,
440,
2688,
8,
1751,
12,
13637,
10,
18,
9,
221,
327,
9498,
440,
5966,
2187,
14,
267,
702,
664,
63,
888,
8,
6031,
29,
2339,
10,
18,
12,
2589,
29,
2339,
9,
508,
283,
1700,
7,
398,
327,
1910,
409,
314,
574,
315,
314,
2202,
14,
3390,
626,
7037,
370,
314,
4340,
267,
327,
5634,
1159,
2202,
909,
5419,
12,
781,
1929,
370,
2879,
24507,
9130,
4345,
267,
24358,
8,
1751,
423,
9130,
12,
13637,
9,
267,
702,
664,
63,
888,
8,
2339,
9,
508,
283,
1700,
7,
267,
702,
664,
63,
888,
8,
1813,
29,
2339,
12,
4260,
29,
797,
9,
508,
283,
1700,
7,
267,
702,
63,
3536,
8,
8263,
547,
12,
664,
63,
888,
12,
4260,
29,
2339,
12,
2589,
29,
797,
9,
339,
347,
511,
63,
20982,
8,
277,
304,
267,
408,
774,
314,
1124,
3235,
1040,
1083,
1202,
370,
6705,
16612,
14,
267,
408,
267,
1021,
1379,
4131,
8,
4131,
304,
288,
347,
3747,
8,
277,
304,
355,
372,
2519,
8,
277,
12,
283,
1418,
297,
488,
9,
267,
289,
17,
275,
1379,
4131,
7303,
267,
289,
18,
275,
1379,
4131,
7303,
398,
327,
3709,
1846,
465,
314,
2877,
4645,
787,
4472,
12,
314,
4766,
787,
267,
327,
8652,
370,
506,
314,
2011,
14,
267,
702,
289,
17,
508,
289,
18,
267,
289,
17,
14,
1418,
275,
283,
1421,
7,
267,
702,
289,
17,
1137,
289,
18,
267,
289,
18,
14,
1418,
275,
283,
1421,
7,
267,
702,
289,
17,
508,
289,
18,
398,
327,
9738,
12,
3747,
342,
365,
1454,
1126,
1021,
27,
2877,
3365,
2457,
267,
327,
3992,
911,
7078,
1336,
1396,
267,
1021,
22604,
4131,
8,
774,
4131,
304,
288,
327,
2263,
12056,
340,
2985,
1172,
314,
2011,
536,
14,
288,
536,
275,
1379,
4131,
14,
354,
288,
347,
3747,
8,
277,
304,
355,
372,
283,
1421,
7,
267,
486,
275,
22604,
4131,
342,
267,
702,
289,
17,
1137,
486,
421,
199,
318,
511,
63,
2683,
63,
1541,
837,
272,
408,
774,
10991,
402,
3537,
4766,
14,
272,
408,
272,
327,
29613,
370,
506,
282,
1124,
4131,
1040,
5516,
14,
272,
702,
63,
3536,
8,
3393,
12,
2274,
63,
1541,
12,
909,
9,
272,
327,
437,
536,
365,
1415,
14,
272,
1021,
4932,
4131,
8,
4131,
304,
267,
536,
275,
488,
272,
702,
63,
3536,
8,
3393,
12,
2274,
63,
1541,
12,
4932,
4131,
9,
272,
327,
710,
2011,
2457,
3913,
506,
7264,
1334,
3663,
1561,
14,
272,
4932,
4131,
14,
354,
275,
283,
1421,
7,
272,
2274,
63,
1541,
8,
5713,
4131,
9,
272,
4932,
4131,
14,
354,
275,
283,
1700,
7,
272,
2274,
63,
1541,
8,
5713,
4131,
9,
272,
327,
11017,
314,
2011,
536,
3913,
506,
7264,
3663,
5431,
14,
272,
702,
63,
3536,
8,
10230,
12,
2274,
63,
1541,
12,
4932,
4131,
9,
421,
199,
318,
511,
63,
362,
63,
1541,
837,
272,
408,
774,
2457,
30685,
14,
272,
408,
272,
327,
4885,
536,
446,
2348,
1808,
1373,
402,
314,
12963,
14,
272,
702,
1228,
8,
362,
63,
1541,
360,
3596,
827,
659,
9388,
9,
272,
702,
63,
3536,
8,
3393,
12,
664,
63,
1541,
12,
283,
1397,
65,
1289,
266,
1957,
3163,
358,
339,
327,
4885,
1021,
14,
272,
1021,
4932,
4131,
8,
4131,
304,
986,
272,
702,
1228,
8,
362,
63,
1541,
8,
5713,
4131,
395,
4932,
4131,
9,
272,
702,
63,
3536,
8,
3393,
12,
664,
63,
1541,
12,
909,
1012,
339,
327,
31755,
376,
1256,
3181,
1133,
886,
7003,
14,
272,
289,
275,
4932,
4131,
342,
272,
702,
1305,
8,
362,
63,
1541,
8,
70,
430,
508,
1305,
8,
70,
9,
339
] |
[
747,
199,
504,
11354,
14,
2537,
492,
702,
63,
3536,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
63,
12186,
14,
1541,
492,
9388,
12,
664,
63,
1541,
12,
2274,
63,
1541,
199,
199,
3,
3254,
26,
2654,
2295,
367,
1006,
314,
6762,
4766,
14,
421,
199,
533,
1379,
4131,
26,
272,
408,
774,
314,
3261,
1124,
4131,
1040,
6571,
370,
26061,
14,
272,
408,
339,
347,
511,
63,
2495,
63,
354,
8,
277,
304,
267,
408,
774,
314,
4834,
10152,
402,
314,
2457,
536,
14,
267,
408,
267,
702,
730,
360,
5686,
297,
334,
4131,
4706,
13056,
354,
508,
283,
1421,
7,
267,
702,
730,
360,
5686,
4131,
297,
334,
4131,
4706,
13056,
354,
508,
283,
1421,
7,
267,
702,
730,
360,
5686,
5281,
4131,
297,
334,
4131,
4706,
13056,
354,
508,
283,
9664,
7,
398,
702,
730,
360,
5686,
297,
334,
4131,
4706,
791,
354,
356,
283,
4229,
936,
680,
354,
508,
283,
4229,
7,
267,
702,
730,
360,
5686,
297,
334,
4131,
4706,
791,
354,
356,
488,
21385,
354,
508,
488,
339,
347,
511,
63,
362,
63,
888,
8,
277,
304,
267,
408,
774,
314,
1124,
362,
63,
888,
1040,
5922,
14,
267,
408,
267,
664,
63,
888,
275,
9388,
1252,
362,
63,
888,
398,
327,
2104,
314,
12901,
402,
314,
2569,
2295,
12,
781,
675,
282,
511,
267,
327,
536,
1314,
781,
4282,
370,
506,
10942,
315,
3865,
2202,
267,
327,
436,
3734,
14,
267,
13637,
275,
283,
13046,
4321,
7,
267,
702,
440,
13637,
315,
747,
14,
2314,
267,
702,
440,
2688,
8,
1751,
12,
13637,
9,
398,
327,
1379,
17026,
402,
1125,
12,
436,
511,
440,
17026,
652,
14,
267,
702,
63,
3536,
8,
8263,
547,
12,
664,
63,
888,
12,
13637,
9,
267,
702,
664,
63,
888,
8,
2339,
12,
4409,
29,
797,
9,
508,
488,
398,
327,
7707,
701,
6425,
314,
574,
465,
282,
4260,
14,
267,
5371,
8,
1751,
12,
13637,
12,
283,
1421,
358,
267,
702,
664,
63,
888,
8,
2339,
9,
508,
283,
1421,
7,
267,
702,
664,
63,
888,
8,
6031,
29,
2339,
12,
2589,
29,
797,
9,
508,
283,
1421,
7,
267,
702,
63,
3536,
8,
8263,
547,
12,
664,
63,
888,
12,
2589,
29,
2339,
9,
398,
327,
2494,
314,
574,
315,
314,
3734,
465,
5521,
14,
267,
747,
14,
2314,
59,
2339,
61,
275,
283,
1700,
7,
267,
327,
7523,
626,
2202,
5452,
13823,
14,
267,
702,
664,
63,
888,
8,
2339,
9,
508,
283,
1421,
7,
267,
327,
16853,
3365,
1561,
883,
506,
6841,
14,
267,
702,
440,
2688,
8,
1751,
12,
13637,
10,
18,
9,
221,
327,
9498,
440,
5966,
2187,
14,
267,
702,
664,
63,
888,
8,
6031,
29,
2339,
10,
18,
12,
2589,
29,
2339,
9,
508,
283,
1700,
7,
398,
327,
1910,
409,
314,
574,
315,
314,
2202,
14,
3390,
626,
7037,
370,
314,
4340,
267,
327,
5634,
1159,
2202,
909,
5419,
12,
781,
1929,
370,
2879,
24507,
9130,
4345,
267,
24358,
8,
1751,
423,
9130,
12,
13637,
9,
267,
702,
664,
63,
888,
8,
2339,
9,
508,
283,
1700,
7,
267,
702,
664,
63,
888,
8,
1813,
29,
2339,
12,
4260,
29,
797,
9,
508,
283,
1700,
7,
267,
702,
63,
3536,
8,
8263,
547,
12,
664,
63,
888,
12,
4260,
29,
2339,
12,
2589,
29,
797,
9,
339,
347,
511,
63,
20982,
8,
277,
304,
267,
408,
774,
314,
1124,
3235,
1040,
1083,
1202,
370,
6705,
16612,
14,
267,
408,
267,
1021,
1379,
4131,
8,
4131,
304,
288,
347,
3747,
8,
277,
304,
355,
372,
2519,
8,
277,
12,
283,
1418,
297,
488,
9,
267,
289,
17,
275,
1379,
4131,
7303,
267,
289,
18,
275,
1379,
4131,
7303,
398,
327,
3709,
1846,
465,
314,
2877,
4645,
787,
4472,
12,
314,
4766,
787,
267,
327,
8652,
370,
506,
314,
2011,
14,
267,
702,
289,
17,
508,
289,
18,
267,
289,
17,
14,
1418,
275,
283,
1421,
7,
267,
702,
289,
17,
1137,
289,
18,
267,
289,
18,
14,
1418,
275,
283,
1421,
7,
267,
702,
289,
17,
508,
289,
18,
398,
327,
9738,
12,
3747,
342,
365,
1454,
1126,
1021,
27,
2877,
3365,
2457,
267,
327,
3992,
911,
7078,
1336,
1396,
267,
1021,
22604,
4131,
8,
774,
4131,
304,
288,
327,
2263,
12056,
340,
2985,
1172,
314,
2011,
536,
14,
288,
536,
275,
1379,
4131,
14,
354,
288,
347,
3747,
8,
277,
304,
355,
372,
283,
1421,
7,
267,
486,
275,
22604,
4131,
342,
267,
702,
289,
17,
1137,
486,
421,
199,
318,
511,
63,
2683,
63,
1541,
837,
272,
408,
774,
10991,
402,
3537,
4766,
14,
272,
408,
272,
327,
29613,
370,
506,
282,
1124,
4131,
1040,
5516,
14,
272,
702,
63,
3536,
8,
3393,
12,
2274,
63,
1541,
12,
909,
9,
272,
327,
437,
536,
365,
1415,
14,
272,
1021,
4932,
4131,
8,
4131,
304,
267,
536,
275,
488,
272,
702,
63,
3536,
8,
3393,
12,
2274,
63,
1541,
12,
4932,
4131,
9,
272,
327,
710,
2011,
2457,
3913,
506,
7264,
1334,
3663,
1561,
14,
272,
4932,
4131,
14,
354,
275,
283,
1421,
7,
272,
2274,
63,
1541,
8,
5713,
4131,
9,
272,
4932,
4131,
14,
354,
275,
283,
1700,
7,
272,
2274,
63,
1541,
8,
5713,
4131,
9,
272,
327,
11017,
314,
2011,
536,
3913,
506,
7264,
3663,
5431,
14,
272,
702,
63,
3536,
8,
10230,
12,
2274,
63,
1541,
12,
4932,
4131,
9,
421,
199,
318,
511,
63,
362,
63,
1541,
837,
272,
408,
774,
2457,
30685,
14,
272,
408,
272,
327,
4885,
536,
446,
2348,
1808,
1373,
402,
314,
12963,
14,
272,
702,
1228,
8,
362,
63,
1541,
360,
3596,
827,
659,
9388,
9,
272,
702,
63,
3536,
8,
3393,
12,
664,
63,
1541,
12,
283,
1397,
65,
1289,
266,
1957,
3163,
358,
339,
327,
4885,
1021,
14,
272,
1021,
4932,
4131,
8,
4131,
304,
986,
272,
702,
1228,
8,
362,
63,
1541,
8,
5713,
4131,
395,
4932,
4131,
9,
272,
702,
63,
3536,
8,
3393,
12,
664,
63,
1541,
12,
909,
1012,
339,
327,
31755,
376,
1256,
3181,
1133,
886,
7003,
14,
272,
289,
275,
4932,
4131,
342,
272,
702,
1305,
8,
362,
63,
1541,
8,
70,
430,
508,
1305,
8,
70,
9,
339,
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,
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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
] |
JIMyungSik/uftrace
|
tests/t137_kernel_tid_update.py
|
2
|
1270
|
#!/usr/bin/env python
from runtest import TestBase
import os
class TestCase(TestBase):
def __init__(self):
TestBase.__init__(self, 'fork2', """
# DURATION TID FUNCTION
[19227] | main() {
328.451 us [19227] | fork();
[19227] | wait() {
[19231] | } /* fork */
[19231] | open() {
17.068 us [19231] | sys_open();
21.964 us [19231] | } /* open */
[19231] | close() {
2.537 us [19231] | sys_close();
7.057 us [19231] | } /* close */
[19231] | } /* main */
40.601 ms [19227] | } /* wait */
[19227] | open() {
30.832 us [19227] | sys_open();
37.121 us [19227] | } /* open */
[19227] | close() {
2.950 us [19227] | sys_close();
9.520 us [19227] | } /* close */
41.010 ms [19227] | } /* main */
""")
def pre(self):
if os.geteuid() != 0:
return TestBase.TEST_SKIP
if os.path.exists('/.dockerenv'):
return TestBase.TEST_SKIP
return TestBase.TEST_SUCCESS
def runcmd(self):
uftrace = TestBase.ftrace
filters = '-F main -F sys_open@kernel -F sys_close@kernel'
return '%s -k %s %s' % (uftrace, filters, 't-' + self.name)
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
504,
1255,
396,
492,
1379,
1563,
199,
646,
747,
199,
199,
533,
7640,
8,
14440,
304,
272,
347,
636,
826,
721,
277,
304,
267,
1379,
1563,
855,
826,
721,
277,
12,
283,
11796,
18,
297,
408,
199,
3,
577,
15301,
259,
377,
998,
258,
32744,
288,
359,
1167,
11385,
61,
1204,
2446,
342,
469,
199,
650,
1651,
14,
24723,
2739,
359,
1167,
11385,
61,
1204,
257,
14926,
7303,
288,
359,
1167,
11385,
61,
1204,
257,
3618,
342,
469,
288,
359,
1167,
11921,
61,
1204,
257,
789,
13505,
14926,
11589,
288,
359,
1167,
11921,
61,
1204,
257,
1551,
342,
469,
523,
5557,
14,
19846,
2739,
359,
1167,
11921,
61,
1204,
258,
984,
63,
1490,
7303,
523,
7829,
14,
31124,
2739,
359,
1167,
11921,
61,
1204,
257,
789,
13505,
1551,
11589,
288,
359,
1167,
11921,
61,
1204,
257,
4002,
342,
469,
2043,
499,
14,
24416,
2739,
359,
1167,
11921,
61,
1204,
258,
984,
63,
1600,
7303,
2043,
1520,
14,
24624,
2739,
359,
1167,
11921,
61,
1204,
257,
789,
13505,
4002,
11589,
288,
359,
1167,
11921,
61,
1204,
789,
13505,
2446,
11589,
523,
6335,
14,
24539,
6605,
359,
1167,
11385,
61,
1204,
257,
789,
13505,
3618,
11589,
288,
359,
1167,
11385,
61,
1204,
257,
1551,
342,
469,
523,
4233,
14,
24,
708,
2739,
359,
1167,
11385,
61,
1204,
258,
984,
63,
1490,
7303,
523,
6877,
14,
10753,
2739,
359,
1167,
11385,
61,
1204,
257,
789,
13505,
1551,
11589,
288,
359,
1167,
11385,
61,
1204,
257,
4002,
342,
469,
2043,
499,
14,
29678,
2739,
359,
1167,
11385,
61,
1204,
258,
984,
63,
1600,
7303,
2043,
1749,
14,
24224,
2739,
359,
1167,
11385,
61,
1204,
257,
789,
13505,
4002,
11589,
523,
13385,
14,
9523,
6605,
359,
1167,
11385,
61,
1204,
789,
13505,
2446,
11589,
199,
6141,
339,
347,
876,
8,
277,
304,
267,
340,
747,
14,
31508,
1535,
342,
1137,
378,
26,
288,
372,
1379,
1563,
14,
2864,
63,
13525,
267,
340,
747,
14,
515,
14,
2444,
2336,
14,
21103,
69,
828,
86,
735,
288,
372,
1379,
1563,
14,
2864,
63,
13525,
398,
372,
1379,
1563,
14,
2864,
63,
12779,
339,
347,
519,
1097,
1064,
8,
277,
304,
267,
399,
24856,
275,
1379,
1563,
14,
24856,
267,
4766,
275,
2475,
38,
2446,
446,
38,
984,
63,
1490,
32,
4989,
446,
38,
984,
63,
1600,
32,
4989,
7,
267,
372,
1543,
83,
446,
75,
450,
83,
450,
83,
7,
450,
334,
85,
24856,
12,
4766,
12,
283,
84,
15668,
435,
291,
14,
354,
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
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
504,
1255,
396,
492,
1379,
1563,
199,
646,
747,
199,
199,
533,
7640,
8,
14440,
304,
272,
347,
636,
826,
721,
277,
304,
267,
1379,
1563,
855,
826,
721,
277,
12,
283,
11796,
18,
297,
408,
199,
3,
577,
15301,
259,
377,
998,
258,
32744,
288,
359,
1167,
11385,
61,
1204,
2446,
342,
469,
199,
650,
1651,
14,
24723,
2739,
359,
1167,
11385,
61,
1204,
257,
14926,
7303,
288,
359,
1167,
11385,
61,
1204,
257,
3618,
342,
469,
288,
359,
1167,
11921,
61,
1204,
257,
789,
13505,
14926,
11589,
288,
359,
1167,
11921,
61,
1204,
257,
1551,
342,
469,
523,
5557,
14,
19846,
2739,
359,
1167,
11921,
61,
1204,
258,
984,
63,
1490,
7303,
523,
7829,
14,
31124,
2739,
359,
1167,
11921,
61,
1204,
257,
789,
13505,
1551,
11589,
288,
359,
1167,
11921,
61,
1204,
257,
4002,
342,
469,
2043,
499,
14,
24416,
2739,
359,
1167,
11921,
61,
1204,
258,
984,
63,
1600,
7303,
2043,
1520,
14,
24624,
2739,
359,
1167,
11921,
61,
1204,
257,
789,
13505,
4002,
11589,
288,
359,
1167,
11921,
61,
1204,
789,
13505,
2446,
11589,
523,
6335,
14,
24539,
6605,
359,
1167,
11385,
61,
1204,
257,
789,
13505,
3618,
11589,
288,
359,
1167,
11385,
61,
1204,
257,
1551,
342,
469,
523,
4233,
14,
24,
708,
2739,
359,
1167,
11385,
61,
1204,
258,
984,
63,
1490,
7303,
523,
6877,
14,
10753,
2739,
359,
1167,
11385,
61,
1204,
257,
789,
13505,
1551,
11589,
288,
359,
1167,
11385,
61,
1204,
257,
4002,
342,
469,
2043,
499,
14,
29678,
2739,
359,
1167,
11385,
61,
1204,
258,
984,
63,
1600,
7303,
2043,
1749,
14,
24224,
2739,
359,
1167,
11385,
61,
1204,
257,
789,
13505,
4002,
11589,
523,
13385,
14,
9523,
6605,
359,
1167,
11385,
61,
1204,
789,
13505,
2446,
11589,
199,
6141,
339,
347,
876,
8,
277,
304,
267,
340,
747,
14,
31508,
1535,
342,
1137,
378,
26,
288,
372,
1379,
1563,
14,
2864,
63,
13525,
267,
340,
747,
14,
515,
14,
2444,
2336,
14,
21103,
69,
828,
86,
735,
288,
372,
1379,
1563,
14,
2864,
63,
13525,
398,
372,
1379,
1563,
14,
2864,
63,
12779,
339,
347,
519,
1097,
1064,
8,
277,
304,
267,
399,
24856,
275,
1379,
1563,
14,
24856,
267,
4766,
275,
2475,
38,
2446,
446,
38,
984,
63,
1490,
32,
4989,
446,
38,
984,
63,
1600,
32,
4989,
7,
267,
372,
1543,
83,
446,
75,
450,
83,
450,
83,
7,
450,
334,
85,
24856,
12,
4766,
12,
283,
84,
15668,
435,
291,
14,
354,
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,
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,
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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
] |
libracore/erpnext
|
erpnext/education/report/assessment_plan_status/assessment_plan_status.py
|
24
|
4374
|
# Copyright (c) 2013, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt
from __future__ import unicode_literals
import frappe
from frappe import _
from itertools import groupby
from frappe.utils import cint
DOCSTATUS = {
0: "saved",
1: "submitted",
}
def execute(filters=None):
columns, data = [], []
args = frappe._dict()
args["assessment_group"] = filters.get("assessment_group")
args["schedule_date"] = filters.get("schedule_date")
columns = get_column()
data, chart = get_assessment_data(args)
return columns, data, None, chart
def get_assessment_data(args=None):
# [total, saved, submitted, remaining]
chart_data = [0, 0, 0, 0]
condition = ''
if args["assessment_group"]:
condition += "and assessment_group = %(assessment_group)s"
if args["schedule_date"]:
condition += "and schedule_date <= %(schedule_date)s"
assessment_plan = frappe.db.sql('''
SELECT
ap.name as assessment_plan,
ap.assessment_name,
ap.student_group,
ap.schedule_date,
(select count(*) from `tabStudent Group Student` sgs where sgs.parent=ap.student_group)
as student_group_strength
FROM
`tabAssessment Plan` ap
WHERE
ap.docstatus = 1 {condition}
ORDER BY
ap.modified desc
'''.format(condition=condition), (args), as_dict=1)
assessment_plan_list = [d.assessment_plan for d in assessment_plan] if assessment_plan else ['']
assessment_result = get_assessment_result(assessment_plan_list)
for d in assessment_plan:
assessment_plan_details = assessment_result.get(d.assessment_plan)
assessment_plan_details = frappe._dict() if not assessment_plan_details else \
frappe._dict(assessment_plan_details)
if "saved" not in assessment_plan_details:
assessment_plan_details.update({"saved": 0})
if "submitted" not in assessment_plan_details:
assessment_plan_details.update({"submitted": 0})
# remaining students whose marks not entered
remaining_students = cint(d.student_group_strength) - cint(assessment_plan_details.saved) -\
cint(assessment_plan_details.submitted)
assessment_plan_details.update({"remaining": remaining_students})
d.update(assessment_plan_details)
chart_data[0] += cint(d.student_group_strength)
chart_data[1] += assessment_plan_details.saved
chart_data[2] += assessment_plan_details.submitted
chart_data[3] += assessment_plan_details.remaining
chart = get_chart(chart_data[1:])
return assessment_plan, chart
def get_assessment_result(assessment_plan_list):
assessment_result_dict = frappe._dict()
assessment_result = frappe.db.sql('''
SELECT
assessment_plan, docstatus, count(*) as count
FROM
`tabAssessment Result`
WHERE
assessment_plan in (%s)
GROUP BY
assessment_plan, docstatus
ORDER BY
assessment_plan
''' %', '.join(['%s']*len(assessment_plan_list)), tuple(assessment_plan_list), as_dict=1)
for key, group in groupby(assessment_result, lambda ap: ap["assessment_plan"]):
tmp = {}
for d in group:
if d.docstatus in [0,1]:
tmp.update({DOCSTATUS[d.docstatus]:d.count})
assessment_result_dict[key] = tmp
return assessment_result_dict
def get_chart(chart_data):
return {
"data": {
"labels": ["Saved", "Submitted", "Remaining"],
"datasets": [{
"values": chart_data
}]
},
"type": 'percentage',
}
def get_column():
return [{
"fieldname": "assessment_plan",
"label": _("Assessment Plan"),
"fieldtype": "Link",
"options": "Assessment Plan",
"width": 120
},
{
"fieldname": "assessment_name",
"label": _("Assessment Plan Name"),
"fieldtype": "Data",
"options": "",
"width": 200
},
{
"fieldname": "schedule_date",
"label": _("Schedule Date"),
"fieldtype": "Date",
"options": "",
"width": 100
},
{
"fieldname": "student_group",
"label": _("Student Group"),
"fieldtype": "Link",
"options": "Student Group",
"width": 200
},
{
"fieldname": "student_group_strength",
"label": _("Total Student"),
"fieldtype": "Data",
"options": "",
"width": 100
},
{
"fieldname": "submitted",
"label": _("Submitted"),
"fieldtype": "Data",
"options": "",
"width": 100
},
{
"fieldname": "saved",
"label": _("Saved"),
"fieldtype": "Data",
"options": "",
"width": 100
},
{
"fieldname": "remaining",
"label": _("Remaining"),
"fieldtype": "Data",
"options": "",
"width": 100
}]
|
gpl-3.0
|
[
3,
1898,
334,
67,
9,
6171,
12,
481,
5034,
19215,
29053,
14,
12126,
14,
436,
8417,
199,
3,
2104,
4190,
2556,
12,
8749,
1937,
4190,
14,
2424,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
646,
6950,
199,
504,
6950,
492,
485,
199,
504,
7975,
492,
20371,
199,
504,
6950,
14,
1208,
492,
286,
442,
199,
199,
16618,
6305,
275,
469,
199,
198,
16,
26,
298,
8420,
401,
199,
198,
17,
26,
298,
23736,
401,
199,
93,
199,
199,
318,
5341,
8,
4273,
29,
403,
304,
199,
198,
3406,
12,
666,
275,
990,
942,
421,
198,
589,
275,
6950,
423,
807,
342,
199,
198,
589,
905,
17452,
63,
923,
937,
275,
4766,
14,
362,
480,
17452,
63,
923,
531,
199,
198,
589,
905,
7211,
63,
602,
937,
275,
4766,
14,
362,
480,
7211,
63,
602,
531,
421,
198,
3406,
275,
664,
63,
2301,
342,
421,
198,
576,
12,
10943,
275,
664,
63,
17452,
63,
576,
8,
589,
9,
421,
198,
1107,
4362,
12,
666,
12,
488,
12,
10943,
421,
199,
318,
664,
63,
17452,
63,
576,
8,
589,
29,
403,
304,
421,
198,
3,
359,
2923,
12,
6290,
12,
16930,
12,
7971,
61,
199,
198,
9019,
63,
576,
275,
359,
16,
12,
378,
12,
378,
12,
378,
61,
421,
198,
5394,
275,
2125,
199,
198,
692,
1249,
905,
17452,
63,
923,
6229,
507,
198,
5394,
847,
298,
460,
28273,
63,
923,
275,
2818,
17452,
63,
923,
9,
83,
2,
199,
198,
692,
1249,
905,
7211,
63,
602,
6229,
507,
198,
5394,
847,
298,
460,
8732,
63,
602,
2695,
2818,
7211,
63,
602,
9,
83,
2,
421,
198,
17452,
63,
5140,
275,
6950,
14,
697,
14,
3009,
10505,
686,
198,
4859,
1585,
198,
439,
14,
354,
465,
28273,
63,
5140,
12,
1585,
198,
439,
14,
17452,
63,
354,
12,
1585,
198,
439,
14,
5500,
63,
923,
12,
1585,
198,
439,
14,
7211,
63,
602,
12,
1585,
198,
8,
2416,
2338,
21565,
687,
658,
2902,
18086,
5611,
17246,
64,
308,
458,
2382,
308,
458,
14,
1708,
29,
439,
14,
5500,
63,
923,
9,
1871,
198,
305,
6474,
63,
923,
63,
21049,
686,
198,
12491,
1585,
198,
64,
2902,
2822,
12104,
32427,
64,
2771,
686,
198,
17688,
1585,
198,
439,
14,
30461,
275,
413,
469,
5394,
93,
686,
198,
12125,
6515,
1585,
198,
439,
14,
5540,
4328,
507,
198,
891,
1370,
908,
8,
5394,
29,
5394,
395,
334,
589,
395,
465,
63,
807,
29,
17,
9,
421,
198,
17452,
63,
5140,
63,
513,
275,
359,
68,
14,
17452,
63,
5140,
367,
366,
315,
28273,
63,
5140,
61,
340,
28273,
63,
5140,
587,
24506,
199,
198,
17452,
63,
1099,
275,
664,
63,
17452,
63,
1099,
8,
17452,
63,
5140,
63,
513,
9,
421,
198,
509,
366,
315,
28273,
63,
5140,
26,
2742,
198,
17452,
63,
5140,
63,
5087,
275,
28273,
63,
1099,
14,
362,
8,
68,
14,
17452,
63,
5140,
9,
507,
198,
17452,
63,
5140,
63,
5087,
275,
6950,
423,
807,
342,
340,
440,
28273,
63,
5140,
63,
5087,
587,
971,
686,
198,
9098,
423,
807,
8,
17452,
63,
5140,
63,
5087,
9,
507,
198,
692,
298,
8420,
2,
440,
315,
28273,
63,
5140,
63,
5087,
26,
686,
198,
17452,
63,
5140,
63,
5087,
14,
873,
6333,
8420,
582,
378,
1552,
507,
198,
692,
298,
23736,
2,
440,
315,
28273,
63,
5140,
63,
5087,
26,
686,
198,
17452,
63,
5140,
63,
5087,
14,
873,
6333,
23736,
582,
378,
1552,
2742,
198,
3,
7971,
18557,
7447,
17370,
440,
19138,
507,
198,
11266,
63,
17921,
275,
286,
442,
8,
68,
14,
5500,
63,
923,
63,
21049,
9,
446,
286,
442,
8,
17452,
63,
5140,
63,
5087,
14,
8420,
9,
446,
60,
686,
198,
67,
442,
8,
17452,
63,
5140,
63,
5087,
14,
23736,
9,
507,
198,
17452,
63,
5140,
63,
5087,
14,
873,
6333,
11266,
582,
7971,
63,
17921,
1552,
507,
198,
68,
14,
873,
8,
17452,
63,
5140,
63,
5087,
9,
2742,
198,
9019,
63,
576,
59,
16,
61,
847,
286,
442,
8,
68,
14,
5500,
63,
923,
63,
21049,
9,
507,
198,
9019,
63,
576,
59,
17,
61,
847,
28273,
63,
5140,
63,
5087,
14,
8420,
507,
198,
9019,
63,
576,
59,
18,
61,
847,
28273,
63,
5140,
63,
5087,
14,
23736,
507,
198,
9019,
63,
576,
59,
19,
61,
847,
28273,
63,
5140,
63,
5087,
14,
11266,
421,
198,
9019,
275,
664,
63,
9019,
8,
9019,
63,
576,
59,
17,
5728,
421,
198,
1107,
28273,
63,
5140,
12,
10943,
421,
199,
318,
664,
63,
17452,
63,
1099,
8,
17452,
63,
5140,
63,
513,
304,
199,
198,
17452,
63,
1099,
63,
807,
275,
6950,
423,
807,
342,
421,
198,
17452,
63,
1099,
275,
6950,
14,
697,
14,
3009,
10505,
507,
198,
4859,
686,
198,
17452,
63,
5140,
12,
1382,
1205,
12,
2338,
21565,
465,
2338,
507,
198,
12491,
686,
198,
64,
2902,
2822,
12104,
10695,
64,
507,
198,
17688,
686,
198,
17452,
63,
5140,
315,
4366,
83,
9,
507,
198,
7823,
6515,
686,
198,
17452,
63,
5140,
12,
1382,
1205,
507,
198,
12125,
6515,
686,
198,
17452,
63,
5140,
199,
198,
2344,
450,
297,
1987,
904,
26861,
83,
20445,
552,
8,
17452,
63,
5140,
63,
513,
1826,
2008,
8,
17452,
63,
5140,
63,
513,
395,
465,
63,
807,
29,
17,
9,
421,
198,
509,
790,
12,
1572,
315,
20371,
8,
17452,
63,
1099,
12,
2400,
2771,
26,
2771,
905,
17452,
63,
5140,
21473,
507,
198,
2791,
275,
1052,
507,
198,
509,
366,
315,
1572,
26,
686,
198,
692,
366,
14,
30461,
315,
359,
16,
12,
17,
2189,
1585,
198,
2791,
14,
873,
2561,
16618,
6305,
59,
68,
14,
30461,
2189,
68,
14,
835,
1552,
507,
198,
17452,
63,
1099,
63,
807,
59,
498,
61,
275,
3529,
421,
198,
1107,
28273,
63,
1099,
63,
807,
421,
199,
318,
664,
63,
9019,
8,
9019,
63,
576,
304,
199,
198,
1107,
469,
507,
198,
2,
576,
582,
469,
686,
198,
2,
3512,
582,
2097,
21969,
401,
298,
2610,
4485,
401,
298,
31109,
2255,
686,
198,
2,
12281,
582,
8910,
1585,
198,
2,
1459,
582,
10943,
63,
576,
686,
198,
11049,
507,
198,
1386,
507,
198,
2,
466,
582,
283,
14200,
297,
199,
198,
93,
421,
199,
318
] |
[
1898,
334,
67,
9,
6171,
12,
481,
5034,
19215,
29053,
14,
12126,
14,
436,
8417,
199,
3,
2104,
4190,
2556,
12,
8749,
1937,
4190,
14,
2424,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
646,
6950,
199,
504,
6950,
492,
485,
199,
504,
7975,
492,
20371,
199,
504,
6950,
14,
1208,
492,
286,
442,
199,
199,
16618,
6305,
275,
469,
199,
198,
16,
26,
298,
8420,
401,
199,
198,
17,
26,
298,
23736,
401,
199,
93,
199,
199,
318,
5341,
8,
4273,
29,
403,
304,
199,
198,
3406,
12,
666,
275,
990,
942,
421,
198,
589,
275,
6950,
423,
807,
342,
199,
198,
589,
905,
17452,
63,
923,
937,
275,
4766,
14,
362,
480,
17452,
63,
923,
531,
199,
198,
589,
905,
7211,
63,
602,
937,
275,
4766,
14,
362,
480,
7211,
63,
602,
531,
421,
198,
3406,
275,
664,
63,
2301,
342,
421,
198,
576,
12,
10943,
275,
664,
63,
17452,
63,
576,
8,
589,
9,
421,
198,
1107,
4362,
12,
666,
12,
488,
12,
10943,
421,
199,
318,
664,
63,
17452,
63,
576,
8,
589,
29,
403,
304,
421,
198,
3,
359,
2923,
12,
6290,
12,
16930,
12,
7971,
61,
199,
198,
9019,
63,
576,
275,
359,
16,
12,
378,
12,
378,
12,
378,
61,
421,
198,
5394,
275,
2125,
199,
198,
692,
1249,
905,
17452,
63,
923,
6229,
507,
198,
5394,
847,
298,
460,
28273,
63,
923,
275,
2818,
17452,
63,
923,
9,
83,
2,
199,
198,
692,
1249,
905,
7211,
63,
602,
6229,
507,
198,
5394,
847,
298,
460,
8732,
63,
602,
2695,
2818,
7211,
63,
602,
9,
83,
2,
421,
198,
17452,
63,
5140,
275,
6950,
14,
697,
14,
3009,
10505,
686,
198,
4859,
1585,
198,
439,
14,
354,
465,
28273,
63,
5140,
12,
1585,
198,
439,
14,
17452,
63,
354,
12,
1585,
198,
439,
14,
5500,
63,
923,
12,
1585,
198,
439,
14,
7211,
63,
602,
12,
1585,
198,
8,
2416,
2338,
21565,
687,
658,
2902,
18086,
5611,
17246,
64,
308,
458,
2382,
308,
458,
14,
1708,
29,
439,
14,
5500,
63,
923,
9,
1871,
198,
305,
6474,
63,
923,
63,
21049,
686,
198,
12491,
1585,
198,
64,
2902,
2822,
12104,
32427,
64,
2771,
686,
198,
17688,
1585,
198,
439,
14,
30461,
275,
413,
469,
5394,
93,
686,
198,
12125,
6515,
1585,
198,
439,
14,
5540,
4328,
507,
198,
891,
1370,
908,
8,
5394,
29,
5394,
395,
334,
589,
395,
465,
63,
807,
29,
17,
9,
421,
198,
17452,
63,
5140,
63,
513,
275,
359,
68,
14,
17452,
63,
5140,
367,
366,
315,
28273,
63,
5140,
61,
340,
28273,
63,
5140,
587,
24506,
199,
198,
17452,
63,
1099,
275,
664,
63,
17452,
63,
1099,
8,
17452,
63,
5140,
63,
513,
9,
421,
198,
509,
366,
315,
28273,
63,
5140,
26,
2742,
198,
17452,
63,
5140,
63,
5087,
275,
28273,
63,
1099,
14,
362,
8,
68,
14,
17452,
63,
5140,
9,
507,
198,
17452,
63,
5140,
63,
5087,
275,
6950,
423,
807,
342,
340,
440,
28273,
63,
5140,
63,
5087,
587,
971,
686,
198,
9098,
423,
807,
8,
17452,
63,
5140,
63,
5087,
9,
507,
198,
692,
298,
8420,
2,
440,
315,
28273,
63,
5140,
63,
5087,
26,
686,
198,
17452,
63,
5140,
63,
5087,
14,
873,
6333,
8420,
582,
378,
1552,
507,
198,
692,
298,
23736,
2,
440,
315,
28273,
63,
5140,
63,
5087,
26,
686,
198,
17452,
63,
5140,
63,
5087,
14,
873,
6333,
23736,
582,
378,
1552,
2742,
198,
3,
7971,
18557,
7447,
17370,
440,
19138,
507,
198,
11266,
63,
17921,
275,
286,
442,
8,
68,
14,
5500,
63,
923,
63,
21049,
9,
446,
286,
442,
8,
17452,
63,
5140,
63,
5087,
14,
8420,
9,
446,
60,
686,
198,
67,
442,
8,
17452,
63,
5140,
63,
5087,
14,
23736,
9,
507,
198,
17452,
63,
5140,
63,
5087,
14,
873,
6333,
11266,
582,
7971,
63,
17921,
1552,
507,
198,
68,
14,
873,
8,
17452,
63,
5140,
63,
5087,
9,
2742,
198,
9019,
63,
576,
59,
16,
61,
847,
286,
442,
8,
68,
14,
5500,
63,
923,
63,
21049,
9,
507,
198,
9019,
63,
576,
59,
17,
61,
847,
28273,
63,
5140,
63,
5087,
14,
8420,
507,
198,
9019,
63,
576,
59,
18,
61,
847,
28273,
63,
5140,
63,
5087,
14,
23736,
507,
198,
9019,
63,
576,
59,
19,
61,
847,
28273,
63,
5140,
63,
5087,
14,
11266,
421,
198,
9019,
275,
664,
63,
9019,
8,
9019,
63,
576,
59,
17,
5728,
421,
198,
1107,
28273,
63,
5140,
12,
10943,
421,
199,
318,
664,
63,
17452,
63,
1099,
8,
17452,
63,
5140,
63,
513,
304,
199,
198,
17452,
63,
1099,
63,
807,
275,
6950,
423,
807,
342,
421,
198,
17452,
63,
1099,
275,
6950,
14,
697,
14,
3009,
10505,
507,
198,
4859,
686,
198,
17452,
63,
5140,
12,
1382,
1205,
12,
2338,
21565,
465,
2338,
507,
198,
12491,
686,
198,
64,
2902,
2822,
12104,
10695,
64,
507,
198,
17688,
686,
198,
17452,
63,
5140,
315,
4366,
83,
9,
507,
198,
7823,
6515,
686,
198,
17452,
63,
5140,
12,
1382,
1205,
507,
198,
12125,
6515,
686,
198,
17452,
63,
5140,
199,
198,
2344,
450,
297,
1987,
904,
26861,
83,
20445,
552,
8,
17452,
63,
5140,
63,
513,
1826,
2008,
8,
17452,
63,
5140,
63,
513,
395,
465,
63,
807,
29,
17,
9,
421,
198,
509,
790,
12,
1572,
315,
20371,
8,
17452,
63,
1099,
12,
2400,
2771,
26,
2771,
905,
17452,
63,
5140,
21473,
507,
198,
2791,
275,
1052,
507,
198,
509,
366,
315,
1572,
26,
686,
198,
692,
366,
14,
30461,
315,
359,
16,
12,
17,
2189,
1585,
198,
2791,
14,
873,
2561,
16618,
6305,
59,
68,
14,
30461,
2189,
68,
14,
835,
1552,
507,
198,
17452,
63,
1099,
63,
807,
59,
498,
61,
275,
3529,
421,
198,
1107,
28273,
63,
1099,
63,
807,
421,
199,
318,
664,
63,
9019,
8,
9019,
63,
576,
304,
199,
198,
1107,
469,
507,
198,
2,
576,
582,
469,
686,
198,
2,
3512,
582,
2097,
21969,
401,
298,
2610,
4485,
401,
298,
31109,
2255,
686,
198,
2,
12281,
582,
8910,
1585,
198,
2,
1459,
582,
10943,
63,
576,
686,
198,
11049,
507,
198,
1386,
507,
198,
2,
466,
582,
283,
14200,
297,
199,
198,
93,
421,
199,
318,
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,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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
] |
Abhinav117/pymtl
|
accel/strsearch/StrSearchOO_test.py
|
7
|
16705
|
#=========================================================================
# StrSearchOO_test.py
#=========================================================================
#
# Object-Oriented implementation of strsearch.
#
# This dataset is borrowed from the stringsearch implementation provided
# the MiBench embedded system benchmark suite from Michigan:
# http://www.eecs.umich.edu/mibench
strings = ["abb", "you", "not", "it", "dad", "yoo", "hoo",
"oo", "oh", "xx", "xx", "x", "x", "field", "new", "row",
"regime", "boom", "that", "impact", "and", "zoom",
"texture", "magnet", "doom", "loom", "freq", "current",
"phase", "images", "appears", "phase", "conductor",
"wavez", "normal", "free", "termed",
"provide", "for", "and", "struct", "about", "have",
"proper", "involve", "describedly", "thats", "spaces",
"circumstance", "the", "member", "such", "guide",
"regard", "officers","implement","principalities"]
docs = ["cabbie", "your", "It isn't here",
"But it is here", "hodad", "yoohoo", "yoohoo",
"yoohoo", "yoohoo", "yoohoo", "xx", "x", ".",
"In recent years, the field of photonic ",
"crystals has found new",
"applications in the RF and microwave",
"regime. A new type of metallic",
"electromagnetic crystal has been",
"developed that is having a",
"significant impact on the field of",
"antennas. It consists of a",
"conductive surface, covered with a",
"special texture which alters its",
"electromagnetic properties. Made of solid",
"metal, the structure",
"conducts DC currents, but over a",
"particular frequency range it does",
"not conduct AC currents. It does not",
"reverse the phase of reflected",
"waves, and the effective image currents",
"appear in-phase, rather than",
"out-of-phase as they are on normal",
"conductors. Furthermore, surface",
"waves do not propagate, and instead",
"radiate efficiently into free",
"space. This new material, termed a",
"high-impedance surface, provides",
"a useful new ground plane for novel",
"low-profile antennas and other",
"electromagnetic structures.",
"The recent protests about the Michigamua",
"student organization have raised an",
"important question as to the proper nature",
"and scope of University involvement",
"with student organizations. Accordingly",
"the panel described in my Statement of",
"February 25, 2000 that is considering the",
"question of privileged space also will",
"consider under what circumstances and in",
"what ways the University, its",
"administrators and faculty members should",
"be associated with such organizations",
"and it will recommend guiding principles",
"in this regard. The University's",
"Executive Officers and I will then decide",
"whether and how to implement such",
"principles."]
reference = [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, 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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, 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]
#-------------------------------------------------------------------------
# run_test
#-------------------------------------------------------------------------
def run_test( SearchClass ):
i = 0
for string in strings:
searcher = SearchClass( string )
for doc in docs:
assert searcher.find( doc ) == reference[ i ]
i += 1
from StrSearchOO import StrSearchMath, StrSearchAlg
#-------------------------------------------------------------------------
# test_strsearch_math
#-------------------------------------------------------------------------
def test_strsearch_math():
run_test( StrSearchMath )
#-------------------------------------------------------------------------
# test_strsearch_alg
#-------------------------------------------------------------------------
def test_strsearch_alg():
run_test( StrSearchAlg )
|
bsd-3-clause
|
[
14813,
15495,
199,
3,
8303,
5278,
5757,
63,
396,
14,
647,
199,
14813,
15495,
199,
3,
199,
3,
6935,
13,
15736,
287,
471,
4514,
402,
620,
1733,
14,
199,
3,
199,
3,
961,
4789,
365,
330,
19598,
379,
687,
314,
1059,
1733,
4514,
2741,
199,
3,
314,
603,
17587,
5368,
12169,
2656,
12338,
5241,
687,
603,
1158,
528,
290,
26,
199,
3,
1455,
921,
1544,
14,
69,
23075,
14,
453,
1158,
14,
8654,
15,
77,
1892,
5368,
421,
199,
5465,
258,
275,
2097,
12198,
401,
221,
298,
13297,
401,
298,
1397,
401,
298,
390,
401,
298,
25805,
401,
298,
89,
1534,
401,
298,
19112,
401,
2049,
298,
1534,
401,
298,
19194,
401,
298,
2154,
401,
298,
2154,
401,
298,
88,
401,
298,
88,
401,
298,
698,
401,
298,
1222,
401,
298,
1143,
401,
2049,
298,
1135,
1036,
401,
298,
656,
676,
401,
298,
9099,
401,
298,
31822,
401,
298,
460,
401,
298,
10598,
401,
2049,
298,
12611,
401,
298,
19902,
386,
401,
298,
1117,
676,
401,
298,
320,
676,
401,
298,
5646,
401,
298,
1818,
401,
2049,
298,
6971,
401,
298,
4782,
401,
298,
31711,
4291,
401,
298,
6971,
401,
298,
28678,
401,
2049,
298,
10024,
90,
401,
298,
3302,
401,
298,
4624,
401,
298,
351,
3594,
401,
2049,
298,
20824,
401,
298,
509,
401,
298,
460,
401,
298,
1820,
401,
298,
10254,
401,
298,
7804,
401,
2049,
298,
28314,
401,
298,
5350,
3344,
401,
298,
271,
14922,
590,
401,
298,
273,
1956,
401,
298,
10749,
401,
2049,
298,
6092,
453,
611,
401,
298,
1589,
401,
298,
1114,
401,
298,
10180,
401,
298,
17348,
401,
2049,
298,
1135,
1005,
401,
298,
1618,
1792,
1192,
2266,
21463,
2266,
2700,
10352,
10874,
1417,
937,
199,
199,
4757,
263,
275,
2097,
67,
12198,
1873,
401,
298,
12695,
401,
298,
7940,
5712,
1133,
2348,
401,
2049,
298,
28543,
652,
365,
2348,
401,
298,
72,
364,
350,
401,
298,
89,
1534,
19112,
401,
298,
89,
1534,
19112,
401,
2049,
298,
89,
1534,
19112,
401,
298,
89,
1534,
19112,
401,
298,
89,
1534,
19112,
401,
298,
2154,
401,
298,
88,
401,
3680,
401,
2049,
298,
607,
8058,
17399,
12,
314,
901,
402,
3945,
18692,
3872,
2049,
298,
3019,
270,
2551,
965,
1911,
892,
401,
2049,
298,
15853,
315,
314,
820,
38,
436,
9967,
10024,
401,
2049,
298,
1135,
1036,
14,
437,
892,
730,
402,
7647,
279,
606,
401,
2049,
298,
26334,
293,
5615,
685,
764,
286,
651,
32100,
965,
2757,
401,
2049,
298,
271,
27813,
626,
365,
9445,
282,
401,
2049,
298,
1037,
14266,
25568,
641,
314,
901,
402,
401,
2049,
298,
290,
724,
24292,
14,
2779,
18581,
402,
282,
401,
2049,
298,
2067,
947,
857,
13195,
12,
24295,
543,
282,
401,
2049,
298,
6664,
14855,
1314,
741,
878,
2399,
401,
2049,
298,
26334,
293,
5615,
685,
764,
4382,
14,
603,
9587,
402,
18609,
401,
2049,
298,
22420,
12,
314,
5523,
401,
2049,
298,
388,
1601,
83,
30592,
1453,
83,
12,
1325,
1806,
282,
401,
2049,
298,
462,
6628,
9857,
1425,
652,
1630,
401,
2049,
298,
1397,
406,
1601,
6570,
1453,
83,
14,
2779,
1630,
440,
401,
2049,
298,
4471,
314,
7669,
402,
31948,
401,
2049,
298,
758,
2310,
12,
436,
314,
15826,
1834,
1453,
83,
401,
2049,
298,
27307,
315,
13,
6971,
12,
7830,
2419,
401,
2049,
298,
548,
13,
1618,
13,
6971,
465,
2985,
787,
641,
3293,
401,
2049,
298,
388,
2033,
13451,
14,
28876,
6878,
12,
13195,
401,
2049,
298,
758,
2310,
886,
440,
19843,
12,
436,
3140,
401,
2049,
298,
12841,
323,
30427,
1901,
2867,
401,
2049,
298,
2638,
14,
961,
892,
6285,
12,
2044,
3594,
282,
401,
2049,
298,
6260,
13,
3236,
379,
554,
13195,
12,
6571,
401,
2049,
298,
65,
2997,
892,
19252,
16388,
367,
949,
1090,
401,
2049,
298,
674,
13,
2913,
376,
724,
24292,
436,
1163,
401,
2049,
298,
26334,
293,
5615,
685,
764,
13955,
4765,
2049,
298,
1918,
8058,
557,
2219,
3595,
314,
603,
1158,
528,
455,
1458,
401,
2049,
298,
5500,
13237,
1172,
4915,
376,
401,
2049,
298,
19559,
7894,
465,
370,
314,
5576,
302,
1463,
401,
2049,
298,
460,
4194,
402,
15904,
4572,
3344,
434,
401,
2049,
298,
1045,
6474,
20765,
12270,
14,
31970,
590,
401,
2049,
298,
1589,
12748,
11736,
315,
3002,
29697,
402,
401,
2049,
298,
27717,
26709,
5661,
12,
12293,
626,
365,
11201,
316,
314,
401,
2049,
298,
4790,
402,
1979,
21744,
4601,
2597,
911,
401,
2049,
298,
388,
16994,
1334,
4052,
27027,
611,
83,
436,
315,
401,
2049,
298,
10058,
15217,
314,
15904,
12,
2399,
401,
2049,
298,
2113,
3075,
2750,
436,
21625,
17323,
7556,
1077,
401,
2049,
298,
1235,
4568,
543,
4066,
20765,
12270,
401,
2049,
298,
460,
652,
911,
27747,
15593,
316,
5448,
10352,
2978,
401,
2049,
298,
262,
642,
8794,
14,
710,
15904,
1159,
401,
2049,
298,
4858,
13441,
593,
8376,
1192,
436,
473,
911,
2066,
19822,
401,
2049,
298,
87,
3081,
436,
4212,
370,
5669,
4066,
401,
2049,
298,
2700,
10352,
2978,
14,
937,
199,
199,
4443,
257,
275,
359,
17,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
2049,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
2049,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
2049,
378,
12,
413,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
2049,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
2049,
378,
12,
378,
12,
378,
12
] |
[
15495,
199,
3,
8303,
5278,
5757,
63,
396,
14,
647,
199,
14813,
15495,
199,
3,
199,
3,
6935,
13,
15736,
287,
471,
4514,
402,
620,
1733,
14,
199,
3,
199,
3,
961,
4789,
365,
330,
19598,
379,
687,
314,
1059,
1733,
4514,
2741,
199,
3,
314,
603,
17587,
5368,
12169,
2656,
12338,
5241,
687,
603,
1158,
528,
290,
26,
199,
3,
1455,
921,
1544,
14,
69,
23075,
14,
453,
1158,
14,
8654,
15,
77,
1892,
5368,
421,
199,
5465,
258,
275,
2097,
12198,
401,
221,
298,
13297,
401,
298,
1397,
401,
298,
390,
401,
298,
25805,
401,
298,
89,
1534,
401,
298,
19112,
401,
2049,
298,
1534,
401,
298,
19194,
401,
298,
2154,
401,
298,
2154,
401,
298,
88,
401,
298,
88,
401,
298,
698,
401,
298,
1222,
401,
298,
1143,
401,
2049,
298,
1135,
1036,
401,
298,
656,
676,
401,
298,
9099,
401,
298,
31822,
401,
298,
460,
401,
298,
10598,
401,
2049,
298,
12611,
401,
298,
19902,
386,
401,
298,
1117,
676,
401,
298,
320,
676,
401,
298,
5646,
401,
298,
1818,
401,
2049,
298,
6971,
401,
298,
4782,
401,
298,
31711,
4291,
401,
298,
6971,
401,
298,
28678,
401,
2049,
298,
10024,
90,
401,
298,
3302,
401,
298,
4624,
401,
298,
351,
3594,
401,
2049,
298,
20824,
401,
298,
509,
401,
298,
460,
401,
298,
1820,
401,
298,
10254,
401,
298,
7804,
401,
2049,
298,
28314,
401,
298,
5350,
3344,
401,
298,
271,
14922,
590,
401,
298,
273,
1956,
401,
298,
10749,
401,
2049,
298,
6092,
453,
611,
401,
298,
1589,
401,
298,
1114,
401,
298,
10180,
401,
298,
17348,
401,
2049,
298,
1135,
1005,
401,
298,
1618,
1792,
1192,
2266,
21463,
2266,
2700,
10352,
10874,
1417,
937,
199,
199,
4757,
263,
275,
2097,
67,
12198,
1873,
401,
298,
12695,
401,
298,
7940,
5712,
1133,
2348,
401,
2049,
298,
28543,
652,
365,
2348,
401,
298,
72,
364,
350,
401,
298,
89,
1534,
19112,
401,
298,
89,
1534,
19112,
401,
2049,
298,
89,
1534,
19112,
401,
298,
89,
1534,
19112,
401,
298,
89,
1534,
19112,
401,
298,
2154,
401,
298,
88,
401,
3680,
401,
2049,
298,
607,
8058,
17399,
12,
314,
901,
402,
3945,
18692,
3872,
2049,
298,
3019,
270,
2551,
965,
1911,
892,
401,
2049,
298,
15853,
315,
314,
820,
38,
436,
9967,
10024,
401,
2049,
298,
1135,
1036,
14,
437,
892,
730,
402,
7647,
279,
606,
401,
2049,
298,
26334,
293,
5615,
685,
764,
286,
651,
32100,
965,
2757,
401,
2049,
298,
271,
27813,
626,
365,
9445,
282,
401,
2049,
298,
1037,
14266,
25568,
641,
314,
901,
402,
401,
2049,
298,
290,
724,
24292,
14,
2779,
18581,
402,
282,
401,
2049,
298,
2067,
947,
857,
13195,
12,
24295,
543,
282,
401,
2049,
298,
6664,
14855,
1314,
741,
878,
2399,
401,
2049,
298,
26334,
293,
5615,
685,
764,
4382,
14,
603,
9587,
402,
18609,
401,
2049,
298,
22420,
12,
314,
5523,
401,
2049,
298,
388,
1601,
83,
30592,
1453,
83,
12,
1325,
1806,
282,
401,
2049,
298,
462,
6628,
9857,
1425,
652,
1630,
401,
2049,
298,
1397,
406,
1601,
6570,
1453,
83,
14,
2779,
1630,
440,
401,
2049,
298,
4471,
314,
7669,
402,
31948,
401,
2049,
298,
758,
2310,
12,
436,
314,
15826,
1834,
1453,
83,
401,
2049,
298,
27307,
315,
13,
6971,
12,
7830,
2419,
401,
2049,
298,
548,
13,
1618,
13,
6971,
465,
2985,
787,
641,
3293,
401,
2049,
298,
388,
2033,
13451,
14,
28876,
6878,
12,
13195,
401,
2049,
298,
758,
2310,
886,
440,
19843,
12,
436,
3140,
401,
2049,
298,
12841,
323,
30427,
1901,
2867,
401,
2049,
298,
2638,
14,
961,
892,
6285,
12,
2044,
3594,
282,
401,
2049,
298,
6260,
13,
3236,
379,
554,
13195,
12,
6571,
401,
2049,
298,
65,
2997,
892,
19252,
16388,
367,
949,
1090,
401,
2049,
298,
674,
13,
2913,
376,
724,
24292,
436,
1163,
401,
2049,
298,
26334,
293,
5615,
685,
764,
13955,
4765,
2049,
298,
1918,
8058,
557,
2219,
3595,
314,
603,
1158,
528,
455,
1458,
401,
2049,
298,
5500,
13237,
1172,
4915,
376,
401,
2049,
298,
19559,
7894,
465,
370,
314,
5576,
302,
1463,
401,
2049,
298,
460,
4194,
402,
15904,
4572,
3344,
434,
401,
2049,
298,
1045,
6474,
20765,
12270,
14,
31970,
590,
401,
2049,
298,
1589,
12748,
11736,
315,
3002,
29697,
402,
401,
2049,
298,
27717,
26709,
5661,
12,
12293,
626,
365,
11201,
316,
314,
401,
2049,
298,
4790,
402,
1979,
21744,
4601,
2597,
911,
401,
2049,
298,
388,
16994,
1334,
4052,
27027,
611,
83,
436,
315,
401,
2049,
298,
10058,
15217,
314,
15904,
12,
2399,
401,
2049,
298,
2113,
3075,
2750,
436,
21625,
17323,
7556,
1077,
401,
2049,
298,
1235,
4568,
543,
4066,
20765,
12270,
401,
2049,
298,
460,
652,
911,
27747,
15593,
316,
5448,
10352,
2978,
401,
2049,
298,
262,
642,
8794,
14,
710,
15904,
1159,
401,
2049,
298,
4858,
13441,
593,
8376,
1192,
436,
473,
911,
2066,
19822,
401,
2049,
298,
87,
3081,
436,
4212,
370,
5669,
4066,
401,
2049,
298,
2700,
10352,
2978,
14,
937,
199,
199,
4443,
257,
275,
359,
17,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
2049,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
2049,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
2049,
378,
12,
413,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
2049,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
378,
12,
2049,
378,
12,
378,
12,
378,
12,
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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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
thjashin/tensorflow
|
tensorflow/tools/test/run_and_gather_logs.py
|
137
|
4918
|
# 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.
# ==============================================================================
"""Test runner for TensorFlow tests."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import argparse
import os
import shlex
from string import maketrans
import sys
import time
from google.protobuf import json_format
from google.protobuf import text_format
from tensorflow.core.util import test_log_pb2
from tensorflow.python.platform import app
from tensorflow.python.platform import gfile
from tensorflow.python.platform import test
from tensorflow.python.platform import tf_logging
from tensorflow.tools.test import run_and_gather_logs_lib
# pylint: disable=g-import-not-at-top
# pylint: disable=g-bad-import-order
# pylint: disable=unused-import
# Note: cpuinfo and psutil are not installed for you in the TensorFlow
# OSS tree. They are installable via pip.
try:
import cpuinfo
import psutil
except ImportError as e:
tf_logging.error("\n\n\nERROR: Unable to import necessary library: {}. "
"Issuing a soft exit.\n\n\n".format(e))
sys.exit(0)
# pylint: enable=g-bad-import-order
# pylint: enable=unused-import
FLAGS = None
def gather_build_configuration():
build_config = test_log_pb2.BuildConfiguration()
build_config.mode = FLAGS.compilation_mode
# Include all flags except includes
cc_flags = [
flag for flag in shlex.split(FLAGS.cc_flags) if not flag.startswith("-i")
]
build_config.cc_flags.extend(cc_flags)
return build_config
def main(unused_args):
name = FLAGS.name
test_name = FLAGS.test_name
test_args = FLAGS.test_args
benchmark_type = FLAGS.benchmark_type
test_results, _ = run_and_gather_logs_lib.run_and_gather_logs(
name, test_name=test_name, test_args=test_args,
benchmark_type=benchmark_type)
# Additional bits we receive from bazel
test_results.build_configuration.CopyFrom(gather_build_configuration())
if not FLAGS.test_log_output_dir:
print(text_format.MessageToString(test_results))
return
if FLAGS.test_log_output_filename:
file_name = FLAGS.test_log_output_filename
else:
file_name = (name.strip("/").translate(maketrans("/:", "__")) +
time.strftime("%Y%m%d%H%M%S", time.gmtime()))
if FLAGS.test_log_output_use_tmpdir:
tmpdir = test.get_temp_dir()
output_path = os.path.join(tmpdir, FLAGS.test_log_output_dir, file_name)
else:
output_path = os.path.join(
os.path.abspath(FLAGS.test_log_output_dir), file_name)
json_test_results = json_format.MessageToJson(test_results)
gfile.GFile(output_path + ".json", "w").write(json_test_results)
tf_logging.info("Test results written to: %s" % output_path)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.register(
"type", "bool", lambda v: v.lower() in ("true", "t", "y", "yes"))
parser.add_argument(
"--name", type=str, default="", help="Benchmark target identifier.")
parser.add_argument(
"--test_name", type=str, default="", help="Test target to run.")
parser.add_argument(
"--benchmark_type",
type=str,
default="",
help="BenchmarkType enum string (benchmark type).")
parser.add_argument(
"--test_args",
type=str,
default="",
help="Test arguments, space separated.")
parser.add_argument(
"--test_log_output_use_tmpdir",
type="bool",
nargs="?",
const=True,
default=False,
help="Store the log output into tmpdir?")
parser.add_argument(
"--compilation_mode",
type=str,
default="",
help="Mode used during this build (e.g. opt, dbg).")
parser.add_argument(
"--cc_flags",
type=str,
default="",
help="CC flags used during this build.")
parser.add_argument(
"--test_log_output_dir",
type=str,
default="",
help="Directory to write benchmark results to.")
parser.add_argument(
"--test_log_output_filename",
type=str,
default="",
help="Filename to output benchmark results to. If the filename is not "
"specified, it will be automatically created based on --name "
"and current time.")
FLAGS, unparsed = parser.parse_known_args()
app.run(main=main, argv=[sys.argv[0]] + unparsed)
|
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,
774,
7876,
367,
9134,
2295,
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,
7534,
199,
646,
747,
199,
646,
16701,
199,
504,
1059,
492,
5475,
31552,
199,
646,
984,
199,
646,
900,
199,
199,
504,
6233,
14,
7204,
492,
2022,
63,
908,
199,
504,
6233,
14,
7204,
492,
1318,
63,
908,
199,
199,
504,
3228,
14,
1018,
14,
1974,
492,
511,
63,
793,
63,
3317,
18,
199,
504,
3228,
14,
1548,
14,
3246,
492,
1145,
199,
504,
3228,
14,
1548,
14,
3246,
492,
26532,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
199,
504,
3228,
14,
1548,
14,
3246,
492,
2833,
63,
4806,
199,
504,
3228,
14,
2537,
14,
396,
492,
1255,
63,
460,
63,
13737,
63,
7270,
63,
773,
199,
199,
3,
4287,
26,
3507,
29,
71,
13,
646,
13,
1397,
13,
292,
13,
2119,
199,
3,
4287,
26,
3507,
29,
71,
13,
4087,
13,
646,
13,
1648,
199,
3,
4287,
26,
3507,
29,
8618,
13,
646,
199,
3,
3390,
26,
5033,
815,
436,
22214,
787,
440,
4903,
367,
1265,
315,
314,
9134,
199,
3,
593,
2300,
3123,
14,
221,
9322,
787,
3907,
461,
4799,
7305,
14,
199,
893,
26,
523,
492,
5033,
815,
523,
492,
22214,
199,
2590,
3545,
465,
325,
26,
523,
2833,
63,
4806,
14,
705,
4582,
78,
60,
78,
60,
78,
3170,
26,
30849,
370,
492,
5784,
3555,
26,
30332,
221,
298,
673,
298,
41,
385,
23221,
282,
11620,
4458,
3134,
78,
60,
78,
60,
78,
1674,
908,
8,
69,
430,
523,
984,
14,
2224,
8,
16,
9,
199,
3,
4287,
26,
4756,
29,
71,
13,
4087,
13,
646,
13,
1648,
199,
3,
4287,
26,
4756,
29,
8618,
13,
646,
199,
199,
4831,
275,
488,
421,
199,
318,
13082,
63,
1506,
63,
4758,
837,
523,
1900,
63,
888,
275,
511,
63,
793,
63,
3317,
18,
14,
3425,
5688,
342,
523,
1900,
63,
888,
14,
632,
275,
12846,
14,
863,
13696,
63,
632,
523,
327,
15783,
1006,
3285,
871,
6952,
523,
7429,
63,
2469,
275,
359,
489,
3305,
367,
3305,
315,
16701,
14,
1294,
8,
4831,
14,
2055,
63,
2469,
9,
340,
440,
3305,
14,
2460,
6096,
73,
531,
523,
1622,
523,
1900,
63,
888,
14,
2055,
63,
2469,
14,
2880,
8,
2055,
63,
2469,
9,
523,
372,
1900,
63,
888,
421,
199,
318,
2446,
8,
8618,
63,
589,
304,
523,
536,
275,
12846,
14,
354,
523,
511,
63,
354,
275,
12846,
14,
396,
63,
354,
523,
511,
63,
589,
275,
12846,
14,
396,
63,
589,
523,
12338,
63,
466,
275,
12846,
14,
11861,
63,
466,
523,
511,
63,
2604,
12,
485,
275,
1255,
63,
460,
63,
13737,
63,
7270,
63,
773,
14,
1065,
63,
460,
63,
13737,
63,
7270,
8,
489,
536,
12,
511,
63,
354,
29,
396,
63,
354,
12,
511,
63,
589,
29,
396,
63,
589,
12,
489,
12338,
63,
466,
29,
11861,
63,
466,
9,
819,
327,
10961,
5821,
781,
9128,
687,
15507,
352,
523,
511,
63,
2604,
14,
1506,
63,
4758,
14,
22853,
8,
13737,
63,
1506,
63,
4758,
1012,
819,
340,
440,
12846,
14,
396,
63,
793,
63,
1199,
63,
694,
26,
272,
870,
8,
505,
63,
908,
14,
2209,
7756,
8,
396,
63,
2604,
430,
272,
372,
819,
340,
12846,
14,
396,
63,
793,
63,
1199,
63,
1501,
26,
272,
570,
63,
354,
275,
12846,
14,
396,
63,
793,
63,
1199,
63,
1501,
523,
587,
26,
272,
570,
63,
354,
275,
334,
354,
14,
1913,
4769,
3471,
5275,
8,
22191,
31552,
4769,
6783,
4396,
2237,
435,
326,
900,
14,
6205,
3647,
57,
5,
77,
5,
68,
5,
40,
5,
45,
5,
51,
401,
900,
14,
22227,
4059,
523,
340,
12846,
14,
396,
63,
793,
63,
1199,
63,
1180,
63,
8616,
26,
272,
12885,
275,
511,
14,
362,
63,
808,
63,
694,
342,
272,
1072,
63,
515,
275,
747,
14,
515,
14,
904,
8,
8616,
12,
12846,
14,
396,
63,
793,
63,
1199,
63,
694,
12,
570,
63,
354,
9,
523,
587,
26,
272,
1072,
63,
515,
275,
747,
14,
515,
14,
904,
8,
267,
747,
14,
515,
14,
4832,
8,
4831,
14,
396,
63,
793,
63,
1199,
63,
694,
395,
570,
63,
354,
9,
523,
2022,
63,
396,
63,
2604,
275,
2022,
63,
908,
14,
2209,
1378,
9653,
8,
396,
63,
2604,
9,
523,
26532,
14,
39,
1173,
8,
1199,
63,
515,
435,
3680,
1001,
401,
298,
87,
3471,
952,
8,
1001,
63,
396,
63,
2604,
9,
523,
2833,
63,
4806,
14,
815,
480,
774,
2058,
5313,
370,
26,
450,
83,
2,
450,
1072,
63,
515,
9,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
523,
1798,
275,
7534,
14,
10730,
342,
523,
1798,
14,
2683,
8,
489,
298,
466,
401,
298,
2245,
401,
2400,
373,
26,
373,
14,
2325,
342,
315,
1689,
2052,
401,
298,
84,
401,
298,
89,
401,
298,
5066,
2237,
523,
1798,
14,
525,
63,
2094,
8,
489,
4320,
354,
401,
730,
29,
495,
12,
849,
8772,
1720,
628,
18644,
1347,
5148,
2685,
523,
1798,
14,
525,
63,
2094,
8,
489,
4320,
396,
63,
354,
401,
730,
29,
495,
12,
849,
8772,
1720,
628,
774,
1347,
370,
1255,
2685,
523,
1798,
14,
525,
63,
2094,
8,
489
] |
[
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,
774,
7876,
367,
9134,
2295,
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,
7534,
199,
646,
747,
199,
646,
16701,
199,
504,
1059,
492,
5475,
31552,
199,
646,
984,
199,
646,
900,
199,
199,
504,
6233,
14,
7204,
492,
2022,
63,
908,
199,
504,
6233,
14,
7204,
492,
1318,
63,
908,
199,
199,
504,
3228,
14,
1018,
14,
1974,
492,
511,
63,
793,
63,
3317,
18,
199,
504,
3228,
14,
1548,
14,
3246,
492,
1145,
199,
504,
3228,
14,
1548,
14,
3246,
492,
26532,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
199,
504,
3228,
14,
1548,
14,
3246,
492,
2833,
63,
4806,
199,
504,
3228,
14,
2537,
14,
396,
492,
1255,
63,
460,
63,
13737,
63,
7270,
63,
773,
199,
199,
3,
4287,
26,
3507,
29,
71,
13,
646,
13,
1397,
13,
292,
13,
2119,
199,
3,
4287,
26,
3507,
29,
71,
13,
4087,
13,
646,
13,
1648,
199,
3,
4287,
26,
3507,
29,
8618,
13,
646,
199,
3,
3390,
26,
5033,
815,
436,
22214,
787,
440,
4903,
367,
1265,
315,
314,
9134,
199,
3,
593,
2300,
3123,
14,
221,
9322,
787,
3907,
461,
4799,
7305,
14,
199,
893,
26,
523,
492,
5033,
815,
523,
492,
22214,
199,
2590,
3545,
465,
325,
26,
523,
2833,
63,
4806,
14,
705,
4582,
78,
60,
78,
60,
78,
3170,
26,
30849,
370,
492,
5784,
3555,
26,
30332,
221,
298,
673,
298,
41,
385,
23221,
282,
11620,
4458,
3134,
78,
60,
78,
60,
78,
1674,
908,
8,
69,
430,
523,
984,
14,
2224,
8,
16,
9,
199,
3,
4287,
26,
4756,
29,
71,
13,
4087,
13,
646,
13,
1648,
199,
3,
4287,
26,
4756,
29,
8618,
13,
646,
199,
199,
4831,
275,
488,
421,
199,
318,
13082,
63,
1506,
63,
4758,
837,
523,
1900,
63,
888,
275,
511,
63,
793,
63,
3317,
18,
14,
3425,
5688,
342,
523,
1900,
63,
888,
14,
632,
275,
12846,
14,
863,
13696,
63,
632,
523,
327,
15783,
1006,
3285,
871,
6952,
523,
7429,
63,
2469,
275,
359,
489,
3305,
367,
3305,
315,
16701,
14,
1294,
8,
4831,
14,
2055,
63,
2469,
9,
340,
440,
3305,
14,
2460,
6096,
73,
531,
523,
1622,
523,
1900,
63,
888,
14,
2055,
63,
2469,
14,
2880,
8,
2055,
63,
2469,
9,
523,
372,
1900,
63,
888,
421,
199,
318,
2446,
8,
8618,
63,
589,
304,
523,
536,
275,
12846,
14,
354,
523,
511,
63,
354,
275,
12846,
14,
396,
63,
354,
523,
511,
63,
589,
275,
12846,
14,
396,
63,
589,
523,
12338,
63,
466,
275,
12846,
14,
11861,
63,
466,
523,
511,
63,
2604,
12,
485,
275,
1255,
63,
460,
63,
13737,
63,
7270,
63,
773,
14,
1065,
63,
460,
63,
13737,
63,
7270,
8,
489,
536,
12,
511,
63,
354,
29,
396,
63,
354,
12,
511,
63,
589,
29,
396,
63,
589,
12,
489,
12338,
63,
466,
29,
11861,
63,
466,
9,
819,
327,
10961,
5821,
781,
9128,
687,
15507,
352,
523,
511,
63,
2604,
14,
1506,
63,
4758,
14,
22853,
8,
13737,
63,
1506,
63,
4758,
1012,
819,
340,
440,
12846,
14,
396,
63,
793,
63,
1199,
63,
694,
26,
272,
870,
8,
505,
63,
908,
14,
2209,
7756,
8,
396,
63,
2604,
430,
272,
372,
819,
340,
12846,
14,
396,
63,
793,
63,
1199,
63,
1501,
26,
272,
570,
63,
354,
275,
12846,
14,
396,
63,
793,
63,
1199,
63,
1501,
523,
587,
26,
272,
570,
63,
354,
275,
334,
354,
14,
1913,
4769,
3471,
5275,
8,
22191,
31552,
4769,
6783,
4396,
2237,
435,
326,
900,
14,
6205,
3647,
57,
5,
77,
5,
68,
5,
40,
5,
45,
5,
51,
401,
900,
14,
22227,
4059,
523,
340,
12846,
14,
396,
63,
793,
63,
1199,
63,
1180,
63,
8616,
26,
272,
12885,
275,
511,
14,
362,
63,
808,
63,
694,
342,
272,
1072,
63,
515,
275,
747,
14,
515,
14,
904,
8,
8616,
12,
12846,
14,
396,
63,
793,
63,
1199,
63,
694,
12,
570,
63,
354,
9,
523,
587,
26,
272,
1072,
63,
515,
275,
747,
14,
515,
14,
904,
8,
267,
747,
14,
515,
14,
4832,
8,
4831,
14,
396,
63,
793,
63,
1199,
63,
694,
395,
570,
63,
354,
9,
523,
2022,
63,
396,
63,
2604,
275,
2022,
63,
908,
14,
2209,
1378,
9653,
8,
396,
63,
2604,
9,
523,
26532,
14,
39,
1173,
8,
1199,
63,
515,
435,
3680,
1001,
401,
298,
87,
3471,
952,
8,
1001,
63,
396,
63,
2604,
9,
523,
2833,
63,
4806,
14,
815,
480,
774,
2058,
5313,
370,
26,
450,
83,
2,
450,
1072,
63,
515,
9,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
523,
1798,
275,
7534,
14,
10730,
342,
523,
1798,
14,
2683,
8,
489,
298,
466,
401,
298,
2245,
401,
2400,
373,
26,
373,
14,
2325,
342,
315,
1689,
2052,
401,
298,
84,
401,
298,
89,
401,
298,
5066,
2237,
523,
1798,
14,
525,
63,
2094,
8,
489,
4320,
354,
401,
730,
29,
495,
12,
849,
8772,
1720,
628,
18644,
1347,
5148,
2685,
523,
1798,
14,
525,
63,
2094,
8,
489,
4320,
396,
63,
354,
401,
730,
29,
495,
12,
849,
8772,
1720,
628,
774,
1347,
370,
1255,
2685,
523,
1798,
14,
525,
63,
2094,
8,
489,
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,
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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
] |
mcanthony/rethinkdb
|
packaging/osx/biplist/__init__.py
|
37
|
31532
|
"""biplist -- a library for reading and writing binary property list files.
Binary Property List (plist) files provide a faster and smaller serialization
format for property lists on OS X. This is a library for generating binary
plists which can be read by OS X, iOS, or other clients.
The API models the plistlib API, and will call through to plistlib when
XML serialization or deserialization is required.
To generate plists with UID values, wrap the values with the Uid object. The
value must be an int.
To generate plists with NSData/CFData values, wrap the values with the
Data object. The value must be a string.
Date values can only be datetime.datetime objects.
The exceptions InvalidPlistException and NotBinaryPlistException may be
thrown to indicate that the data cannot be serialized or deserialized as
a binary plist.
Plist generation example:
from biplist import *
from datetime import datetime
plist = {'aKey':'aValue',
'0':1.322,
'now':datetime.now(),
'list':[1,2,3],
'tuple':('a','b','c')
}
try:
writePlist(plist, "example.plist")
except (InvalidPlistException, NotBinaryPlistException), e:
print "Something bad happened:", e
Plist parsing example:
from biplist import *
try:
plist = readPlist("example.plist")
print plist
except (InvalidPlistException, NotBinaryPlistException), e:
print "Not a plist:", e
"""
import sys
from collections import namedtuple
import datetime
import io
import math
import plistlib
from struct import pack, unpack
from struct import error as struct_error
import sys
import time
try:
unicode
unicodeEmpty = r''
except NameError:
unicode = str
unicodeEmpty = ''
try:
long
except NameError:
long = int
try:
{}.iteritems
iteritems = lambda x: x.iteritems()
except AttributeError:
iteritems = lambda x: x.items()
__all__ = [
'Uid', 'Data', 'readPlist', 'writePlist', 'readPlistFromString',
'writePlistToString', 'InvalidPlistException', 'NotBinaryPlistException'
]
# Apple uses Jan 1, 2001 as a base for all plist date/times.
apple_reference_date = datetime.datetime.utcfromtimestamp(978307200)
class Uid(int):
"""Wrapper around integers for representing UID values. This
is used in keyed archiving."""
def __repr__(self):
return "Uid(%d)" % self
class Data(bytes):
"""Wrapper around bytes to distinguish Data values."""
class InvalidPlistException(Exception):
"""Raised when the plist is incorrectly formatted."""
class NotBinaryPlistException(Exception):
"""Raised when a binary plist was expected but not encountered."""
def readPlist(pathOrFile):
"""Raises NotBinaryPlistException, InvalidPlistException"""
didOpen = False
result = None
if isinstance(pathOrFile, (bytes, unicode)):
pathOrFile = open(pathOrFile, 'rb')
didOpen = True
try:
reader = PlistReader(pathOrFile)
result = reader.parse()
except NotBinaryPlistException as e:
try:
pathOrFile.seek(0)
result = None
if hasattr(plistlib, 'loads'):
contents = None
if isinstance(pathOrFile, (bytes, unicode)):
with open(pathOrFile, 'rb') as f:
contents = f.read()
else:
contents = pathOrFile.read()
result = plistlib.loads(contents)
else:
result = plistlib.readPlist(pathOrFile)
result = wrapDataObject(result, for_binary=True)
except Exception as e:
raise InvalidPlistException(e)
finally:
if didOpen:
pathOrFile.close()
return result
def wrapDataObject(o, for_binary=False):
if isinstance(o, Data) and not for_binary:
v = sys.version_info
if not (v[0] >= 3 and v[1] >= 4):
o = plistlib.Data(o)
elif isinstance(o, (bytes, plistlib.Data)) and for_binary:
if hasattr(o, 'data'):
o = Data(o.data)
elif isinstance(o, tuple):
o = wrapDataObject(list(o), for_binary)
o = tuple(o)
elif isinstance(o, list):
for i in range(len(o)):
o[i] = wrapDataObject(o[i], for_binary)
elif isinstance(o, dict):
for k in o:
o[k] = wrapDataObject(o[k], for_binary)
return o
def writePlist(rootObject, pathOrFile, binary=True):
if not binary:
rootObject = wrapDataObject(rootObject, binary)
if hasattr(plistlib, "dump"):
if isinstance(pathOrFile, (bytes, unicode)):
with open(pathOrFile, 'wb') as f:
return plistlib.dump(rootObject, f)
else:
return plistlib.dump(rootObject, pathOrFile)
else:
return plistlib.writePlist(rootObject, pathOrFile)
else:
didOpen = False
if isinstance(pathOrFile, (bytes, unicode)):
pathOrFile = open(pathOrFile, 'wb')
didOpen = True
writer = PlistWriter(pathOrFile)
result = writer.writeRoot(rootObject)
if didOpen:
pathOrFile.close()
return result
def readPlistFromString(data):
return readPlist(io.BytesIO(data))
def writePlistToString(rootObject, binary=True):
if not binary:
rootObject = wrapDataObject(rootObject, binary)
if hasattr(plistlib, "dumps"):
return plistlib.dumps(rootObject)
elif hasattr(plistlib, "writePlistToBytes"):
return plistlib.writePlistToBytes(rootObject)
else:
return plistlib.writePlistToString(rootObject)
else:
ioObject = io.BytesIO()
writer = PlistWriter(ioObject)
writer.writeRoot(rootObject)
return ioObject.getvalue()
def is_stream_binary_plist(stream):
stream.seek(0)
header = stream.read(7)
if header == b'bplist0':
return True
else:
return False
PlistTrailer = namedtuple('PlistTrailer', 'offsetSize, objectRefSize, offsetCount, topLevelObjectNumber, offsetTableOffset')
PlistByteCounts = namedtuple('PlistByteCounts', 'nullBytes, boolBytes, intBytes, realBytes, dateBytes, dataBytes, stringBytes, uidBytes, arrayBytes, setBytes, dictBytes')
class PlistReader(object):
file = None
contents = ''
offsets = None
trailer = None
currentOffset = 0
def __init__(self, fileOrStream):
"""Raises NotBinaryPlistException."""
self.reset()
self.file = fileOrStream
def parse(self):
return self.readRoot()
def reset(self):
self.trailer = None
self.contents = ''
self.offsets = []
self.currentOffset = 0
def readRoot(self):
result = None
self.reset()
# Get the header, make sure it's a valid file.
if not is_stream_binary_plist(self.file):
raise NotBinaryPlistException()
self.file.seek(0)
self.contents = self.file.read()
if len(self.contents) < 32:
raise InvalidPlistException("File is too short.")
trailerContents = self.contents[-32:]
try:
self.trailer = PlistTrailer._make(unpack("!xxxxxxBBQQQ", trailerContents))
offset_size = self.trailer.offsetSize * self.trailer.offsetCount
offset = self.trailer.offsetTableOffset
offset_contents = self.contents[offset:offset+offset_size]
offset_i = 0
while offset_i < self.trailer.offsetCount:
begin = self.trailer.offsetSize*offset_i
tmp_contents = offset_contents[begin:begin+self.trailer.offsetSize]
tmp_sized = self.getSizedInteger(tmp_contents, self.trailer.offsetSize)
self.offsets.append(tmp_sized)
offset_i += 1
self.setCurrentOffsetToObjectNumber(self.trailer.topLevelObjectNumber)
result = self.readObject()
except TypeError as e:
raise InvalidPlistException(e)
return result
def setCurrentOffsetToObjectNumber(self, objectNumber):
self.currentOffset = self.offsets[objectNumber]
def readObject(self):
result = None
tmp_byte = self.contents[self.currentOffset:self.currentOffset+1]
marker_byte = unpack("!B", tmp_byte)[0]
format = (marker_byte >> 4) & 0x0f
extra = marker_byte & 0x0f
self.currentOffset += 1
def proc_extra(extra):
if extra == 0b1111:
#self.currentOffset += 1
extra = self.readObject()
return extra
# bool, null, or fill byte
if format == 0b0000:
if extra == 0b0000:
result = None
elif extra == 0b1000:
result = False
elif extra == 0b1001:
result = True
elif extra == 0b1111:
pass # fill byte
else:
raise InvalidPlistException("Invalid object found at offset: %d" % (self.currentOffset - 1))
# int
elif format == 0b0001:
extra = proc_extra(extra)
result = self.readInteger(pow(2, extra))
# real
elif format == 0b0010:
extra = proc_extra(extra)
result = self.readReal(extra)
# date
elif format == 0b0011 and extra == 0b0011:
result = self.readDate()
# data
elif format == 0b0100:
extra = proc_extra(extra)
result = self.readData(extra)
# ascii string
elif format == 0b0101:
extra = proc_extra(extra)
result = self.readAsciiString(extra)
# Unicode string
elif format == 0b0110:
extra = proc_extra(extra)
result = self.readUnicode(extra)
# uid
elif format == 0b1000:
result = self.readUid(extra)
# array
elif format == 0b1010:
extra = proc_extra(extra)
result = self.readArray(extra)
# set
elif format == 0b1100:
extra = proc_extra(extra)
result = set(self.readArray(extra))
# dict
elif format == 0b1101:
extra = proc_extra(extra)
result = self.readDict(extra)
else:
raise InvalidPlistException("Invalid object found: {format: %s, extra: %s}" % (bin(format), bin(extra)))
return result
def readInteger(self, byteSize):
result = 0
original_offset = self.currentOffset
data = self.contents[self.currentOffset:self.currentOffset + byteSize]
result = self.getSizedInteger(data, byteSize, as_number=True)
self.currentOffset = original_offset + byteSize
return result
def readReal(self, length):
result = 0.0
to_read = pow(2, length)
data = self.contents[self.currentOffset:self.currentOffset+to_read]
if length == 2: # 4 bytes
result = unpack('>f', data)[0]
elif length == 3: # 8 bytes
result = unpack('>d', data)[0]
else:
raise InvalidPlistException("Unknown real of length %d bytes" % to_read)
return result
def readRefs(self, count):
refs = []
i = 0
while i < count:
fragment = self.contents[self.currentOffset:self.currentOffset+self.trailer.objectRefSize]
ref = self.getSizedInteger(fragment, len(fragment))
refs.append(ref)
self.currentOffset += self.trailer.objectRefSize
i += 1
return refs
def readArray(self, count):
result = []
values = self.readRefs(count)
i = 0
while i < len(values):
self.setCurrentOffsetToObjectNumber(values[i])
value = self.readObject()
result.append(value)
i += 1
return result
def readDict(self, count):
result = {}
keys = self.readRefs(count)
values = self.readRefs(count)
i = 0
while i < len(keys):
self.setCurrentOffsetToObjectNumber(keys[i])
key = self.readObject()
self.setCurrentOffsetToObjectNumber(values[i])
value = self.readObject()
result[key] = value
i += 1
return result
def readAsciiString(self, length):
result = unpack("!%ds" % length, self.contents[self.currentOffset:self.currentOffset+length])[0]
self.currentOffset += length
return result
def readUnicode(self, length):
actual_length = length*2
data = self.contents[self.currentOffset:self.currentOffset+actual_length]
# unpack not needed?!! data = unpack(">%ds" % (actual_length), data)[0]
self.currentOffset += actual_length
return data.decode('utf_16_be')
def readDate(self):
result = unpack(">d", self.contents[self.currentOffset:self.currentOffset+8])[0]
# Use timedelta to workaround time_t size limitation on 32-bit python.
result = datetime.timedelta(seconds=result) + apple_reference_date
self.currentOffset += 8
return result
def readData(self, length):
result = self.contents[self.currentOffset:self.currentOffset+length]
self.currentOffset += length
return Data(result)
def readUid(self, length):
return Uid(self.readInteger(length+1))
def getSizedInteger(self, data, byteSize, as_number=False):
"""Numbers of 8 bytes are signed integers when they refer to numbers, but unsigned otherwise."""
result = 0
# 1, 2, and 4 byte integers are unsigned
if byteSize == 1:
result = unpack('>B', data)[0]
elif byteSize == 2:
result = unpack('>H', data)[0]
elif byteSize == 4:
result = unpack('>L', data)[0]
elif byteSize == 8:
if as_number:
result = unpack('>q', data)[0]
else:
result = unpack('>Q', data)[0]
elif byteSize <= 16:
# Handle odd-sized or integers larger than 8 bytes
# Don't naively go over 16 bytes, in order to prevent infinite loops.
result = 0
if hasattr(int, 'from_bytes'):
result = int.from_bytes(data, 'big')
else:
for byte in data:
result = (result << 8) | unpack('>B', byte)[0]
else:
raise InvalidPlistException("Encountered integer longer than 16 bytes.")
return result
class HashableWrapper(object):
def __init__(self, value):
self.value = value
def __repr__(self):
return "<HashableWrapper: %s>" % [self.value]
class BoolWrapper(object):
def __init__(self, value):
self.value = value
def __repr__(self):
return "<BoolWrapper: %s>" % self.value
class FloatWrapper(object):
_instances = {}
def __new__(klass, value):
# Ensure FloatWrapper(x) for a given float x is always the same object
wrapper = klass._instances.get(value)
if wrapper is None:
wrapper = object.__new__(klass)
wrapper.value = value
klass._instances[value] = wrapper
return wrapper
def __repr__(self):
return "<FloatWrapper: %s>" % self.value
class StringWrapper(object):
__instances = {}
encodedValue = None
encoding = None
def __new__(cls, value):
'''Ensure we only have a only one instance for any string,
and that we encode ascii as 1-byte-per character when possible'''
encodedValue = None
for encoding in ('ascii', 'utf_16_be'):
try:
encodedValue = value.encode(encoding)
except: pass
if encodedValue is not None:
if encodedValue not in cls.__instances:
cls.__instances[encodedValue] = super(StringWrapper, cls).__new__(cls)
cls.__instances[encodedValue].encodedValue = encodedValue
cls.__instances[encodedValue].encoding = encoding
return cls.__instances[encodedValue]
raise ValueError('Unable to get ascii or utf_16_be encoding for %s' % repr(value))
def __len__(self):
'''Return roughly the number of characters in this string (half the byte length)'''
if self.encoding == 'ascii':
return len(self.encodedValue)
else:
return len(self.encodedValue)//2
@property
def encodingMarker(self):
if self.encoding == 'ascii':
return 0b0101
else:
return 0b0110
def __repr__(self):
return '<StringWrapper (%s): %s>' % (self.encoding, self.encodedValue)
class PlistWriter(object):
header = b'bplist00bybiplist1.0'
file = None
byteCounts = None
trailer = None
computedUniques = None
writtenReferences = None
referencePositions = None
wrappedTrue = None
wrappedFalse = None
def __init__(self, file):
self.reset()
self.file = file
self.wrappedTrue = BoolWrapper(True)
self.wrappedFalse = BoolWrapper(False)
def reset(self):
self.byteCounts = PlistByteCounts(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
self.trailer = PlistTrailer(0, 0, 0, 0, 0)
# A set of all the uniques which have been computed.
self.computedUniques = set()
# A list of all the uniques which have been written.
self.writtenReferences = {}
# A dict of the positions of the written uniques.
self.referencePositions = {}
def positionOfObjectReference(self, obj):
"""If the given object has been written already, return its
position in the offset table. Otherwise, return None."""
return self.writtenReferences.get(obj)
def writeRoot(self, root):
"""
Strategy is:
- write header
- wrap root object so everything is hashable
- compute size of objects which will be written
- need to do this in order to know how large the object refs
will be in the list/dict/set reference lists
- write objects
- keep objects in writtenReferences
- keep positions of object references in referencePositions
- write object references with the length computed previously
- computer object reference length
- write object reference positions
- write trailer
"""
output = self.header
wrapped_root = self.wrapRoot(root)
should_reference_root = True#not isinstance(wrapped_root, HashableWrapper)
self.computeOffsets(wrapped_root, asReference=should_reference_root, isRoot=True)
self.trailer = self.trailer._replace(**{'objectRefSize':self.intSize(len(self.computedUniques))})
self.writeObjectReference(wrapped_root, output)
output = self.writeObject(wrapped_root, output, setReferencePosition=True)
# output size at this point is an upper bound on how big the
# object reference offsets need to be.
self.trailer = self.trailer._replace(**{
'offsetSize':self.intSize(len(output)),
'offsetCount':len(self.computedUniques),
'offsetTableOffset':len(output),
'topLevelObjectNumber':0
})
output = self.writeOffsetTable(output)
output += pack('!xxxxxxBBQQQ', *self.trailer)
self.file.write(output)
def wrapRoot(self, root):
if isinstance(root, bool):
if root is True:
return self.wrappedTrue
else:
return self.wrappedFalse
elif isinstance(root, float):
return FloatWrapper(root)
elif isinstance(root, set):
n = set()
for value in root:
n.add(self.wrapRoot(value))
return HashableWrapper(n)
elif isinstance(root, dict):
n = {}
for key, value in iteritems(root):
n[self.wrapRoot(key)] = self.wrapRoot(value)
return HashableWrapper(n)
elif isinstance(root, list):
n = []
for value in root:
n.append(self.wrapRoot(value))
return HashableWrapper(n)
elif isinstance(root, tuple):
n = tuple([self.wrapRoot(value) for value in root])
return HashableWrapper(n)
elif isinstance(root, (str, unicode)) and not isinstance(root, Data):
return StringWrapper(root)
else:
return root
def incrementByteCount(self, field, incr=1):
self.byteCounts = self.byteCounts._replace(**{field:self.byteCounts.__getattribute__(field) + incr})
def computeOffsets(self, obj, asReference=False, isRoot=False):
def check_key(key):
if key is None:
raise InvalidPlistException('Dictionary keys cannot be null in plists.')
elif isinstance(key, Data):
raise InvalidPlistException('Data cannot be dictionary keys in plists.')
elif not isinstance(key, StringWrapper):
raise InvalidPlistException('Keys must be strings.')
def proc_size(size):
if size > 0b1110:
size += self.intSize(size)
return size
# If this should be a reference, then we keep a record of it in the
# uniques table.
if asReference:
if obj in self.computedUniques:
return
else:
self.computedUniques.add(obj)
if obj is None:
self.incrementByteCount('nullBytes')
elif isinstance(obj, BoolWrapper):
self.incrementByteCount('boolBytes')
elif isinstance(obj, Uid):
size = self.intSize(obj)
self.incrementByteCount('uidBytes', incr=1+size)
elif isinstance(obj, (int, long)):
size = self.intSize(obj)
self.incrementByteCount('intBytes', incr=1+size)
elif isinstance(obj, FloatWrapper):
size = self.realSize(obj)
self.incrementByteCount('realBytes', incr=1+size)
elif isinstance(obj, datetime.datetime):
self.incrementByteCount('dateBytes', incr=2)
elif isinstance(obj, Data):
size = proc_size(len(obj))
self.incrementByteCount('dataBytes', incr=1+size)
elif isinstance(obj, StringWrapper):
size = proc_size(len(obj))
self.incrementByteCount('stringBytes', incr=1+size)
elif isinstance(obj, HashableWrapper):
obj = obj.value
if isinstance(obj, set):
size = proc_size(len(obj))
self.incrementByteCount('setBytes', incr=1+size)
for value in obj:
self.computeOffsets(value, asReference=True)
elif isinstance(obj, (list, tuple)):
size = proc_size(len(obj))
self.incrementByteCount('arrayBytes', incr=1+size)
for value in obj:
asRef = True
self.computeOffsets(value, asReference=True)
elif isinstance(obj, dict):
size = proc_size(len(obj))
self.incrementByteCount('dictBytes', incr=1+size)
for key, value in iteritems(obj):
check_key(key)
self.computeOffsets(key, asReference=True)
self.computeOffsets(value, asReference=True)
else:
raise InvalidPlistException("Unknown object type.")
def writeObjectReference(self, obj, output):
"""Tries to write an object reference, adding it to the references
table. Does not write the actual object bytes or set the reference
position. Returns a tuple of whether the object was a new reference
(True if it was, False if it already was in the reference table)
and the new output.
"""
position = self.positionOfObjectReference(obj)
if position is None:
self.writtenReferences[obj] = len(self.writtenReferences)
output += self.binaryInt(len(self.writtenReferences) - 1, byteSize=self.trailer.objectRefSize)
return (True, output)
else:
output += self.binaryInt(position, byteSize=self.trailer.objectRefSize)
return (False, output)
def writeObject(self, obj, output, setReferencePosition=False):
"""Serializes the given object to the output. Returns output.
If setReferencePosition is True, will set the position the
object was written.
"""
def proc_variable_length(format, length):
result = b''
if length > 0b1110:
result += pack('!B', (format << 4) | 0b1111)
result = self.writeObject(length, result)
else:
result += pack('!B', (format << 4) | length)
return result
if isinstance(obj, (str, unicode)) and obj == unicodeEmpty:
# The Apple Plist decoder can't decode a zero length Unicode string.
obj = b''
if setReferencePosition:
self.referencePositions[obj] = len(output)
if obj is None:
output += pack('!B', 0b00000000)
elif isinstance(obj, BoolWrapper):
if obj.value is False:
output += pack('!B', 0b00001000)
else:
output += pack('!B', 0b00001001)
elif isinstance(obj, Uid):
size = self.intSize(obj)
output += pack('!B', (0b1000 << 4) | size - 1)
output += self.binaryInt(obj)
elif isinstance(obj, (int, long)):
byteSize = self.intSize(obj)
root = math.log(byteSize, 2)
output += pack('!B', (0b0001 << 4) | int(root))
output += self.binaryInt(obj, as_number=True)
elif isinstance(obj, FloatWrapper):
# just use doubles
output += pack('!B', (0b0010 << 4) | 3)
output += self.binaryReal(obj)
elif isinstance(obj, datetime.datetime):
timestamp = (obj - apple_reference_date).total_seconds()
output += pack('!B', 0b00110011)
output += pack('!d', float(timestamp))
elif isinstance(obj, Data):
output += proc_variable_length(0b0100, len(obj))
output += obj
elif isinstance(obj, StringWrapper):
output += proc_variable_length(obj.encodingMarker, len(obj))
output += obj.encodedValue
elif isinstance(obj, bytes):
output += proc_variable_length(0b0101, len(obj))
output += obj
elif isinstance(obj, HashableWrapper):
obj = obj.value
if isinstance(obj, (set, list, tuple)):
if isinstance(obj, set):
output += proc_variable_length(0b1100, len(obj))
else:
output += proc_variable_length(0b1010, len(obj))
objectsToWrite = []
for objRef in obj:
(isNew, output) = self.writeObjectReference(objRef, output)
if isNew:
objectsToWrite.append(objRef)
for objRef in objectsToWrite:
output = self.writeObject(objRef, output, setReferencePosition=True)
elif isinstance(obj, dict):
output += proc_variable_length(0b1101, len(obj))
keys = []
values = []
objectsToWrite = []
for key, value in iteritems(obj):
keys.append(key)
values.append(value)
for key in keys:
(isNew, output) = self.writeObjectReference(key, output)
if isNew:
objectsToWrite.append(key)
for value in values:
(isNew, output) = self.writeObjectReference(value, output)
if isNew:
objectsToWrite.append(value)
for objRef in objectsToWrite:
output = self.writeObject(objRef, output, setReferencePosition=True)
return output
def writeOffsetTable(self, output):
"""Writes all of the object reference offsets."""
all_positions = []
writtenReferences = list(self.writtenReferences.items())
writtenReferences.sort(key=lambda x: x[1])
for obj,order in writtenReferences:
# Porting note: Elsewhere we deliberately replace empty unicdoe strings
# with empty binary strings, but the empty unicode string
# goes into writtenReferences. This isn't an issue in Py2
# because u'' and b'' have the same hash; but it is in
# Py3, where they don't.
if bytes != str and obj == unicodeEmpty:
obj = b''
position = self.referencePositions.get(obj)
if position is None:
raise InvalidPlistException("Error while writing offsets table. Object not found. %s" % obj)
output += self.binaryInt(position, self.trailer.offsetSize)
all_positions.append(position)
return output
def binaryReal(self, obj):
# just use doubles
result = pack('>d', obj.value)
return result
def binaryInt(self, obj, byteSize=None, as_number=False):
result = b''
if byteSize is None:
byteSize = self.intSize(obj)
if byteSize == 1:
result += pack('>B', obj)
elif byteSize == 2:
result += pack('>H', obj)
elif byteSize == 4:
result += pack('>L', obj)
elif byteSize == 8:
if as_number:
result += pack('>q', obj)
else:
result += pack('>Q', obj)
elif byteSize <= 16:
try:
result = pack('>Q', 0) + pack('>Q', obj)
except struct_error as e:
raise InvalidPlistException("Unable to pack integer %d: %s" % (obj, e))
else:
raise InvalidPlistException("Core Foundation can't handle integers with size greater than 16 bytes.")
return result
def intSize(self, obj):
"""Returns the number of bytes necessary to store the given integer."""
# SIGNED
if obj < 0: # Signed integer, always 8 bytes
return 8
# UNSIGNED
elif obj <= 0xFF: # 1 byte
return 1
elif obj <= 0xFFFF: # 2 bytes
return 2
elif obj <= 0xFFFFFFFF: # 4 bytes
return 4
# SIGNED
# 0x7FFFFFFFFFFFFFFF is the max.
elif obj <= 0x7FFFFFFFFFFFFFFF: # 8 bytes signed
return 8
elif obj <= 0xffffffffffffffff: # 8 bytes unsigned
return 16
else:
raise InvalidPlistException("Core Foundation can't handle integers with size greater than 8 bytes.")
def realSize(self, obj):
return 8
|
agpl-3.0
|
[
624,
27566,
513,
1553,
282,
3555,
367,
7664,
436,
3575,
3366,
3324,
769,
1584,
14,
199,
199,
6636,
16158,
3820,
334,
10265,
9,
1584,
5647,
282,
12930,
436,
12700,
16953,
199,
908,
367,
3324,
5548,
641,
4403,
1323,
14,
961,
365,
282,
3555,
367,
12999,
3366,
199,
80,
6717,
1314,
883,
506,
1586,
701,
4403,
1323,
12,
284,
3100,
12,
503,
1163,
13431,
14,
199,
199,
1918,
3261,
1709,
314,
14459,
773,
3261,
12,
436,
911,
1240,
4012,
370,
14459,
773,
1380,
199,
4317,
16953,
503,
477,
12161,
365,
1415,
14,
199,
199,
1378,
3550,
299,
6717,
543,
20746,
1338,
12,
4816,
314,
1338,
543,
314,
738,
344,
909,
14,
710,
199,
585,
1471,
506,
376,
1109,
14,
199,
199,
1378,
3550,
299,
6717,
543,
9380,
1451,
15,
5487,
1451,
1338,
12,
4816,
314,
1338,
543,
314,
199,
1451,
909,
14,
710,
574,
1471,
506,
282,
1059,
14,
199,
199,
2506,
1338,
883,
1454,
506,
2197,
14,
2083,
2251,
14,
199,
199,
1918,
4967,
6378,
21073,
1726,
436,
2832,
6636,
21073,
1726,
1443,
506,
221,
199,
11964,
78,
370,
6623,
626,
314,
666,
3913,
506,
6380,
503,
13256,
465,
199,
65,
3366,
14459,
14,
199,
199,
21073,
10152,
2893,
26,
2286,
687,
330,
711,
513,
492,
627,
272,
687,
2197,
492,
2197,
272,
14459,
275,
791,
65,
1197,
5242,
65,
1110,
297,
1467,
283,
16,
356,
17,
14,
15858,
12,
1467,
283,
2131,
356,
2083,
14,
2131,
1062,
1467,
283,
513,
15211,
17,
12,
18,
12,
19,
467,
1467,
283,
2960,
17150,
65,
1673,
66,
1673,
67,
358,
1467,
789,
272,
862,
26,
267,
2218,
21073,
8,
10265,
12,
298,
2694,
14,
10265,
531,
272,
871,
334,
3364,
21073,
1726,
12,
2832,
6636,
21073,
1726,
395,
325,
26,
267,
870,
298,
20641,
4875,
21056,
6783,
325,
199,
199,
21073,
6057,
2893,
26,
339,
687,
330,
711,
513,
492,
627,
272,
862,
26,
267,
14459,
275,
1586,
21073,
480,
2694,
14,
10265,
531,
267,
870,
14459,
272,
871,
334,
3364,
21073,
1726,
12,
2832,
6636,
21073,
1726,
395,
325,
26,
267,
870,
298,
1763,
282,
14459,
6783,
325,
199,
624,
199,
199,
646,
984,
199,
504,
5055,
492,
12863,
199,
646,
2197,
199,
646,
5890,
199,
646,
3473,
199,
646,
14459,
773,
199,
504,
2702,
492,
1706,
12,
7787,
199,
504,
2702,
492,
1125,
465,
2702,
63,
705,
199,
646,
984,
199,
646,
900,
199,
199,
893,
26,
272,
2649,
272,
2649,
4699,
275,
519,
891,
199,
2590,
12746,
26,
272,
2649,
275,
620,
272,
2649,
4699,
275,
2125,
199,
893,
26,
272,
1846,
199,
2590,
12746,
26,
272,
1846,
275,
1109,
199,
893,
26,
272,
30332,
4611,
272,
10849,
275,
2400,
671,
26,
671,
14,
4611,
342,
199,
2590,
4281,
26,
272,
10849,
275,
2400,
671,
26,
671,
14,
1744,
342,
199,
199,
363,
452,
363,
275,
359,
272,
283,
18326,
297,
283,
1451,
297,
283,
739,
21073,
297,
283,
952,
21073,
297,
283,
739,
21073,
7671,
297,
272,
283,
952,
21073,
7756,
297,
283,
3364,
21073,
1726,
297,
283,
1763,
6636,
21073,
1726,
7,
199,
61,
199,
199,
3,
21257,
4440,
17474,
413,
12,
12521,
465,
282,
1300,
367,
1006,
14459,
1434,
15,
4508,
14,
199,
12820,
63,
4443,
63,
602,
275,
2197,
14,
2083,
14,
5834,
18531,
8,
28690,
11516,
1840,
9,
199,
199,
533,
738,
344,
8,
442,
304,
272,
408,
4590,
6818,
9446,
367,
6144,
20746,
1338,
14,
961,
2126,
365,
1202,
315,
19272,
3819,
12616,
1041,
272,
347,
636,
2722,
721,
277,
304,
267,
372,
298,
18326,
4042,
68,
2924,
450,
291,
199,
199,
533,
3918,
8,
2394,
304,
272,
408,
4590,
6818,
2783,
370,
22237,
3918,
1338,
1041,
199,
199,
533,
6378,
21073,
1726,
8,
1726,
304,
272,
408,
16894,
1380,
314,
14459,
365,
22743,
7871,
1041,
199,
199,
533,
2832,
6636,
21073,
1726,
8,
1726,
304,
272,
408,
16894,
1380,
282,
3366,
14459,
1990,
1420,
1325,
440,
14556,
1041,
199,
199,
318,
1586,
21073,
8,
515,
2844,
1173,
304,
272,
408,
1811,
2832,
6636,
21073,
1726,
12,
6378,
21073,
1726,
624,
272,
8103,
4299,
275,
756,
272,
754,
275,
488,
272,
340,
1228,
8,
515,
2844,
1173,
12,
334,
2394,
12,
2649,
2298,
267,
931,
2844,
1173,
275,
1551,
8,
515,
2844,
1173,
12,
283,
4848,
358,
267,
8103,
4299,
275,
715,
272,
862,
26,
267,
7002,
275,
510,
513,
5929,
8,
515,
2844,
1173,
9,
267,
754,
275,
7002,
14,
1122,
342,
272,
871,
2832,
6636,
21073,
1726,
465,
325,
26,
267,
862,
26,
288,
931,
2844,
1173,
14,
5507,
8,
16,
9,
288,
754,
275,
488,
288,
340,
2688,
8,
10265,
773,
12,
283,
3640,
735,
355,
4072,
275,
488,
355,
340,
1228,
8,
515,
2844,
1173,
12,
334,
2394,
12,
2649,
2298,
490,
543,
1551,
8,
515,
2844,
1173,
12,
283,
4848,
358,
465,
289,
26,
717,
4072,
275,
289,
14,
739,
342,
355,
587,
26,
490,
4072,
275,
931,
2844,
1173,
14,
739,
342,
355,
754,
275,
14459,
773,
14,
3640,
8,
4407,
9,
288,
587,
26,
355,
754,
275,
14459,
773,
14,
739,
21073,
8,
515,
2844,
1173,
9,
288,
754,
275,
4816,
1451,
1692,
8,
1099,
12,
367,
63,
3008,
29,
549,
9,
267,
871,
2186,
465,
325,
26,
288,
746,
6378,
21073,
1726,
8,
69,
9,
272,
3753,
26,
267,
340,
8103,
4299,
26,
288,
931,
2844,
1173,
14,
1600,
342,
272,
372,
754,
199,
199,
318,
4816,
1451,
1692,
8,
79,
12,
367,
63,
3008,
29,
797,
304,
272,
340,
1228,
8,
79,
12,
3918,
9,
436,
440,
367,
63,
3008,
26,
267,
373,
275,
984,
14,
1023,
63,
815,
267,
340,
440,
334,
86,
59,
16,
61,
2356,
650,
436,
373,
59,
17,
61,
2356,
841,
304,
288,
312,
275,
14459,
773,
14,
1451,
8,
79,
9,
272,
916,
1228,
8,
79,
12,
334,
2394,
12,
14459,
773,
14,
1451,
430,
436,
367,
63,
3008,
26,
267,
340,
2688,
8,
79,
12,
283,
576,
735,
288,
312,
275,
3918,
8,
79,
14,
576,
9,
272,
916,
1228,
8,
79,
12,
2008,
304,
267,
312,
275,
4816,
1451,
1692,
8,
513,
8,
79,
395,
367,
63,
3008,
9,
267,
312,
275,
2008,
8,
79,
9,
272,
916,
1228,
8
] |
[
27566,
513,
1553,
282,
3555,
367,
7664,
436,
3575,
3366,
3324,
769,
1584,
14,
199,
199,
6636,
16158,
3820,
334,
10265,
9,
1584,
5647,
282,
12930,
436,
12700,
16953,
199,
908,
367,
3324,
5548,
641,
4403,
1323,
14,
961,
365,
282,
3555,
367,
12999,
3366,
199,
80,
6717,
1314,
883,
506,
1586,
701,
4403,
1323,
12,
284,
3100,
12,
503,
1163,
13431,
14,
199,
199,
1918,
3261,
1709,
314,
14459,
773,
3261,
12,
436,
911,
1240,
4012,
370,
14459,
773,
1380,
199,
4317,
16953,
503,
477,
12161,
365,
1415,
14,
199,
199,
1378,
3550,
299,
6717,
543,
20746,
1338,
12,
4816,
314,
1338,
543,
314,
738,
344,
909,
14,
710,
199,
585,
1471,
506,
376,
1109,
14,
199,
199,
1378,
3550,
299,
6717,
543,
9380,
1451,
15,
5487,
1451,
1338,
12,
4816,
314,
1338,
543,
314,
199,
1451,
909,
14,
710,
574,
1471,
506,
282,
1059,
14,
199,
199,
2506,
1338,
883,
1454,
506,
2197,
14,
2083,
2251,
14,
199,
199,
1918,
4967,
6378,
21073,
1726,
436,
2832,
6636,
21073,
1726,
1443,
506,
221,
199,
11964,
78,
370,
6623,
626,
314,
666,
3913,
506,
6380,
503,
13256,
465,
199,
65,
3366,
14459,
14,
199,
199,
21073,
10152,
2893,
26,
2286,
687,
330,
711,
513,
492,
627,
272,
687,
2197,
492,
2197,
272,
14459,
275,
791,
65,
1197,
5242,
65,
1110,
297,
1467,
283,
16,
356,
17,
14,
15858,
12,
1467,
283,
2131,
356,
2083,
14,
2131,
1062,
1467,
283,
513,
15211,
17,
12,
18,
12,
19,
467,
1467,
283,
2960,
17150,
65,
1673,
66,
1673,
67,
358,
1467,
789,
272,
862,
26,
267,
2218,
21073,
8,
10265,
12,
298,
2694,
14,
10265,
531,
272,
871,
334,
3364,
21073,
1726,
12,
2832,
6636,
21073,
1726,
395,
325,
26,
267,
870,
298,
20641,
4875,
21056,
6783,
325,
199,
199,
21073,
6057,
2893,
26,
339,
687,
330,
711,
513,
492,
627,
272,
862,
26,
267,
14459,
275,
1586,
21073,
480,
2694,
14,
10265,
531,
267,
870,
14459,
272,
871,
334,
3364,
21073,
1726,
12,
2832,
6636,
21073,
1726,
395,
325,
26,
267,
870,
298,
1763,
282,
14459,
6783,
325,
199,
624,
199,
199,
646,
984,
199,
504,
5055,
492,
12863,
199,
646,
2197,
199,
646,
5890,
199,
646,
3473,
199,
646,
14459,
773,
199,
504,
2702,
492,
1706,
12,
7787,
199,
504,
2702,
492,
1125,
465,
2702,
63,
705,
199,
646,
984,
199,
646,
900,
199,
199,
893,
26,
272,
2649,
272,
2649,
4699,
275,
519,
891,
199,
2590,
12746,
26,
272,
2649,
275,
620,
272,
2649,
4699,
275,
2125,
199,
893,
26,
272,
1846,
199,
2590,
12746,
26,
272,
1846,
275,
1109,
199,
893,
26,
272,
30332,
4611,
272,
10849,
275,
2400,
671,
26,
671,
14,
4611,
342,
199,
2590,
4281,
26,
272,
10849,
275,
2400,
671,
26,
671,
14,
1744,
342,
199,
199,
363,
452,
363,
275,
359,
272,
283,
18326,
297,
283,
1451,
297,
283,
739,
21073,
297,
283,
952,
21073,
297,
283,
739,
21073,
7671,
297,
272,
283,
952,
21073,
7756,
297,
283,
3364,
21073,
1726,
297,
283,
1763,
6636,
21073,
1726,
7,
199,
61,
199,
199,
3,
21257,
4440,
17474,
413,
12,
12521,
465,
282,
1300,
367,
1006,
14459,
1434,
15,
4508,
14,
199,
12820,
63,
4443,
63,
602,
275,
2197,
14,
2083,
14,
5834,
18531,
8,
28690,
11516,
1840,
9,
199,
199,
533,
738,
344,
8,
442,
304,
272,
408,
4590,
6818,
9446,
367,
6144,
20746,
1338,
14,
961,
2126,
365,
1202,
315,
19272,
3819,
12616,
1041,
272,
347,
636,
2722,
721,
277,
304,
267,
372,
298,
18326,
4042,
68,
2924,
450,
291,
199,
199,
533,
3918,
8,
2394,
304,
272,
408,
4590,
6818,
2783,
370,
22237,
3918,
1338,
1041,
199,
199,
533,
6378,
21073,
1726,
8,
1726,
304,
272,
408,
16894,
1380,
314,
14459,
365,
22743,
7871,
1041,
199,
199,
533,
2832,
6636,
21073,
1726,
8,
1726,
304,
272,
408,
16894,
1380,
282,
3366,
14459,
1990,
1420,
1325,
440,
14556,
1041,
199,
199,
318,
1586,
21073,
8,
515,
2844,
1173,
304,
272,
408,
1811,
2832,
6636,
21073,
1726,
12,
6378,
21073,
1726,
624,
272,
8103,
4299,
275,
756,
272,
754,
275,
488,
272,
340,
1228,
8,
515,
2844,
1173,
12,
334,
2394,
12,
2649,
2298,
267,
931,
2844,
1173,
275,
1551,
8,
515,
2844,
1173,
12,
283,
4848,
358,
267,
8103,
4299,
275,
715,
272,
862,
26,
267,
7002,
275,
510,
513,
5929,
8,
515,
2844,
1173,
9,
267,
754,
275,
7002,
14,
1122,
342,
272,
871,
2832,
6636,
21073,
1726,
465,
325,
26,
267,
862,
26,
288,
931,
2844,
1173,
14,
5507,
8,
16,
9,
288,
754,
275,
488,
288,
340,
2688,
8,
10265,
773,
12,
283,
3640,
735,
355,
4072,
275,
488,
355,
340,
1228,
8,
515,
2844,
1173,
12,
334,
2394,
12,
2649,
2298,
490,
543,
1551,
8,
515,
2844,
1173,
12,
283,
4848,
358,
465,
289,
26,
717,
4072,
275,
289,
14,
739,
342,
355,
587,
26,
490,
4072,
275,
931,
2844,
1173,
14,
739,
342,
355,
754,
275,
14459,
773,
14,
3640,
8,
4407,
9,
288,
587,
26,
355,
754,
275,
14459,
773,
14,
739,
21073,
8,
515,
2844,
1173,
9,
288,
754,
275,
4816,
1451,
1692,
8,
1099,
12,
367,
63,
3008,
29,
549,
9,
267,
871,
2186,
465,
325,
26,
288,
746,
6378,
21073,
1726,
8,
69,
9,
272,
3753,
26,
267,
340,
8103,
4299,
26,
288,
931,
2844,
1173,
14,
1600,
342,
272,
372,
754,
199,
199,
318,
4816,
1451,
1692,
8,
79,
12,
367,
63,
3008,
29,
797,
304,
272,
340,
1228,
8,
79,
12,
3918,
9,
436,
440,
367,
63,
3008,
26,
267,
373,
275,
984,
14,
1023,
63,
815,
267,
340,
440,
334,
86,
59,
16,
61,
2356,
650,
436,
373,
59,
17,
61,
2356,
841,
304,
288,
312,
275,
14459,
773,
14,
1451,
8,
79,
9,
272,
916,
1228,
8,
79,
12,
334,
2394,
12,
14459,
773,
14,
1451,
430,
436,
367,
63,
3008,
26,
267,
340,
2688,
8,
79,
12,
283,
576,
735,
288,
312,
275,
3918,
8,
79,
14,
576,
9,
272,
916,
1228,
8,
79,
12,
2008,
304,
267,
312,
275,
4816,
1451,
1692,
8,
513,
8,
79,
395,
367,
63,
3008,
9,
267,
312,
275,
2008,
8,
79,
9,
272,
916,
1228,
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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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
] |
mit-ll/LO-PHI
|
lophi-automation/lophi_automation/configs/controllerconfig.py
|
1
|
5240
|
"""
Class for handling configuration files for controller nodes
(c) 2015 Massachusetts Institute of Technology
"""
# Native
import socket
import logging
logger = logging.getLogger(__name__)
from time import sleep
# LO-PHI
import lophi.globals as G
# LO-PHI Automation
import lophi_automation.protobuf.helper as ProtoBuf
from lophi_automation.configs import LophiConfig
from lophi_automation.network.command import LophiCommand
SOCKET_RETRY = 5
class ControllerConfig(LophiConfig):
"""
Very simple class to hand around and leave room for improvement in the
future
"""
def __init__(self, name, Config):
"""
Initialize all of our variables and set any new settings that were
specified in the config file.
"""
# Some storage
self.SOCK = None
self.lophi_configs = None
self.machines = None
# Set our name
self.name = name
# Set our host
if not self._get_option(Config, name, "host"):
logger.error("No host ip provided for %s."%name)
# Set our port
if not self._get_option(Config, name, "port"):
logger.error("No host port provided for %s."%name)
# Make it easier when opening sockets
self.address = (self.host, int(self.port))
def __str__(self):
""" Print out information of this controller """
o = "[%s] IP: %s, Port: %s"%(self.name,self.host,self.port)
return o
def get_machines(self):
""" Get protocol buffer version of remote machines """
while 1:
try:
logger.debug("Getting machine list for Controller/%s" % self.name)
# Get response
cmd = LophiCommand(G.CTRL_CMD_PICKLE, args=["machines"])
data = self.send_cmd(cmd)
status = G.read_socket_data(self.SOCK)
# Unpack our machine list
# (WARNING: This a subset of the objects at the server
if data is not None:
self.machines = ProtoBuf.unpack_machine_list(data)
else:
self.machines = []
return status
except:
G.print_traceback()
self.connect()
def get_analysis(self):
""" Get protocol buffer version of remote analysis """
while 1:
try:
logger.debug("Getting analysis list for Controller/%s" % self.name)
# Get reply
cmd = LophiCommand(G.CTRL_CMD_PICKLE, args=["analysis"])
analysis_buf = self.send_cmd(cmd)
status = G.read_socket_data(self.SOCK)
# unpack protocol buffer
self.analysis = ProtoBuf.unpack_analysis_list(analysis_buf)
return status
except:
self.connect()
def connect(self):
"""
Connect to our controller, retrieve all of the relevant information
and add it to our list.
"""
while 1:
# Try forever to connect
try:
print G.bcolors.WARNING + "Connecting to %s(%s:%s)..." % (self.name, self.host, self.port) + G.bcolors.ENDC,
# Open our socket
self.SOCK = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.SOCK.connect(self.address)
print G.bcolors.OKGREEN + "Connected." + G.bcolors.ENDC
break
except socket.error:
print G.bcolors.FAIL \
+ "Retrying in %d seconds..." % (SOCKET_RETRY) \
+ G.bcolors.ENDC
sleep(SOCKET_RETRY)
continue
def disconnect(self):
"""
Stop all analysis at controllers and close our socket nicely
"""
# Close socket
self.SOCK.close()
def send_analysis(self, filename, cmd):
""" Sends start message and our JSON config """
while 1:
try:
# Send our command to start the analysis
G.send_socket_data(self.SOCK, str(cmd))
# read our analysis file
f = open(filename)
script = f.read()
f.close()
# Send the json config
G.send_socket_data(self.SOCK, script)
status = G.read_socket_data(self.SOCK)
return status
except:
self.connect()
def send_cmd(self, command):
""" Send arbitrary message """
while 1:
try:
# Send our command to start the analysis
G.send_socket_data(self.SOCK, str(command))
# Get our return status
self.status = G.read_socket_data(self.SOCK)
if self.status is None:
raise Exception("Controller Disconnected.")
return self.status
except:
self.connect()
|
bsd-3-clause
|
[
624,
272,
8089,
367,
7252,
2897,
1584,
367,
7614,
3380,
339,
334,
67,
9,
6900,
603,
405,
1225,
29589,
1086,
1010,
25585,
402,
21580,
199,
624,
199,
3,
653,
1905,
199,
646,
2838,
199,
646,
2050,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
504,
900,
492,
9435,
421,
199,
3,
3412,
13,
9791,
41,
199,
646,
560,
10909,
14,
8473,
465,
598,
199,
3,
3412,
13,
9791,
41,
9195,
1615,
199,
646,
560,
10909,
63,
23867,
14,
7204,
14,
3676,
465,
2165,
475,
11312,
199,
504,
560,
10909,
63,
23867,
14,
7532,
492,
491,
411,
5812,
2028,
199,
504,
560,
10909,
63,
23867,
14,
1200,
14,
1531,
492,
491,
411,
5812,
3110,
199,
199,
17462,
63,
27778,
275,
959,
199,
199,
533,
16282,
2028,
8,
44,
411,
5812,
2028,
304,
272,
408,
267,
812,
994,
3486,
1021,
370,
4926,
6818,
436,
10137,
14726,
367,
19053,
434,
315,
314,
4960,
6466,
272,
408,
339,
347,
636,
826,
721,
277,
12,
536,
12,
4094,
304,
267,
408,
288,
11578,
1006,
402,
4154,
2860,
436,
663,
1263,
892,
2202,
626,
4898,
288,
2013,
315,
314,
1101,
570,
14,
267,
408,
398,
327,
6601,
4887,
267,
291,
14,
9469,
275,
488,
267,
291,
14,
320,
10909,
63,
7532,
275,
488,
267,
291,
14,
26489,
275,
488,
398,
327,
2494,
4154,
536,
267,
291,
14,
354,
275,
536,
398,
327,
2494,
4154,
1591,
267,
340,
440,
291,
423,
362,
63,
1422,
8,
2028,
12,
536,
12,
298,
1102,
2349,
288,
2512,
14,
705,
480,
1944,
1591,
3384,
2741,
367,
450,
83,
2122,
5,
354,
9,
398,
327,
2494,
4154,
1844,
267,
340,
440,
291,
423,
362,
63,
1422,
8,
2028,
12,
536,
12,
298,
719,
2349,
288,
2512,
14,
705,
480,
1944,
1591,
1844,
2741,
367,
450,
83,
2122,
5,
354,
9,
398,
327,
4155,
652,
14905,
1380,
13618,
18772,
267,
291,
14,
1562,
275,
334,
277,
14,
1102,
12,
1109,
8,
277,
14,
719,
430,
2378,
347,
636,
495,
721,
277,
304,
267,
408,
9101,
734,
2556,
402,
642,
7614,
408,
2728,
312,
275,
26503,
83,
61,
3531,
26,
450,
83,
12,
10977,
26,
450,
83,
14007,
277,
14,
354,
12,
277,
14,
1102,
12,
277,
14,
719,
9,
2728,
372,
312,
339,
347,
664,
63,
26489,
8,
277,
304,
398,
408,
2372,
4113,
3335,
1015,
402,
3982,
20601,
408,
267,
1830,
413,
26,
288,
862,
26,
355,
2512,
14,
1757,
480,
28277,
6844,
769,
367,
16282,
3149,
83,
2,
450,
291,
14,
354,
9,
2234,
327,
2372,
1177,
355,
2088,
275,
491,
411,
5812,
3110,
8,
39,
14,
22584,
63,
9744,
63,
48,
13884,
906,
12,
1249,
6270,
26489,
3135,
355,
666,
275,
291,
14,
2254,
63,
1760,
8,
1760,
9,
355,
2004,
275,
598,
14,
739,
63,
3450,
63,
576,
8,
277,
14,
9469,
9,
14977,
327,
31017,
4154,
6844,
769,
8892,
327,
259,
334,
9171,
26,
961,
282,
10026,
402,
314,
2251,
737,
314,
1654,
355,
340,
666,
365,
440,
488,
26,
490,
291,
14,
26489,
275,
2165,
475,
11312,
14,
5301,
63,
6744,
63,
513,
8,
576,
9,
355,
587,
26,
490,
291,
14,
26489,
275,
942,
2234,
372,
2004,
288,
871,
26,
355,
598,
14,
1361,
63,
6894,
342,
355,
291,
14,
2242,
342,
2378,
347,
664,
63,
10466,
8,
277,
304,
267,
408,
2372,
4113,
3335,
1015,
402,
3982,
11284,
408,
267,
1830,
413,
26,
288,
862,
26,
355,
2512,
14,
1757,
480,
28277,
11284,
769,
367,
16282,
3149,
83,
2,
450,
291,
14,
354,
9,
2151,
355,
327,
2372,
9351,
355,
2088,
275,
491,
411,
5812,
3110,
8,
39,
14,
22584,
63,
9744,
63,
48,
13884,
906,
12,
1249,
6270,
10466,
3135,
355,
11284,
63,
1436,
275,
291,
14,
2254,
63,
1760,
8,
1760,
9,
355,
2004,
275,
598,
14,
739,
63,
3450,
63,
576,
8,
277,
14,
9469,
9,
2234,
327,
7787,
4113,
3335,
355,
291,
14,
10466,
275,
2165,
475,
11312,
14,
5301,
63,
10466,
63,
513,
8,
10466,
63,
1436,
9,
2234,
372,
2004,
288,
871,
26,
355,
291,
14,
2242,
342,
339,
347,
4907,
8,
277,
304,
267,
408,
288,
15175,
370,
4154,
7614,
12,
8044,
1006,
402,
314,
12082,
2556,
288,
436,
1050,
652,
370,
4154,
769,
14,
267,
408,
398,
1830,
413,
26,
288,
327,
7649,
28688,
370,
4907,
288,
862,
26,
355,
870,
598,
14,
66,
7120,
14,
9171,
435,
298,
32000,
370,
450,
83,
4042,
83,
2689,
83,
680,
703,
2,
450,
334,
277,
14,
354,
12,
291,
14,
1102,
12,
291,
14,
719,
9,
435,
598,
14,
66,
7120,
14,
3902,
35,
12,
355,
327,
3232,
4154,
2838,
355,
291,
14,
9469,
275,
2838,
14,
3450,
8,
3450,
14,
5699,
63,
11367,
12,
2838,
14,
9469,
63,
9484,
9,
2234,
291,
14,
9469,
14,
2242,
8,
277,
14,
1562,
9,
2234,
870,
598,
14,
66,
7120,
14,
3593,
22501,
435,
298,
16382,
2122,
435,
598,
14,
66,
7120,
14,
3902,
35,
2234,
2059,
288,
871,
2838,
14,
705,
26,
355,
870,
598,
14,
66,
7120,
14,
8784,
971,
490,
435,
298,
12989,
316,
315,
450,
68,
4696,
11500,
450,
334,
17462,
63,
27778,
9,
971,
490,
435,
598,
14,
66,
7120,
14,
3902,
35,
355,
9435,
8,
17462,
63,
27778,
9,
355,
1980,
339,
347,
17639,
8,
277,
304,
267,
408,
288,
8015,
1006,
11284,
737,
27325,
436,
4002,
4154,
2838,
14213,
590,
267,
408,
398,
327,
15524,
2838,
267,
291,
14,
9469,
14,
1600,
342,
2378,
347,
3222,
63,
10466,
8,
277,
12,
1788,
12,
2088,
304,
267,
408,
428,
3198,
1343,
1245,
436,
4154,
4840,
1101,
408,
267,
1830,
413,
26,
288,
862,
26,
355,
327,
10217,
4154,
1414,
370,
1343,
314,
11284,
355,
598,
14,
2254,
63,
3450,
63,
576,
8,
277,
14,
9469,
12,
620,
8,
1760,
430,
2234,
327,
1586,
4154,
11284,
570,
355,
289,
275,
1551,
8,
1501,
9,
355,
2884,
275,
289,
14,
739,
342,
355,
289,
14,
1600,
342,
2234,
327,
10217,
314,
2022,
1101,
355,
598,
14,
2254,
63,
3450,
63,
576,
8,
277,
14,
9469,
12,
2884,
9,
2234,
2004,
275,
598,
14,
739,
63,
3450,
63,
576,
8,
277,
14,
9469,
9,
14977,
372,
2004,
24850,
871,
26
] |
[
272,
8089,
367,
7252,
2897,
1584,
367,
7614,
3380,
339,
334,
67,
9,
6900,
603,
405,
1225,
29589,
1086,
1010,
25585,
402,
21580,
199,
624,
199,
3,
653,
1905,
199,
646,
2838,
199,
646,
2050,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
504,
900,
492,
9435,
421,
199,
3,
3412,
13,
9791,
41,
199,
646,
560,
10909,
14,
8473,
465,
598,
199,
3,
3412,
13,
9791,
41,
9195,
1615,
199,
646,
560,
10909,
63,
23867,
14,
7204,
14,
3676,
465,
2165,
475,
11312,
199,
504,
560,
10909,
63,
23867,
14,
7532,
492,
491,
411,
5812,
2028,
199,
504,
560,
10909,
63,
23867,
14,
1200,
14,
1531,
492,
491,
411,
5812,
3110,
199,
199,
17462,
63,
27778,
275,
959,
199,
199,
533,
16282,
2028,
8,
44,
411,
5812,
2028,
304,
272,
408,
267,
812,
994,
3486,
1021,
370,
4926,
6818,
436,
10137,
14726,
367,
19053,
434,
315,
314,
4960,
6466,
272,
408,
339,
347,
636,
826,
721,
277,
12,
536,
12,
4094,
304,
267,
408,
288,
11578,
1006,
402,
4154,
2860,
436,
663,
1263,
892,
2202,
626,
4898,
288,
2013,
315,
314,
1101,
570,
14,
267,
408,
398,
327,
6601,
4887,
267,
291,
14,
9469,
275,
488,
267,
291,
14,
320,
10909,
63,
7532,
275,
488,
267,
291,
14,
26489,
275,
488,
398,
327,
2494,
4154,
536,
267,
291,
14,
354,
275,
536,
398,
327,
2494,
4154,
1591,
267,
340,
440,
291,
423,
362,
63,
1422,
8,
2028,
12,
536,
12,
298,
1102,
2349,
288,
2512,
14,
705,
480,
1944,
1591,
3384,
2741,
367,
450,
83,
2122,
5,
354,
9,
398,
327,
2494,
4154,
1844,
267,
340,
440,
291,
423,
362,
63,
1422,
8,
2028,
12,
536,
12,
298,
719,
2349,
288,
2512,
14,
705,
480,
1944,
1591,
1844,
2741,
367,
450,
83,
2122,
5,
354,
9,
398,
327,
4155,
652,
14905,
1380,
13618,
18772,
267,
291,
14,
1562,
275,
334,
277,
14,
1102,
12,
1109,
8,
277,
14,
719,
430,
2378,
347,
636,
495,
721,
277,
304,
267,
408,
9101,
734,
2556,
402,
642,
7614,
408,
2728,
312,
275,
26503,
83,
61,
3531,
26,
450,
83,
12,
10977,
26,
450,
83,
14007,
277,
14,
354,
12,
277,
14,
1102,
12,
277,
14,
719,
9,
2728,
372,
312,
339,
347,
664,
63,
26489,
8,
277,
304,
398,
408,
2372,
4113,
3335,
1015,
402,
3982,
20601,
408,
267,
1830,
413,
26,
288,
862,
26,
355,
2512,
14,
1757,
480,
28277,
6844,
769,
367,
16282,
3149,
83,
2,
450,
291,
14,
354,
9,
2234,
327,
2372,
1177,
355,
2088,
275,
491,
411,
5812,
3110,
8,
39,
14,
22584,
63,
9744,
63,
48,
13884,
906,
12,
1249,
6270,
26489,
3135,
355,
666,
275,
291,
14,
2254,
63,
1760,
8,
1760,
9,
355,
2004,
275,
598,
14,
739,
63,
3450,
63,
576,
8,
277,
14,
9469,
9,
14977,
327,
31017,
4154,
6844,
769,
8892,
327,
259,
334,
9171,
26,
961,
282,
10026,
402,
314,
2251,
737,
314,
1654,
355,
340,
666,
365,
440,
488,
26,
490,
291,
14,
26489,
275,
2165,
475,
11312,
14,
5301,
63,
6744,
63,
513,
8,
576,
9,
355,
587,
26,
490,
291,
14,
26489,
275,
942,
2234,
372,
2004,
288,
871,
26,
355,
598,
14,
1361,
63,
6894,
342,
355,
291,
14,
2242,
342,
2378,
347,
664,
63,
10466,
8,
277,
304,
267,
408,
2372,
4113,
3335,
1015,
402,
3982,
11284,
408,
267,
1830,
413,
26,
288,
862,
26,
355,
2512,
14,
1757,
480,
28277,
11284,
769,
367,
16282,
3149,
83,
2,
450,
291,
14,
354,
9,
2151,
355,
327,
2372,
9351,
355,
2088,
275,
491,
411,
5812,
3110,
8,
39,
14,
22584,
63,
9744,
63,
48,
13884,
906,
12,
1249,
6270,
10466,
3135,
355,
11284,
63,
1436,
275,
291,
14,
2254,
63,
1760,
8,
1760,
9,
355,
2004,
275,
598,
14,
739,
63,
3450,
63,
576,
8,
277,
14,
9469,
9,
2234,
327,
7787,
4113,
3335,
355,
291,
14,
10466,
275,
2165,
475,
11312,
14,
5301,
63,
10466,
63,
513,
8,
10466,
63,
1436,
9,
2234,
372,
2004,
288,
871,
26,
355,
291,
14,
2242,
342,
339,
347,
4907,
8,
277,
304,
267,
408,
288,
15175,
370,
4154,
7614,
12,
8044,
1006,
402,
314,
12082,
2556,
288,
436,
1050,
652,
370,
4154,
769,
14,
267,
408,
398,
1830,
413,
26,
288,
327,
7649,
28688,
370,
4907,
288,
862,
26,
355,
870,
598,
14,
66,
7120,
14,
9171,
435,
298,
32000,
370,
450,
83,
4042,
83,
2689,
83,
680,
703,
2,
450,
334,
277,
14,
354,
12,
291,
14,
1102,
12,
291,
14,
719,
9,
435,
598,
14,
66,
7120,
14,
3902,
35,
12,
355,
327,
3232,
4154,
2838,
355,
291,
14,
9469,
275,
2838,
14,
3450,
8,
3450,
14,
5699,
63,
11367,
12,
2838,
14,
9469,
63,
9484,
9,
2234,
291,
14,
9469,
14,
2242,
8,
277,
14,
1562,
9,
2234,
870,
598,
14,
66,
7120,
14,
3593,
22501,
435,
298,
16382,
2122,
435,
598,
14,
66,
7120,
14,
3902,
35,
2234,
2059,
288,
871,
2838,
14,
705,
26,
355,
870,
598,
14,
66,
7120,
14,
8784,
971,
490,
435,
298,
12989,
316,
315,
450,
68,
4696,
11500,
450,
334,
17462,
63,
27778,
9,
971,
490,
435,
598,
14,
66,
7120,
14,
3902,
35,
355,
9435,
8,
17462,
63,
27778,
9,
355,
1980,
339,
347,
17639,
8,
277,
304,
267,
408,
288,
8015,
1006,
11284,
737,
27325,
436,
4002,
4154,
2838,
14213,
590,
267,
408,
398,
327,
15524,
2838,
267,
291,
14,
9469,
14,
1600,
342,
2378,
347,
3222,
63,
10466,
8,
277,
12,
1788,
12,
2088,
304,
267,
408,
428,
3198,
1343,
1245,
436,
4154,
4840,
1101,
408,
267,
1830,
413,
26,
288,
862,
26,
355,
327,
10217,
4154,
1414,
370,
1343,
314,
11284,
355,
598,
14,
2254,
63,
3450,
63,
576,
8,
277,
14,
9469,
12,
620,
8,
1760,
430,
2234,
327,
1586,
4154,
11284,
570,
355,
289,
275,
1551,
8,
1501,
9,
355,
2884,
275,
289,
14,
739,
342,
355,
289,
14,
1600,
342,
2234,
327,
10217,
314,
2022,
1101,
355,
598,
14,
2254,
63,
3450,
63,
576,
8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